Skip to content

Commit

Permalink
Spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
lriggs committed Oct 2, 2024
1 parent b25f8c6 commit aaa3b41
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 64 deletions.
4 changes: 2 additions & 2 deletions java/gandiva/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ under the License.

<dependencies>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-format</artifactId>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-format</artifactId>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,7 +112,8 @@ private static Set<FunctionSignature> getSupportedFunctionsFromGandiva() throws

String functionName = protoFunctionSignature.getName();
ArrowType returnType = getArrowType(protoFunctionSignature.getReturnType());
ArrowType returnListType = getArrowTypeSimple(protoFunctionSignature.getReturnType().getListType());
ArrowType returnListType =
getArrowTypeSimple(protoFunctionSignature.getReturnType().getListType());
List<List<ArrowType>> paramTypes = new ArrayList<List<ArrowType>>();
for (ExtGandivaType type : protoFunctionSignature.getParamTypesList()) {
ArrowType paramType = getArrowType(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<List<ArrowType>> paramTypes) {
this.name = name;
this.returnType = returnType;
Expand All @@ -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.
Expand All @@ -78,7 +81,6 @@ public FunctionSignature(String name, ArrowType returnType, List<ArrowType> para
paramArrowList.add(paramType);
this.paramTypes.add(paramArrowList);
}

}

/**
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,20 +31,18 @@ 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;
public long validityaddress;

/**
* 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;
Expand All @@ -55,29 +52,44 @@ 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) {
throw new IllegalArgumentException("invalid index " + index);
}

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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -365,7 +365,6 @@ public static GandivaTypes.ExtGandivaType arrowTypeToProtobuf(ArrowType arrowTyp
return builder.build();
}


/**
* Converts an arrow type into a protobuf.
*
Expand Down Expand Up @@ -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();
}

Expand All @@ -413,7 +412,6 @@ public static GandivaTypes.Field arrowFieldToProtobuf(Field field) throws Gandiv
builder.addChildren(ArrowTypeHelper.arrowFieldToProtobuf(child));
}
}


return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<TreeNode> children, ArrowType inType) {
Expand All @@ -51,7 +48,7 @@ class FunctionNode implements TreeNode {
this.retType = inType;
this.retListType = null;
}

FunctionNode(String function, List<TreeNode> children, ArrowType inType, ArrowType listType) {
this.function = function;
this.children = children;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,12 @@ public static TreeNode makeFunction(String function, List<TreeNode> 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<TreeNode> children,
ArrowType retType, ArrowType listType) {
public static TreeNode makeFunction(
String function, List<TreeNode> children, ArrowType retType, ArrowType listType) {
return new FunctionNode(function, children, retType, listType);
}

Expand All @@ -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<TreeNode> children,
Field retType) {
public static TreeNode makeFunction(String function, List<TreeNode> children, Field retType) {
return new FunctionNode(function, children, retType);
}

Expand Down

0 comments on commit aaa3b41

Please sign in to comment.