diff --git a/java/gandiva/pom.xml b/java/gandiva/pom.xml index 1c17023e5c8a..d8ecf10e6d54 100644 --- a/java/gandiva/pom.xml +++ b/java/gandiva/pom.xml @@ -25,6 +25,8 @@ true + dev/checkstyle/checkstyle-spotless.xml + none ../../../cpp/release-build diff --git a/java/gandiva/src/main/java/module-info.java b/java/gandiva/src/main/java/module-info.java index 533717d91f7f..5bce445707a3 100644 --- a/java/gandiva/src/main/java/module-info.java +++ b/java/gandiva/src/main/java/module-info.java @@ -26,4 +26,4 @@ requires org.apache.arrow.vector; requires org.slf4j; requires protobuf.java; -} \ No newline at end of file +} diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ConfigurationBuilder.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ConfigurationBuilder.java index fa5d285b9099..70c181e8ee0b 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ConfigurationBuilder.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ConfigurationBuilder.java @@ -14,14 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import java.util.Objects; -/** - * Used to construct gandiva configuration objects. - */ +/** Used to construct gandiva configuration objects. */ public class ConfigurationBuilder { public long buildConfigInstance(ConfigOptions configOptions) { @@ -32,9 +29,7 @@ public long buildConfigInstance(ConfigOptions configOptions) { public native void releaseConfigInstance(long configId); - /** - * ConfigOptions contains the configuration parameters to provide to gandiva. - */ + /** ConfigOptions contains the configuration parameters to provide to gandiva. */ public static class ConfigOptions { private boolean optimize = true; private boolean targetCPU = true; @@ -43,8 +38,7 @@ public static ConfigOptions getDefault() { return new ConfigOptions(); } - public ConfigOptions() { - } + public ConfigOptions() {} public ConfigOptions withOptimize(boolean optimize) { this.optimize = optimize; @@ -66,8 +60,8 @@ public boolean equals(Object obj) { if (!(obj instanceof ConfigOptions)) { return false; } - return this.optimize == ((ConfigOptions) obj).optimize && - this.targetCPU == ((ConfigOptions) obj).targetCPU; + return this.optimize == ((ConfigOptions) obj).optimize + && this.targetCPU == ((ConfigOptions) obj).targetCPU; } } } diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/DecimalTypeUtil.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/DecimalTypeUtil.java index 703cfaa8be88..13c86285c0aa 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/DecimalTypeUtil.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/DecimalTypeUtil.java @@ -14,21 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import org.apache.arrow.vector.types.pojo.ArrowType.Decimal; -/** - * Utility methods for working with {@link Decimal} values. - */ +/** Utility methods for working with {@link Decimal} values. */ public class DecimalTypeUtil { - private DecimalTypeUtil() { - } + private DecimalTypeUtil() {} - /** - * Enum for supported mathematical operations. - */ + /** Enum for supported mathematical operations. */ public enum OperationType { ADD, SUBTRACT, @@ -41,11 +35,9 @@ public enum OperationType { /// The maximum precision representable by a 16-byte decimal private static final int MAX_PRECISION = 38; - /** - * Determines the scale and precision of applying the given operation to the operands. - */ - public static Decimal getResultTypeForOperation(OperationType operation, Decimal operand1, Decimal - operand2) { + /** Determines the scale and precision of applying the given operation to the operands. */ + public static Decimal getResultTypeForOperation( + OperationType operation, Decimal operand1, Decimal operand2) { int s1 = operand1.getScale(); int s2 = operand2.getScale(); int p1 = operand1.getPrecision(); @@ -56,8 +48,12 @@ public static Decimal getResultTypeForOperation(OperationType operation, Decimal case ADD: case SUBTRACT: resultScale = Math.max(operand1.getScale(), operand2.getScale()); - resultPrecision = resultScale + Math.max(operand1.getPrecision() - operand1.getScale(), - operand2.getPrecision() - operand2.getScale()) + 1; + resultPrecision = + resultScale + + Math.max( + operand1.getPrecision() - operand1.getScale(), + operand2.getPrecision() - operand2.getScale()) + + 1; break; case MULTIPLY: resultScale = s1 + s2; @@ -65,15 +61,17 @@ public static Decimal getResultTypeForOperation(OperationType operation, Decimal break; case DIVIDE: resultScale = - Math.max(MIN_ADJUSTED_SCALE, operand1.getScale() + operand2.getPrecision() + 1); + Math.max(MIN_ADJUSTED_SCALE, operand1.getScale() + operand2.getPrecision() + 1); resultPrecision = - operand1.getPrecision() - operand1.getScale() + operand2.getScale() + resultScale; + operand1.getPrecision() - operand1.getScale() + operand2.getScale() + resultScale; break; case MOD: resultScale = Math.max(operand1.getScale(), operand2.getScale()); - resultPrecision = Math.min(operand1.getPrecision() - operand1.getScale(), - operand2.getPrecision() - operand2.getScale()) + - resultScale; + resultPrecision = + Math.min( + operand1.getPrecision() - operand1.getScale(), + operand2.getPrecision() - operand2.getScale()) + + resultScale; break; default: throw new RuntimeException("Needs support"); @@ -90,6 +88,4 @@ private static Decimal adjustScaleIfNeeded(int precision, int scale) { } return new Decimal(precision, scale, 128); } - } - diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistry.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistry.java index 0155af08234a..49625edf27a5 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistry.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistry.java @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import com.google.protobuf.InvalidProtocolBufferException; import java.util.List; import java.util.Set; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; import org.apache.arrow.gandiva.ipc.GandivaTypes.ExtGandivaType; @@ -32,14 +33,8 @@ import org.apache.arrow.vector.types.TimeUnit; import org.apache.arrow.vector.types.pojo.ArrowType; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.google.protobuf.InvalidProtocolBufferException; - /** - * Used to get the functions and data types supported by - * Gandiva. - * All types are in Arrow namespace. + * Used to get the functions and data types supported by Gandiva. All types are in Arrow namespace. */ public class ExpressionRegistry { @@ -55,14 +50,15 @@ public class ExpressionRegistry { private static volatile ExpressionRegistry INSTANCE; - private ExpressionRegistry(Set supportedTypes, - Set functionSignatures) { + private ExpressionRegistry( + Set supportedTypes, Set functionSignatures) { this.supportedTypes = supportedTypes; this.functionSignatures = functionSignatures; } /** * Returns a singleton instance of the class. + * * @return singleton instance * @throws GandivaException if error in Gandiva Library integration. */ @@ -92,8 +88,8 @@ public Set getSupportedTypes() { private static Set getSupportedTypesFromGandiva() throws GandivaException { Set supportedTypes = Sets.newHashSet(); try { - byte[] gandivaSupportedDataTypes = new ExpressionRegistryJniHelper() - .getGandivaSupportedDataTypes(); + byte[] gandivaSupportedDataTypes = + new ExpressionRegistryJniHelper().getGandivaSupportedDataTypes(); GandivaDataTypes gandivaDataTypes = GandivaDataTypes.parseFrom(gandivaSupportedDataTypes); for (ExtGandivaType type : gandivaDataTypes.getDataTypeList()) { supportedTypes.add(getArrowType(type)); @@ -104,15 +100,14 @@ private static Set getSupportedTypesFromGandiva() throws GandivaExcep return supportedTypes; } - private static Set getSupportedFunctionsFromGandiva() throws - GandivaException { + private static Set getSupportedFunctionsFromGandiva() throws GandivaException { Set supportedTypes = Sets.newHashSet(); try { - byte[] gandivaSupportedFunctions = new ExpressionRegistryJniHelper() - .getGandivaSupportedFunctions(); + byte[] gandivaSupportedFunctions = + new ExpressionRegistryJniHelper().getGandivaSupportedFunctions(); GandivaFunctions gandivaFunctions = GandivaFunctions.parseFrom(gandivaSupportedFunctions); - for (GandivaTypes.FunctionSignature protoFunctionSignature - : gandivaFunctions.getFunctionList()) { + for (GandivaTypes.FunctionSignature protoFunctionSignature : + gandivaFunctions.getFunctionList()) { String functionName = protoFunctionSignature.getName(); ArrowType returnType = getArrowType(protoFunctionSignature.getReturnType()); @@ -120,8 +115,8 @@ private static Set getSupportedFunctionsFromGandiva() throws for (ExtGandivaType type : protoFunctionSignature.getParamTypesList()) { paramTypes.add(getArrowType(type)); } - FunctionSignature functionSignature = new FunctionSignature(functionName, - returnType, paramTypes); + FunctionSignature functionSignature = + new FunctionSignature(functionName, returnType, paramTypes); supportedTypes.add(functionSignature); } } catch (InvalidProtocolBufferException invalidProtException) { @@ -167,11 +162,9 @@ private static ArrowType getArrowType(ExtGandivaType type) { case GandivaType.TIMESTAMP_VALUE: return new ArrowType.Timestamp(mapArrowTimeUnit(type.getTimeUnit()), null); case GandivaType.TIME32_VALUE: - return new ArrowType.Time(mapArrowTimeUnit(type.getTimeUnit()), - BIT_WIDTH_32); + return new ArrowType.Time(mapArrowTimeUnit(type.getTimeUnit()), BIT_WIDTH_32); case GandivaType.TIME64_VALUE: - return new ArrowType.Time(mapArrowTimeUnit(type.getTimeUnit()), - BIT_WIDTH_64); + return new ArrowType.Time(mapArrowTimeUnit(type.getTimeUnit()), BIT_WIDTH_64); case GandivaType.NONE_VALUE: return new ArrowType.Null(); case GandivaType.DECIMAL_VALUE: @@ -215,6 +208,4 @@ private static IntervalUnit mapArrowIntervalUnit(GandivaTypes.IntervalType inter return null; } } - } - diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistryJniHelper.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistryJniHelper.java index 86c1eaaedac8..6c0ee1f2751a 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistryJniHelper.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistryJniHelper.java @@ -14,13 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; -/** - * JNI Adapter used to get supported types and functions - * from Gandiva. - */ +/** JNI Adapter used to get supported types and functions from Gandiva. */ class ExpressionRegistryJniHelper { native byte[] getGandivaSupportedDataTypes(); diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/Filter.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/Filter.java index 010d644d107a..f584564e0920 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/Filter.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/Filter.java @@ -14,12 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import java.util.ArrayList; import java.util.List; - import org.apache.arrow.gandiva.exceptions.EvaluatorClosedException; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.expression.ArrowTypeHelper; @@ -59,7 +57,7 @@ private Filter(JniWrapper wrapper, long moduleId, Schema schema) { * Filter::Evaluate() against a RecordBatch to evaluate the filter on this record batch * * @param schema Table schema. The field names in the schema should match the fields used to - * create the TreeNodes + * create the TreeNodes * @param condition condition to be evaluated against data * @return A native filter object that can be used to invoke on a RecordBatch */ @@ -72,13 +70,14 @@ public static Filter make(Schema schema, Condition condition) throws GandivaExce * Filter::Evaluate() against a RecordBatch to evaluate the filter on this record batch * * @param schema Table schema. The field names in the schema should match the fields used to - * create the TreeNodes + * create the TreeNodes * @param condition condition to be evaluated against data * @param configOptions ConfigOptions parameter * @return A native filter object that can be used to invoke on a RecordBatch */ - public static Filter make(Schema schema, Condition condition, ConfigurationBuilder.ConfigOptions configOptions) - throws GandivaException { + public static Filter make( + Schema schema, Condition condition, ConfigurationBuilder.ConfigOptions configOptions) + throws GandivaException { return make(schema, condition, JniLoader.getConfiguration(configOptions)); } @@ -87,15 +86,19 @@ public static Filter make(Schema schema, Condition condition, ConfigurationBuild * Filter::Evaluate() against a RecordBatch to evaluate the filter on this record batch * * @param schema Table schema. The field names in the schema should match the fields used to - * create the TreeNodes + * create the TreeNodes * @param condition condition to be evaluated against data * @param optimize Flag to choose if the generated llvm code is to be optimized * @return A native filter object that can be used to invoke on a RecordBatch */ @Deprecated - public static Filter make(Schema schema, Condition condition, boolean optimize) throws GandivaException { - return make(schema, condition, JniLoader.getConfiguration((new ConfigurationBuilder.ConfigOptions()) - .withOptimize(optimize))); + public static Filter make(Schema schema, Condition condition, boolean optimize) + throws GandivaException { + return make( + schema, + condition, + JniLoader.getConfiguration( + (new ConfigurationBuilder.ConfigOptions()).withOptimize(optimize))); } /** @@ -103,7 +106,7 @@ public static Filter make(Schema schema, Condition condition, boolean optimize) * Filter::Evaluate() against a RecordBatch to evaluate the filter on this record batch * * @param schema Table schema. The field names in the schema should match the fields used to - * create the TreeNodes + * create the TreeNodes * @param condition condition to be evaluated against data * @param configurationId Custom configuration created through config builder. * @return A native evaluator object that can be used to invoke these projections on a RecordBatch @@ -114,8 +117,8 @@ public static Filter make(Schema schema, Condition condition, long configuration GandivaTypes.Condition conditionBuf = condition.toProtobuf(); GandivaTypes.Schema schemaBuf = ArrowTypeHelper.arrowSchemaToProtobuf(schema); JniWrapper wrapper = JniLoader.getInstance().getWrapper(); - long moduleId = wrapper.buildFilter(schemaBuf.toByteArray(), - conditionBuf.toByteArray(), configurationId); + long moduleId = + wrapper.buildFilter(schemaBuf.toByteArray(), conditionBuf.toByteArray(), configurationId); logger.debug("Created module for the filter with id {}", moduleId); return new Filter(wrapper, moduleId, schema); } @@ -128,7 +131,10 @@ public static Filter make(Schema schema, Condition condition, long configuration */ public void evaluate(ArrowRecordBatch recordBatch, SelectionVector selectionVector) throws GandivaException { - evaluate(recordBatch.getLength(), recordBatch.getBuffers(), recordBatch.getBuffersLayout(), + evaluate( + recordBatch.getLength(), + recordBatch.getBuffers(), + recordBatch.getBuffersLayout(), selectionVector); } @@ -140,8 +146,8 @@ public void evaluate(ArrowRecordBatch recordBatch, SelectionVector selectionVect * @param buffers List of input arrow buffers * @param selectionVector Result of applying the filter on the data */ - public void evaluate(int numRows, List buffers, - SelectionVector selectionVector) throws GandivaException { + public void evaluate(int numRows, List buffers, SelectionVector selectionVector) + throws GandivaException { List buffersLayout = new ArrayList<>(); long offset = 0; for (ArrowBuf arrowBuf : buffers) { @@ -152,14 +158,21 @@ public void evaluate(int numRows, List buffers, evaluate(numRows, buffers, buffersLayout, selectionVector); } - private void evaluate(int numRows, List buffers, List buffersLayout, - SelectionVector selectionVector) throws GandivaException { + private void evaluate( + int numRows, + List buffers, + List buffersLayout, + SelectionVector selectionVector) + throws GandivaException { if (this.closed) { throw new EvaluatorClosedException(); } if (selectionVector.getMaxRecords() < numRows) { - logger.error("selectionVector has capacity for " + selectionVector.getMaxRecords() + - " rows, minimum required " + numRows); + logger.error( + "selectionVector has capacity for " + + selectionVector.getMaxRecords() + + " rows, minimum required " + + numRows); throw new GandivaException("SelectionVector too small"); } @@ -176,18 +189,21 @@ private void evaluate(int numRows, List buffers, List buf bufSizes[idx++] = bufLayout.getSize(); } - int numRecords = wrapper.evaluateFilter(this.moduleId, numRows, - bufAddrs, bufSizes, - selectionVector.getType().getNumber(), - selectionVector.getBuffer().memoryAddress(), selectionVector.getBuffer().capacity()); + int numRecords = + wrapper.evaluateFilter( + this.moduleId, + numRows, + bufAddrs, + bufSizes, + selectionVector.getType().getNumber(), + selectionVector.getBuffer().memoryAddress(), + selectionVector.getBuffer().capacity()); if (numRecords >= 0) { selectionVector.setRecordCount(numRecords); } } - /** - * Closes the LLVM module representing this filter. - */ + /** Closes the LLVM module representing this filter. */ public void close() throws GandivaException { if (this.closed) { return; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/FunctionSignature.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/FunctionSignature.java index d01881843de4..164b6aaac668 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/FunctionSignature.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/FunctionSignature.java @@ -14,19 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; -import java.util.List; - -import org.apache.arrow.vector.types.pojo.ArrowType; - import com.google.common.base.MoreObjects; import com.google.common.base.Objects; +import java.util.List; +import org.apache.arrow.vector.types.pojo.ArrowType; -/** - * POJO to define a function signature. - */ +/** POJO to define a function signature. */ public class FunctionSignature { private final String name; private final ArrowType returnType; @@ -46,6 +41,7 @@ public String getName() { /** * Ctor. + * * @param name - name of the function. * @param returnType - data type of return * @param paramTypes - data type of input args. @@ -58,6 +54,7 @@ public FunctionSignature(String name, ArrowType returnType, List para /** * Override equals. + * * @param signature - signature to compare * @return true if equal and false if not. */ @@ -69,9 +66,9 @@ public boolean equals(Object signature) { return false; } final FunctionSignature other = (FunctionSignature) signature; - return this.name.equalsIgnoreCase(other.name) && - Objects.equal(this.returnType, other.returnType) && - Objects.equal(this.paramTypes, other.paramTypes); + return this.name.equalsIgnoreCase(other.name) + && Objects.equal(this.returnType, other.returnType) + && Objects.equal(this.paramTypes, other.paramTypes); } @Override @@ -82,12 +79,9 @@ public int hashCode() { @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("name ", name) - .add("return type ", returnType) - .add("param types ", paramTypes) - .toString(); - + .add("name ", name) + .add("return type ", returnType) + .add("param types ", paramTypes) + .toString(); } - - } diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/JniLoader.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/JniLoader.java index 57748e9c8e1a..6f4cdc58c5a9 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/JniLoader.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/JniLoader.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import static java.util.UUID.randomUUID; @@ -27,19 +26,16 @@ import java.util.Locale; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; - import org.apache.arrow.gandiva.exceptions.GandivaException; -/** - * This class handles loading of the jni library, and acts as a bridge for the native functions. - */ +/** This class handles loading of the jni library, and acts as a bridge for the native functions. */ class JniLoader { private static final String LIBRARY_NAME = "gandiva_jni"; private static volatile JniLoader INSTANCE; private static volatile long defaultConfiguration = 0L; - private static final ConcurrentMap configurationMap - = new ConcurrentHashMap<>(); + private static final ConcurrentMap configurationMap = + new ConcurrentHashMap<>(); private final JniWrapper wrapper; @@ -69,7 +65,7 @@ private static JniLoader setupInstance() throws GandivaException { } private static void loadGandivaLibraryFromJar(final String tmpDir) - throws IOException, GandivaException { + throws IOException, GandivaException { final String libraryToLoad = LIBRARY_NAME + "/" + getNormalizedArch() + "/" + System.mapLibraryName(LIBRARY_NAME); final File libraryFile = moveFileFromJarToTemp(tmpDir, libraryToLoad, LIBRARY_NAME); @@ -91,11 +87,12 @@ private static String getNormalizedArch() { return arch; } - private static File moveFileFromJarToTemp(final String tmpDir, String libraryToLoad, String libraryName) - throws IOException, GandivaException { + private static File moveFileFromJarToTemp( + final String tmpDir, String libraryToLoad, String libraryName) + throws IOException, GandivaException { final File temp = setupFile(tmpDir, libraryName); - try (final InputStream is = JniLoader.class.getClassLoader() - .getResourceAsStream(libraryToLoad)) { + try (final InputStream is = + JniLoader.class.getClassLoader().getResourceAsStream(libraryToLoad)) { if (is == null) { throw new GandivaException(libraryToLoad + " was not found inside JAR."); } else { @@ -106,37 +103,34 @@ private static File moveFileFromJarToTemp(final String tmpDir, String libraryToL } private static File setupFile(String tmpDir, String libraryToLoad) - throws IOException, GandivaException { + throws IOException, GandivaException { // accommodate multiple processes running with gandiva jar. // length should be ok since uuid is only 36 characters. final String randomizeFileName = libraryToLoad + randomUUID(); final File temp = new File(tmpDir, randomizeFileName); if (temp.exists() && !temp.delete()) { - throw new GandivaException("File: " + temp.getAbsolutePath() + - " already exists and cannot be removed."); + throw new GandivaException( + "File: " + temp.getAbsolutePath() + " already exists and cannot be removed."); } if (!temp.createNewFile()) { - throw new GandivaException("File: " + temp.getAbsolutePath() + - " could not be created."); + throw new GandivaException("File: " + temp.getAbsolutePath() + " could not be created."); } temp.deleteOnExit(); return temp; } - /** - * Returns the jni wrapper. - */ + /** Returns the jni wrapper. */ JniWrapper getWrapper() throws GandivaException { return wrapper; } - static long getConfiguration(ConfigurationBuilder.ConfigOptions configOptions) throws GandivaException { + static long getConfiguration(ConfigurationBuilder.ConfigOptions configOptions) + throws GandivaException { if (!configurationMap.containsKey(configOptions)) { synchronized (ConfigurationBuilder.class) { if (!configurationMap.containsKey(configOptions)) { JniLoader.getInstance(); // setup - long configInstance = new ConfigurationBuilder() - .buildConfigInstance(configOptions); + long configInstance = new ConfigurationBuilder().buildConfigInstance(configOptions); configurationMap.put(configOptions, configInstance); if (ConfigurationBuilder.ConfigOptions.getDefault().equals(configOptions)) { defaultConfiguration = configInstance; @@ -150,6 +144,7 @@ static long getConfiguration(ConfigurationBuilder.ConfigOptions configOptions) t /** * Get the default configuration to invoke gandiva. + * * @return default configuration * @throws GandivaException if unable to get native builder instance. */ @@ -158,9 +153,10 @@ static long getDefaultConfiguration() throws GandivaException { synchronized (ConfigurationBuilder.class) { if (defaultConfiguration == 0L) { JniLoader.getInstance(); // setup - ConfigurationBuilder.ConfigOptions defaultConfigOptions = ConfigurationBuilder.ConfigOptions.getDefault(); - defaultConfiguration = new ConfigurationBuilder() - .buildConfigInstance(defaultConfigOptions); + ConfigurationBuilder.ConfigOptions defaultConfigOptions = + ConfigurationBuilder.ConfigOptions.getDefault(); + defaultConfiguration = + new ConfigurationBuilder().buildConfigInstance(defaultConfigOptions); configurationMap.put(defaultConfigOptions, defaultConfiguration); } } @@ -168,14 +164,13 @@ static long getDefaultConfiguration() throws GandivaException { return defaultConfiguration; } - /** - * Remove the configuration. - */ + /** Remove the configuration. */ static void removeConfiguration(ConfigurationBuilder.ConfigOptions configOptions) { if (configurationMap.containsKey(configOptions)) { synchronized (ConfigurationBuilder.class) { if (configurationMap.containsKey(configOptions)) { - (new ConfigurationBuilder()).releaseConfigInstance(configurationMap.remove(configOptions)); + (new ConfigurationBuilder()) + .releaseConfigInstance(configurationMap.remove(configOptions)); if (configOptions.equals(ConfigurationBuilder.ConfigOptions.getDefault())) { defaultConfiguration = 0; } diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/JniWrapper.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/JniWrapper.java index 520ef5f443e1..acb25ebae28a 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/JniWrapper.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/JniWrapper.java @@ -14,59 +14,60 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import org.apache.arrow.gandiva.exceptions.GandivaException; /** - * This class is implemented in JNI. This provides the Java interface - * to invoke functions in JNI. - * This file is used to generated the .h files required for jni. Avoid all - * external dependencies in this file. + * This class is implemented in JNI. This provides the Java interface to invoke functions in JNI. + * This file is used to generated the .h files required for jni. Avoid all external dependencies in + * this file. */ public class JniWrapper { /** - * Generates the projector module to evaluate the expressions with - * custom configuration. + * Generates the projector module to evaluate the expressions with custom configuration. * - * @param schemaBuf The schema serialized as a protobuf. See Types.proto - * to see the protobuf specification - * @param exprListBuf The serialized protobuf of the expression vector. Each - * expression is created using TreeBuilder::MakeExpression. + * @param schemaBuf The schema serialized as a protobuf. See Types.proto to see the protobuf + * specification + * @param exprListBuf The serialized protobuf of the expression vector. Each expression is created + * using TreeBuilder::MakeExpression. * @param selectionVectorType type of selection vector - * @param configId Configuration to gandiva. + * @param configId Configuration to gandiva. * @return A moduleId that is passed to the evaluateProjector() and closeProjector() methods - * */ - native long buildProjector(byte[] schemaBuf, byte[] exprListBuf, - int selectionVectorType, - long configId) throws GandivaException; + native long buildProjector( + byte[] schemaBuf, byte[] exprListBuf, int selectionVectorType, long configId) + throws GandivaException; /** - * Evaluate the expressions represented by the moduleId on a record batch - * and store the output in ValueVectors. Throws an exception in case of errors + * Evaluate the expressions represented by the moduleId on a record batch and store the output in + * ValueVectors. Throws an exception in case of errors * * @param expander VectorExpander object. Used for callbacks from cpp. - * @param moduleId moduleId representing expressions. Created using a call to - * buildNativeCode + * @param moduleId moduleId representing expressions. Created using a call to buildNativeCode * @param numRows Number of rows in the record batch - * @param bufAddrs An array of memory addresses. Each memory address points to - * a validity vector or a data vector (will add support for offset - * vectors later). - * @param bufSizes An array of buffer sizes. For each memory address in bufAddrs, - * the size of the buffer is present in bufSizes - * @param outAddrs An array of output buffers, including the validity and data - * addresses. - * @param outSizes The allocated size of the output buffers. On successful evaluation, - * the result is stored in the output buffers + * @param bufAddrs An array of memory addresses. Each memory address points to a validity vector + * or a data vector (will add support for offset vectors later). + * @param bufSizes An array of buffer sizes. For each memory address in bufAddrs, the size of the + * buffer is present in bufSizes + * @param outAddrs An array of output buffers, including the validity and data addresses. + * @param outSizes The allocated size of the output buffers. On successful evaluation, the result + * is stored in the output buffers */ - native void evaluateProjector(Object expander, long moduleId, int numRows, - long[] bufAddrs, long[] bufSizes, - int selectionVectorType, int selectionVectorSize, - long selectionVectorBufferAddr, long selectionVectorBufferSize, - long[] outAddrs, long[] outSizes) throws GandivaException; + native void evaluateProjector( + Object expander, + long moduleId, + int numRows, + long[] bufAddrs, + long[] bufSizes, + int selectionVectorType, + int selectionVectorSize, + long selectionVectorBufferAddr, + long selectionVectorBufferSize, + long[] outAddrs, + long[] outSizes) + throws GandivaException; /** * Closes the projector referenced by moduleId. @@ -76,40 +77,42 @@ native void evaluateProjector(Object expander, long moduleId, int numRows, native void closeProjector(long moduleId); /** - * Generates the filter module to evaluate the condition expression with - * custom configuration. + * Generates the filter module to evaluate the condition expression with custom configuration. * - * @param schemaBuf The schema serialized as a protobuf. See Types.proto - * to see the protobuf specification - * @param conditionBuf The serialized protobuf of the condition expression. Each - * expression is created using TreeBuilder::MakeCondition - * @param configId Configuration to gandiva. + * @param schemaBuf The schema serialized as a protobuf. See Types.proto to see the protobuf + * specification + * @param conditionBuf The serialized protobuf of the condition expression. Each expression is + * created using TreeBuilder::MakeCondition + * @param configId Configuration to gandiva. * @return A moduleId that is passed to the evaluateFilter() and closeFilter() methods - * */ - native long buildFilter(byte[] schemaBuf, byte[] conditionBuf, - long configId) throws GandivaException; + native long buildFilter(byte[] schemaBuf, byte[] conditionBuf, long configId) + throws GandivaException; /** - * Evaluate the filter represented by the moduleId on a record batch - * and store the output in buffer 'outAddr'. Throws an exception in case of errors + * Evaluate the filter represented by the moduleId on a record batch and store the output in + * buffer 'outAddr'. Throws an exception in case of errors * - * @param moduleId moduleId representing expressions. Created using a call to - * buildNativeCode + * @param moduleId moduleId representing expressions. Created using a call to buildNativeCode * @param numRows Number of rows in the record batch - * @param bufAddrs An array of memory addresses. Each memory address points to - * a validity vector or a data vector (will add support for offset - * vectors later). - * @param bufSizes An array of buffer sizes. For each memory address in bufAddrs, - * the size of the buffer is present in bufSizes + * @param bufAddrs An array of memory addresses. Each memory address points to a validity vector + * or a data vector (will add support for offset vectors later). + * @param bufSizes An array of buffer sizes. For each memory address in bufAddrs, the size of the + * buffer is present in bufSizes * @param selectionVectorType type of selection vector - * @param outAddr output buffer, whose type is represented by selectionVectorType - * @param outSize The allocated size of the output buffer. On successful evaluation, - * the result is stored in the output buffer + * @param outAddr output buffer, whose type is represented by selectionVectorType + * @param outSize The allocated size of the output buffer. On successful evaluation, the result is + * stored in the output buffer */ - native int evaluateFilter(long moduleId, int numRows, long[] bufAddrs, long[] bufSizes, - int selectionVectorType, - long outAddr, long outSize) throws GandivaException; + native int evaluateFilter( + long moduleId, + int numRows, + long[] bufAddrs, + long[] bufSizes, + int selectionVectorType, + long outAddr, + long outSize) + throws GandivaException; /** * Closes the filter referenced by moduleId. diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/Projector.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/Projector.java index 471ddbced0e6..5c16c46e5ea4 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/Projector.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/Projector.java @@ -14,12 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import java.util.ArrayList; import java.util.List; - import org.apache.arrow.gandiva.exceptions.EvaluatorClosedException; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.exceptions.UnsupportedTypeException; @@ -37,16 +35,13 @@ import org.apache.arrow.vector.types.pojo.Schema; /** - * This class provides a mechanism to evaluate a set of expressions against a RecordBatch. - * Follow these steps to use this class: - * 1) Use the static method make() to create an instance of this class that evaluates a - * set of expressions - * 2) Invoke the method evaluate() to evaluate these expressions against a RecordBatch - * 3) Invoke close() to release resources + * This class provides a mechanism to evaluate a set of expressions against a RecordBatch. Follow + * these steps to use this class: 1) Use the static method make() to create an instance of this + * class that evaluates a set of expressions 2) Invoke the method evaluate() to evaluate these + * expressions against a RecordBatch 3) Invoke close() to release resources */ public class Projector { - private static final org.slf4j.Logger logger = - org.slf4j.LoggerFactory.getLogger(Projector.class); + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Projector.class); private JniWrapper wrapper; private final long moduleId; @@ -63,130 +58,142 @@ private Projector(JniWrapper wrapper, long moduleId, Schema schema, int numExprs } /** - * Invoke this function to generate LLVM code to evaluate the list of project expressions. - * Invoke Projector::Evaluate() against a RecordBatch to evaluate the record batch - * against these projections. - * - * @param schema Table schema. The field names in the schema should match the fields used - * to create the TreeNodes - * @param exprs List of expressions to be evaluated against data + * Invoke this function to generate LLVM code to evaluate the list of project expressions. Invoke + * Projector::Evaluate() against a RecordBatch to evaluate the record batch against these + * projections. * + * @param schema Table schema. The field names in the schema should match the fields used to + * create the TreeNodes + * @param exprs List of expressions to be evaluated against data * @return A native evaluator object that can be used to invoke these projections on a RecordBatch */ - public static Projector make(Schema schema, List exprs) - throws GandivaException { + public static Projector make(Schema schema, List exprs) throws GandivaException { return make(schema, exprs, SelectionVectorType.SV_NONE, JniLoader.getDefaultConfiguration()); } /** - * Invoke this function to generate LLVM code to evaluate the list of project expressions. - * Invoke Projector::Evaluate() against a RecordBatch to evaluate the record batch - * against these projections. + * Invoke this function to generate LLVM code to evaluate the list of project expressions. Invoke + * Projector::Evaluate() against a RecordBatch to evaluate the record batch against these + * projections. * - * @param schema Table schema. The field names in the schema should match the fields used - * to create the TreeNodes - * @param exprs List of expressions to be evaluated against data + * @param schema Table schema. The field names in the schema should match the fields used to + * create the TreeNodes + * @param exprs List of expressions to be evaluated against data * @param configOptions ConfigOptions parameter - * * @return A native evaluator object that can be used to invoke these projections on a RecordBatch */ - public static Projector make(Schema schema, List exprs, - ConfigurationBuilder.ConfigOptions configOptions) throws GandivaException { - return make(schema, exprs, SelectionVectorType.SV_NONE, JniLoader.getConfiguration(configOptions)); + public static Projector make( + Schema schema, List exprs, ConfigurationBuilder.ConfigOptions configOptions) + throws GandivaException { + return make( + schema, exprs, SelectionVectorType.SV_NONE, JniLoader.getConfiguration(configOptions)); } /** - * Invoke this function to generate LLVM code to evaluate the list of project expressions. - * Invoke Projector::Evaluate() against a RecordBatch to evaluate the record batch - * against these projections. + * Invoke this function to generate LLVM code to evaluate the list of project expressions. Invoke + * Projector::Evaluate() against a RecordBatch to evaluate the record batch against these + * projections. * - * @param schema Table schema. The field names in the schema should match the fields used - * to create the TreeNodes - * @param exprs List of expressions to be evaluated against data + * @param schema Table schema. The field names in the schema should match the fields used to + * create the TreeNodes + * @param exprs List of expressions to be evaluated against data * @param optimize Flag to choose if the generated llvm code is to be optimized - * * @return A native evaluator object that can be used to invoke these projections on a RecordBatch */ @Deprecated public static Projector make(Schema schema, List exprs, boolean optimize) throws GandivaException { - return make(schema, exprs, SelectionVectorType.SV_NONE, - JniLoader.getConfiguration((new ConfigurationBuilder.ConfigOptions()).withOptimize(optimize))); + return make( + schema, + exprs, + SelectionVectorType.SV_NONE, + JniLoader.getConfiguration( + (new ConfigurationBuilder.ConfigOptions()).withOptimize(optimize))); } /** - * Invoke this function to generate LLVM code to evaluate the list of project expressions. - * Invoke Projector::Evaluate() against a RecordBatch to evaluate the record batch - * against these projections. + * Invoke this function to generate LLVM code to evaluate the list of project expressions. Invoke + * Projector::Evaluate() against a RecordBatch to evaluate the record batch against these + * projections. * - * @param schema Table schema. The field names in the schema should match the fields used - * to create the TreeNodes - * @param exprs List of expressions to be evaluated against data + * @param schema Table schema. The field names in the schema should match the fields used to + * create the TreeNodes + * @param exprs List of expressions to be evaluated against data * @param selectionVectorType type of selection vector - * * @return A native evaluator object that can be used to invoke these projections on a RecordBatch */ - public static Projector make(Schema schema, List exprs, - SelectionVectorType selectionVectorType) - throws GandivaException { + public static Projector make( + Schema schema, List exprs, SelectionVectorType selectionVectorType) + throws GandivaException { return make(schema, exprs, selectionVectorType, JniLoader.getDefaultConfiguration()); } /** - * Invoke this function to generate LLVM code to evaluate the list of project expressions. - * Invoke Projector::Evaluate() against a RecordBatch to evaluate the record batch - * against these projections. + * Invoke this function to generate LLVM code to evaluate the list of project expressions. Invoke + * Projector::Evaluate() against a RecordBatch to evaluate the record batch against these + * projections. * - * @param schema Table schema. The field names in the schema should match the fields used - * to create the TreeNodes - * @param exprs List of expressions to be evaluated against data + * @param schema Table schema. The field names in the schema should match the fields used to + * create the TreeNodes + * @param exprs List of expressions to be evaluated against data * @param selectionVectorType type of selection vector * @param configOptions ConfigOptions parameter - * * @return A native evaluator object that can be used to invoke these projections on a RecordBatch */ - public static Projector make(Schema schema, List exprs, SelectionVectorType selectionVectorType, - ConfigurationBuilder.ConfigOptions configOptions) throws GandivaException { + public static Projector make( + Schema schema, + List exprs, + SelectionVectorType selectionVectorType, + ConfigurationBuilder.ConfigOptions configOptions) + throws GandivaException { return make(schema, exprs, selectionVectorType, JniLoader.getConfiguration(configOptions)); } /** - * Invoke this function to generate LLVM code to evaluate the list of project expressions. - * Invoke Projector::Evaluate() against a RecordBatch to evaluate the record batch - * against these projections. + * Invoke this function to generate LLVM code to evaluate the list of project expressions. Invoke + * Projector::Evaluate() against a RecordBatch to evaluate the record batch against these + * projections. * - * @param schema Table schema. The field names in the schema should match the fields used - * to create the TreeNodes - * @param exprs List of expressions to be evaluated against data + * @param schema Table schema. The field names in the schema should match the fields used to + * create the TreeNodes + * @param exprs List of expressions to be evaluated against data * @param selectionVectorType type of selection vector * @param optimize Flag to choose if the generated llvm code is to be optimized - * * @return A native evaluator object that can be used to invoke these projections on a RecordBatch */ @Deprecated - public static Projector make(Schema schema, List exprs, - SelectionVectorType selectionVectorType, boolean optimize) + public static Projector make( + Schema schema, + List exprs, + SelectionVectorType selectionVectorType, + boolean optimize) throws GandivaException { - return make(schema, exprs, selectionVectorType, - JniLoader.getConfiguration((new ConfigurationBuilder.ConfigOptions()).withOptimize(optimize))); + return make( + schema, + exprs, + selectionVectorType, + JniLoader.getConfiguration( + (new ConfigurationBuilder.ConfigOptions()).withOptimize(optimize))); } /** - * Invoke this function to generate LLVM code to evaluate the list of project expressions. - * Invoke Projector::Evaluate() against a RecordBatch to evaluate the record batch - * against these projections. + * Invoke this function to generate LLVM code to evaluate the list of project expressions. Invoke + * Projector::Evaluate() against a RecordBatch to evaluate the record batch against these + * projections. * - * @param schema Table schema. The field names in the schema should match the fields used - * to create the TreeNodes - * @param exprs List of expressions to be evaluated against data + * @param schema Table schema. The field names in the schema should match the fields used to + * create the TreeNodes + * @param exprs List of expressions to be evaluated against data * @param selectionVectorType type of selection vector * @param configurationId Custom configuration created through config builder. - * * @return A native evaluator object that can be used to invoke these projections on a RecordBatch */ - public static Projector make(Schema schema, List exprs, + public static Projector make( + Schema schema, + List exprs, SelectionVectorType selectionVectorType, - long configurationId) throws GandivaException { + long configurationId) + throws GandivaException { // serialize the schema and the list of expressions as a protobuf GandivaTypes.ExpressionList.Builder builder = GandivaTypes.ExpressionList.newBuilder(); for (ExpressionTree expr : exprs) { @@ -196,8 +203,12 @@ public static Projector make(Schema schema, List exprs, // Invoke the JNI layer to create the LLVM module representing the expressions GandivaTypes.Schema schemaBuf = ArrowTypeHelper.arrowSchemaToProtobuf(schema); JniWrapper wrapper = JniLoader.getInstance().getWrapper(); - long moduleId = wrapper.buildProjector(schemaBuf.toByteArray(), - builder.build().toByteArray(), selectionVectorType.getNumber(), configurationId); + long moduleId = + wrapper.buildProjector( + schemaBuf.toByteArray(), + builder.build().toByteArray(), + selectionVectorType.getNumber(), + configurationId); logger.debug("Created module for the projector with id {}", moduleId); return new Projector(wrapper, moduleId, schema, exprs.size()); } @@ -209,23 +220,28 @@ public static Projector make(Schema schema, List exprs, * @param outColumns Result of applying the project on the data */ public void evaluate(ArrowRecordBatch recordBatch, List outColumns) - throws GandivaException { - evaluate(recordBatch.getLength(), recordBatch.getBuffers(), - recordBatch.getBuffersLayout(), - SelectionVectorType.SV_NONE.getNumber(), recordBatch.getLength(), - 0, 0, outColumns); + throws GandivaException { + evaluate( + recordBatch.getLength(), + recordBatch.getBuffers(), + recordBatch.getBuffersLayout(), + SelectionVectorType.SV_NONE.getNumber(), + recordBatch.getLength(), + 0, + 0, + outColumns); } /** - * Invoke this function to evaluate a set of expressions against a set of arrow buffers. - * (this is an optimised version that skips taking references). + * Invoke this function to evaluate a set of expressions against a set of arrow buffers. (this is + * an optimised version that skips taking references). * * @param numRows number of rows. * @param buffers List of input arrow buffers * @param outColumns Result of applying the project on the data */ - public void evaluate(int numRows, List buffers, - List outColumns) throws GandivaException { + public void evaluate(int numRows, List buffers, List outColumns) + throws GandivaException { List buffersLayout = new ArrayList<>(); long offset = 0; for (ArrowBuf arrowBuf : buffers) { @@ -233,9 +249,15 @@ public void evaluate(int numRows, List buffers, buffersLayout.add(new ArrowBuffer(offset, size)); offset += size; } - evaluate(numRows, buffers, buffersLayout, - SelectionVectorType.SV_NONE.getNumber(), - numRows, 0, 0, outColumns); + evaluate( + numRows, + buffers, + buffersLayout, + SelectionVectorType.SV_NONE.getNumber(), + numRows, + 0, + 0, + outColumns); } /** @@ -245,10 +267,12 @@ public void evaluate(int numRows, List buffers, * @param selectionVector Selection vector which stores the selected rows. * @param outColumns Result of applying the project on the data */ - public void evaluate(ArrowRecordBatch recordBatch, - SelectionVector selectionVector, List outColumns) - throws GandivaException { - evaluate(recordBatch.getLength(), recordBatch.getBuffers(), + public void evaluate( + ArrowRecordBatch recordBatch, SelectionVector selectionVector, List outColumns) + throws GandivaException { + evaluate( + recordBatch.getLength(), + recordBatch.getBuffers(), recordBatch.getBuffersLayout(), selectionVector.getType().getNumber(), selectionVector.getRecordCount(), @@ -258,18 +282,20 @@ public void evaluate(ArrowRecordBatch recordBatch, } /** - * Invoke this function to evaluate a set of expressions against a set of arrow buffers - * on the selected positions. - * (this is an optimised version that skips taking references). - * - * @param numRows number of rows. - * @param buffers List of input arrow buffers - * @param selectionVector Selection vector which stores the selected rows. - * @param outColumns Result of applying the project on the data - */ - public void evaluate(int numRows, List buffers, - SelectionVector selectionVector, - List outColumns) throws GandivaException { + * Invoke this function to evaluate a set of expressions against a set of arrow buffers on the + * selected positions. (this is an optimised version that skips taking references). + * + * @param numRows number of rows. + * @param buffers List of input arrow buffers + * @param selectionVector Selection vector which stores the selected rows. + * @param outColumns Result of applying the project on the data + */ + public void evaluate( + int numRows, + List buffers, + SelectionVector selectionVector, + List outColumns) + throws GandivaException { List buffersLayout = new ArrayList<>(); long offset = 0; for (ArrowBuf arrowBuf : buffers) { @@ -277,7 +303,10 @@ public void evaluate(int numRows, List buffers, buffersLayout.add(new ArrowBuffer(offset, size)); offset += size; } - evaluate(numRows, buffers, buffersLayout, + evaluate( + numRows, + buffers, + buffersLayout, selectionVector.getType().getNumber(), selectionVector.getRecordCount(), selectionVector.getBuffer().memoryAddress(), @@ -285,10 +314,16 @@ public void evaluate(int numRows, List buffers, outColumns); } - private void evaluate(int numRows, List buffers, List buffersLayout, - int selectionVectorType, int selectionVectorRecordCount, - long selectionVectorAddr, long selectionVectorSize, - List outColumns) throws GandivaException { + private void evaluate( + int numRows, + List buffers, + List buffersLayout, + int selectionVectorType, + int selectionVectorRecordCount, + long selectionVectorAddr, + long selectionVectorSize, + List outColumns) + throws GandivaException { if (this.closed) { throw new EvaluatorClosedException(); } @@ -344,15 +379,19 @@ private void evaluate(int numRows, List buffers, List buf wrapper.evaluateProjector( hasVariableWidthColumns ? new VectorExpander(resizableVectors) : null, - this.moduleId, numRows, bufAddrs, bufSizes, - selectionVectorType, selectionVectorRecordCount, - selectionVectorAddr, selectionVectorSize, - outAddrs, outSizes); + this.moduleId, + numRows, + bufAddrs, + bufSizes, + selectionVectorType, + selectionVectorRecordCount, + selectionVectorAddr, + selectionVectorSize, + outAddrs, + outSizes); } - /** - * Closes the LLVM module representing this evaluator. - */ + /** Closes the LLVM module representing this evaluator. */ public void close() throws GandivaException { if (this.closed) { return; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVector.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVector.java index 2af88b52636e..4bb1f2be74a0 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVector.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVector.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import static org.apache.arrow.memory.util.LargeMemoryUtil.capAtMaxInt; @@ -24,8 +23,7 @@ /** * A selection vector contains the indexes of "selected" records in a row batch. It is backed by an - * arrow buffer. - * Client manages the lifecycle of the arrow buffer - to release the reference. + * arrow buffer. Client manages the lifecycle of the arrow buffer - to release the reference. */ public abstract class SelectionVector { private int recordCount; @@ -58,9 +56,13 @@ public final int getRecordCount() { */ final void setRecordCount(int recordCount) { if (recordCount * getRecordSize() > buffer.capacity()) { - throw new IllegalArgumentException("recordCount " + recordCount + - " of size " + getRecordSize() + - " exceeds buffer capacity " + buffer.capacity()); + throw new IllegalArgumentException( + "recordCount " + + recordCount + + " of size " + + getRecordSize() + + " exceeds buffer capacity " + + buffer.capacity()); } this.recordCount = recordCount; @@ -83,5 +85,4 @@ final void checkReadBounds(int index) { throw new IllegalArgumentException("index " + index + " is >= recordCount " + recordCount); } } - } diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVectorInt16.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVectorInt16.java index 84c795b67027..8ef35d0073cb 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVectorInt16.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVectorInt16.java @@ -14,15 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import org.apache.arrow.gandiva.ipc.GandivaTypes.SelectionVectorType; import org.apache.arrow.memory.ArrowBuf; -/** - * Selection vector with records of arrow type INT16. - */ +/** Selection vector with records of arrow type INT16. */ public class SelectionVectorInt16 extends SelectionVector { public SelectionVectorInt16(ArrowBuf buffer) { diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVectorInt32.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVectorInt32.java index c938f6691117..324dd54be244 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVectorInt32.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/SelectionVectorInt32.java @@ -14,15 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import org.apache.arrow.gandiva.ipc.GandivaTypes.SelectionVectorType; import org.apache.arrow.memory.ArrowBuf; -/** - * Selection vector with records of arrow type INT32. - */ +/** Selection vector with records of arrow type INT32. */ public class SelectionVectorInt32 extends SelectionVector { public SelectionVectorInt32(ArrowBuf buffer) { diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/VectorExpander.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/VectorExpander.java index f22ebbd37878..a50a1f567700 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/VectorExpander.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/VectorExpander.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import org.apache.arrow.vector.BaseVariableWidthVector; @@ -30,9 +29,7 @@ public VectorExpander(BaseVariableWidthVector[] vectors) { this.vectors = vectors; } - /** - * Result of vector expansion. - */ + /** Result of vector expansion. */ public static class ExpandResult { public long address; public long capacity; @@ -44,13 +41,12 @@ public ExpandResult(long address, long capacity) { } /** - * Expand vector at specified index. This is used as a back call from jni, and is only - * relevant for variable width vectors. + * Expand vector at specified index. This is used as a back call from jni, and is only relevant + * for variable width vectors. * * @param index index of buffer in the list passed to jni. * @param toCapacity the size to which the buffer should be expanded to. - * - * @return address and size of the buffer after expansion. + * @return address and size of the buffer after expansion. */ public ExpandResult expandOutputVectorAtIndex(int index, long toCapacity) { if (index >= vectors.length || vectors[index] == null) { @@ -62,8 +58,6 @@ public ExpandResult expandOutputVectorAtIndex(int index, long toCapacity) { vector.reallocDataBuffer(); } return new ExpandResult( - vector.getDataBuffer().memoryAddress(), - vector.getDataBuffer().capacity()); + vector.getDataBuffer().memoryAddress(), vector.getDataBuffer().capacity()); } - } diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/EvaluatorClosedException.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/EvaluatorClosedException.java index d3fb8b60df0b..0526e2cdeaf6 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/EvaluatorClosedException.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/EvaluatorClosedException.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.exceptions; /** Indicates an attempted call to methods on a closed evaluator. */ diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/GandivaException.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/GandivaException.java index e7fce58a38da..4f3f0f8fcf29 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/GandivaException.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/GandivaException.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.exceptions; /** Base class for all specialized exceptions this package uses. */ diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/UnsupportedTypeException.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/UnsupportedTypeException.java index 90e06e80ec55..82b4b371d2be 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/UnsupportedTypeException.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/exceptions/UnsupportedTypeException.java @@ -14,12 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.exceptions; -/** - * Represents an exception thrown while dealing with unsupported types. - */ +/** Represents an exception thrown while dealing with unsupported types. */ public class UnsupportedTypeException extends GandivaException { public UnsupportedTypeException(String msg) { super(msg); diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/AndNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/AndNode.java index ecc577fa78d4..5fdff20b2a8c 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/AndNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/AndNode.java @@ -14,17 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import java.util.List; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; -/** - * Node representing a logical And expression. - */ +/** Node representing a logical And expression. */ class AndNode implements TreeNode { private final List children; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ArrowTypeHelper.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ArrowTypeHelper.java index e7377cc5c9db..1bfac58b270c 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ArrowTypeHelper.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ArrowTypeHelper.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.flatbuf.DateUnit; @@ -29,12 +28,9 @@ import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.Schema; -/** - * Utility methods to convert between Arrow and Gandiva types. - */ +/** Utility methods to convert between Arrow and Gandiva types. */ public class ArrowTypeHelper { - private ArrowTypeHelper() { - } + private ArrowTypeHelper() {} static final int WIDTH_8 = 8; static final int WIDTH_16 = 16; @@ -47,49 +43,59 @@ private static void initArrowTypeInt( if (intType.getIsSigned()) { switch (width) { - case WIDTH_8: { - builder.setType(GandivaTypes.GandivaType.INT8); + case WIDTH_8: + { + builder.setType(GandivaTypes.GandivaType.INT8); + return; + } + case WIDTH_16: + { + builder.setType(GandivaTypes.GandivaType.INT16); + return; + } + case WIDTH_32: + { + builder.setType(GandivaTypes.GandivaType.INT32); + return; + } + case WIDTH_64: + { + builder.setType(GandivaTypes.GandivaType.INT64); + return; + } + default: + { + throw new UnsupportedTypeException("Unsupported width for integer type"); + } + } + } + + // unsigned int + switch (width) { + case WIDTH_8: + { + builder.setType(GandivaTypes.GandivaType.UINT8); return; } - case WIDTH_16: { - builder.setType(GandivaTypes.GandivaType.INT16); + case WIDTH_16: + { + builder.setType(GandivaTypes.GandivaType.UINT16); return; } - case WIDTH_32: { - builder.setType(GandivaTypes.GandivaType.INT32); + case WIDTH_32: + { + builder.setType(GandivaTypes.GandivaType.UINT32); return; } - case WIDTH_64: { - builder.setType(GandivaTypes.GandivaType.INT64); + case WIDTH_64: + { + builder.setType(GandivaTypes.GandivaType.UINT64); return; } - default: { + default: + { throw new UnsupportedTypeException("Unsupported width for integer type"); } - } - } - - // unsigned int - switch (width) { - case WIDTH_8: { - builder.setType(GandivaTypes.GandivaType.UINT8); - return; - } - case WIDTH_16: { - builder.setType(GandivaTypes.GandivaType.UINT16); - return; - } - case WIDTH_32: { - builder.setType(GandivaTypes.GandivaType.UINT32); - return; - } - case WIDTH_64: { - builder.setType(GandivaTypes.GandivaType.UINT64); - return; - } - default: { - throw new UnsupportedTypeException("Unsupported width for integer type"); - } } } @@ -97,130 +103,152 @@ private static void initArrowTypeFloat( ArrowType.FloatingPoint floatType, GandivaTypes.ExtGandivaType.Builder builder) throws GandivaException { switch (floatType.getPrecision()) { - case HALF: { - builder.setType(GandivaTypes.GandivaType.HALF_FLOAT); - break; - } - case SINGLE: { - builder.setType(GandivaTypes.GandivaType.FLOAT); - break; - } - case DOUBLE: { - builder.setType(GandivaTypes.GandivaType.DOUBLE); - break; - } - default: { - throw new UnsupportedTypeException("Floating point type with unknown precision"); - } + case HALF: + { + builder.setType(GandivaTypes.GandivaType.HALF_FLOAT); + break; + } + case SINGLE: + { + builder.setType(GandivaTypes.GandivaType.FLOAT); + break; + } + case DOUBLE: + { + builder.setType(GandivaTypes.GandivaType.DOUBLE); + break; + } + default: + { + throw new UnsupportedTypeException("Floating point type with unknown precision"); + } } } - private static void initArrowTypeDecimal(ArrowType.Decimal decimalType, - GandivaTypes.ExtGandivaType.Builder builder) { - Preconditions.checkArgument(decimalType.getPrecision() > 0 && - decimalType.getPrecision() <= 38, "Gandiva only supports decimals of upto 38 " + - "precision. Input precision : " + decimalType.getPrecision()); + private static void initArrowTypeDecimal( + ArrowType.Decimal decimalType, GandivaTypes.ExtGandivaType.Builder builder) { + Preconditions.checkArgument( + decimalType.getPrecision() > 0 && decimalType.getPrecision() <= 38, + "Gandiva only supports decimals of upto 38 " + + "precision. Input precision : " + + decimalType.getPrecision()); builder.setPrecision(decimalType.getPrecision()); builder.setScale(decimalType.getScale()); builder.setType(GandivaTypes.GandivaType.DECIMAL); } - private static void initArrowTypeDate(ArrowType.Date dateType, - GandivaTypes.ExtGandivaType.Builder builder) { + private static void initArrowTypeDate( + ArrowType.Date dateType, GandivaTypes.ExtGandivaType.Builder builder) { short dateUnit = dateType.getUnit().getFlatbufID(); switch (dateUnit) { - case DateUnit.DAY: { - builder.setType(GandivaTypes.GandivaType.DATE32); - break; - } - case DateUnit.MILLISECOND: { - builder.setType(GandivaTypes.GandivaType.DATE64); - break; - } - default: { - // not supported - break; - } + case DateUnit.DAY: + { + builder.setType(GandivaTypes.GandivaType.DATE32); + break; + } + case DateUnit.MILLISECOND: + { + builder.setType(GandivaTypes.GandivaType.DATE64); + break; + } + default: + { + // not supported + break; + } } } - private static void initArrowTypeTime(ArrowType.Time timeType, - GandivaTypes.ExtGandivaType.Builder builder) { + private static void initArrowTypeTime( + ArrowType.Time timeType, GandivaTypes.ExtGandivaType.Builder builder) { short timeUnit = timeType.getUnit().getFlatbufID(); switch (timeUnit) { - case TimeUnit.SECOND: { - builder.setType(GandivaTypes.GandivaType.TIME32); - builder.setTimeUnit(GandivaTypes.TimeUnit.SEC); - break; - } - case TimeUnit.MILLISECOND: { - builder.setType(GandivaTypes.GandivaType.TIME32); - builder.setTimeUnit(GandivaTypes.TimeUnit.MILLISEC); - break; - } - case TimeUnit.MICROSECOND: { - builder.setType(GandivaTypes.GandivaType.TIME64); - builder.setTimeUnit(GandivaTypes.TimeUnit.MICROSEC); - break; - } - case TimeUnit.NANOSECOND: { - builder.setType(GandivaTypes.GandivaType.TIME64); - builder.setTimeUnit(GandivaTypes.TimeUnit.NANOSEC); - break; - } - default: { - // not supported - } + case TimeUnit.SECOND: + { + builder.setType(GandivaTypes.GandivaType.TIME32); + builder.setTimeUnit(GandivaTypes.TimeUnit.SEC); + break; + } + case TimeUnit.MILLISECOND: + { + builder.setType(GandivaTypes.GandivaType.TIME32); + builder.setTimeUnit(GandivaTypes.TimeUnit.MILLISEC); + break; + } + case TimeUnit.MICROSECOND: + { + builder.setType(GandivaTypes.GandivaType.TIME64); + builder.setTimeUnit(GandivaTypes.TimeUnit.MICROSEC); + break; + } + case TimeUnit.NANOSECOND: + { + builder.setType(GandivaTypes.GandivaType.TIME64); + builder.setTimeUnit(GandivaTypes.TimeUnit.NANOSEC); + break; + } + default: + { + // not supported + } } } - private static void initArrowTypeTimestamp(ArrowType.Timestamp timestampType, - GandivaTypes.ExtGandivaType.Builder builder) { + private static void initArrowTypeTimestamp( + ArrowType.Timestamp timestampType, GandivaTypes.ExtGandivaType.Builder builder) { short timeUnit = timestampType.getUnit().getFlatbufID(); switch (timeUnit) { - case TimeUnit.SECOND: { - builder.setType(GandivaTypes.GandivaType.TIMESTAMP); - builder.setTimeUnit(GandivaTypes.TimeUnit.SEC); - break; - } - case TimeUnit.MILLISECOND: { - builder.setType(GandivaTypes.GandivaType.TIMESTAMP); - builder.setTimeUnit(GandivaTypes.TimeUnit.MILLISEC); - break; - } - case TimeUnit.MICROSECOND: { - builder.setType(GandivaTypes.GandivaType.TIMESTAMP); - builder.setTimeUnit(GandivaTypes.TimeUnit.MICROSEC); - break; - } - case TimeUnit.NANOSECOND: { - builder.setType(GandivaTypes.GandivaType.TIMESTAMP); - builder.setTimeUnit(GandivaTypes.TimeUnit.NANOSEC); - break; - } - default: { - // not supported - } + case TimeUnit.SECOND: + { + builder.setType(GandivaTypes.GandivaType.TIMESTAMP); + builder.setTimeUnit(GandivaTypes.TimeUnit.SEC); + break; + } + case TimeUnit.MILLISECOND: + { + builder.setType(GandivaTypes.GandivaType.TIMESTAMP); + builder.setTimeUnit(GandivaTypes.TimeUnit.MILLISEC); + break; + } + case TimeUnit.MICROSECOND: + { + builder.setType(GandivaTypes.GandivaType.TIMESTAMP); + builder.setTimeUnit(GandivaTypes.TimeUnit.MICROSEC); + break; + } + case TimeUnit.NANOSECOND: + { + builder.setType(GandivaTypes.GandivaType.TIMESTAMP); + builder.setTimeUnit(GandivaTypes.TimeUnit.NANOSEC); + break; + } + default: + { + // not supported + } } } - private static void initArrowTypeInterval(ArrowType.Interval interval, - GandivaTypes.ExtGandivaType.Builder builder) { + private static void initArrowTypeInterval( + ArrowType.Interval interval, GandivaTypes.ExtGandivaType.Builder builder) { short intervalUnit = interval.getUnit().getFlatbufID(); switch (intervalUnit) { - case IntervalUnit.YEAR_MONTH: { - builder.setType(GandivaTypes.GandivaType.INTERVAL); - builder.setIntervalType(GandivaTypes.IntervalType.YEAR_MONTH); - break; - } - case IntervalUnit.DAY_TIME: { - builder.setType(GandivaTypes.GandivaType.INTERVAL); - builder.setIntervalType(GandivaTypes.IntervalType.DAY_TIME); - break; - } - default: { - // not supported - } + case IntervalUnit.YEAR_MONTH: + { + builder.setType(GandivaTypes.GandivaType.INTERVAL); + builder.setIntervalType(GandivaTypes.IntervalType.YEAR_MONTH); + break; + } + case IntervalUnit.DAY_TIME: + { + builder.setType(GandivaTypes.GandivaType.INTERVAL); + builder.setIntervalType(GandivaTypes.IntervalType.DAY_TIME); + break; + } + default: + { + // not supported + } } } @@ -236,75 +264,94 @@ public static GandivaTypes.ExtGandivaType arrowTypeToProtobuf(ArrowType arrowTyp byte typeId = arrowType.getTypeID().getFlatbufID(); switch (typeId) { - case Type.NONE: { // 0 - builder.setType(GandivaTypes.GandivaType.NONE); - break; - } - case Type.Null: { // 1 - // TODO: Need to handle this later - break; - } - case Type.Int: { // 2 - ArrowTypeHelper.initArrowTypeInt((ArrowType.Int) arrowType, builder); - break; - } - case Type.FloatingPoint: { // 3 - ArrowTypeHelper.initArrowTypeFloat((ArrowType.FloatingPoint) arrowType, builder); - break; - } - case Type.Binary: { // 4 - builder.setType(GandivaTypes.GandivaType.BINARY); - break; - } - case Type.Utf8: { // 5 - builder.setType(GandivaTypes.GandivaType.UTF8); - break; - } - case Type.Bool: { // 6 - builder.setType(GandivaTypes.GandivaType.BOOL); - break; - } - case Type.Decimal: { // 7 - ArrowTypeHelper.initArrowTypeDecimal((ArrowType.Decimal) arrowType, builder); - break; - } - case Type.Date: { // 8 - ArrowTypeHelper.initArrowTypeDate((ArrowType.Date) arrowType, builder); - break; - } - case Type.Time: { // 9 - ArrowTypeHelper.initArrowTypeTime((ArrowType.Time) arrowType, builder); - break; - } - case Type.Timestamp: { // 10 - ArrowTypeHelper.initArrowTypeTimestamp((ArrowType.Timestamp) arrowType, builder); - break; - } - case Type.Interval: { // 11 - ArrowTypeHelper.initArrowTypeInterval((ArrowType.Interval) arrowType, builder); - break; - } - case Type.List: { // 12 - break; - } - case Type.Struct_: { // 13 - break; - } - case Type.Union: { // 14 - break; - } - case Type.FixedSizeBinary: { // 15 - break; - } - case Type.FixedSizeList: { // 16 - break; - } - case Type.Map: { // 17 - break; - } - default: { - break; - } + case Type.NONE: + { // 0 + builder.setType(GandivaTypes.GandivaType.NONE); + break; + } + case Type.Null: + { // 1 + // TODO: Need to handle this later + break; + } + case Type.Int: + { // 2 + ArrowTypeHelper.initArrowTypeInt((ArrowType.Int) arrowType, builder); + break; + } + case Type.FloatingPoint: + { // 3 + ArrowTypeHelper.initArrowTypeFloat((ArrowType.FloatingPoint) arrowType, builder); + break; + } + case Type.Binary: + { // 4 + builder.setType(GandivaTypes.GandivaType.BINARY); + break; + } + case Type.Utf8: + { // 5 + builder.setType(GandivaTypes.GandivaType.UTF8); + break; + } + case Type.Bool: + { // 6 + builder.setType(GandivaTypes.GandivaType.BOOL); + break; + } + case Type.Decimal: + { // 7 + ArrowTypeHelper.initArrowTypeDecimal((ArrowType.Decimal) arrowType, builder); + break; + } + case Type.Date: + { // 8 + ArrowTypeHelper.initArrowTypeDate((ArrowType.Date) arrowType, builder); + break; + } + case Type.Time: + { // 9 + ArrowTypeHelper.initArrowTypeTime((ArrowType.Time) arrowType, builder); + break; + } + case Type.Timestamp: + { // 10 + ArrowTypeHelper.initArrowTypeTimestamp((ArrowType.Timestamp) arrowType, builder); + break; + } + case Type.Interval: + { // 11 + ArrowTypeHelper.initArrowTypeInterval((ArrowType.Interval) arrowType, builder); + break; + } + case Type.List: + { // 12 + break; + } + case Type.Struct_: + { // 13 + break; + } + case Type.Union: + { // 14 + break; + } + case Type.FixedSizeBinary: + { // 15 + break; + } + case Type.FixedSizeList: + { // 16 + break; + } + case Type.Map: + { // 17 + break; + } + default: + { + break; + } } if (!builder.hasType()) { @@ -318,6 +365,7 @@ public static GandivaTypes.ExtGandivaType arrowTypeToProtobuf(ArrowType arrowTyp /** * Converts an arrow field object to a protobuf. + * * @param field Arrow field to be converted * @return Protobuf representing the arrow field */ @@ -336,6 +384,7 @@ public static GandivaTypes.Field arrowFieldToProtobuf(Field field) throws Gandiv /** * Converts a schema object to a protobuf. + * * @param schema Schema object to be converted * @return Protobuf representing a schema object */ diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/BinaryNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/BinaryNode.java index 8455f29b2d92..2559a398fdfe 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/BinaryNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/BinaryNode.java @@ -14,17 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; +import com.google.protobuf.ByteString; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; -import com.google.protobuf.ByteString; - -/** - * Used to represent expression tree nodes representing binary constants. - */ +/** Used to represent expression tree nodes representing binary constants. */ class BinaryNode implements TreeNode { private final byte[] value; @@ -34,12 +30,9 @@ public BinaryNode(byte[] value) { @Override public GandivaTypes.TreeNode toProtobuf() throws GandivaException { - GandivaTypes.BinaryNode binaryNode = GandivaTypes.BinaryNode.newBuilder() - .setValue(ByteString.copyFrom(value)) - .build(); + GandivaTypes.BinaryNode binaryNode = + GandivaTypes.BinaryNode.newBuilder().setValue(ByteString.copyFrom(value)).build(); - return GandivaTypes.TreeNode.newBuilder() - .setBinaryNode(binaryNode) - .build(); + return GandivaTypes.TreeNode.newBuilder().setBinaryNode(binaryNode).build(); } } diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/BooleanNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/BooleanNode.java index 505f01919c99..5cbc0ace3ea7 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/BooleanNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/BooleanNode.java @@ -14,15 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; /** - * Used to represent expression tree nodes representing boolean constants. - * Used while creating expressions like if (!x). + * Used to represent expression tree nodes representing boolean constants. Used while creating + * expressions like if (!x). */ class BooleanNode implements TreeNode { private final Boolean value; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/Condition.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/Condition.java index 1d584d673f6f..89cc39812cd1 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/Condition.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/Condition.java @@ -14,15 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; -/** - * Opaque class representing a filter condition. - */ +/** Opaque class representing a filter condition. */ public class Condition { private final TreeNode root; @@ -32,6 +29,7 @@ public class Condition { /** * Converts an condition expression into a protobuf. + * * @return A protobuf representing the condition expression tree */ public GandivaTypes.Condition toProtobuf() throws GandivaException { diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/DecimalNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/DecimalNode.java index bf17aa0aa6d1..0d0f72226e84 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/DecimalNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/DecimalNode.java @@ -14,15 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; /** - * Used to represent expression tree nodes representing decimal constants. - * Used in the expression (x + 5.0) + * Used to represent expression tree nodes representing decimal constants. Used in the expression (x + * + 5.0) */ class DecimalNode implements TreeNode { private final String value; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/DoubleNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/DoubleNode.java index f7a9436f1f38..0fbb92d8a567 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/DoubleNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/DoubleNode.java @@ -14,15 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; /** - * Used to represent expression tree nodes representing double constants. - * Used in the expression (x + 5.0) + * Used to represent expression tree nodes representing double constants. Used in the expression (x + * + 5.0) */ class DoubleNode implements TreeNode { private final Double value; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ExpressionTree.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ExpressionTree.java index 353c8d12b3e5..67ad8eef53b8 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ExpressionTree.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/ExpressionTree.java @@ -14,16 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; import org.apache.arrow.vector.types.pojo.Field; -/** - * Opaque class representing an expression. - */ +/** Opaque class representing an expression. */ public class ExpressionTree { private final TreeNode root; private final Field resultField; @@ -35,6 +32,7 @@ public class ExpressionTree { /** * Converts an expression tree into a protobuf. + * * @return A protobuf representing the expression tree */ public GandivaTypes.ExpressionRoot toProtobuf() throws GandivaException { diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FieldNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FieldNode.java index 893bf7191258..b1667fdaec6b 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FieldNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FieldNode.java @@ -14,16 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; import org.apache.arrow.vector.types.pojo.Field; -/** - * Opaque class that represents a tree node. - */ +/** Opaque class that represents a tree node. */ class FieldNode implements TreeNode { private final Field field; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FloatNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FloatNode.java index 6afe96bfe8fc..ae152372212e 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FloatNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FloatNode.java @@ -14,15 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; /** - * Used to represent expression tree nodes representing float constants. - * Used in the expression (x + 5.0) + * Used to represent expression tree nodes representing float constants. Used in the expression (x + + * 5.0) */ class FloatNode implements TreeNode { private final Float value; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FunctionNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FunctionNode.java index ead1e146d5d8..a5c6fb77f962 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FunctionNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/FunctionNode.java @@ -14,18 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import java.util.List; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; import org.apache.arrow.vector.types.pojo.ArrowType; -/** - * Node representing an arbitrary function in an expression. - */ +/** Node representing an arbitrary function in an expression. */ class FunctionNode implements TreeNode { private final String function; private final List children; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/IfNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/IfNode.java index 19f9095fb762..cbb3f80f4e35 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/IfNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/IfNode.java @@ -14,16 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; import org.apache.arrow.vector.types.pojo.ArrowType; -/** - * Node representing a if-then-else block expression. - */ +/** Node representing a if-then-else block expression. */ class IfNode implements TreeNode { private final TreeNode condition; private final TreeNode thenNode; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/InNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/InNode.java index bb1391b4001e..2089c9b7cbe6 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/InNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/InNode.java @@ -14,21 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; +import com.google.protobuf.ByteString; import java.math.BigDecimal; import java.nio.charset.Charset; import java.util.Set; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; -import com.google.protobuf.ByteString; - -/** - * In Node representation in java. - */ +/** In Node representation in java. */ public class InNode implements TreeNode { private static final Charset charset = Charset.forName("UTF-8"); @@ -44,9 +39,17 @@ public class InNode implements TreeNode { private final Integer precision; private final Integer scale; - private InNode(Set values, Set longValues, Set stringValues, Set - binaryValues, Set decimalValues, Integer precision, Integer scale, - Set floatValues, Set doubleValues, TreeNode node) { + private InNode( + Set values, + Set longValues, + Set stringValues, + Set binaryValues, + Set decimalValues, + Integer precision, + Integer scale, + Set floatValues, + Set doubleValues, + TreeNode node) { this.intValues = values; this.longValues = longValues; this.decimalValues = decimalValues; @@ -62,67 +65,58 @@ private InNode(Set values, Set longValues, Set stringValu /** * Makes an IN node for int values. * - * @param node Node with the 'IN' clause. + * @param node Node with the 'IN' clause. * @param intValues Int values to build the IN node. * @return InNode referring to tree node. */ public static InNode makeIntInExpr(TreeNode node, Set intValues) { - return new InNode(intValues, - null, null, null, null, null, null, null, - null, node); + return new InNode(intValues, null, null, null, null, null, null, null, null, node); } /** * Makes an IN node for long values. * - * @param node Node with the 'IN' clause. + * @param node Node with the 'IN' clause. * @param longValues Long values to build the IN node. * @return InNode referring to tree node. */ public static InNode makeLongInExpr(TreeNode node, Set longValues) { - return new InNode(null, longValues, - null, null, null, null, null, null, - null, node); + return new InNode(null, longValues, null, null, null, null, null, null, null, node); } /** * Makes an IN node for float values. * - * @param node Node with the 'IN' clause. + * @param node Node with the 'IN' clause. * @param floatValues Float values to build the IN node. * @return InNode referring to tree node. */ public static InNode makeFloatInExpr(TreeNode node, Set floatValues) { - return new InNode(null, null, null, null, null, null, - null, floatValues, null, node); + return new InNode(null, null, null, null, null, null, null, floatValues, null, node); } /** * Makes an IN node for double values. * - * @param node Node with the 'IN' clause. + * @param node Node with the 'IN' clause. * @param doubleValues Double values to build the IN node. * @return InNode referring to tree node. */ public static InNode makeDoubleInExpr(TreeNode node, Set doubleValues) { - return new InNode(null, null, null, null, null, - null, null, null, doubleValues, node); + return new InNode(null, null, null, null, null, null, null, null, doubleValues, node); } - public static InNode makeDecimalInExpr(TreeNode node, Set decimalValues, - Integer precision, Integer scale) { - return new InNode(null, null, null, null, - decimalValues, precision, scale, null, null, node); + public static InNode makeDecimalInExpr( + TreeNode node, Set decimalValues, Integer precision, Integer scale) { + return new InNode(null, null, null, null, decimalValues, precision, scale, null, null, node); } public static InNode makeStringInExpr(TreeNode node, Set stringValues) { - return new InNode(null, null, stringValues, null, - null, null, null, null, null, node); + return new InNode(null, null, stringValues, null, null, null, null, null, null, node); } public static InNode makeBinaryInExpr(TreeNode node, Set binaryValues) { - return new InNode(null, null, null, binaryValues, - null, null, null, null, null, node); + return new InNode(null, null, null, binaryValues, null, null, null, null, null, node); } @Override @@ -133,40 +127,71 @@ public GandivaTypes.TreeNode toProtobuf() throws GandivaException { if (intValues != null) { GandivaTypes.IntConstants.Builder intConstants = GandivaTypes.IntConstants.newBuilder(); - intValues.stream().forEach(val -> intConstants.addIntValues(GandivaTypes.IntNode.newBuilder() - .setValue(val).build())); + intValues.stream() + .forEach( + val -> + intConstants.addIntValues( + GandivaTypes.IntNode.newBuilder().setValue(val).build())); inNode.setIntValues(intConstants.build()); } else if (longValues != null) { GandivaTypes.LongConstants.Builder longConstants = GandivaTypes.LongConstants.newBuilder(); - longValues.stream().forEach(val -> longConstants.addLongValues(GandivaTypes.LongNode.newBuilder() - .setValue(val).build())); + longValues.stream() + .forEach( + val -> + longConstants.addLongValues( + GandivaTypes.LongNode.newBuilder().setValue(val).build())); inNode.setLongValues(longConstants.build()); } else if (floatValues != null) { GandivaTypes.FloatConstants.Builder floatConstants = GandivaTypes.FloatConstants.newBuilder(); - floatValues.stream().forEach(val -> floatConstants.addFloatValues(GandivaTypes.FloatNode.newBuilder() - .setValue(val).build())); + floatValues.stream() + .forEach( + val -> + floatConstants.addFloatValues( + GandivaTypes.FloatNode.newBuilder().setValue(val).build())); inNode.setFloatValues(floatConstants.build()); } else if (doubleValues != null) { - GandivaTypes.DoubleConstants.Builder doubleConstants = GandivaTypes.DoubleConstants.newBuilder(); - doubleValues.stream().forEach(val -> doubleConstants.addDoubleValues(GandivaTypes.DoubleNode.newBuilder() - .setValue(val).build())); + GandivaTypes.DoubleConstants.Builder doubleConstants = + GandivaTypes.DoubleConstants.newBuilder(); + doubleValues.stream() + .forEach( + val -> + doubleConstants.addDoubleValues( + GandivaTypes.DoubleNode.newBuilder().setValue(val).build())); inNode.setDoubleValues(doubleConstants.build()); } else if (decimalValues != null) { - GandivaTypes.DecimalConstants.Builder decimalConstants = GandivaTypes.DecimalConstants.newBuilder(); - decimalValues.stream().forEach(val -> decimalConstants.addDecimalValues(GandivaTypes.DecimalNode.newBuilder() - .setValue(val.toPlainString()).setPrecision(precision).setScale(scale).build())); + GandivaTypes.DecimalConstants.Builder decimalConstants = + GandivaTypes.DecimalConstants.newBuilder(); + decimalValues.stream() + .forEach( + val -> + decimalConstants.addDecimalValues( + GandivaTypes.DecimalNode.newBuilder() + .setValue(val.toPlainString()) + .setPrecision(precision) + .setScale(scale) + .build())); inNode.setDecimalValues(decimalConstants.build()); } else if (stringValues != null) { - GandivaTypes.StringConstants.Builder stringConstants = GandivaTypes.StringConstants - .newBuilder(); - stringValues.stream().forEach(val -> stringConstants.addStringValues(GandivaTypes.StringNode - .newBuilder().setValue(ByteString.copyFrom(val.getBytes(charset))).build())); + GandivaTypes.StringConstants.Builder stringConstants = + GandivaTypes.StringConstants.newBuilder(); + stringValues.stream() + .forEach( + val -> + stringConstants.addStringValues( + GandivaTypes.StringNode.newBuilder() + .setValue(ByteString.copyFrom(val.getBytes(charset))) + .build())); inNode.setStringValues(stringConstants.build()); } else if (binaryValues != null) { - GandivaTypes.BinaryConstants.Builder binaryConstants = GandivaTypes.BinaryConstants - .newBuilder(); - binaryValues.stream().forEach(val -> binaryConstants.addBinaryValues(GandivaTypes.BinaryNode - .newBuilder().setValue(ByteString.copyFrom(val)).build())); + GandivaTypes.BinaryConstants.Builder binaryConstants = + GandivaTypes.BinaryConstants.newBuilder(); + binaryValues.stream() + .forEach( + val -> + binaryConstants.addBinaryValues( + GandivaTypes.BinaryNode.newBuilder() + .setValue(ByteString.copyFrom(val)) + .build())); inNode.setBinaryValues(binaryConstants.build()); } GandivaTypes.TreeNode.Builder builder = GandivaTypes.TreeNode.newBuilder(); diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/IntNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/IntNode.java index c3858ef7ec92..26321b4dfd4e 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/IntNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/IntNode.java @@ -14,15 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; /** - * Used to represent expression tree nodes representing int constants. - * Used in the expression (x + 5) + * Used to represent expression tree nodes representing int constants. Used in the expression (x + + * 5) */ class IntNode implements TreeNode { private final Integer value; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/LongNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/LongNode.java index 311c5d94d330..8a2c8812603f 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/LongNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/LongNode.java @@ -14,15 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; /** - * Used to represent expression tree nodes representing long constants. - * Used in the expression (x + 5L) + * Used to represent expression tree nodes representing long constants. Used in the expression (x + + * 5L) */ class LongNode implements TreeNode { private final Long value; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/NullNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/NullNode.java index a8e7d6f82e52..110b367ff835 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/NullNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/NullNode.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/OrNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/OrNode.java index 2dbdfed7c7a6..b8e273a5faf9 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/OrNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/OrNode.java @@ -14,17 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import java.util.List; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; -/** - * Represents a logical OR Node. - */ +/** Represents a logical OR Node. */ class OrNode implements TreeNode { private final List children; diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/StringNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/StringNode.java index a44329739dbe..ad7ff9197aed 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/StringNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/StringNode.java @@ -14,19 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; +import com.google.protobuf.ByteString; import java.nio.charset.Charset; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; -import com.google.protobuf.ByteString; - -/** - * Used to represent expression tree nodes representing utf8 constants. - */ +/** Used to represent expression tree nodes representing utf8 constants. */ class StringNode implements TreeNode { private static final Charset charset = Charset.forName("UTF-8"); private final String value; @@ -37,12 +32,11 @@ public StringNode(String value) { @Override public GandivaTypes.TreeNode toProtobuf() throws GandivaException { - GandivaTypes.StringNode stringNode = GandivaTypes.StringNode.newBuilder() - .setValue(ByteString.copyFrom(value.getBytes(charset))) - .build(); + GandivaTypes.StringNode stringNode = + GandivaTypes.StringNode.newBuilder() + .setValue(ByteString.copyFrom(value.getBytes(charset))) + .build(); - return GandivaTypes.TreeNode.newBuilder() - .setStringNode(stringNode) - .build(); + return GandivaTypes.TreeNode.newBuilder().setStringNode(stringNode).build(); } } diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/TreeBuilder.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/TreeBuilder.java index 3d2ea27d044e..96838e5ad153 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/TreeBuilder.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/TreeBuilder.java @@ -14,27 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Set; - import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.Field; -/** - * Contains helper functions for constructing expression trees. - */ +/** Contains helper functions for constructing expression trees. */ public class TreeBuilder { - private TreeBuilder() { - } + private TreeBuilder() {} - /** - * Helper functions to create literal constants. - */ + /** Helper functions to create literal constants. */ public static TreeNode makeLiteral(Boolean booleanConstant) { return new BooleanNode(booleanConstant); } @@ -67,9 +60,7 @@ public static TreeNode makeDecimalLiteral(String decimalConstant, int precision, return new DecimalNode(decimalConstant, precision, scale); } - /** - * create a null literal. - */ + /** create a null literal. */ public static TreeNode makeNull(ArrowType type) { return new NullNode(type); } @@ -89,12 +80,10 @@ public static TreeNode makeField(Field field) { * * @param function Name of the function, e.g. add * @param children The arguments to the function - * @param retType The type of the return value of the operator + * @param retType The type of the return value of the operator * @return Node representing a function */ - public static TreeNode makeFunction(String function, - List children, - ArrowType retType) { + public static TreeNode makeFunction(String function, List children, ArrowType retType) { return new FunctionNode(function, children, retType); } @@ -102,22 +91,20 @@ public static TreeNode makeFunction(String function, * Invoke this function to create a node representing an if-clause. * * @param condition Node representing the condition - * @param thenNode Node representing the if-block - * @param elseNode Node representing the else-block - * @param retType Return type of the node + * @param thenNode Node representing the if-block + * @param elseNode Node representing the else-block + * @param retType Return type of the node * @return Node representing an if-clause */ - public static TreeNode makeIf(TreeNode condition, - TreeNode thenNode, - TreeNode elseNode, - ArrowType retType) { + public static TreeNode makeIf( + TreeNode condition, TreeNode thenNode, TreeNode elseNode, ArrowType retType) { return new IfNode(condition, thenNode, elseNode, retType); } /** * Invoke this function to create a node representing an and-clause. * - * @param nodes Nodes in the 'and' clause. + * @param nodes Nodes in the 'and' clause. * @return Node representing an and-clause */ public static TreeNode makeAnd(List nodes) { @@ -127,7 +114,7 @@ public static TreeNode makeAnd(List nodes) { /** * Invoke this function to create a node representing an or-clause. * - * @param nodes Nodes in the 'or' clause. + * @param nodes Nodes in the 'or' clause. * @return Node representing an or-clause */ public static TreeNode makeOr(List nodes) { @@ -137,26 +124,24 @@ public static TreeNode makeOr(List nodes) { /** * Invoke this function to create an expression tree. * - * @param root is returned by a call to MakeField, MakeFunction, or MakeIf + * @param root is returned by a call to MakeField, MakeFunction, or MakeIf * @param resultField represents the return value of the expression * @return ExpressionTree referring to the root of an expression tree */ - public static ExpressionTree makeExpression(TreeNode root, - Field resultField) { + public static ExpressionTree makeExpression(TreeNode root, Field resultField) { return new ExpressionTree(root, resultField); } /** * Short cut to create an expression tree involving a single function, e.g. a+b+c. * - * @param function Name of the function, e.g. add() - * @param inFields In arguments to the function + * @param function Name of the function, e.g. add() + * @param inFields In arguments to the function * @param resultField represents the return value of the expression * @return ExpressionTree referring to the root of an expression tree */ - public static ExpressionTree makeExpression(String function, - List inFields, - Field resultField) { + public static ExpressionTree makeExpression( + String function, List inFields, Field resultField) { List children = new ArrayList(inFields.size()); for (Field field : inFields) { children.add(makeField(field)); @@ -169,8 +154,8 @@ public static ExpressionTree makeExpression(String function, /** * Invoke this function to create a condition. * - * @param root is returned by a call to MakeField, MakeFunction, MakeIf, .. - * @return condition referring to the root of an expression tree + * @param root is returned by a call to MakeField, MakeFunction, MakeIf, .. + * @return condition referring to the root of an expression tree */ public static Condition makeCondition(TreeNode root) { return new Condition(root); @@ -179,12 +164,11 @@ public static Condition makeCondition(TreeNode root) { /** * Short cut to create an expression tree involving a single function, e.g. a+b+c. * - * @param function Name of the function, e.g. add() - * @param inFields In arguments to the function - * @return condition referring to the root of an expression tree + * @param function Name of the function, e.g. add() + * @param inFields In arguments to the function + * @return condition referring to the root of an expression tree */ - public static Condition makeCondition(String function, - List inFields) { + public static Condition makeCondition(String function, List inFields) { List children = new ArrayList<>(inFields.size()); for (Field field : inFields) { children.add(makeField(field)); @@ -194,38 +178,32 @@ public static Condition makeCondition(String function, return makeCondition(root); } - public static TreeNode makeInExpressionInt32(TreeNode resultNode, - Set intValues) { + public static TreeNode makeInExpressionInt32(TreeNode resultNode, Set intValues) { return InNode.makeIntInExpr(resultNode, intValues); } - public static TreeNode makeInExpressionBigInt(TreeNode resultNode, - Set longValues) { + public static TreeNode makeInExpressionBigInt(TreeNode resultNode, Set longValues) { return InNode.makeLongInExpr(resultNode, longValues); } - public static TreeNode makeInExpressionDecimal(TreeNode resultNode, - Set decimalValues, Integer precision, Integer scale) { + public static TreeNode makeInExpressionDecimal( + TreeNode resultNode, Set decimalValues, Integer precision, Integer scale) { return InNode.makeDecimalInExpr(resultNode, decimalValues, precision, scale); } - public static TreeNode makeInExpressionFloat(TreeNode resultNode, - Set floatValues) { + public static TreeNode makeInExpressionFloat(TreeNode resultNode, Set floatValues) { return InNode.makeFloatInExpr(resultNode, floatValues); } - public static TreeNode makeInExpressionDouble(TreeNode resultNode, - Set doubleValues) { + public static TreeNode makeInExpressionDouble(TreeNode resultNode, Set doubleValues) { return InNode.makeDoubleInExpr(resultNode, doubleValues); } - public static TreeNode makeInExpressionString(TreeNode resultNode, - Set stringValues) { + public static TreeNode makeInExpressionString(TreeNode resultNode, Set stringValues) { return InNode.makeStringInExpr(resultNode, stringValues); } - public static TreeNode makeInExpressionBinary(TreeNode resultNode, - Set binaryValues) { + public static TreeNode makeInExpressionBinary(TreeNode resultNode, Set binaryValues) { return InNode.makeBinaryInExpr(resultNode, binaryValues); } } diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/TreeNode.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/TreeNode.java index b8d70d6e7684..b79ec6df2153 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/TreeNode.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/expression/TreeNode.java @@ -14,15 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; -/** - * Defines an internal node in the expression tree. - */ +/** Defines an internal node in the expression tree. */ public interface TreeNode { /** * Converts a TreeNode into a protobuf. diff --git a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/BaseEvaluatorTest.java b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/BaseEvaluatorTest.java index 4a36c0405bd2..5646a47a9829 100644 --- a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/BaseEvaluatorTest.java +++ b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/BaseEvaluatorTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import java.math.BigDecimal; @@ -25,7 +24,6 @@ import java.util.Random; import java.util.Set; import java.util.concurrent.TimeUnit; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.expression.Condition; import org.apache.arrow.gandiva.expression.ExpressionTree; @@ -62,10 +60,8 @@ class ProjectEvaluator implements BaseEvaluator { private long elapsedTime = 0; private List outputVectors = new ArrayList<>(); - public ProjectEvaluator(Projector projector, - DataAndVectorGenerator generator, - int numExprs, - int maxRowsInBatch) { + public ProjectEvaluator( + Projector projector, DataAndVectorGenerator generator, int numExprs, int maxRowsInBatch) { this.projector = projector; this.generator = generator; this.numExprs = numExprs; @@ -73,8 +69,8 @@ public ProjectEvaluator(Projector projector, } @Override - public void evaluate(ArrowRecordBatch recordBatch, - BufferAllocator allocator) throws GandivaException { + public void evaluate(ArrowRecordBatch recordBatch, BufferAllocator allocator) + throws GandivaException { // set up output vectors // for each expression, generate the output vector for (int i = 0; i < numExprs; i++) { @@ -111,8 +107,8 @@ public FilterEvaluator(Filter filter) { } @Override - public void evaluate(ArrowRecordBatch recordBatch, - BufferAllocator allocator) throws GandivaException { + public void evaluate(ArrowRecordBatch recordBatch, BufferAllocator allocator) + throws GandivaException { ArrowBuf selectionBuffer = allocator.buffer(recordBatch.getLength() * 2); SelectionVectorInt16 selectionVector = new SelectionVectorInt16(selectionBuffer); @@ -234,7 +230,8 @@ ArrowBuf intBuf(int[] ints) { } DecimalVector decimalVector(String[] values, int precision, int scale) { - DecimalVector vector = new DecimalVector("decimal" + Math.random(), allocator, precision, scale); + DecimalVector vector = + new DecimalVector("decimal" + Math.random(), allocator, precision, scale); vector.allocateNew(); for (int i = 0; i < values.length; i++) { BigDecimal decimal = new BigDecimal(values[i]).setScale(scale); @@ -324,10 +321,12 @@ void generateData(DataAndVectorGenerator generator, int numRecords, ArrowBuf buf } } - private void generateDataAndEvaluate(DataAndVectorGenerator generator, + private void generateDataAndEvaluate( + DataAndVectorGenerator generator, BaseEvaluator evaluator, int numFields, - int numRows, int maxRowsInBatch, + int numRows, + int maxRowsInBatch, int inputFieldSize) throws GandivaException, Exception { int numRemaining = numRows; @@ -368,34 +367,40 @@ private void generateDataAndEvaluate(DataAndVectorGenerator generator, } } - long timedProject(DataAndVectorGenerator generator, - Schema schema, List exprs, - int numRows, int maxRowsInBatch, + long timedProject( + DataAndVectorGenerator generator, + Schema schema, + List exprs, + int numRows, + int maxRowsInBatch, int inputFieldSize) throws GandivaException, Exception { Projector projector = Projector.make(schema, exprs); try { ProjectEvaluator evaluator = new ProjectEvaluator(projector, generator, exprs.size(), maxRowsInBatch); - generateDataAndEvaluate(generator, evaluator, - schema.getFields().size(), numRows, maxRowsInBatch, inputFieldSize); + generateDataAndEvaluate( + generator, evaluator, schema.getFields().size(), numRows, maxRowsInBatch, inputFieldSize); return evaluator.getElapsedMillis(); } finally { projector.close(); } } - long timedFilter(DataAndVectorGenerator generator, - Schema schema, Condition condition, - int numRows, int maxRowsInBatch, + long timedFilter( + DataAndVectorGenerator generator, + Schema schema, + Condition condition, + int numRows, + int maxRowsInBatch, int inputFieldSize) throws GandivaException, Exception { Filter filter = Filter.make(schema, condition); try { FilterEvaluator evaluator = new FilterEvaluator(filter); - generateDataAndEvaluate(generator, evaluator, - schema.getFields().size(), numRows, maxRowsInBatch, inputFieldSize); + generateDataAndEvaluate( + generator, evaluator, schema.getFields().size(), numRows, maxRowsInBatch, inputFieldSize); return evaluator.getElapsedMillis(); } finally { filter.close(); diff --git a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/DecimalTypeUtilTest.java b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/DecimalTypeUtilTest.java index fe51c09e33d5..4ad65c7d4652 100644 --- a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/DecimalTypeUtilTest.java +++ b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/DecimalTypeUtilTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import org.apache.arrow.vector.types.pojo.ArrowType; @@ -27,63 +26,68 @@ public class DecimalTypeUtilTest { public void testOutputTypesForAdd() { ArrowType.Decimal operand1 = getDecimal(30, 10); ArrowType.Decimal operand2 = getDecimal(30, 10); - ArrowType.Decimal resultType = DecimalTypeUtil.getResultTypeForOperation(DecimalTypeUtil - .OperationType.ADD, operand1, operand2); + ArrowType.Decimal resultType = + DecimalTypeUtil.getResultTypeForOperation( + DecimalTypeUtil.OperationType.ADD, operand1, operand2); Assert.assertTrue(getDecimal(31, 10).equals(resultType)); operand1 = getDecimal(30, 6); operand2 = getDecimal(30, 5); - resultType = DecimalTypeUtil.getResultTypeForOperation(DecimalTypeUtil - .OperationType.ADD, operand1, operand2); + resultType = + DecimalTypeUtil.getResultTypeForOperation( + DecimalTypeUtil.OperationType.ADD, operand1, operand2); Assert.assertTrue(getDecimal(32, 6).equals(resultType)); operand1 = getDecimal(30, 10); operand2 = getDecimal(38, 10); - resultType = DecimalTypeUtil.getResultTypeForOperation(DecimalTypeUtil - .OperationType.ADD, operand1, operand2); + resultType = + DecimalTypeUtil.getResultTypeForOperation( + DecimalTypeUtil.OperationType.ADD, operand1, operand2); Assert.assertTrue(getDecimal(38, 9).equals(resultType)); operand1 = getDecimal(38, 10); operand2 = getDecimal(38, 38); - resultType = DecimalTypeUtil.getResultTypeForOperation(DecimalTypeUtil - .OperationType.ADD, operand1, operand2); + resultType = + DecimalTypeUtil.getResultTypeForOperation( + DecimalTypeUtil.OperationType.ADD, operand1, operand2); Assert.assertTrue(getDecimal(38, 9).equals(resultType)); operand1 = getDecimal(38, 10); operand2 = getDecimal(38, 2); - resultType = DecimalTypeUtil.getResultTypeForOperation(DecimalTypeUtil - .OperationType.ADD, operand1, operand2); + resultType = + DecimalTypeUtil.getResultTypeForOperation( + DecimalTypeUtil.OperationType.ADD, operand1, operand2); Assert.assertTrue(getDecimal(38, 6).equals(resultType)); - } @Test public void testOutputTypesForMultiply() { ArrowType.Decimal operand1 = getDecimal(30, 10); ArrowType.Decimal operand2 = getDecimal(30, 10); - ArrowType.Decimal resultType = DecimalTypeUtil.getResultTypeForOperation(DecimalTypeUtil - .OperationType.MULTIPLY, operand1, operand2); + ArrowType.Decimal resultType = + DecimalTypeUtil.getResultTypeForOperation( + DecimalTypeUtil.OperationType.MULTIPLY, operand1, operand2); Assert.assertTrue(getDecimal(38, 6).equals(resultType)); operand1 = getDecimal(38, 10); operand2 = getDecimal(9, 2); - resultType = DecimalTypeUtil.getResultTypeForOperation(DecimalTypeUtil - .OperationType.MULTIPLY, operand1, operand2); + resultType = + DecimalTypeUtil.getResultTypeForOperation( + DecimalTypeUtil.OperationType.MULTIPLY, operand1, operand2); Assert.assertTrue(getDecimal(38, 6).equals(resultType)); - } @Test public void testOutputTypesForMod() { ArrowType.Decimal operand1 = getDecimal(30, 10); ArrowType.Decimal operand2 = getDecimal(28, 7); - ArrowType.Decimal resultType = DecimalTypeUtil.getResultTypeForOperation(DecimalTypeUtil - .OperationType.MOD, operand1, operand2); + ArrowType.Decimal resultType = + DecimalTypeUtil.getResultTypeForOperation( + DecimalTypeUtil.OperationType.MOD, operand1, operand2); Assert.assertTrue(getDecimal(30, 10).equals(resultType)); } private ArrowType.Decimal getDecimal(int precision, int scale) { return new ArrowType.Decimal(precision, scale, 128); } - } diff --git a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistryTest.java b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistryTest.java index a51ac09ba1a5..8711ff045a61 100644 --- a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistryTest.java +++ b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ExpressionRegistryTest.java @@ -14,18 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; +import com.google.common.collect.Lists; import java.util.Set; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.vector.types.pojo.ArrowType; import org.junit.Assert; import org.junit.Test; -import com.google.common.collect.Lists; - public class ExpressionRegistryTest { @Test diff --git a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/FilterProjectTest.java b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/FilterProjectTest.java index 51fc1c2915ed..7ee8cb833afc 100644 --- a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/FilterProjectTest.java +++ b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/FilterProjectTest.java @@ -14,15 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.List; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.expression.Condition; import org.apache.arrow.gandiva.expression.ExpressionTree; @@ -37,8 +36,6 @@ import org.apache.arrow.vector.types.pojo.Schema; import org.junit.Test; -import com.google.common.collect.Lists; - public class FilterProjectTest extends BaseEvaluatorTest { @Test @@ -54,25 +51,34 @@ public void testSimpleSV16() throws GandivaException, Exception { Filter filter = Filter.make(schema, condition); ExpressionTree expression = TreeBuilder.makeExpression("add", Lists.newArrayList(a, b), c); - Projector projector = Projector.make(schema, Lists.newArrayList(expression), SelectionVectorType.SV_INT16); + Projector projector = + Projector.make(schema, Lists.newArrayList(expression), SelectionVectorType.SV_INT16); int numRows = 16; - byte[] validity = new byte[]{(byte) 255, 0}; + byte[] validity = new byte[] {(byte) 255, 0}; // second half is "undefined" - int[] aValues = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - int[] bValues = new int[]{2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 14, 15}; + int[] aValues = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + int[] bValues = new int[] {2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 14, 15}; int[] expected = {3, 7, 11, 15}; verifyTestCaseFor16(filter, projector, numRows, validity, aValues, bValues, expected); } - private void verifyTestCaseFor16(Filter filter, Projector projector, int numRows, byte[] validity, - int[] aValues, int[] bValues, int[] expected) throws GandivaException { + private void verifyTestCaseFor16( + Filter filter, + Projector projector, + int numRows, + byte[] validity, + int[] aValues, + int[] bValues, + int[] expected) + throws GandivaException { ArrowBuf validitya = buf(validity); ArrowBuf valuesa = intBuf(aValues); ArrowBuf validityb = buf(validity); ArrowBuf valuesb = intBuf(bValues); - ArrowRecordBatch batch = new ArrowRecordBatch( + ArrowRecordBatch batch = + new ArrowRecordBatch( numRows, Lists.newArrayList(new ArrowFieldNode(numRows, 0), new ArrowFieldNode(numRows, 0)), Lists.newArrayList(validitya, valuesa, validityb, valuesb)); diff --git a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/FilterTest.java b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/FilterTest.java index ed6e43cd6c40..ff68b060e3ff 100644 --- a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/FilterTest.java +++ b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/FilterTest.java @@ -14,14 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import java.nio.charset.Charset; import java.util.Arrays; import java.util.List; import java.util.stream.IntStream; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.expression.Condition; import org.apache.arrow.gandiva.expression.TreeBuilder; @@ -35,9 +35,6 @@ import org.junit.Assert; import org.junit.Test; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - public class FilterTest extends BaseEvaluatorTest { private int[] selectionVectorToArray(SelectionVector vector) { @@ -83,7 +80,7 @@ public void testSimpleInString() throws GandivaException, Exception { List args = Lists.newArrayList(TreeBuilder.makeField(c1), l1, l2); TreeNode substr = TreeBuilder.makeFunction("substr", args, new ArrowType.Utf8()); TreeNode inExpr = - TreeBuilder.makeInExpressionString(substr, Sets.newHashSet("one", "two", "thr", "fou")); + TreeBuilder.makeInExpressionString(substr, Sets.newHashSet("one", "two", "thr", "fou")); Condition condition = TreeBuilder.makeCondition(inExpr); @@ -93,9 +90,25 @@ public void testSimpleInString() throws GandivaException, Exception { int numRows = 16; byte[] validity = new byte[] {(byte) 255, 0}; // second half is "undefined" - String[] c1Values = new String[]{"one", "two", "three", "four", "five", "six", "seven", - "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", - "sixteen"}; + String[] c1Values = + new String[] { + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", + "ten", + "eleven", + "twelve", + "thirteen", + "fourteen", + "fifteen", + "sixteen" + }; int[] expected = {0, 1, 2, 3}; ArrowBuf c1Validity = buf(validity); ArrowBuf c2Validity = buf(validity); @@ -103,10 +116,10 @@ public void testSimpleInString() throws GandivaException, Exception { ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(fieldNode), - Lists.newArrayList(c1Validity, dataBufsX.get(0), dataBufsX.get(1), c2Validity)); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(fieldNode), + Lists.newArrayList(c1Validity, dataBufsX.get(0), dataBufsX.get(1), c2Validity)); ArrowBuf selectionBuffer = buf(numRows * 2); SelectionVectorInt16 selectionVector = new SelectionVectorInt16(selectionBuffer); @@ -126,7 +139,7 @@ public void testSimpleInInt() throws GandivaException, Exception { List argsSchema = Lists.newArrayList(c1); TreeNode inExpr = - TreeBuilder.makeInExpressionInt32(TreeBuilder.makeField(c1), Sets.newHashSet(1, 2, 3, 4)); + TreeBuilder.makeInExpressionInt32(TreeBuilder.makeField(c1), Sets.newHashSet(1, 2, 3, 4)); Condition condition = TreeBuilder.makeCondition(inExpr); @@ -145,10 +158,10 @@ public void testSimpleInInt() throws GandivaException, Exception { ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(fieldNode), - Lists.newArrayList(validitya, valuesa, validityb)); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(fieldNode), + Lists.newArrayList(validitya, valuesa, validityb)); ArrowBuf selectionBuffer = buf(numRows * 2); SelectionVectorInt16 selectionVector = new SelectionVectorInt16(selectionBuffer); diff --git a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/MicroBenchmarkTest.java b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/MicroBenchmarkTest.java index 6934c3f9e7d1..c7da2f83088b 100644 --- a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/MicroBenchmarkTest.java +++ b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/MicroBenchmarkTest.java @@ -14,11 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; +import com.google.common.collect.Lists; import java.util.List; - import org.apache.arrow.gandiva.expression.Condition; import org.apache.arrow.gandiva.expression.ExpressionTree; import org.apache.arrow.gandiva.expression.TreeBuilder; @@ -29,8 +28,6 @@ import org.junit.Ignore; import org.junit.Test; -import com.google.common.collect.Lists; - @Ignore public class MicroBenchmarkTest extends BaseEvaluatorTest { @@ -54,11 +51,14 @@ public void testAdd3() throws Exception { List cols = Lists.newArrayList(x, n2x, n3x); Schema schema = new Schema(cols); - long timeTaken = timedProject(new Int32DataAndVectorGenerator(allocator), - schema, - Lists.newArrayList(expr), - 1 * MILLION, 16 * THOUSAND, - 4); + long timeTaken = + timedProject( + new Int32DataAndVectorGenerator(allocator), + schema, + Lists.newArrayList(expr), + 1 * MILLION, + 16 * THOUSAND, + 4); System.out.println("Time taken for projecting 1m records of add3 is " + timeTaken + "ms"); Assert.assertTrue(timeTaken <= 13 * toleranceRatio); } @@ -115,11 +115,14 @@ public void testIf() throws Exception { ExpressionTree expr = TreeBuilder.makeExpression(topNode, x); Schema schema = new Schema(Lists.newArrayList(x)); - long timeTaken = timedProject(new BoundedInt32DataAndVectorGenerator(allocator, 250), - schema, - Lists.newArrayList(expr), - 1 * MILLION, 16 * THOUSAND, - 4); + long timeTaken = + timedProject( + new BoundedInt32DataAndVectorGenerator(allocator, 250), + schema, + Lists.newArrayList(expr), + 1 * MILLION, + 16 * THOUSAND, + 4); System.out.println("Time taken for projecting 10m records of nestedIf is " + timeTaken + "ms"); Assert.assertTrue(timeTaken <= 15 * toleranceRatio); } @@ -131,20 +134,25 @@ public void testFilterAdd2() throws Exception { Field n3x = Field.nullable("n3x", int32); // x + n2x < n3x - TreeNode add = TreeBuilder.makeFunction("add", - Lists.newArrayList(TreeBuilder.makeField(x), TreeBuilder.makeField(n2x)), int32); - TreeNode lessThan = TreeBuilder - .makeFunction("less_than", Lists.newArrayList(add, TreeBuilder.makeField(n3x)), boolType); + TreeNode add = + TreeBuilder.makeFunction( + "add", Lists.newArrayList(TreeBuilder.makeField(x), TreeBuilder.makeField(n2x)), int32); + TreeNode lessThan = + TreeBuilder.makeFunction( + "less_than", Lists.newArrayList(add, TreeBuilder.makeField(n3x)), boolType); Condition condition = TreeBuilder.makeCondition(lessThan); List cols = Lists.newArrayList(x, n2x, n3x); Schema schema = new Schema(cols); - long timeTaken = timedFilter(new Int32DataAndVectorGenerator(allocator), - schema, - condition, - 1 * MILLION, 16 * THOUSAND, - 4); + long timeTaken = + timedFilter( + new Int32DataAndVectorGenerator(allocator), + schema, + condition, + 1 * MILLION, + 16 * THOUSAND, + 4); System.out.println("Time taken for filtering 10m records of a+b args = Lists.newArrayList(a, b); - ArrowType.Decimal outputType = DecimalTypeUtil.getResultTypeForOperation(DecimalTypeUtil - .OperationType.ADD, decimal, decimal); + ArrowType.Decimal outputType = + DecimalTypeUtil.getResultTypeForOperation( + DecimalTypeUtil.OperationType.ADD, decimal, decimal); Field retType = Field.nullable("c", outputType); ExpressionTree root = TreeBuilder.makeExpression("add", args, retType); @@ -72,21 +69,25 @@ public void test_add() throws GandivaException { Projector eval = Projector.make(schema, exprs); int numRows = 4; - byte[] validity = new byte[]{(byte) 255}; - String[] aValues = new String[]{"1.12345678", "2.12345678", "3.12345678", "4.12345678"}; - String[] bValues = new String[]{"2.12345678", "3.12345678", "4.12345678", "5.12345678"}; + byte[] validity = new byte[] {(byte) 255}; + String[] aValues = new String[] {"1.12345678", "2.12345678", "3.12345678", "4.12345678"}; + String[] bValues = new String[] {"2.12345678", "3.12345678", "4.12345678", "5.12345678"}; DecimalVector valuesa = decimalVector(aValues, precision, scale); DecimalVector valuesb = decimalVector(bValues, precision, scale); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(new ArrowFieldNode(numRows, 0), new ArrowFieldNode(numRows, 0)), - Lists.newArrayList(valuesa.getValidityBuffer(), valuesa.getDataBuffer(), - valuesb.getValidityBuffer(), valuesb.getDataBuffer())); - - DecimalVector outVector = new DecimalVector("decimal_output", allocator, outputType.getPrecision(), - outputType.getScale()); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(new ArrowFieldNode(numRows, 0), new ArrowFieldNode(numRows, 0)), + Lists.newArrayList( + valuesa.getValidityBuffer(), + valuesa.getDataBuffer(), + valuesb.getValidityBuffer(), + valuesb.getDataBuffer())); + + DecimalVector outVector = + new DecimalVector( + "decimal_output", allocator, outputType.getPrecision(), outputType.getScale()); outVector.allocateNew(numRows); List output = new ArrayList(); @@ -94,15 +95,18 @@ public void test_add() throws GandivaException { eval.evaluate(batch, output); // should have scaled down. - BigDecimal[] expOutput = new BigDecimal[]{BigDecimal.valueOf(3.2469136), - BigDecimal.valueOf(5.2469136), - BigDecimal.valueOf(7.2469136), - BigDecimal.valueOf(9.2469136)}; + BigDecimal[] expOutput = + new BigDecimal[] { + BigDecimal.valueOf(3.2469136), + BigDecimal.valueOf(5.2469136), + BigDecimal.valueOf(7.2469136), + BigDecimal.valueOf(9.2469136) + }; for (int i = 0; i < 4; i++) { assertFalse(outVector.isNull(i)); - assertTrue("index : " + i + " failed compare", expOutput[i].compareTo(outVector.getObject(i) - ) == 0); + assertTrue( + "index : " + i + " failed compare", expOutput[i].compareTo(outVector.getObject(i)) == 0); } // free buffers @@ -119,8 +123,9 @@ public void test_add_literal() throws GandivaException { ArrowType.Decimal literalType = new ArrowType.Decimal(2, 1, 128); Field a = Field.nullable("a", decimal); - ArrowType.Decimal outputType = DecimalTypeUtil.getResultTypeForOperation(DecimalTypeUtil - .OperationType.ADD, decimal, literalType); + ArrowType.Decimal outputType = + DecimalTypeUtil.getResultTypeForOperation( + DecimalTypeUtil.OperationType.ADD, decimal, literalType); Field retType = Field.nullable("c", outputType); TreeNode field = TreeBuilder.makeField(a); TreeNode literal = TreeBuilder.makeDecimalLiteral("6", 2, 1); @@ -134,25 +139,31 @@ public void test_add_literal() throws GandivaException { Projector eval = Projector.make(schema, exprs); int numRows = 4; - String[] aValues = new String[]{"1", "2", "3", "4"}; + String[] aValues = new String[] {"1", "2", "3", "4"}; DecimalVector valuesa = decimalVector(aValues, precision, scale); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(new ArrowFieldNode(numRows, 0)), - Lists.newArrayList(valuesa.getValidityBuffer(), valuesa.getDataBuffer())); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(new ArrowFieldNode(numRows, 0)), + Lists.newArrayList(valuesa.getValidityBuffer(), valuesa.getDataBuffer())); - DecimalVector outVector = new DecimalVector("decimal_output", allocator, outputType.getPrecision(), - outputType.getScale()); + DecimalVector outVector = + new DecimalVector( + "decimal_output", allocator, outputType.getPrecision(), outputType.getScale()); outVector.allocateNew(numRows); List output = new ArrayList(); output.add(outVector); eval.evaluate(batch, output); - BigDecimal[] expOutput = new BigDecimal[]{BigDecimal.valueOf(1.6), BigDecimal.valueOf(2.6), - BigDecimal.valueOf(3.6), BigDecimal.valueOf(4.6)}; + BigDecimal[] expOutput = + new BigDecimal[] { + BigDecimal.valueOf(1.6), + BigDecimal.valueOf(2.6), + BigDecimal.valueOf(3.6), + BigDecimal.valueOf(4.6) + }; for (int i = 0; i < 4; i++) { assertFalse(outVector.isNull(i)); @@ -174,8 +185,9 @@ public void test_multiply() throws GandivaException { Field b = Field.nullable("b", decimal); List args = Lists.newArrayList(a, b); - ArrowType.Decimal outputType = DecimalTypeUtil.getResultTypeForOperation(DecimalTypeUtil - .OperationType.MULTIPLY, decimal, decimal); + ArrowType.Decimal outputType = + DecimalTypeUtil.getResultTypeForOperation( + DecimalTypeUtil.OperationType.MULTIPLY, decimal, decimal); Field retType = Field.nullable("c", outputType); ExpressionTree root = TreeBuilder.makeExpression("multiply", args, retType); @@ -185,9 +197,11 @@ public void test_multiply() throws GandivaException { Projector eval = Projector.make(schema, exprs); int numRows = 4; - byte[] validity = new byte[]{(byte) 255}; - String[] aValues = new String[]{"1.12345678", "2.12345678", "3.12345678", "999999999999.99999999"}; - String[] bValues = new String[]{"2.12345678", "3.12345678", "4.12345678", "999999999999.99999999"}; + byte[] validity = new byte[] {(byte) 255}; + String[] aValues = + new String[] {"1.12345678", "2.12345678", "3.12345678", "999999999999.99999999"}; + String[] bValues = + new String[] {"2.12345678", "3.12345678", "4.12345678", "999999999999.99999999"}; DecimalVector valuesa = decimalVector(aValues, precision, scale); DecimalVector valuesb = decimalVector(bValues, precision, scale); @@ -195,11 +209,15 @@ public void test_multiply() throws GandivaException { new ArrowRecordBatch( numRows, Lists.newArrayList(new ArrowFieldNode(numRows, 0), new ArrowFieldNode(numRows, 0)), - Lists.newArrayList(valuesa.getValidityBuffer(), valuesa.getDataBuffer(), - valuesb.getValidityBuffer(), valuesb.getDataBuffer())); - - DecimalVector outVector = new DecimalVector("decimal_output", allocator, outputType.getPrecision(), - outputType.getScale()); + Lists.newArrayList( + valuesa.getValidityBuffer(), + valuesa.getDataBuffer(), + valuesb.getValidityBuffer(), + valuesb.getDataBuffer())); + + DecimalVector outVector = + new DecimalVector( + "decimal_output", allocator, outputType.getPrecision(), outputType.getScale()); outVector.allocateNew(numRows); List output = new ArrayList(); @@ -207,15 +225,18 @@ public void test_multiply() throws GandivaException { eval.evaluate(batch, output); // should have scaled down. - BigDecimal[] expOutput = new BigDecimal[]{BigDecimal.valueOf(2.385612), - BigDecimal.valueOf(6.632525), - BigDecimal.valueOf(12.879439), - new BigDecimal("999999999999999999980000.000000")}; + BigDecimal[] expOutput = + new BigDecimal[] { + BigDecimal.valueOf(2.385612), + BigDecimal.valueOf(6.632525), + BigDecimal.valueOf(12.879439), + new BigDecimal("999999999999999999980000.000000") + }; for (int i = 0; i < 4; i++) { assertFalse(outVector.isNull(i)); - assertTrue("index : " + i + " failed compare", expOutput[i].compareTo(outVector.getObject(i) - ) == 0); + assertTrue( + "index : " + i + " failed compare", expOutput[i].compareTo(outVector.getObject(i)) == 0); } // free buffers @@ -232,16 +253,17 @@ public void testCompare() throws GandivaException { Field b = Field.nullable("b", bType); List args = Lists.newArrayList(a, b); - List exprs = new ArrayList<>( - Arrays.asList( - TreeBuilder.makeExpression("equal", args, Field.nullable("eq", boolType)), - TreeBuilder.makeExpression("not_equal", args, Field.nullable("ne", boolType)), - TreeBuilder.makeExpression("less_than", args, Field.nullable("lt", boolType)), - TreeBuilder.makeExpression("less_than_or_equal_to", args, Field.nullable("le", boolType)), - TreeBuilder.makeExpression("greater_than", args, Field.nullable("gt", boolType)), - TreeBuilder.makeExpression("greater_than_or_equal_to", args, Field.nullable("ge", boolType)) - ) - ); + List exprs = + new ArrayList<>( + Arrays.asList( + TreeBuilder.makeExpression("equal", args, Field.nullable("eq", boolType)), + TreeBuilder.makeExpression("not_equal", args, Field.nullable("ne", boolType)), + TreeBuilder.makeExpression("less_than", args, Field.nullable("lt", boolType)), + TreeBuilder.makeExpression( + "less_than_or_equal_to", args, Field.nullable("le", boolType)), + TreeBuilder.makeExpression("greater_than", args, Field.nullable("gt", boolType)), + TreeBuilder.makeExpression( + "greater_than_or_equal_to", args, Field.nullable("ge", boolType)))); Schema schema = new Schema(args); Projector eval = Projector.make(schema, exprs); @@ -250,8 +272,8 @@ public void testCompare() throws GandivaException { ArrowRecordBatch batch = null; try { int numRows = 4; - String[] aValues = new String[]{"7.620", "2.380", "3.860", "-18.160"}; - String[] bValues = new String[]{"7.62", "3.50", "1.90", "-1.45"}; + String[] aValues = new String[] {"7.620", "2.380", "3.860", "-18.160"}; + String[] bValues = new String[] {"7.62", "3.50", "1.90", "-1.45"}; DecimalVector valuesa = decimalVector(aValues, aType.getPrecision(), aType.getScale()); DecimalVector valuesb = decimalVector(bValues, bType.getPrecision(), bType.getScale()); @@ -259,30 +281,32 @@ public void testCompare() throws GandivaException { new ArrowRecordBatch( numRows, Lists.newArrayList(new ArrowFieldNode(numRows, 0), new ArrowFieldNode(numRows, 0)), - Lists.newArrayList(valuesa.getValidityBuffer(), valuesa.getDataBuffer(), - valuesb.getValidityBuffer(), valuesb.getDataBuffer())); + Lists.newArrayList( + valuesa.getValidityBuffer(), + valuesa.getDataBuffer(), + valuesb.getValidityBuffer(), + valuesb.getDataBuffer())); // expected results. boolean[][] expected = { - {true, false, false, false}, // eq - {false, true, true, true}, // ne - {false, true, false, true}, // lt - {true, true, false, true}, // le - {false, false, true, false}, // gt - {true, false, true, false}, // ge + {true, false, false, false}, // eq + {false, true, true, true}, // ne + {false, true, false, true}, // lt + {true, true, false, true}, // le + {false, false, true, false}, // gt + {true, false, true, false}, // ge }; // Allocate output vectors. - output = new ArrayList<>( - Arrays.asList( - new BitVector("eq", allocator), - new BitVector("ne", allocator), - new BitVector("lt", allocator), - new BitVector("le", allocator), - new BitVector("gt", allocator), - new BitVector("ge", allocator) - ) - ); + output = + new ArrayList<>( + Arrays.asList( + new BitVector("eq", allocator), + new BitVector("ne", allocator), + new BitVector("lt", allocator), + new BitVector("le", allocator), + new BitVector("gt", allocator), + new BitVector("ge", allocator))); for (ValueVector v : output) { v.allocateNew(); } @@ -297,8 +321,10 @@ public void testCompare() throws GandivaException { for (int i = 0; i < numRows; i++) { assertFalse(resultVector.isNull(i)); - assertEquals("mismatch in result for expr at idx " + idx + " for row " + i, - expectedArray[i], resultVector.getObject(i).booleanValue()); + assertEquals( + "mismatch in result for expr at idx " + idx + " for row " + i, + expectedArray[i], + resultVector.getObject(i).booleanValue()); } } } finally { @@ -321,25 +347,27 @@ public void testRound() throws GandivaException { Field a = Field.nullable("a", aType); List args = Lists.newArrayList(a); - List exprs = new ArrayList<>( - Arrays.asList( - TreeBuilder.makeExpression("abs", args, Field.nullable("abs", aType)), - TreeBuilder.makeExpression("ceil", args, Field.nullable("ceil", aWithScaleZero)), - TreeBuilder.makeExpression("floor", args, Field.nullable("floor", aWithScaleZero)), - TreeBuilder.makeExpression("round", args, Field.nullable("round", aWithScaleZero)), - TreeBuilder.makeExpression("truncate", args, Field.nullable("truncate", aWithScaleZero)), - TreeBuilder.makeExpression( - TreeBuilder.makeFunction("round", - Lists.newArrayList(TreeBuilder.makeField(a), TreeBuilder.makeLiteral(1)), - aWithScaleOne), - Field.nullable("round_scale_1", aWithScaleOne)), - TreeBuilder.makeExpression( - TreeBuilder.makeFunction("truncate", - Lists.newArrayList(TreeBuilder.makeField(a), TreeBuilder.makeLiteral(1)), - aWithScaleOne), - Field.nullable("truncate_scale_1", aWithScaleOne)) - ) - ); + List exprs = + new ArrayList<>( + Arrays.asList( + TreeBuilder.makeExpression("abs", args, Field.nullable("abs", aType)), + TreeBuilder.makeExpression("ceil", args, Field.nullable("ceil", aWithScaleZero)), + TreeBuilder.makeExpression("floor", args, Field.nullable("floor", aWithScaleZero)), + TreeBuilder.makeExpression("round", args, Field.nullable("round", aWithScaleZero)), + TreeBuilder.makeExpression( + "truncate", args, Field.nullable("truncate", aWithScaleZero)), + TreeBuilder.makeExpression( + TreeBuilder.makeFunction( + "round", + Lists.newArrayList(TreeBuilder.makeField(a), TreeBuilder.makeLiteral(1)), + aWithScaleOne), + Field.nullable("round_scale_1", aWithScaleOne)), + TreeBuilder.makeExpression( + TreeBuilder.makeFunction( + "truncate", + Lists.newArrayList(TreeBuilder.makeField(a), TreeBuilder.makeLiteral(1)), + aWithScaleOne), + Field.nullable("truncate_scale_1", aWithScaleOne)))); Schema schema = new Schema(args); Projector eval = Projector.make(schema, exprs); @@ -348,7 +376,7 @@ public void testRound() throws GandivaException { ArrowRecordBatch batch = null; try { int numRows = 4; - String[] aValues = new String[]{"1.23", "1.58", "-1.23", "-1.58"}; + String[] aValues = new String[] {"1.23", "1.58", "-1.23", "-1.58"}; DecimalVector valuesa = decimalVector(aValues, aType.getPrecision(), aType.getScale()); batch = @@ -359,30 +387,61 @@ public void testRound() throws GandivaException { // expected results. BigDecimal[][] expected = { - {BigDecimal.valueOf(1.23), BigDecimal.valueOf(1.58), - BigDecimal.valueOf(1.23), BigDecimal.valueOf(1.58)}, // abs - {BigDecimal.valueOf(2), BigDecimal.valueOf(2), BigDecimal.valueOf(-1), BigDecimal.valueOf(-1)}, // ceil - {BigDecimal.valueOf(1), BigDecimal.valueOf(1), BigDecimal.valueOf(-2), BigDecimal.valueOf(-2)}, // floor - {BigDecimal.valueOf(1), BigDecimal.valueOf(2), BigDecimal.valueOf(-1), BigDecimal.valueOf(-2)}, // round - {BigDecimal.valueOf(1), BigDecimal.valueOf(1), BigDecimal.valueOf(-1), BigDecimal.valueOf(-1)}, // truncate - {BigDecimal.valueOf(1.2), BigDecimal.valueOf(1.6), - BigDecimal.valueOf(-1.2), BigDecimal.valueOf(-1.6)}, // round-to-scale-1 - {BigDecimal.valueOf(1.2), BigDecimal.valueOf(1.5), - BigDecimal.valueOf(-1.2), BigDecimal.valueOf(-1.5)}, // truncate-to-scale-1 + { + BigDecimal.valueOf(1.23), + BigDecimal.valueOf(1.58), + BigDecimal.valueOf(1.23), + BigDecimal.valueOf(1.58) + }, // abs + { + BigDecimal.valueOf(2), + BigDecimal.valueOf(2), + BigDecimal.valueOf(-1), + BigDecimal.valueOf(-1) + }, // ceil + { + BigDecimal.valueOf(1), + BigDecimal.valueOf(1), + BigDecimal.valueOf(-2), + BigDecimal.valueOf(-2) + }, // floor + { + BigDecimal.valueOf(1), + BigDecimal.valueOf(2), + BigDecimal.valueOf(-1), + BigDecimal.valueOf(-2) + }, // round + { + BigDecimal.valueOf(1), + BigDecimal.valueOf(1), + BigDecimal.valueOf(-1), + BigDecimal.valueOf(-1) + }, // truncate + { + BigDecimal.valueOf(1.2), + BigDecimal.valueOf(1.6), + BigDecimal.valueOf(-1.2), + BigDecimal.valueOf(-1.6) + }, // round-to-scale-1 + { + BigDecimal.valueOf(1.2), + BigDecimal.valueOf(1.5), + BigDecimal.valueOf(-1.2), + BigDecimal.valueOf(-1.5) + }, // truncate-to-scale-1 }; // Allocate output vectors. - output = new ArrayList<>( - Arrays.asList( - new DecimalVector("abs", allocator, aType.getPrecision(), aType.getScale()), - new DecimalVector("ceil", allocator, aType.getPrecision(), 0), - new DecimalVector("floor", allocator, aType.getPrecision(), 0), - new DecimalVector("round", allocator, aType.getPrecision(), 0), - new DecimalVector("truncate", allocator, aType.getPrecision(), 0), - new DecimalVector("round_to_scale_1", allocator, aType.getPrecision(), 1), - new DecimalVector("truncate_to_scale_1", allocator, aType.getPrecision(), 1) - ) - ); + output = + new ArrayList<>( + Arrays.asList( + new DecimalVector("abs", allocator, aType.getPrecision(), aType.getScale()), + new DecimalVector("ceil", allocator, aType.getPrecision(), 0), + new DecimalVector("floor", allocator, aType.getPrecision(), 0), + new DecimalVector("round", allocator, aType.getPrecision(), 0), + new DecimalVector("truncate", allocator, aType.getPrecision(), 0), + new DecimalVector("round_to_scale_1", allocator, aType.getPrecision(), 1), + new DecimalVector("truncate_to_scale_1", allocator, aType.getPrecision(), 1))); for (ValueVector v : output) { v.allocateNew(); } @@ -397,11 +456,16 @@ public void testRound() throws GandivaException { for (int i = 0; i < numRows; i++) { assertFalse(resultVector.isNull(i)); - assertTrue("mismatch in result for " + - "field " + resultVector.getField().getName() + - " for row " + i + - " expected " + expectedArray[i] + - ", got " + resultVector.getObject(i), + assertTrue( + "mismatch in result for " + + "field " + + resultVector.getField().getName() + + " for row " + + i + + " expected " + + expectedArray[i] + + ", got " + + resultVector.getObject(i), expectedArray[i].compareTo(resultVector.getObject(i)) == 0); } } @@ -425,21 +489,21 @@ public void testCastToDecimal() throws GandivaException { Field int64f = Field.nullable("int64", int64); Field doublef = Field.nullable("float64", float64); - List exprs = new ArrayList<>( - Arrays.asList( - TreeBuilder.makeExpression("castDECIMAL", - Lists.newArrayList(int64f), - Field.nullable("int64_to_dec", decimalType)), - - TreeBuilder.makeExpression("castDECIMAL", - Lists.newArrayList(doublef), - Field.nullable("float64_to_dec", decimalType)), - - TreeBuilder.makeExpression("castDECIMAL", - Lists.newArrayList(dec), - Field.nullable("dec_to_dec", decimalWithScaleOne)) - ) - ); + List exprs = + new ArrayList<>( + Arrays.asList( + TreeBuilder.makeExpression( + "castDECIMAL", + Lists.newArrayList(int64f), + Field.nullable("int64_to_dec", decimalType)), + TreeBuilder.makeExpression( + "castDECIMAL", + Lists.newArrayList(doublef), + Field.nullable("float64_to_dec", decimalType)), + TreeBuilder.makeExpression( + "castDECIMAL", + Lists.newArrayList(dec), + Field.nullable("dec_to_dec", decimalWithScaleOne)))); Schema schema = new Schema(Lists.newArrayList(int64f, doublef, dec)); Projector eval = Projector.make(schema, exprs); @@ -448,32 +512,43 @@ public void testCastToDecimal() throws GandivaException { ArrowRecordBatch batch = null; try { int numRows = 4; - String[] aValues = new String[]{"1.23", "1.58", "-1.23", "-1.58"}; - DecimalVector valuesa = decimalVector(aValues, decimalType.getPrecision(), decimalType.getScale()); - batch = new ArrowRecordBatch( - numRows, - Lists.newArrayList( - new ArrowFieldNode(numRows, 0), - new ArrowFieldNode(numRows, 0), - new ArrowFieldNode(numRows, 0)), - Lists.newArrayList( - arrowBufWithAllValid(4), - longBuf(new long[]{123, 158, -123, -158}), - arrowBufWithAllValid(4), - doubleBuf(new double[]{1.23, 1.58, -1.23, -1.58}), - valuesa.getValidityBuffer(), - valuesa.getDataBuffer()) - ); + String[] aValues = new String[] {"1.23", "1.58", "-1.23", "-1.58"}; + DecimalVector valuesa = + decimalVector(aValues, decimalType.getPrecision(), decimalType.getScale()); + batch = + new ArrowRecordBatch( + numRows, + Lists.newArrayList( + new ArrowFieldNode(numRows, 0), + new ArrowFieldNode(numRows, 0), + new ArrowFieldNode(numRows, 0)), + Lists.newArrayList( + arrowBufWithAllValid(4), + longBuf(new long[] {123, 158, -123, -158}), + arrowBufWithAllValid(4), + doubleBuf(new double[] {1.23, 1.58, -1.23, -1.58}), + valuesa.getValidityBuffer(), + valuesa.getDataBuffer())); // Allocate output vectors. - output = new ArrayList<>( - Arrays.asList( - new DecimalVector("int64_to_dec", allocator, decimalType.getPrecision(), decimalType.getScale()), - new DecimalVector("float64_to_dec", allocator, decimalType.getPrecision(), decimalType.getScale()), - new DecimalVector("dec_to_dec", allocator, - decimalWithScaleOne.getPrecision(), decimalWithScaleOne.getScale()) - ) - ); + output = + new ArrayList<>( + Arrays.asList( + new DecimalVector( + "int64_to_dec", + allocator, + decimalType.getPrecision(), + decimalType.getScale()), + new DecimalVector( + "float64_to_dec", + allocator, + decimalType.getPrecision(), + decimalType.getScale()), + new DecimalVector( + "dec_to_dec", + allocator, + decimalWithScaleOne.getPrecision(), + decimalWithScaleOne.getScale()))); for (ValueVector v : output) { v.allocateNew(); } @@ -483,24 +558,41 @@ public void testCastToDecimal() throws GandivaException { // compare the outputs. BigDecimal[][] expected = { - { BigDecimal.valueOf(123), BigDecimal.valueOf(158), - BigDecimal.valueOf(-123), BigDecimal.valueOf(-158)}, - { BigDecimal.valueOf(1.23), BigDecimal.valueOf(1.58), - BigDecimal.valueOf(-1.23), BigDecimal.valueOf(-1.58)}, - { BigDecimal.valueOf(1.2), BigDecimal.valueOf(1.6), - BigDecimal.valueOf(-1.2), BigDecimal.valueOf(-1.6)} + { + BigDecimal.valueOf(123), + BigDecimal.valueOf(158), + BigDecimal.valueOf(-123), + BigDecimal.valueOf(-158) + }, + { + BigDecimal.valueOf(1.23), + BigDecimal.valueOf(1.58), + BigDecimal.valueOf(-1.23), + BigDecimal.valueOf(-1.58) + }, + { + BigDecimal.valueOf(1.2), + BigDecimal.valueOf(1.6), + BigDecimal.valueOf(-1.2), + BigDecimal.valueOf(-1.6) + } }; for (int idx = 0; idx < output.size(); ++idx) { BigDecimal[] expectedArray = expected[idx]; DecimalVector resultVector = (DecimalVector) output.get(idx); for (int i = 0; i < numRows; i++) { assertFalse(resultVector.isNull(i)); - assertTrue("mismatch in result for " + - "field " + resultVector.getField().getName() + - " for row " + i + - " expected " + expectedArray[i] + - ", got " + resultVector.getObject(i), - expectedArray[i].compareTo(resultVector.getObject(i)) == 0); + assertTrue( + "mismatch in result for " + + "field " + + resultVector.getField().getName() + + " for row " + + i + + " expected " + + expectedArray[i] + + ", got " + + resultVector.getObject(i), + expectedArray[i].compareTo(resultVector.getObject(i)) == 0); } } } finally { @@ -521,31 +613,25 @@ public void testCastToLong() throws GandivaException { Field dec = Field.nullable("dec", decimalType); Schema schema = new Schema(Lists.newArrayList(dec)); - Projector eval = Projector.make(schema, - Lists.newArrayList( - TreeBuilder.makeExpression("castBIGINT", - Lists.newArrayList(dec), - Field.nullable("dec_to_int64", int64) - ) - ) - ); + Projector eval = + Projector.make( + schema, + Lists.newArrayList( + TreeBuilder.makeExpression( + "castBIGINT", Lists.newArrayList(dec), Field.nullable("dec_to_int64", int64)))); List output = null; ArrowRecordBatch batch = null; try { int numRows = 5; - String[] aValues = new String[]{"1.23", "1.50", "98765.78", "-1.23", "-1.58"}; - DecimalVector valuesa = decimalVector(aValues, decimalType.getPrecision(), decimalType.getScale()); - batch = new ArrowRecordBatch( - numRows, - Lists.newArrayList( - new ArrowFieldNode(numRows, 0) - ), - Lists.newArrayList( - valuesa.getValidityBuffer(), - valuesa.getDataBuffer() - ) - ); + String[] aValues = new String[] {"1.23", "1.50", "98765.78", "-1.23", "-1.58"}; + DecimalVector valuesa = + decimalVector(aValues, decimalType.getPrecision(), decimalType.getScale()); + batch = + new ArrowRecordBatch( + numRows, + Lists.newArrayList(new ArrowFieldNode(numRows, 0)), + Lists.newArrayList(valuesa.getValidityBuffer(), valuesa.getDataBuffer())); // Allocate output vectors. BigIntVector resultVector = new BigIntVector("dec_to_int64", allocator); @@ -579,31 +665,27 @@ public void testCastToDouble() throws GandivaException { Field dec = Field.nullable("dec", decimalType); Schema schema = new Schema(Lists.newArrayList(dec)); - Projector eval = Projector.make(schema, - Lists.newArrayList( - TreeBuilder.makeExpression("castFLOAT8", - Lists.newArrayList(dec), - Field.nullable("dec_to_float64", float64) - ) - ) - ); + Projector eval = + Projector.make( + schema, + Lists.newArrayList( + TreeBuilder.makeExpression( + "castFLOAT8", + Lists.newArrayList(dec), + Field.nullable("dec_to_float64", float64)))); List output = null; ArrowRecordBatch batch = null; try { int numRows = 4; - String[] aValues = new String[]{"1.23", "1.58", "-1.23", "-1.58"}; - DecimalVector valuesa = decimalVector(aValues, decimalType.getPrecision(), decimalType.getScale()); - batch = new ArrowRecordBatch( - numRows, - Lists.newArrayList( - new ArrowFieldNode(numRows, 0) - ), - Lists.newArrayList( - valuesa.getValidityBuffer(), - valuesa.getDataBuffer() - ) - ); + String[] aValues = new String[] {"1.23", "1.58", "-1.23", "-1.58"}; + DecimalVector valuesa = + decimalVector(aValues, decimalType.getPrecision(), decimalType.getScale()); + batch = + new ArrowRecordBatch( + numRows, + Lists.newArrayList(new ArrowFieldNode(numRows, 0)), + Lists.newArrayList(valuesa.getValidityBuffer(), valuesa.getDataBuffer())); // Allocate output vectors. Float8Vector resultVector = new Float8Vector("dec_to_float64", allocator); @@ -640,35 +722,34 @@ public void testCastToString() throws GandivaException { TreeNode literal = TreeBuilder.makeLiteral(5L); List args = Lists.newArrayList(field, literal); TreeNode cast = TreeBuilder.makeFunction("castVARCHAR", args, new ArrowType.Utf8()); - TreeNode root = TreeBuilder.makeFunction("equal", - Lists.newArrayList(cast, TreeBuilder.makeField(str)), new ArrowType.Bool()); - ExpressionTree tree = TreeBuilder.makeExpression(root, Field.nullable("are_equal", new ArrowType.Bool())); + TreeNode root = + TreeBuilder.makeFunction( + "equal", Lists.newArrayList(cast, TreeBuilder.makeField(str)), new ArrowType.Bool()); + ExpressionTree tree = + TreeBuilder.makeExpression(root, Field.nullable("are_equal", new ArrowType.Bool())); Schema schema = new Schema(Lists.newArrayList(dec, str)); - Projector eval = Projector.make(schema, Lists.newArrayList(tree) - ); + Projector eval = Projector.make(schema, Lists.newArrayList(tree)); List output = null; ArrowRecordBatch batch = null; try { int numRows = 4; - String[] aValues = new String[]{"10.51", "100.23", "-1000.23", "-0000.10"}; + String[] aValues = new String[] {"10.51", "100.23", "-1000.23", "-0000.10"}; String[] expected = {"10.51", "100.2", "-1000", "-0.10"}; - DecimalVector valuesa = decimalVector(aValues, decimalType.getPrecision(), decimalType.getScale()); + DecimalVector valuesa = + decimalVector(aValues, decimalType.getPrecision(), decimalType.getScale()); VarCharVector result = varcharVector(expected); - batch = new ArrowRecordBatch( - numRows, - Lists.newArrayList( - new ArrowFieldNode(numRows, 0) - ), - Lists.newArrayList( - valuesa.getValidityBuffer(), - valuesa.getDataBuffer(), - result.getValidityBuffer(), - result.getOffsetBuffer(), - result.getDataBuffer() - ) - ); + batch = + new ArrowRecordBatch( + numRows, + Lists.newArrayList(new ArrowFieldNode(numRows, 0)), + Lists.newArrayList( + valuesa.getValidityBuffer(), + valuesa.getDataBuffer(), + result.getValidityBuffer(), + result.getOffsetBuffer(), + result.getDataBuffer())); BitVector resultVector = new BitVector("res", allocator); resultVector.allocateNew(); @@ -705,44 +786,48 @@ public void testCastStringToDecimal() throws GandivaException { ExpressionTree tree = TreeBuilder.makeExpression(cast, Field.nullable("dec_str", decimalType)); Schema schema = new Schema(Lists.newArrayList(str)); - Projector eval = Projector.make(schema, Lists.newArrayList(tree) - ); + Projector eval = Projector.make(schema, Lists.newArrayList(tree)); List output = null; ArrowRecordBatch batch = null; try { int numRows = 4; - String[] aValues = new String[]{"10.5134", "-0.1", "10.516", "-1000"}; + String[] aValues = new String[] {"10.5134", "-0.1", "10.516", "-1000"}; VarCharVector valuesa = varcharVector(aValues); - batch = new ArrowRecordBatch( - numRows, - Lists.newArrayList( - new ArrowFieldNode(numRows, 0) - ), - Lists.newArrayList( - valuesa.getValidityBuffer(), - valuesa.getOffsetBuffer(), - valuesa.getDataBuffer() - ) - ); - - DecimalVector resultVector = new DecimalVector("res", allocator, - decimalType.getPrecision(), decimalType.getScale()); + batch = + new ArrowRecordBatch( + numRows, + Lists.newArrayList(new ArrowFieldNode(numRows, 0)), + Lists.newArrayList( + valuesa.getValidityBuffer(), valuesa.getOffsetBuffer(), valuesa.getDataBuffer())); + + DecimalVector resultVector = + new DecimalVector("res", allocator, decimalType.getPrecision(), decimalType.getScale()); resultVector.allocateNew(); output = new ArrayList<>(Arrays.asList(resultVector)); - BigDecimal[] expected = {BigDecimal.valueOf(10.51), BigDecimal.valueOf(-0.10), - BigDecimal.valueOf(10.52), BigDecimal.valueOf(0.00)}; + BigDecimal[] expected = { + BigDecimal.valueOf(10.51), + BigDecimal.valueOf(-0.10), + BigDecimal.valueOf(10.52), + BigDecimal.valueOf(0.00) + }; // evaluate expressions. eval.evaluate(batch, output); // compare the outputs. for (int i = 0; i < numRows; i++) { - assertTrue("mismatch in result for " + - "field " + resultVector.getField().getName() + - " for row " + i + - " expected " + expected[i] + - ", got " + resultVector.getObject(i), expected[i].compareTo(resultVector.getObject(i)) == 0); + assertTrue( + "mismatch in result for " + + "field " + + resultVector.getField().getName() + + " for row " + + i + + " expected " + + expected[i] + + ", got " + + resultVector.getObject(i), + expected[i].compareTo(resultVector.getObject(i)) == 0); } } finally { // free buffers @@ -759,39 +844,38 @@ public void testCastStringToDecimal() throws GandivaException { @Test public void testInvalidDecimal() throws GandivaException { exception.expect(IllegalArgumentException.class); - exception.expectMessage("Gandiva only supports decimals of upto 38 precision. Input precision" + - " : 0"); + exception.expectMessage( + "Gandiva only supports decimals of upto 38 precision. Input precision" + " : 0"); Decimal decimalType = new Decimal(0, 0, 128); Field int64f = Field.nullable("int64", int64); Schema schema = new Schema(Lists.newArrayList(int64f)); - Projector eval = Projector.make(schema, + Projector eval = + Projector.make( + schema, Lists.newArrayList( - TreeBuilder.makeExpression("castDECIMAL", - Lists.newArrayList(int64f), - Field.nullable("invalid_dec", decimalType) - ) - ) - ); + TreeBuilder.makeExpression( + "castDECIMAL", + Lists.newArrayList(int64f), + Field.nullable("invalid_dec", decimalType)))); } @Test public void testInvalidDecimalGt38() throws GandivaException { exception.expect(IllegalArgumentException.class); - exception.expectMessage("Gandiva only supports decimals of upto 38 precision. Input precision" + - " : 42"); + exception.expectMessage( + "Gandiva only supports decimals of upto 38 precision. Input precision" + " : 42"); Decimal decimalType = new Decimal(42, 0, 128); Field int64f = Field.nullable("int64", int64); Schema schema = new Schema(Lists.newArrayList(int64f)); - Projector eval = Projector.make(schema, + Projector eval = + Projector.make( + schema, Lists.newArrayList( - TreeBuilder.makeExpression("castDECIMAL", - Lists.newArrayList(int64f), - Field.nullable("invalid_dec", decimalType) - ) - ) - ); + TreeBuilder.makeExpression( + "castDECIMAL", + Lists.newArrayList(int64f), + Field.nullable("invalid_dec", decimalType)))); } } - diff --git a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorTest.java b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorTest.java index fce983fdeca6..547190390896 100644 --- a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorTest.java +++ b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/ProjectorTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import static org.junit.Assert.assertEquals; @@ -22,6 +21,8 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import java.math.BigDecimal; import java.nio.charset.Charset; import java.time.Instant; @@ -33,7 +34,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.IntStream; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.expression.ExpressionTree; import org.apache.arrow.gandiva.expression.TreeBuilder; @@ -64,16 +64,12 @@ import org.junit.Test; import org.junit.rules.ExpectedException; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - public class ProjectorTest extends BaseEvaluatorTest { private Charset utf8Charset = Charset.forName("UTF-8"); private Charset utf16Charset = Charset.forName("UTF-16"); - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule public ExpectedException thrown = ExpectedException.none(); List varBufs(String[] strings, Charset charset) { ArrowBuf offsetsBuffer = allocator.buffer((strings.length + 1) * 4); @@ -107,7 +103,8 @@ List binaryBufs(String[] strings) { return varBufs(strings, utf16Charset); } - private void testMakeProjectorParallel(ConfigurationBuilder.ConfigOptions configOptions) throws InterruptedException { + private void testMakeProjectorParallel(ConfigurationBuilder.ConfigOptions configOptions) + throws InterruptedException { List schemas = Lists.newArrayList(); Field a = Field.nullable("a", int64); Field b = Field.nullable("b", int64); @@ -140,9 +137,11 @@ private void testMakeProjectorParallel(ConfigurationBuilder.ConfigOptions config executors.submit( () -> { try { - Projector evaluator = configOptions == null ? - Projector.make(schemas.get((int) (Math.random() * 100)), exprs) : - Projector.make(schemas.get((int) (Math.random() * 100)), exprs, configOptions); + Projector evaluator = + configOptions == null + ? Projector.make(schemas.get((int) (Math.random() * 100)), exprs) + : Projector.make( + schemas.get((int) (Math.random() * 100)), exprs, configOptions); evaluator.close(); } catch (GandivaException e) { e.printStackTrace(); @@ -157,7 +156,8 @@ private void testMakeProjectorParallel(ConfigurationBuilder.ConfigOptions config public void testMakeProjectorParallel() throws Exception { testMakeProjectorParallel(null); testMakeProjectorParallel(new ConfigurationBuilder.ConfigOptions().withTargetCPU(false)); - testMakeProjectorParallel(new ConfigurationBuilder.ConfigOptions().withTargetCPU(false).withOptimize(false)); + testMakeProjectorParallel( + new ConfigurationBuilder.ConfigOptions().withTargetCPU(false).withOptimize(false)); } // Will be fixed by https://issues.apache.org/jira/browse/ARROW-4371 @@ -252,10 +252,10 @@ public void testEvaluate() throws GandivaException, Exception { Projector eval = Projector.make(schema, exprs); int numRows = 16; - byte[] validity = new byte[]{(byte) 255, 0}; + byte[] validity = new byte[] {(byte) 255, 0}; // second half is "undefined" - int[] aValues = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - int[] bValues = new int[]{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; + int[] aValues = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + int[] bValues = new int[] {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; ArrowBuf validitya = buf(validity); ArrowBuf valuesa = intBuf(aValues); @@ -303,19 +303,20 @@ public void testEvaluateDivZero() throws GandivaException, Exception { Projector eval = Projector.make(schema, exprs); int numRows = 2; - byte[] validity = new byte[]{(byte) 255}; + byte[] validity = new byte[] {(byte) 255}; // second half is "undefined" - int[] aValues = new int[]{2, 2}; - int[] bValues = new int[]{1, 0}; + int[] aValues = new int[] {2, 2}; + int[] bValues = new int[] {1, 0}; ArrowBuf validitya = buf(validity); ArrowBuf valuesa = intBuf(aValues); ArrowBuf validityb = buf(validity); ArrowBuf valuesb = intBuf(bValues); - ArrowRecordBatch batch = new ArrowRecordBatch( - numRows, - Lists.newArrayList(new ArrowFieldNode(numRows, 0), new ArrowFieldNode(numRows, 0)), - Lists.newArrayList(validitya, valuesa, validityb, valuesb)); + ArrowRecordBatch batch = + new ArrowRecordBatch( + numRows, + Lists.newArrayList(new ArrowFieldNode(numRows, 0), new ArrowFieldNode(numRows, 0)), + Lists.newArrayList(validitya, valuesa, validityb, valuesb)); IntVector intVector = new IntVector(EMPTY_SCHEMA_PATH, allocator); intVector.allocateNew(numRows); @@ -357,49 +358,53 @@ public void testDivZeroParallel() throws GandivaException, InterruptedException // pre-build the projector so that same projector is used for all executions. Projector test = Projector.make(s, exprs); - IntStream.range(0, 1000).forEach(i -> { - executors.submit(() -> { - try { - Projector evaluator = Projector.make(s, exprs); - int numRows = 2; - byte[] validity = new byte[]{(byte) 255}; - int[] aValues = new int[]{2, 2}; - int[] bValues; - if (i % 2 == 0) { - errorCountExp.incrementAndGet(); - bValues = new int[]{1, 0}; - } else { - bValues = new int[]{1, 1}; - } - - ArrowBuf validitya = buf(validity); - ArrowBuf valuesa = intBuf(aValues); - ArrowBuf validityb = buf(validity); - ArrowBuf valuesb = intBuf(bValues); - ArrowRecordBatch batch = new ArrowRecordBatch( - numRows, - Lists.newArrayList(new ArrowFieldNode(numRows, 0), new ArrowFieldNode(numRows, - 0)), - Lists.newArrayList(validitya, valuesa, validityb, valuesb)); - - IntVector intVector = new IntVector(EMPTY_SCHEMA_PATH, allocator); - intVector.allocateNew(numRows); - - List output = new ArrayList(); - output.add(intVector); - try { - evaluator.evaluate(batch, output); - } catch (GandivaException e) { - errorCount.incrementAndGet(); - } - // free buffers - releaseRecordBatch(batch); - releaseValueVectors(output); - evaluator.close(); - } catch (GandivaException ignore) { - } - }); - }); + IntStream.range(0, 1000) + .forEach( + i -> { + executors.submit( + () -> { + try { + Projector evaluator = Projector.make(s, exprs); + int numRows = 2; + byte[] validity = new byte[] {(byte) 255}; + int[] aValues = new int[] {2, 2}; + int[] bValues; + if (i % 2 == 0) { + errorCountExp.incrementAndGet(); + bValues = new int[] {1, 0}; + } else { + bValues = new int[] {1, 1}; + } + + ArrowBuf validitya = buf(validity); + ArrowBuf valuesa = intBuf(aValues); + ArrowBuf validityb = buf(validity); + ArrowBuf valuesb = intBuf(bValues); + ArrowRecordBatch batch = + new ArrowRecordBatch( + numRows, + Lists.newArrayList( + new ArrowFieldNode(numRows, 0), new ArrowFieldNode(numRows, 0)), + Lists.newArrayList(validitya, valuesa, validityb, valuesb)); + + IntVector intVector = new IntVector(EMPTY_SCHEMA_PATH, allocator); + intVector.allocateNew(numRows); + + List output = new ArrayList(); + output.add(intVector); + try { + evaluator.evaluate(batch, output); + } catch (GandivaException e) { + errorCount.incrementAndGet(); + } + // free buffers + releaseRecordBatch(batch); + releaseValueVectors(output); + evaluator.close(); + } catch (GandivaException ignore) { + } + }); + }); executors.shutdown(); executors.awaitTermination(100, java.util.concurrent.TimeUnit.SECONDS); test.close(); @@ -429,13 +434,13 @@ public void testAdd3() throws GandivaException, Exception { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 16; - byte[] validity = new byte[]{(byte) 255, 0}; + byte[] validity = new byte[] {(byte) 255, 0}; // second half is "undefined" - int[] xValues = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - int[] n2xValues = new int[]{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; - int[] n3xValues = new int[]{1, 2, 3, 4, 4, 3, 2, 1, 5, 6, 7, 8, 8, 7, 6, 5}; + int[] xValues = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + int[] n2xValues = new int[] {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; + int[] n3xValues = new int[] {1, 2, 3, 4, 4, 3, 2, 1, 5, 6, 7, 8, 8, 7, 6, 5}; - int[] expected = new int[]{18, 19, 20, 21, 21, 20, 19, 18, 18, 19, 20, 21, 21, 20, 19, 18}; + int[] expected = new int[] {18, 19, 20, 21, 21, 20, 19, 18, 18, 19, 20, 21, 21, 20, 19, 18}; ArrowBuf xValidity = buf(validity); ArrowBuf xData = intBuf(xValues); @@ -506,12 +511,12 @@ public void testStringFields() throws GandivaException { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 5; - byte[] validity = new byte[]{(byte) 255, 0}; + byte[] validity = new byte[] {(byte) 255, 0}; // "A função" means "The function" in portugese - String[] valuesX = new String[]{"hell", "abc", "hellox", "ijk", "A função"}; - int[] valuesA = new int[]{10, 20, 30, 40, 50}; - int[] valuesB = new int[]{110, 120, 130, 140, 150}; - int[] expected = new int[]{14, 23, 136, 143, 60}; + String[] valuesX = new String[] {"hell", "abc", "hellox", "ijk", "A função"}; + int[] valuesA = new int[] {10, 20, 30, 40, 50}; + int[] valuesB = new int[] {110, 120, 130, 140, 150}; + int[] expected = new int[] {14, 23, 136, 143, 60}; ArrowBuf validityX = buf(validity); List dataBufsX = stringBufs(valuesX); @@ -554,17 +559,15 @@ public void testStringOutput() throws GandivaException { ArrowType retType = new ArrowType.Utf8(); - TreeNode ifHiBye = TreeBuilder.makeIf( - TreeBuilder.makeFunction( - "greater_than_or_equal_to", - Lists.newArrayList( - TreeBuilder.makeField(x), - TreeBuilder.makeLiteral(0) - ), - boolType), - TreeBuilder.makeStringLiteral("hi"), - TreeBuilder.makeStringLiteral("bye"), - retType); + TreeNode ifHiBye = + TreeBuilder.makeIf( + TreeBuilder.makeFunction( + "greater_than_or_equal_to", + Lists.newArrayList(TreeBuilder.makeField(x), TreeBuilder.makeLiteral(0)), + boolType), + TreeBuilder.makeStringLiteral("hi"), + TreeBuilder.makeStringLiteral("bye"), + retType); ExpressionTree expr = TreeBuilder.makeExpression(ifHiBye, Field.nullable("res", retType)); Schema schema = new Schema(Lists.newArrayList(x)); @@ -572,22 +575,21 @@ public void testStringOutput() throws GandivaException { // fill up input record batch int numRows = 4; - byte[] validity = new byte[]{(byte) 255, 0}; - int[] xValues = new int[]{10, -10, 20, -20}; - String[] expected = new String[]{"hi", "bye", "hi", "bye"}; + byte[] validity = new byte[] {(byte) 255, 0}; + int[] xValues = new int[] {10, -10, 20, -20}; + String[] expected = new String[] {"hi", "bye", "hi", "bye"}; ArrowBuf validityX = buf(validity); ArrowBuf dataX = intBuf(xValues); ArrowRecordBatch batch = new ArrowRecordBatch( numRows, Lists.newArrayList(new ArrowFieldNode(numRows, 0)), - Lists.newArrayList( validityX, dataX)); + Lists.newArrayList(validityX, dataX)); // allocate data for output vector. VarCharVector outVector = new VarCharVector(EMPTY_SCHEMA_PATH, allocator); outVector.allocateNew(64, numRows); - // evaluate expression List output = new ArrayList<>(); output.add(outVector); @@ -628,9 +630,9 @@ public void testRegex() throws GandivaException { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 5; - byte[] validity = new byte[]{(byte) 255, 0}; - String[] valuesX = new String[]{"mapD", "maps", "google maps", "map", "MapR"}; - boolean[] expected = new boolean[]{true, true, true, true, false}; + byte[] validity = new byte[] {(byte) 255, 0}; + String[] valuesX = new String[] {"mapD", "maps", "google maps", "map", "MapR"}; + boolean[] expected = new boolean[] {true, true, true, true, false}; ArrowBuf validityX = buf(validity); List dataBufsX = stringBufs(valuesX); @@ -667,20 +669,22 @@ public void testRegexpReplace() throws GandivaException { Field retType = Field.nullable("c", new ArrowType.Utf8()); TreeNode cond = - TreeBuilder.makeFunction( - "regexp_replace", - Lists.newArrayList(TreeBuilder.makeField(x), TreeBuilder.makeStringLiteral("ana"), - TreeBuilder.makeField(replaceString)), - new ArrowType.Utf8()); + TreeBuilder.makeFunction( + "regexp_replace", + Lists.newArrayList( + TreeBuilder.makeField(x), + TreeBuilder.makeStringLiteral("ana"), + TreeBuilder.makeField(replaceString)), + new ArrowType.Utf8()); ExpressionTree expr = TreeBuilder.makeExpression(cond, retType); Schema schema = new Schema(Lists.newArrayList(x, replaceString)); Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 5; - byte[] validity = new byte[]{(byte) 15, 0}; - String[] valuesX = new String[]{"banana", "bananaana", "bananana", "anaana", "anaana"}; - String[] valuesReplace = new String[]{"ue", "", "", "c", ""}; - String[] expected = new String[]{"buena", "bna", "bn", "cc", null}; + byte[] validity = new byte[] {(byte) 15, 0}; + String[] valuesX = new String[] {"banana", "bananaana", "bananana", "anaana", "anaana"}; + String[] valuesReplace = new String[] {"ue", "", "", "c", ""}; + String[] expected = new String[] {"buena", "bna", "bn", "cc", null}; ArrowBuf validityX = buf(validity); ArrowBuf validityReplace = buf(validity); @@ -690,11 +694,16 @@ public void testRegexpReplace() throws GandivaException { ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(fieldNode, fieldNode), - Lists.newArrayList(validityX, dataBufsX.get(0), dataBufsX.get(1), validityReplace, - dataBufsReplace.get(0), dataBufsReplace.get(1))); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(fieldNode, fieldNode), + Lists.newArrayList( + validityX, + dataBufsX.get(0), + dataBufsX.get(1), + validityReplace, + dataBufsReplace.get(0), + dataBufsReplace.get(1))); // allocate data for output vector. VarCharVector outVector = new VarCharVector(EMPTY_SCHEMA_PATH, allocator); @@ -726,23 +735,21 @@ public void testCastIntervalDay() throws GandivaException { Field retType = Field.nullable("c", new ArrowType.Interval(IntervalUnit.DAY_TIME)); TreeNode cond = - TreeBuilder.makeFunction( - "castintervalday", - Lists.newArrayList(TreeBuilder.makeField(x)), - new ArrowType.Interval(IntervalUnit.DAY_TIME)); + TreeBuilder.makeFunction( + "castintervalday", + Lists.newArrayList(TreeBuilder.makeField(x)), + new ArrowType.Interval(IntervalUnit.DAY_TIME)); ExpressionTree expr = TreeBuilder.makeExpression(cond, retType); Schema schema = new Schema(Lists.newArrayList(x)); Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 4; - byte[] validity = new byte[]{(byte) 7, 0}; - String[] valuesX = new String[]{"1742461111", "P1Y1M1DT1H1M1S", "PT48H1M1S", "test"}; + byte[] validity = new byte[] {(byte) 7, 0}; + String[] valuesX = new String[] {"1742461111", "P1Y1M1DT1H1M1S", "PT48H1M1S", "test"}; int[][] expected = - new int[][]{ // day and millis - {20, 14461111}, - {1, 3661000}, - {2, 61000}, - null}; + new int[][] { // day and millis + {20, 14461111}, {1, 3661000}, {2, 61000}, null + }; ArrowBuf validityX = buf(validity); List dataBufsX = stringBufs(valuesX); @@ -750,10 +757,10 @@ public void testCastIntervalDay() throws GandivaException { ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(fieldNode, fieldNode), - Lists.newArrayList(validityX, dataBufsX.get(0), dataBufsX.get(1))); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(fieldNode, fieldNode), + Lists.newArrayList(validityX, dataBufsX.get(0), dataBufsX.get(1))); // allocate data for output vector. IntervalDayVector outVector = new IntervalDayVector(EMPTY_SCHEMA_PATH, allocator); @@ -789,23 +796,21 @@ public void testCastIntervalYear() throws GandivaException { Field retType = Field.nullable("c", new ArrowType.Interval(IntervalUnit.YEAR_MONTH)); TreeNode cond = - TreeBuilder.makeFunction( - "castintervalyear", - Lists.newArrayList(TreeBuilder.makeField(x)), - new ArrowType.Interval(IntervalUnit.YEAR_MONTH)); + TreeBuilder.makeFunction( + "castintervalyear", + Lists.newArrayList(TreeBuilder.makeField(x)), + new ArrowType.Interval(IntervalUnit.YEAR_MONTH)); ExpressionTree expr = TreeBuilder.makeExpression(cond, retType); Schema schema = new Schema(Lists.newArrayList(x)); Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 4; - byte[] validity = new byte[]{(byte) 7, 0}; - String[] valuesX = new String[]{"65851111", "P1Y1M1DT1H1M1S", "P1Y", "test"}; + byte[] validity = new byte[] {(byte) 7, 0}; + String[] valuesX = new String[] {"65851111", "P1Y1M1DT1H1M1S", "P1Y", "test"}; int[][] expected = - new int[][]{ // year and month - {0, 65851111}, - {1, 1}, - {1, 0}, - null}; + new int[][] { // year and month + {0, 65851111}, {1, 1}, {1, 0}, null + }; ArrowBuf validityX = buf(validity); List dataBufsX = stringBufs(valuesX); @@ -813,10 +818,10 @@ public void testCastIntervalYear() throws GandivaException { ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(fieldNode, fieldNode), - Lists.newArrayList(validityX, dataBufsX.get(0), dataBufsX.get(1))); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(fieldNode, fieldNode), + Lists.newArrayList(validityX, dataBufsX.get(0), dataBufsX.get(1))); // allocate data for output vector. IntervalYearVector outVector = new IntervalYearVector(EMPTY_SCHEMA_PATH, allocator); @@ -834,7 +839,9 @@ public void testCastIntervalYear() throws GandivaException { assertFalse("Expect none value equals null", outVector.isNull(i)); outVector.get(i, holder); - int numberMonths = expected[i][0] * 12 + // number of years + int numberMonths = + expected[i][0] * 12 + + // number of years expected[i][1]; // number of months assertEquals(numberMonths, holder.value); @@ -850,16 +857,10 @@ public void testCastIntervalYear() throws GandivaException { public void testRand() throws GandivaException { TreeNode randWithSeed = - TreeBuilder.makeFunction( - "rand", - Lists.newArrayList(TreeBuilder.makeLiteral(12)), - float64); - TreeNode rand = - TreeBuilder.makeFunction( - "rand", - Lists.newArrayList(), - float64); - ExpressionTree exprWithSeed = TreeBuilder.makeExpression(randWithSeed, Field.nullable("res", float64)); + TreeBuilder.makeFunction("rand", Lists.newArrayList(TreeBuilder.makeLiteral(12)), float64); + TreeNode rand = TreeBuilder.makeFunction("rand", Lists.newArrayList(), float64); + ExpressionTree exprWithSeed = + TreeBuilder.makeExpression(randWithSeed, Field.nullable("res", float64)); ExpressionTree expr = TreeBuilder.makeExpression(rand, Field.nullable("res2", float64)); Field x = Field.nullable("x", new ArrowType.Utf8()); Schema schema = new Schema(Lists.newArrayList(x)); @@ -869,8 +870,14 @@ public void testRand() throws GandivaException { int numRows = 5; byte[] validity = new byte[] {(byte) 255, 0}; String[] valuesX = new String[] {"mapD", "maps", "google maps", "map", "MapR"}; - double[] expected = new double[] {0.1597116001879662D, 0.7347813877263527D, 0.6069965050584282D, - 0.7240285696335824D, 0.09975540272957834D}; + double[] expected = + new double[] { + 0.1597116001879662D, + 0.7347813877263527D, + 0.6069965050584282D, + 0.7240285696335824D, + 0.09975540272957834D + }; ArrowBuf validityX = buf(validity); List dataBufsX = stringBufs(valuesX); @@ -915,10 +922,10 @@ public void testBinaryFields() throws GandivaException { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 5; - byte[] validity = new byte[]{(byte) 255, 0}; - String[] valuesA = new String[]{"a", "aa", "aaa", "aaaa", "A função"}; - String[] valuesB = new String[]{"a", "bb", "aaa", "bbbbb", "A função"}; - boolean[] expected = new boolean[]{true, false, true, false, true}; + byte[] validity = new byte[] {(byte) 255, 0}; + String[] valuesA = new String[] {"a", "aa", "aaa", "aaaa", "A função"}; + String[] valuesB = new String[] {"a", "bb", "aaa", "bbbbb", "A função"}; + boolean[] expected = new boolean[] {true, false, true, false, true}; ArrowBuf validitya = buf(validity); ArrowBuf validityb = buf(validity); @@ -1014,9 +1021,9 @@ public void testIf() throws GandivaException, Exception { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 16; - byte[] validity = new byte[]{(byte) 255, (byte) 255}; - long[] xValues = new long[]{9, 15, 21, 32, 43, 54, 65, 76, 87, 98, 109, 200, -10, 60, 77, 80}; - long[] expected = new long[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 0, 6, 7, 8}; + byte[] validity = new byte[] {(byte) 255, (byte) 255}; + long[] xValues = new long[] {9, 15, 21, 32, 43, 54, 65, 76, 87, 98, 109, 200, -10, 60, 77, 80}; + long[] expected = new long[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 0, 6, 7, 8}; ArrowBuf bufValidity = buf(validity); ArrowBuf xData = longBuf(xValues); @@ -1063,9 +1070,9 @@ public void testAnd() throws GandivaException, Exception { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 4; - byte[] validity = new byte[]{(byte) 255}; - long[] xValues = new long[]{9, 15, 17, 25}; - boolean[] expected = new boolean[]{false, true, true, false}; + byte[] validity = new byte[] {(byte) 255}; + long[] xValues = new long[] {9, 15, 17, 25}; + boolean[] expected = new boolean[] {false, true, true, false}; ArrowBuf bufValidity = buf(validity); ArrowBuf xData = longBuf(xValues); @@ -1112,9 +1119,9 @@ public void testOr() throws GandivaException, Exception { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 4; - byte[] validity = new byte[]{(byte) 255}; - long[] xValues = new long[]{4, 9, 15, 17}; - boolean[] expected = new boolean[]{true, false, true, true}; + byte[] validity = new byte[] {(byte) 255}; + long[] xValues = new long[] {4, 9, 15, 17}; + boolean[] expected = new boolean[] {true, false, true, true}; ArrowBuf bufValidity = buf(validity); ArrowBuf xData = longBuf(xValues); @@ -1160,9 +1167,9 @@ public void testNull() throws GandivaException, Exception { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 2; - byte[] validity = new byte[]{(byte) 255}; - long[] xValues = new long[]{5, 32}; - long[] expected = new long[]{1, 0}; + byte[] validity = new byte[] {(byte) 255}; + long[] xValues = new long[] {5, 32}; + long[] expected = new long[] {1, 0}; ArrowBuf bufValidity = buf(validity); ArrowBuf xData = longBuf(xValues); @@ -1204,8 +1211,8 @@ public void testTimeNull() throws GandivaException, Exception { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 2; - byte[] validity = new byte[]{(byte) 255}; - int[] xValues = new int[]{5, 32}; + byte[] validity = new byte[] {(byte) 255}; + int[] xValues = new int[] {5, 32}; ArrowBuf bufValidity = buf(validity); ArrowBuf xData = intBuf(xValues); @@ -1231,10 +1238,11 @@ public void testTimeNull() throws GandivaException, Exception { } @Test - public void testTimeEquals() throws GandivaException, Exception { /* - * when isnotnull(x) then x - * else y - */ + public void testTimeEquals() throws GandivaException, Exception { + /* + * when isnotnull(x) then x + * else y + */ Field x = Field.nullable("x", new ArrowType.Time(TimeUnit.MILLISECOND, 32)); TreeNode xNode = TreeBuilder.makeField(x); @@ -1242,24 +1250,20 @@ public void testTimeEquals() throws GandivaException, Exception { /* TreeNode yNode = TreeBuilder.makeField(y); // if isnotnull(x) then x else y - TreeNode condition = TreeBuilder.makeFunction("isnotnull", Lists.newArrayList(xNode), - boolType); - TreeNode ifCoalesce = TreeBuilder.makeIf( - condition, - xNode, - yNode, - new ArrowType.Time(TimeUnit.MILLISECOND, 32)); + TreeNode condition = TreeBuilder.makeFunction("isnotnull", Lists.newArrayList(xNode), boolType); + TreeNode ifCoalesce = + TreeBuilder.makeIf(condition, xNode, yNode, new ArrowType.Time(TimeUnit.MILLISECOND, 32)); ExpressionTree expr = TreeBuilder.makeExpression(ifCoalesce, x); Schema schema = new Schema(Lists.newArrayList(x, y)); Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 2; - byte[] validity = new byte[]{(byte) 1}; - byte[] yValidity = new byte[]{(byte) 3}; - int[] xValues = new int[]{5, 1}; - int[] yValues = new int[]{10, 2}; - int[] expected = new int[]{5, 2}; + byte[] validity = new byte[] {(byte) 1}; + byte[] yValidity = new byte[] {(byte) 3}; + int[] xValues = new int[] {5, 1}; + int[] yValues = new int[] {10, 2}; + int[] expected = new int[] {5, 2}; ArrowBuf bufValidity = buf(validity); ArrowBuf xData = intBuf(xValues); @@ -1268,10 +1272,11 @@ public void testTimeEquals() throws GandivaException, Exception { /* ArrowBuf yData = intBuf(yValues); ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); - ArrowRecordBatch batch = new ArrowRecordBatch( - numRows, - Lists.newArrayList(fieldNode), - Lists.newArrayList(bufValidity, xData, yBufValidity, yData)); + ArrowRecordBatch batch = + new ArrowRecordBatch( + numRows, + Lists.newArrayList(fieldNode), + Lists.newArrayList(bufValidity, xData, yBufValidity, yData)); IntVector intVector = new IntVector(EMPTY_SCHEMA_PATH, allocator); intVector.allocateNew(numRows); @@ -1301,10 +1306,10 @@ public void testIsNull() throws GandivaException, Exception { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 16; - byte[] validity = new byte[]{(byte) 255, 0}; + byte[] validity = new byte[] {(byte) 255, 0}; double[] xValues = - new double[]{ - 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 + new double[] { + 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 }; ArrowBuf bufValidity = buf(validity); @@ -1348,9 +1353,9 @@ public void testEquals() throws GandivaException, Exception { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 16; - byte[] validity = new byte[]{(byte) 255, 0}; - int[] c1Values = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - int[] c2Values = new int[]{1, 2, 3, 4, 8, 7, 6, 5, 16, 15, 14, 13, 12, 11, 10, 9}; + byte[] validity = new byte[] {(byte) 255, 0}; + int[] c1Values = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + int[] c2Values = new int[] {1, 2, 3, 4, 8, 7, 6, 5, 16, 15, 14, 13, 12, 11, 10, 9}; ArrowBuf c1Validity = buf(validity); ArrowBuf c1Data = intBuf(c1Values); @@ -1391,14 +1396,15 @@ public void testInExpr() throws GandivaException, Exception { Field c1 = Field.nullable("c1", int32); TreeNode inExpr = - TreeBuilder.makeInExpressionInt32(TreeBuilder.makeField(c1), Sets.newHashSet(1, 2, 3, 4, 5, 15, 16)); + TreeBuilder.makeInExpressionInt32( + TreeBuilder.makeField(c1), Sets.newHashSet(1, 2, 3, 4, 5, 15, 16)); ExpressionTree expr = TreeBuilder.makeExpression(inExpr, Field.nullable("result", boolType)); Schema schema = new Schema(Lists.newArrayList(c1)); Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 16; - byte[] validity = new byte[]{(byte) 255, 0}; - int[] c1Values = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + byte[] validity = new byte[] {(byte) 255, 0}; + int[] c1Values = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; ArrowBuf c1Validity = buf(validity); ArrowBuf c1Data = intBuf(c1Values); @@ -1437,25 +1443,39 @@ public void testInExprDecimal() throws GandivaException, Exception { ArrowType.Decimal decimal = new ArrowType.Decimal(precision, scale, 128); Field c1 = Field.nullable("c1", decimal); - String[] values = new String[]{"1", "2", "3", "4"}; + String[] values = new String[] {"1", "2", "3", "4"}; Set decimalSet = decimalSet(values, scale); decimalSet.add(new BigDecimal(-0.0)); decimalSet.add(new BigDecimal(Long.MAX_VALUE)); decimalSet.add(new BigDecimal(Long.MIN_VALUE)); TreeNode inExpr = - TreeBuilder.makeInExpressionDecimal(TreeBuilder.makeField(c1), - decimalSet, precision, scale); - ExpressionTree expr = TreeBuilder.makeExpression(inExpr, - Field.nullable("result", boolType)); + TreeBuilder.makeInExpressionDecimal( + TreeBuilder.makeField(c1), decimalSet, precision, scale); + ExpressionTree expr = TreeBuilder.makeExpression(inExpr, Field.nullable("result", boolType)); Schema schema = new Schema(Lists.newArrayList(c1)); Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 16; - byte[] validity = new byte[]{(byte) 255, 0}; + byte[] validity = new byte[] {(byte) 255, 0}; String[] c1Values = - new String[]{"1", "2", "3", "4", "-0.0", "6", "7", "8", "9", "10", "11", "12", "13", "14", - String.valueOf(Long.MAX_VALUE), - String.valueOf(Long.MIN_VALUE)}; + new String[] { + "1", + "2", + "3", + "4", + "-0.0", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + String.valueOf(Long.MAX_VALUE), + String.valueOf(Long.MIN_VALUE) + }; DecimalVector c1Data = decimalVector(c1Values, precision, scale); ArrowBuf c1Validity = buf(validity); @@ -1491,9 +1511,16 @@ public void testInExprDouble() throws GandivaException, Exception { Field c1 = Field.nullable("c1", float64); TreeNode inExpr = - TreeBuilder.makeInExpressionDouble(TreeBuilder.makeField(c1), - Sets.newHashSet(1.0, -0.0, 3.0, 4.0, Double.NaN, - Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY)); + TreeBuilder.makeInExpressionDouble( + TreeBuilder.makeField(c1), + Sets.newHashSet( + 1.0, + -0.0, + 3.0, + 4.0, + Double.NaN, + Double.POSITIVE_INFINITY, + Double.NEGATIVE_INFINITY)); ExpressionTree expr = TreeBuilder.makeExpression(inExpr, Field.nullable("result", boolType)); Schema schema = new Schema(Lists.newArrayList(c1)); Projector eval = Projector.make(schema, Lists.newArrayList(expr)); @@ -1501,9 +1528,26 @@ public void testInExprDouble() throws GandivaException, Exception { // Create a row-batch with some sample data to look for int numRows = 16; // Only the first 8 values will be valid. - byte[] validity = new byte[]{(byte) 255, 0}; - double[] c1Values = new double[]{1, -0.0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN, - 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 3}; + byte[] validity = new byte[] {(byte) 255, 0}; + double[] c1Values = + new double[] { + 1, + -0.0, + Double.NEGATIVE_INFINITY, + Double.POSITIVE_INFINITY, + Double.NaN, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 4, + 3 + }; ArrowBuf c1Validity = buf(validity); ArrowBuf c1Data = doubleBuf(c1Values); @@ -1551,10 +1595,26 @@ public void testInExprStrings() throws GandivaException, Exception { Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 16; - byte[] validity = new byte[]{(byte) 255, 0}; - String[] c1Values = new String[]{"one", "two", "three", "four", "five", "six", "seven", - "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", - "sixteen"}; + byte[] validity = new byte[] {(byte) 255, 0}; + String[] c1Values = + new String[] { + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", + "ten", + "eleven", + "twelve", + "thirteen", + "fourteen", + "fifteen", + "sixteen" + }; ArrowBuf c1Validity = buf(validity); List dataBufsX = stringBufs(c1Values); @@ -1601,10 +1661,10 @@ public void testSmallOutputVectors() throws GandivaException, Exception { Projector eval = Projector.make(schema, exprs); int numRows = 16; - byte[] validity = new byte[]{(byte) 255, 0}; + byte[] validity = new byte[] {(byte) 255, 0}; // second half is "undefined" - int[] aValues = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - int[] bValues = new int[]{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; + int[] aValues = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + int[] bValues = new int[] {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; ArrowBuf aValidity = buf(validity); ArrowBuf aData = intBuf(aValues); @@ -1686,27 +1746,27 @@ public void testDateTime() throws GandivaException, Exception { Projector eval = Projector.make(schema, exprs); int numRows = 8; - byte[] validity = new byte[]{(byte) 255}; + byte[] validity = new byte[] {(byte) 255}; String[] values = - new String[]{ - "2007-01-01T01:00:00.00Z", - "2007-03-05T03:40:00.00Z", - "2008-05-31T13:55:00.00Z", - "2000-06-30T23:20:00.00Z", - "2000-07-10T20:30:00.00Z", - "2000-08-20T00:14:00.00Z", - "2000-09-30T02:29:00.00Z", - "2000-10-31T05:33:00.00Z" + new String[] { + "2007-01-01T01:00:00.00Z", + "2007-03-05T03:40:00.00Z", + "2008-05-31T13:55:00.00Z", + "2000-06-30T23:20:00.00Z", + "2000-07-10T20:30:00.00Z", + "2000-08-20T00:14:00.00Z", + "2000-09-30T02:29:00.00Z", + "2000-10-31T05:33:00.00Z" }; - long[] expYearFromDate = new long[]{2007, 2007, 2008, 2000, 2000, 2000, 2000, 2000}; - long[] expMonthFromDate = new long[]{1, 3, 5, 6, 7, 8, 9, 10}; - long[] expDayFromDate = new long[]{1, 5, 31, 30, 10, 20, 30, 31}; - long[] expHourFromDate = new long[]{1, 3, 13, 23, 20, 0, 2, 5}; - long[] expMinFromDate = new long[]{0, 40, 55, 20, 30, 14, 29, 33}; + long[] expYearFromDate = new long[] {2007, 2007, 2008, 2000, 2000, 2000, 2000, 2000}; + long[] expMonthFromDate = new long[] {1, 3, 5, 6, 7, 8, 9, 10}; + long[] expDayFromDate = new long[] {1, 5, 31, 30, 10, 20, 30, 31}; + long[] expHourFromDate = new long[] {1, 3, 13, 23, 20, 0, 2, 5}; + long[] expMinFromDate = new long[] {0, 40, 55, 20, 30, 14, 29, 33}; long[][] expValues = - new long[][]{ - expYearFromDate, expMonthFromDate, expDayFromDate, expHourFromDate, expMinFromDate + new long[][] { + expYearFromDate, expMonthFromDate, expDayFromDate, expHourFromDate, expMinFromDate }; ArrowBuf bufValidity = buf(validity); @@ -1765,27 +1825,30 @@ public void testDateTrunc() throws Exception { Projector eval = Projector.make(schema, exprs); int numRows = 4; - byte[] validity = new byte[]{(byte) 255}; - String[] values = new String[]{ - "2007-01-01T01:00:00.00Z", - "2007-03-05T03:40:00.00Z", - "2008-05-31T13:55:00.00Z", - "2000-06-30T23:20:00.00Z", - }; - String[] expYearFromDate = new String[]{ - "2007-01-01T00:00:00.00Z", - "2007-01-01T00:00:00.00Z", - "2008-01-01T00:00:00.00Z", - "2000-01-01T00:00:00.00Z", - }; - String[] expMonthFromDate = new String[]{ - "2007-01-01T00:00:00.00Z", - "2007-03-01T00:00:00.00Z", - "2008-05-01T00:00:00.00Z", - "2000-06-01T00:00:00.00Z", - }; - - String[][] expValues = new String[][]{ expYearFromDate, expMonthFromDate}; + byte[] validity = new byte[] {(byte) 255}; + String[] values = + new String[] { + "2007-01-01T01:00:00.00Z", + "2007-03-05T03:40:00.00Z", + "2008-05-31T13:55:00.00Z", + "2000-06-30T23:20:00.00Z", + }; + String[] expYearFromDate = + new String[] { + "2007-01-01T00:00:00.00Z", + "2007-01-01T00:00:00.00Z", + "2008-01-01T00:00:00.00Z", + "2000-01-01T00:00:00.00Z", + }; + String[] expMonthFromDate = + new String[] { + "2007-01-01T00:00:00.00Z", + "2007-03-01T00:00:00.00Z", + "2008-05-01T00:00:00.00Z", + "2000-06-01T00:00:00.00Z", + }; + + String[][] expValues = new String[][] {expYearFromDate, expMonthFromDate}; ArrowBuf bufValidity = buf(validity); ArrowBuf millisData = stringToMillis(values); @@ -1793,9 +1856,7 @@ public void testDateTrunc() throws Exception { ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); ArrowRecordBatch batch = new ArrowRecordBatch( - numRows, - Lists.newArrayList(fieldNode), - Lists.newArrayList(bufValidity, millisData)); + numRows, Lists.newArrayList(fieldNode), Lists.newArrayList(bufValidity, millisData)); List output = new ArrayList(); for (int i = 0; i < exprs.size(); i++) { @@ -1852,13 +1913,13 @@ public void testCastTimestampToString() throws Exception { TreeNode tsNode = TreeBuilder.makeField(tsField); TreeNode lenNode = TreeBuilder.makeField(lenField); - TreeNode tsToString = TreeBuilder.makeFunction("castVARCHAR", Lists.newArrayList(tsNode, lenNode), - new ArrowType.Utf8()); + TreeNode tsToString = + TreeBuilder.makeFunction( + "castVARCHAR", Lists.newArrayList(tsNode, lenNode), new ArrowType.Utf8()); Field resultField = Field.nullable("result", new ArrowType.Utf8()); List exprs = - Lists.newArrayList( - TreeBuilder.makeExpression(tsToString, resultField)); + Lists.newArrayList(TreeBuilder.makeExpression(tsToString, resultField)); Schema schema = new Schema(Lists.newArrayList(tsField, lenField)); Projector eval = Projector.make(schema, exprs); @@ -1867,24 +1928,21 @@ public void testCastTimestampToString() throws Exception { byte[] validity = new byte[] {(byte) 255}; String[] values = new String[] { - "0007-01-01T01:00:00Z", - "2007-03-05T03:40:00Z", - "2008-05-31T13:55:00Z", - "2000-06-30T23:20:00Z", - "2000-07-10T20:30:00Z", - }; - long[] lenValues = - new long[] { - 23L, 24L, 22L, 0L, 4L + "0007-01-01T01:00:00Z", + "2007-03-05T03:40:00Z", + "2008-05-31T13:55:00Z", + "2000-06-30T23:20:00Z", + "2000-07-10T20:30:00Z", }; + long[] lenValues = new long[] {23L, 24L, 22L, 0L, 4L}; String[] expValues = new String[] { - "0007-01-01 01:00:00.000", - "2007-03-05 03:40:00.000", - "2008-05-31 13:55:00.00", - "", - "2000", + "0007-01-01 01:00:00.000", + "2007-03-05 03:40:00.000", + "2008-05-31 13:55:00.00", + "", + "2000", }; ArrowBuf bufValidity = buf(validity); @@ -1930,34 +1988,34 @@ public void testCastDayIntervalToBigInt() throws Exception { TreeNode intervalNode = TreeBuilder.makeField(dayIntervalField); - TreeNode intervalToBigint = TreeBuilder.makeFunction("castBIGINT", Lists.newArrayList(intervalNode), int64); + TreeNode intervalToBigint = + TreeBuilder.makeFunction("castBIGINT", Lists.newArrayList(intervalNode), int64); Field resultField = Field.nullable("result", int64); List exprs = - Lists.newArrayList( - TreeBuilder.makeExpression(intervalToBigint, resultField)); + Lists.newArrayList(TreeBuilder.makeExpression(intervalToBigint, resultField)); Schema schema = new Schema(Lists.newArrayList(dayIntervalField)); Projector eval = Projector.make(schema, exprs); int numRows = 5; - byte[] validity = new byte[]{(byte) 255}; + byte[] validity = new byte[] {(byte) 255}; String[] values = - new String[]{ - "1 0", // "days millis" - "2 0", - "1 1", - "10 5000", - "11 86400001", + new String[] { + "1 0", // "days millis" + "2 0", + "1 1", + "10 5000", + "11 86400001", }; Long[] expValues = - new Long[]{ - 86400000L, - 2 * 86400000L, - 86400000L + 1L, - 10 * 86400000L + 5000L, - 11 * 86400000L + 86400001L + new Long[] { + 86400000L, + 2 * 86400000L, + 86400000L + 1L, + 10 * 86400000L + 5000L, + 11 * 86400000L + 86400001L }; ArrowBuf bufValidity = buf(validity); @@ -2000,8 +2058,7 @@ public void testCaseInsensitiveFunctions() throws Exception { TreeNode tsNode = TreeBuilder.makeField(tsField); - TreeNode extractday = TreeBuilder.makeFunction("extractday", Lists.newArrayList(tsNode), - int64); + TreeNode extractday = TreeBuilder.makeFunction("extractday", Lists.newArrayList(tsNode), int64); ExpressionTree expr = TreeBuilder.makeExpression(extractday, Field.nullable("result", int64)); Schema schema = new Schema(Lists.newArrayList(tsField)); @@ -2011,28 +2068,22 @@ public void testCaseInsensitiveFunctions() throws Exception { byte[] validity = new byte[] {(byte) 255}; String[] values = new String[] { - "0007-01-01T01:00:00Z", - "2007-03-05T03:40:00Z", - "2008-05-31T13:55:00Z", - "2000-06-30T23:20:00Z", - "2000-07-10T20:30:00Z", + "0007-01-01T01:00:00Z", + "2007-03-05T03:40:00Z", + "2008-05-31T13:55:00Z", + "2000-06-30T23:20:00Z", + "2000-07-10T20:30:00Z", }; - long[] expValues = - new long[] { - 1, 5, 31, 30, 10 - }; + long[] expValues = new long[] {1, 5, 31, 30, 10}; ArrowBuf bufValidity = buf(validity); ArrowBuf millisData = stringToMillis(values); - ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); ArrowRecordBatch batch = new ArrowRecordBatch( - numRows, - Lists.newArrayList(fieldNode), - Lists.newArrayList(bufValidity, millisData)); + numRows, Lists.newArrayList(fieldNode), Lists.newArrayList(bufValidity, millisData)); List output = new ArrayList<>(); BigIntVector bigIntVector = new BigIntVector(EMPTY_SCHEMA_PATH, allocator); @@ -2059,24 +2110,16 @@ public void testCaseInsensitiveFunctions() throws Exception { public void testCastInt() throws Exception { Field inField = Field.nullable("input", new ArrowType.Utf8()); TreeNode inNode = TreeBuilder.makeField(inField); - TreeNode castINTFn = TreeBuilder.makeFunction("castINT", Lists.newArrayList(inNode), - int32); + TreeNode castINTFn = TreeBuilder.makeFunction("castINT", Lists.newArrayList(inNode), int32); Field resultField = Field.nullable("result", int32); List exprs = - Lists.newArrayList( - TreeBuilder.makeExpression(castINTFn, resultField)); + Lists.newArrayList(TreeBuilder.makeExpression(castINTFn, resultField)); Schema schema = new Schema(Lists.newArrayList(inField)); Projector eval = Projector.make(schema, exprs); int numRows = 5; byte[] validity = new byte[] {(byte) 255}; - String[] values = - new String[] { - "0", "123", "-123", "-1", "1" - }; - int[] expValues = - new int[] { - 0, 123, -123, -1, 1 - }; + String[] values = new String[] {"0", "123", "-123", "-1", "1"}; + int[] expValues = new int[] {0, 123, -123, -1, 1}; ArrowBuf bufValidity = buf(validity); List bufData = stringBufs(values); ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); @@ -2108,20 +2151,15 @@ public void testCastInt() throws Exception { public void testCastIntInvalidValue() throws Exception { Field inField = Field.nullable("input", new ArrowType.Utf8()); TreeNode inNode = TreeBuilder.makeField(inField); - TreeNode castINTFn = TreeBuilder.makeFunction("castINT", Lists.newArrayList(inNode), - int32); + TreeNode castINTFn = TreeBuilder.makeFunction("castINT", Lists.newArrayList(inNode), int32); Field resultField = Field.nullable("result", int32); List exprs = - Lists.newArrayList( - TreeBuilder.makeExpression(castINTFn, resultField)); + Lists.newArrayList(TreeBuilder.makeExpression(castINTFn, resultField)); Schema schema = new Schema(Lists.newArrayList(inField)); Projector eval = Projector.make(schema, exprs); int numRows = 1; byte[] validity = new byte[] {(byte) 255}; - String[] values = - new String[] { - "abc" - }; + String[] values = new String[] {"abc"}; ArrowBuf bufValidity = buf(validity); List bufData = stringBufs(values); ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); @@ -2149,28 +2187,17 @@ public void testCastIntInvalidValue() throws Exception { public void testCastFloat() throws Exception { Field inField = Field.nullable("input", new ArrowType.Utf8()); TreeNode inNode = TreeBuilder.makeField(inField); - TreeNode castFLOAT8Fn = TreeBuilder.makeFunction("castFLOAT8", Lists.newArrayList(inNode), - float64); + TreeNode castFLOAT8Fn = + TreeBuilder.makeFunction("castFLOAT8", Lists.newArrayList(inNode), float64); Field resultField = Field.nullable("result", float64); List exprs = - Lists.newArrayList( - TreeBuilder.makeExpression(castFLOAT8Fn, resultField)); + Lists.newArrayList(TreeBuilder.makeExpression(castFLOAT8Fn, resultField)); Schema schema = new Schema(Lists.newArrayList(inField)); Projector eval = Projector.make(schema, exprs); int numRows = 5; byte[] validity = new byte[] {(byte) 255}; - String[] values = - new String[] { - "2.3", - "-11.11", - "0", - "111", - "12345.67" - }; - double[] expValues = - new double[] { - 2.3, -11.11, 0, 111, 12345.67 - }; + String[] values = new String[] {"2.3", "-11.11", "0", "111", "12345.67"}; + double[] expValues = new double[] {2.3, -11.11, 0, 111, 12345.67}; ArrowBuf bufValidity = buf(validity); List bufData = stringBufs(values); ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); @@ -2202,36 +2229,25 @@ public void testCastFloat() throws Exception { public void testCastFloatVarbinary() throws Exception { Field inField = Field.nullable("input", new ArrowType.Binary()); TreeNode inNode = TreeBuilder.makeField(inField); - TreeNode castFLOAT8Fn = TreeBuilder.makeFunction("castFLOAT8", Lists.newArrayList(inNode), - float64); + TreeNode castFLOAT8Fn = + TreeBuilder.makeFunction("castFLOAT8", Lists.newArrayList(inNode), float64); Field resultField = Field.nullable("result", float64); List exprs = - Lists.newArrayList( - TreeBuilder.makeExpression(castFLOAT8Fn, resultField)); + Lists.newArrayList(TreeBuilder.makeExpression(castFLOAT8Fn, resultField)); Schema schema = new Schema(Lists.newArrayList(inField)); Projector eval = Projector.make(schema, exprs); int numRows = 5; byte[] validity = new byte[] {(byte) 255}; - String[] values = - new String[] { - "2.3", - "-11.11", - "0", - "111", - "12345.67" - }; - double[] expValues = - new double[] { - 2.3, -11.11, 0, 111, 12345.67 - }; + String[] values = new String[] {"2.3", "-11.11", "0", "111", "12345.67"}; + double[] expValues = new double[] {2.3, -11.11, 0, 111, 12345.67}; ArrowBuf bufValidity = buf(validity); List bufData = stringBufs(values); ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(fieldNode), - Lists.newArrayList(bufValidity, bufData.get(0), bufData.get(1))); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(fieldNode), + Lists.newArrayList(bufValidity, bufData.get(0), bufData.get(1))); List output = new ArrayList<>(); for (int i = 0; i < exprs.size(); i++) { Float8Vector float8Vector = new Float8Vector(EMPTY_SCHEMA_PATH, allocator); @@ -2255,24 +2271,16 @@ public void testCastFloatVarbinary() throws Exception { public void testCastFloatInvalidValue() throws Exception { Field inField = Field.nullable("input", new ArrowType.Utf8()); TreeNode inNode = TreeBuilder.makeField(inField); - TreeNode castFLOAT8Fn = TreeBuilder.makeFunction("castFLOAT8", Lists.newArrayList(inNode), - float64); + TreeNode castFLOAT8Fn = + TreeBuilder.makeFunction("castFLOAT8", Lists.newArrayList(inNode), float64); Field resultField = Field.nullable("result", float64); List exprs = - Lists.newArrayList( - TreeBuilder.makeExpression(castFLOAT8Fn, resultField)); + Lists.newArrayList(TreeBuilder.makeExpression(castFLOAT8Fn, resultField)); Schema schema = new Schema(Lists.newArrayList(inField)); Projector eval = Projector.make(schema, exprs); int numRows = 5; byte[] validity = new byte[] {(byte) 255}; - String[] values = - new String[] { - "2.3", - "-11.11", - "abc", - "111", - "12345.67" - }; + String[] values = new String[] {"2.3", "-11.11", "abc", "111", "12345.67"}; ArrowBuf bufValidity = buf(validity); List bufData = stringBufs(values); ArrowFieldNode fieldNode = new ArrowFieldNode(numRows, 0); @@ -2308,23 +2316,25 @@ public void testEvaluateWithUnsetTargetHostCPU() throws Exception { List exprs = Lists.newArrayList(root); Schema schema = new Schema(args); - Projector eval = Projector.make(schema, exprs, new ConfigurationBuilder.ConfigOptions().withTargetCPU(false )); + Projector eval = + Projector.make( + schema, exprs, new ConfigurationBuilder.ConfigOptions().withTargetCPU(false)); int numRows = 16; - byte[] validity = new byte[]{(byte) 255, 0}; + byte[] validity = new byte[] {(byte) 255, 0}; // second half is "undefined" - int[] aValues = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - int[] bValues = new int[]{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; + int[] aValues = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + int[] bValues = new int[] {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; ArrowBuf validitya = buf(validity); ArrowBuf valuesa = intBuf(aValues); ArrowBuf validityb = buf(validity); ArrowBuf valuesb = intBuf(bValues); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(new ArrowFieldNode(numRows, 8), new ArrowFieldNode(numRows, 8)), - Lists.newArrayList(validitya, valuesa, validityb, valuesb)); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(new ArrowFieldNode(numRows, 8), new ArrowFieldNode(numRows, 8)), + Lists.newArrayList(validitya, valuesa, validityb, valuesb)); IntVector intVector = new IntVector(EMPTY_SCHEMA_PATH, allocator); intVector.allocateNew(numRows); @@ -2355,13 +2365,13 @@ public void testCastVarcharFromInteger() throws Exception { TreeNode inNode = TreeBuilder.makeField(inField); TreeNode lenNode = TreeBuilder.makeField(lenField); - TreeNode tsToString = TreeBuilder.makeFunction("castVARCHAR", Lists.newArrayList(inNode, lenNode), - new ArrowType.Utf8()); + TreeNode tsToString = + TreeBuilder.makeFunction( + "castVARCHAR", Lists.newArrayList(inNode, lenNode), new ArrowType.Utf8()); Field resultField = Field.nullable("result", new ArrowType.Utf8()); List exprs = - Lists.newArrayList( - TreeBuilder.makeExpression(tsToString, resultField)); + Lists.newArrayList(TreeBuilder.makeExpression(tsToString, resultField)); Schema schema = new Schema(Lists.newArrayList(inField, lenField)); Projector eval = Projector.make(schema, exprs); @@ -2370,24 +2380,17 @@ public void testCastVarcharFromInteger() throws Exception { byte[] validity = new byte[] {(byte) 255}; int[] values = new int[] { - 2345, - 2345, - 2345, - 2345, - -2345, - }; - long[] lenValues = - new long[] { - 0L, 4L, 2L, 6L, 5L + 2345, 2345, 2345, 2345, -2345, }; + long[] lenValues = new long[] {0L, 4L, 2L, 6L, 5L}; String[] expValues = new String[] { - "", - Integer.toString(2345).substring(0, 4), - Integer.toString(2345).substring(0, 2), - Integer.toString(2345), - Integer.toString(-2345) + "", + Integer.toString(2345).substring(0, 4), + Integer.toString(2345).substring(0, 2), + Integer.toString(2345), + Integer.toString(-2345) }; ArrowBuf bufValidity = buf(validity); @@ -2433,13 +2436,13 @@ public void testCastVarcharFromFloat() throws Exception { TreeNode inNode = TreeBuilder.makeField(inField); TreeNode lenNode = TreeBuilder.makeField(lenField); - TreeNode tsToString = TreeBuilder.makeFunction("castVARCHAR", Lists.newArrayList(inNode, lenNode), - new ArrowType.Utf8()); + TreeNode tsToString = + TreeBuilder.makeFunction( + "castVARCHAR", Lists.newArrayList(inNode, lenNode), new ArrowType.Utf8()); Field resultField = Field.nullable("result", new ArrowType.Utf8()); List exprs = - Lists.newArrayList( - TreeBuilder.makeExpression(tsToString, resultField)); + Lists.newArrayList(TreeBuilder.makeExpression(tsToString, resultField)); Schema schema = new Schema(Lists.newArrayList(inField, lenField)); Projector eval = Projector.make(schema, exprs); @@ -2448,27 +2451,24 @@ public void testCastVarcharFromFloat() throws Exception { byte[] validity = new byte[] {(byte) 255}; double[] values = new double[] { - 0.0, - -0.0, - 1.0, - 0.001, - 0.0009, - 0.00099893, - 999999.9999, - 10000000.0, - 23943410000000.343434, - Double.POSITIVE_INFINITY, - Double.NEGATIVE_INFINITY, - Double.NaN, - 23.45, - 23.45, - -23.45, + 0.0, + -0.0, + 1.0, + 0.001, + 0.0009, + 0.00099893, + 999999.9999, + 10000000.0, + 23943410000000.343434, + Double.POSITIVE_INFINITY, + Double.NEGATIVE_INFINITY, + Double.NaN, + 23.45, + 23.45, + -23.45, }; long[] lenValues = - new long[] { - 6L, 6L, 6L, 6L, 10L, 15L, 15L, 15L, 30L, - 15L, 15L, 15L, 0L, 6L, 6L - }; + new long[] {6L, 6L, 6L, 6L, 10L, 15L, 15L, 15L, 30L, 15L, 15L, 15L, 0L, 6L, 6L}; /* The Java real numbers are represented in two ways and Gandiva must * follow the same rules: @@ -2483,21 +2483,21 @@ public void testCastVarcharFromFloat() throws Exception { * */ String[] expValues = new String[] { - Double.toString(0.0), // must be cast to -> "0.0" - Double.toString(-0.0), // must be cast to -> "-0.0" - Double.toString(1.0), // must be cast to -> "1.0" - Double.toString(0.001), // must be cast to -> "0.001" - Double.toString(0.0009), // must be cast to -> "9E-4" - Double.toString(0.00099893), // must be cast to -> "9E-4" - Double.toString(999999.9999), // must be cast to -> "999999.9999" - Double.toString(10000000.0), // must be cast to 1E7 - Double.toString(23943410000000.343434), - Double.toString(Double.POSITIVE_INFINITY), - Double.toString(Double.NEGATIVE_INFINITY), - Double.toString(Double.NaN), - "", - Double.toString(23.45), - Double.toString(-23.45) + Double.toString(0.0), // must be cast to -> "0.0" + Double.toString(-0.0), // must be cast to -> "-0.0" + Double.toString(1.0), // must be cast to -> "1.0" + Double.toString(0.001), // must be cast to -> "0.001" + Double.toString(0.0009), // must be cast to -> "9E-4" + Double.toString(0.00099893), // must be cast to -> "9E-4" + Double.toString(999999.9999), // must be cast to -> "999999.9999" + Double.toString(10000000.0), // must be cast to 1E7 + Double.toString(23943410000000.343434), + Double.toString(Double.POSITIVE_INFINITY), + Double.toString(Double.NEGATIVE_INFINITY), + Double.toString(Double.NaN), + "", + Double.toString(23.45), + Double.toString(-23.45) }; ArrowBuf bufValidity = buf(validity); @@ -2543,40 +2543,40 @@ public void testInitCap() throws Exception { Field retType = Field.nullable("c", new ArrowType.Utf8()); TreeNode cond = - TreeBuilder.makeFunction( - "initcap", - Lists.newArrayList(TreeBuilder.makeField(x)), - new ArrowType.Utf8()); + TreeBuilder.makeFunction( + "initcap", Lists.newArrayList(TreeBuilder.makeField(x)), new ArrowType.Utf8()); ExpressionTree expr = TreeBuilder.makeExpression(cond, retType); Schema schema = new Schema(Lists.newArrayList(x)); Projector eval = Projector.make(schema, Lists.newArrayList(expr)); int numRows = 5; - byte[] validity = new byte[]{(byte) 15, 0}; - String[] valuesX = new String[]{ - " øhpqršvñ \n\n", - "möbelträger1füße \nmöbelträge'rfüße", - "ÂbĆDËFgh\néll", - "citroën CaR", - "kjk" - }; - - String[] expected = new String[]{ - " Øhpqršvñ \n\n", - "Möbelträger1füße \nMöbelträge'Rfüße", - "Âbćdëfgh\nÉll", - "Citroën Car", - null - }; + byte[] validity = new byte[] {(byte) 15, 0}; + String[] valuesX = + new String[] { + " øhpqršvñ \n\n", + "möbelträger1füße \nmöbelträge'rfüße", + "ÂbĆDËFgh\néll", + "citroën CaR", + "kjk" + }; + + String[] expected = + new String[] { + " Øhpqršvñ \n\n", + "Möbelträger1füße \nMöbelträge'Rfüße", + "Âbćdëfgh\nÉll", + "Citroën Car", + null + }; ArrowBuf validityX = buf(validity); List dataBufsX = stringBufs(valuesX); ArrowRecordBatch batch = - new ArrowRecordBatch( - numRows, - Lists.newArrayList(new ArrowFieldNode(numRows, 0)), - Lists.newArrayList(validityX, dataBufsX.get(0), dataBufsX.get(1))); + new ArrowRecordBatch( + numRows, + Lists.newArrayList(new ArrowFieldNode(numRows, 0)), + Lists.newArrayList(validityX, dataBufsX.get(0), dataBufsX.get(1))); // allocate data for output vector. VarCharVector outVector = new VarCharVector(EMPTY_SCHEMA_PATH, allocator); diff --git a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/TestJniLoader.java b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/TestJniLoader.java index 116f0dd9eab0..cfc1dbf2f7bc 100644 --- a/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/TestJniLoader.java +++ b/java/gandiva/src/test/java/org/apache/arrow/gandiva/evaluator/TestJniLoader.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.evaluator; import org.junit.Assert; @@ -26,28 +25,39 @@ public class TestJniLoader { public void testDefaultConfiguration() throws Exception { long configId = JniLoader.getConfiguration(ConfigurationBuilder.ConfigOptions.getDefault()); Assert.assertEquals(configId, JniLoader.getDefaultConfiguration()); - Assert.assertEquals(configId, JniLoader.getConfiguration(ConfigurationBuilder.ConfigOptions.getDefault())); + Assert.assertEquals( + configId, JniLoader.getConfiguration(ConfigurationBuilder.ConfigOptions.getDefault())); - long configId2 = JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions().withOptimize(false)); - long configId3 = JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions().withTargetCPU(false)); - long configId4 = JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions().withOptimize(false) - .withTargetCPU(false)); + long configId2 = + JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions().withOptimize(false)); + long configId3 = + JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions().withTargetCPU(false)); + long configId4 = + JniLoader.getConfiguration( + new ConfigurationBuilder.ConfigOptions().withOptimize(false).withTargetCPU(false)); Assert.assertTrue(configId != configId2 && configId2 != configId3 && configId3 != configId4); - Assert.assertEquals(configId2, JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions() - .withOptimize(false))); - Assert.assertEquals(configId3, JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions() - .withTargetCPU(false))); - Assert.assertEquals(configId4, JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions() - .withOptimize(false).withTargetCPU(false))); + Assert.assertEquals( + configId2, + JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions().withOptimize(false))); + Assert.assertEquals( + configId3, + JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions().withTargetCPU(false))); + Assert.assertEquals( + configId4, + JniLoader.getConfiguration( + new ConfigurationBuilder.ConfigOptions().withOptimize(false).withTargetCPU(false))); JniLoader.removeConfiguration(new ConfigurationBuilder.ConfigOptions().withOptimize(false)); - // configids are monotonically updated. after a config is removed, new one is assigned with higher id - Assert.assertNotEquals(configId2, JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions() - .withOptimize(false))); + // configids are monotonically updated. after a config is removed, new one is assigned with + // higher id + Assert.assertNotEquals( + configId2, + JniLoader.getConfiguration(new ConfigurationBuilder.ConfigOptions().withOptimize(false))); JniLoader.removeConfiguration(new ConfigurationBuilder.ConfigOptions()); - Assert.assertNotEquals(configId, JniLoader.getConfiguration(ConfigurationBuilder.ConfigOptions.getDefault())); + Assert.assertNotEquals( + configId, JniLoader.getConfiguration(ConfigurationBuilder.ConfigOptions.getDefault())); } } diff --git a/java/gandiva/src/test/java/org/apache/arrow/gandiva/expression/ArrowTypeHelperTest.java b/java/gandiva/src/test/java/org/apache/arrow/gandiva/expression/ArrowTypeHelperTest.java index 7ddd602bfcef..390717d8b4db 100644 --- a/java/gandiva/src/test/java/org/apache/arrow/gandiva/expression/ArrowTypeHelperTest.java +++ b/java/gandiva/src/test/java/org/apache/arrow/gandiva/expression/ArrowTypeHelperTest.java @@ -14,14 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.List; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; import org.apache.arrow.vector.types.FloatingPointPrecision; diff --git a/java/gandiva/src/test/java/org/apache/arrow/gandiva/expression/TreeBuilderTest.java b/java/gandiva/src/test/java/org/apache/arrow/gandiva/expression/TreeBuilderTest.java index 90373cf792a6..63c4baa8b61a 100644 --- a/java/gandiva/src/test/java/org/apache/arrow/gandiva/expression/TreeBuilderTest.java +++ b/java/gandiva/src/test/java/org/apache/arrow/gandiva/expression/TreeBuilderTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.arrow.gandiva.expression; import static org.junit.Assert.*; @@ -22,7 +21,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; - import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; import org.apache.arrow.vector.types.FloatingPointPrecision;