diff --git a/java/gandiva/pom.xml b/java/gandiva/pom.xml index 9bae1843dd02f..318872accbead 100644 --- a/java/gandiva/pom.xml +++ b/java/gandiva/pom.xml @@ -38,8 +38,8 @@ under the License. - org.apache.arrow - arrow-format + org.apache.arrow + arrow-format org.apache.arrow 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 797cb5187fc71..8e4ba00c8baed 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 @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; - import org.apache.arrow.flatbuf.Type; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; @@ -113,7 +112,8 @@ private static Set getSupportedFunctionsFromGandiva() throws String functionName = protoFunctionSignature.getName(); ArrowType returnType = getArrowType(protoFunctionSignature.getReturnType()); - ArrowType returnListType = getArrowTypeSimple(protoFunctionSignature.getReturnType().getListType()); + ArrowType returnListType = + getArrowTypeSimple(protoFunctionSignature.getReturnType().getListType()); List> paramTypes = new ArrayList>(); for (ExtGandivaType type : protoFunctionSignature.getParamTypesList()) { ArrowType paramType = getArrowType(type); 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 abfdabf010746..c6f32d7fa3c1e 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 @@ -18,7 +18,6 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Objects; - import java.util.ArrayList; import java.util.List; import org.apache.arrow.vector.types.pojo.ArrowType; @@ -54,7 +53,10 @@ public String getName() { * @param returnListType optional list type * @param paramTypes - data type of input args. */ - public FunctionSignature(String name, ArrowType returnType, ArrowType returnListType, + public FunctionSignature( + String name, + ArrowType returnType, + ArrowType returnListType, List> paramTypes) { this.name = name; this.returnType = returnType; @@ -64,6 +66,7 @@ public FunctionSignature(String name, ArrowType returnType, ArrowType returnList /** * Ctor. + * * @param name - name of the function. * @param returnType - data type of return * @param paramTypes - data type of input args. @@ -78,7 +81,6 @@ public FunctionSignature(String name, ArrowType returnType, List para paramArrowList.add(paramType); this.paramTypes.add(paramArrowList); } - } /** @@ -102,7 +104,8 @@ public boolean equals(Object signature) { @Override public int hashCode() { - return Objects.hashCode(this.name.toLowerCase(), this.returnType, this.returnListType, this.paramTypes); + return Objects.hashCode( + this.name.toLowerCase(), this.returnType, this.returnListType, this.paramTypes); } @Override 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 3cb8ef6b95bfd..5c59c219ea74a 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 @@ -18,6 +18,8 @@ import static java.util.UUID.randomUUID; +import com.sun.jna.Library; +import com.sun.jna.NativeLibrary; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -29,15 +31,12 @@ import java.util.concurrent.ConcurrentMap; import org.apache.arrow.gandiva.exceptions.GandivaException; -import com.sun.jna.Library; -import com.sun.jna.NativeLibrary; - /** 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 final int RTLD_GLOBAL = 0x00100; - private static final int RTLD_LAZY = 0x00001; + private static final int RTLD_LAZY = 0x00001; private static volatile JniLoader INSTANCE; private static volatile long defaultConfiguration = 0L; @@ -78,8 +77,7 @@ private static void loadGandivaLibraryFromJar(final String tmpDir) final File libraryFile = moveFileFromJarToTemp(tmpDir, libraryToLoad, LIBRARY_NAME); NativeLibrary.getInstance( libraryFile.getAbsolutePath(), - Collections.singletonMap(Library.OPTION_OPEN_FLAGS, new Integer(RTLD_LAZY | RTLD_GLOBAL)) - ); + Collections.singletonMap(Library.OPTION_OPEN_FLAGS, new Integer(RTLD_LAZY | RTLD_GLOBAL))); System.load(libraryFile.getAbsolutePath()); } diff --git a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ListVectorExpander.java b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ListVectorExpander.java index 1d02f38a4d591..2e4747ee4116e 100644 --- a/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ListVectorExpander.java +++ b/java/gandiva/src/main/java/org/apache/arrow/gandiva/evaluator/ListVectorExpander.java @@ -14,14 +14,13 @@ * 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.complex.ListVector; /** - * This class provides the functionality to expand output ListVectors using a callback mechanism from - * gandiva. + * This class provides the functionality to expand output ListVectors using a callback mechanism + * from gandiva. */ public class ListVectorExpander { private final ListVector[] bufferVectors; @@ -32,9 +31,7 @@ public ListVectorExpander(ListVector[] bufferVectors) { this.bufferVectors = bufferVectors; } - /** - * Result of ListVector expansion. - */ + /** Result of ListVector expansion. */ public static class ExpandResult { public long address; public long capacity; @@ -42,10 +39,10 @@ public static class ExpandResult { /** * Result of expanding the buffer. + * * @param address Data buffer address * @param capacity Capacity * @param validAdd Validity buffer address - * */ public ExpandResult(long address, long capacity, long validAdd) { this.address = address; @@ -55,13 +52,12 @@ public ExpandResult(long address, long capacity, long validAdd) { } /** - * Expand vector at specified index. This is used as a back call from jni, and is only - * relevant for ListVectors. + * Expand vector at specified index. This is used as a back call from jni, and is only relevant + * for ListVectors. * * @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 >= bufferVectors.length || bufferVectors[index] == null) { @@ -69,15 +65,31 @@ public ExpandResult expandOutputVectorAtIndex(int index, long toCapacity) { } ListVector vector = bufferVectors[index]; - while (vector.getDataVector().getFieldBuffers().get(ListVectorExpander.valueBufferIndex).capacity() < toCapacity) { - //Just realloc the data vector. + while (vector + .getDataVector() + .getFieldBuffers() + .get(ListVectorExpander.valueBufferIndex) + .capacity() + < toCapacity) { + // Just realloc the data vector. vector.getDataVector().reAlloc(); } - + return new ExpandResult( - vector.getDataVector().getFieldBuffers().get(ListVectorExpander.valueBufferIndex).memoryAddress(), - vector.getDataVector().getFieldBuffers().get(ListVectorExpander.valueBufferIndex).capacity(), - vector.getDataVector().getFieldBuffers().get(ListVectorExpander.validityBufferIndex).memoryAddress()); + vector + .getDataVector() + .getFieldBuffers() + .get(ListVectorExpander.valueBufferIndex) + .memoryAddress(), + vector + .getDataVector() + .getFieldBuffers() + .get(ListVectorExpander.valueBufferIndex) + .capacity(), + vector + .getDataVector() + .getFieldBuffers() + .get(ListVectorExpander.validityBufferIndex) + .memoryAddress()); } - } 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 1afd5d818c245..951cebc88ee3d 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 @@ -379,17 +379,33 @@ private void evaluate( outAddrs[idx] = valueVector.getOffsetBuffer().memoryAddress(); outSizes[idx++] = valueVector.getOffsetBuffer().capacity(); - //vector valid - outAddrs[idx] = ((ListVector) valueVector).getDataVector().getFieldBuffers() - .get(ListVectorExpander.validityBufferIndex).memoryAddress(); - outSizes[idx++] = ((ListVector) valueVector).getDataVector().getFieldBuffers() - .get(ListVectorExpander.validityBufferIndex).capacity(); + // vector valid + outAddrs[idx] = + ((ListVector) valueVector) + .getDataVector() + .getFieldBuffers() + .get(ListVectorExpander.validityBufferIndex) + .memoryAddress(); + outSizes[idx++] = + ((ListVector) valueVector) + .getDataVector() + .getFieldBuffers() + .get(ListVectorExpander.validityBufferIndex) + .capacity(); - //vector offset - outAddrs[idx] = ((ListVector) valueVector).getDataVector().getFieldBuffers() - .get(ListVectorExpander.valueBufferIndex).memoryAddress(); - outSizes[idx++] = ((ListVector) valueVector).getDataVector().getFieldBuffers() - .get(ListVectorExpander.valueBufferIndex).capacity(); + // vector offset + outAddrs[idx] = + ((ListVector) valueVector) + .getDataVector() + .getFieldBuffers() + .get(ListVectorExpander.valueBufferIndex) + .memoryAddress(); + outSizes[idx++] = + ((ListVector) valueVector) + .getDataVector() + .getFieldBuffers() + .get(ListVectorExpander.valueBufferIndex) + .capacity(); } else { outAddrs[idx] = valueVector.getDataBuffer().memoryAddress(); outSizes[idx++] = valueVector.getDataBuffer().capacity(); 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 de5449ec4cfdc..c454258496020 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 @@ -260,8 +260,8 @@ private static void initArrowTypeInterval( * @param builder the builder to use * @return Protobuf representing the arrow type */ - public static GandivaTypes.ExtGandivaType arrowTypeToProtobuf(ArrowType arrowType, ArrowType subType, - GandivaTypes.ExtGandivaType.Builder builder) + public static GandivaTypes.ExtGandivaType arrowTypeToProtobuf( + ArrowType arrowType, ArrowType subType, GandivaTypes.ExtGandivaType.Builder builder) throws GandivaException { byte typeId = arrowType.getTypeID().getFlatbufID(); @@ -365,7 +365,6 @@ public static GandivaTypes.ExtGandivaType arrowTypeToProtobuf(ArrowType arrowTyp return builder.build(); } - /** * Converts an arrow type into a protobuf. * @@ -402,8 +401,8 @@ public static GandivaTypes.Field arrowFieldToProtobuf(Field field) throws Gandiv builder.setNullable(field.isNullable()); ArrowType subType = null; - if (field.getChildren().size() > 0 && field.getChildren().get(0) - .getType().getTypeID().getFlatbufID() != Type.List) { + if (field.getChildren().size() > 0 + && field.getChildren().get(0).getType().getTypeID().getFlatbufID() != Type.List) { subType = field.getChildren().get(0).getType(); } @@ -413,7 +412,6 @@ public static GandivaTypes.Field arrowFieldToProtobuf(Field field) throws Gandiv builder.addChildren(ArrowTypeHelper.arrowFieldToProtobuf(child)); } } - return builder.build(); } 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 f29b4c006db30..9acfe57d040cf 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 @@ -17,14 +17,12 @@ package org.apache.arrow.gandiva.expression; import java.util.List; - import org.apache.arrow.flatbuf.Type; import org.apache.arrow.gandiva.exceptions.GandivaException; import org.apache.arrow.gandiva.ipc.GandivaTypes; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.Field; - /** Node representing an arbitrary function in an expression. */ class FunctionNode implements TreeNode { private final String function; @@ -36,13 +34,12 @@ class FunctionNode implements TreeNode { this.function = function; this.children = children; this.retType = inField.getType(); - if (inField.getChildren().size() > 0 && inField.getChildren().get(0) - .getType().getTypeID().getFlatbufID() != Type.List) { + if (inField.getChildren().size() > 0 + && inField.getChildren().get(0).getType().getTypeID().getFlatbufID() != Type.List) { this.retListType = inField.getChildren().get(0).getType(); } else { this.retListType = null; } - } FunctionNode(String function, List children, ArrowType inType) { @@ -51,7 +48,7 @@ class FunctionNode implements TreeNode { this.retType = inType; this.retListType = null; } - + FunctionNode(String function, List children, ArrowType inType, ArrowType listType) { this.function = function; this.children = children; 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 fd86ea8df0ce7..bc7f43006773a 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 @@ -92,13 +92,12 @@ public static TreeNode makeFunction(String function, List children, Ar * * @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 listType The type of the list return value of the operator + * @param retType The type of the return value of the operator + * @param listType The type of the list return value of the operator * @return Node representing a function */ - public static TreeNode makeFunction(String function, - List children, - ArrowType retType, ArrowType listType) { + public static TreeNode makeFunction( + String function, List children, ArrowType retType, ArrowType listType) { return new FunctionNode(function, children, retType, listType); } @@ -107,12 +106,10 @@ public static TreeNode makeFunction(String function, * * @param function Name of the function, e.g. add * @param children The arguments to the function - * @param retType The field of the return value of the operator, could be a complex type. + * @param retType The field of the return value of the operator, could be a complex type. * @return Node representing a function */ - public static TreeNode makeFunction(String function, - List children, - Field retType) { + public static TreeNode makeFunction(String function, List children, Field retType) { return new FunctionNode(function, children, retType); }