Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions java/gandiva/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

<properties>
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
<checkstyle.config.location>dev/checkstyle/checkstyle-spotless.xml</checkstyle.config.location>
<spotless.java.excludes>none</spotless.java.excludes>
<arrow.cpp.build.dir>../../../cpp/release-build</arrow.cpp.build.dir>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion java/gandiva/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
requires org.apache.arrow.vector;
requires org.slf4j;
requires protobuf.java;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -43,8 +38,7 @@ public static ConfigOptions getDefault() {
return new ConfigOptions();
}

public ConfigOptions() {
}
public ConfigOptions() {}

public ConfigOptions withOptimize(boolean optimize) {
this.optimize = optimize;
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand All @@ -56,24 +48,30 @@ 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;
resultPrecision = p1 + p2 + 1;
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");
Expand All @@ -90,6 +88,4 @@ private static Decimal adjustScaleIfNeeded(int precision, int scale) {
}
return new Decimal(precision, scale, 128);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -55,14 +50,15 @@ public class ExpressionRegistry {

private static volatile ExpressionRegistry INSTANCE;

private ExpressionRegistry(Set<ArrowType> supportedTypes,
Set<FunctionSignature> functionSignatures) {
private ExpressionRegistry(
Set<ArrowType> supportedTypes, Set<FunctionSignature> 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.
*/
Expand Down Expand Up @@ -92,8 +88,8 @@ public Set<ArrowType> getSupportedTypes() {
private static Set<ArrowType> getSupportedTypesFromGandiva() throws GandivaException {
Set<ArrowType> 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));
Expand All @@ -104,24 +100,23 @@ private static Set<ArrowType> getSupportedTypesFromGandiva() throws GandivaExcep
return supportedTypes;
}

private static Set<FunctionSignature> getSupportedFunctionsFromGandiva() throws
GandivaException {
private static Set<FunctionSignature> getSupportedFunctionsFromGandiva() throws GandivaException {
Set<FunctionSignature> 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());
List<ArrowType> paramTypes = Lists.newArrayList();
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) {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -215,6 +208,4 @@ private static IntervalUnit mapArrowIntervalUnit(GandivaTypes.IntervalType inter
return null;
}
}

}

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