Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve query library performance by using vector iteration #3659

Merged
merged 25 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3a01ec1
Updated Logic.
chipkent Apr 4, 2023
3c11027
Port most of Basic.
chipkent Apr 4, 2023
d5c30e8
Code cleanup.
chipkent Apr 4, 2023
0aa4228
Finish implementing Basic.
chipkent Apr 4, 2023
73da864
Finish implementing Basic and Cast.
chipkent Apr 4, 2023
5972e3b
Finish implementing Numeric.
chipkent Apr 4, 2023
38dbc0e
Make variables final.
chipkent Apr 4, 2023
7aa83de
Use isEmpty where possible.
chipkent Apr 4, 2023
3616b99
Addressing review comments.
chipkent Apr 4, 2023
03d1b32
Addressing review comments.
chipkent Apr 4, 2023
cef4044
Addressing review comments.
chipkent Apr 5, 2023
88f8965
Addressing review comments.
chipkent Apr 5, 2023
cb6b795
Avoid boxing.
chipkent Apr 5, 2023
aeaa1c5
Perf improvement for replaceIfNull
chipkent Apr 5, 2023
70720a6
Spotless fixes
chipkent Apr 5, 2023
c464494
Addressing review comments.
chipkent Apr 5, 2023
737d598
Addressing review comments.
chipkent Apr 5, 2023
7d6bb08
Addressing review comments.
chipkent Apr 5, 2023
a8d344c
Addressing review comments.
chipkent Apr 5, 2023
a4869ae
Revert "Addressing review comments."
chipkent Apr 5, 2023
1a03ee9
Address ambiguity of Vector.toArray() regarding mutation safety with …
rcaudy Apr 5, 2023
369f02b
Address incorrect targetExclude in Base/build.gradle, and commit ring…
rcaudy Apr 5, 2023
8bb02af
Use Vector.copyToArray() where appropriate in function libraries, and…
rcaudy Apr 5, 2023
647cc73
Remove PrimitiveType and ValueType for Boolean, and associate special…
rcaudy Apr 5, 2023
3b397f3
Merge pull request #4 from rcaudy/rwc-vectorarraysafety
chipkent Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class PrimitiveType {
private final String boxed;
private final String vector;
private final String vectorDirect;
private final String vectorIterator;
private final String iteratorNext;
private final String nullValue;
private final String maxValue;
private final String minValue;
Expand All @@ -26,17 +28,22 @@ public class PrimitiveType {
* @param boxed name of the boxed primitive
* @param vector name of the Vector interface
* @param vectorDirect name of the concrete Vector wrapper
* @param vectorIterator name of the Vector iterator
* @param iteratorNext name of the next method on the Vector iterator
* @param nullValue null value
* @param maxValue maximum value
* @param minValue minimum value
* @param valueType type of value
*/
public PrimitiveType(final String primitive, final String boxed, final String vector, final String vectorDirect,
final String vectorIterator, final String iteratorNext,
final String nullValue, final String maxValue, final String minValue, final ValueType valueType) {
this.primitive = primitive;
this.boxed = boxed;
this.vector = vector;
this.vectorDirect = vectorDirect;
this.vectorIterator = vectorIterator;
this.iteratorNext = iteratorNext;
this.nullValue = nullValue;
this.maxValue = maxValue;
this.minValue = minValue;
Expand Down Expand Up @@ -79,6 +86,24 @@ public String getVectorDirect() {
return vectorDirect;
}

/**
* Gets the Vector iterator of the primitive.
*
* @return Vector iterator of the primitive.
*/
public String getVectorIterator() {
return vectorIterator;
}

/**
* Gets the next method on the Vector iterator of the primitive.
*
* @return next method on the Vector iterator of the primitive.
*/
public String getIteratorNext() {
return iteratorNext;
}

/**
* Gets the null value of the primitive.
*
Expand Down Expand Up @@ -134,34 +159,42 @@ public static PrimitiveType[] primitiveTypes() {
return new PrimitiveType[] {
new PrimitiveType("Boolean", "Boolean",
"ObjectVector", "ObjectVectorDirect",
"CloseableIterator", "next",
"NULL_BOOLEAN", null, null,
ValueType.BOOLEAN),
new PrimitiveType("char", "Character",
"CharVector", "CharVectorDirect",
"CloseablePrimitiveIteratorOfChar", "nextChar",
"NULL_CHAR", null, null,
ValueType.CHARACTER),
new PrimitiveType("byte", "Byte",
"ByteVector", "ByteVectorDirect",
"CloseablePrimitiveIteratorOfByte", "nextByte",
"NULL_BYTE", "MAX_BYTE", "MIN_BYTE",
ValueType.INTEGER),
new PrimitiveType("short", "Short",
"ShortVector", "ShortVectorDirect",
"CloseablePrimitiveIteratorOfShort", "nextShort",
"NULL_SHORT", "MAX_SHORT", "MIN_SHORT",
ValueType.INTEGER),
new PrimitiveType("int", "Integer",
"IntVector", "IntVectorDirect",
"CloseablePrimitiveIteratorOfInt", "nextInt",
"NULL_INT", "MAX_INT", "MIN_INT",
ValueType.INTEGER),
new PrimitiveType("long", "Long",
"LongVector", "LongVectorDirect",
"CloseablePrimitiveIteratorOfLong", "nextLong",
"NULL_LONG", "MAX_LONG", "MIN_LONG",
ValueType.INTEGER),
new PrimitiveType("float", "Float",
"FloatVector", "FloatVectorDirect",
"CloseablePrimitiveIteratorOfFloat", "nextFloat",
"NULL_FLOAT", "MAX_FLOAT", "MIN_FLOAT",
ValueType.FLOATING_POINT),
new PrimitiveType("double", "Double",
"DoubleVector", "DoubleVectorDirect",
"CloseablePrimitiveIteratorOfDouble", "nextDouble",
"NULL_DOUBLE", "MAX_DOUBLE", "MIN_DOUBLE",
ValueType.FLOATING_POINT),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ public void testPrimitiveType() {
final PrimitiveType pt = new PrimitiveType(
"primitive", "boxed",
"VectorDEBUG", "DirectDEBUG",
"IteratorDEBUG", "IteratorNextDEBUG",
"NULLDEBUG", "POSINFDEBUG", "NEGINFDEBUG",
ValueType.CHARACTER);

assertEquals("primitive", pt.getPrimitive());
assertEquals("boxed", pt.getBoxed());
assertEquals("VectorDEBUG", pt.getVector());
assertEquals("DirectDEBUG", pt.getVectorDirect());
assertEquals("IteratorDEBUG", pt.getVectorIterator());
assertEquals("IteratorNextDEBUG", pt.getIteratorNext());
assertEquals("NULLDEBUG", pt.getNull());
assertEquals("POSINFDEBUG", pt.getMaxValue());
assertEquals("NEGINFDEBUG", pt.getMinValue());
Expand Down
1 change: 1 addition & 0 deletions engine/function/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
api 'net.sf.trove4j:trove4j:3.0.3'
api project(':Util')
api project(':engine-vector')
api project(':engine-primitive')

implementation project(':Base')
implementation depCommonsLang3
Expand Down
25 changes: 15 additions & 10 deletions engine/function/src/main/java/io/deephaven/function/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package io.deephaven.function;

import io.deephaven.vector.ObjectVector;
import io.deephaven.engine.primitive.iterator.*;

/**
* Logic functions.
Expand Down Expand Up @@ -49,10 +50,12 @@ static public Boolean and(boolean... values) {
* @return logical and of all the values in the array. By convention, returns true if the array is empty.
*/
static public Boolean and(ObjectVector<Boolean> values) {
for (int ii = 0; ii < values.size(); ++ii) {
Boolean b = values.get(ii);
if (!b) {
return false;
try (final CloseableIterator<Boolean> vi = values.iterator()) {
while (vi.hasNext()) {
final Boolean b = vi.next();
if (!b) {
return false;
}
}
}

Expand Down Expand Up @@ -86,12 +89,14 @@ static public Boolean and(Boolean[] values, Boolean nullValue) {
* @return logical and of all the values in the array. By convention, returns true if the array is empty.
*/
static public Boolean and(ObjectVector<Boolean> values, Boolean nullValue) {
for (int ii = 0; ii < values.size(); ++ii) {
Boolean b = values.get(ii);
b = b == null ? nullValue : b;

if (!b) {
return false;
try (final CloseableIterator<Boolean> vi = values.iterator()) {
while (vi.hasNext()) {
final Boolean b = vi.next();
final Boolean b2 = b == null ? nullValue : b;

if (!b2) {
return false;
}
}
}

Expand Down
Loading