use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.
the class TestChecksumAggregation method testLongDecimal.
@Test
public void testLongDecimal() {
InternalAggregationFunction decimalAgg = metadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction("checksum"), AGGREGATE, parseTypeSignature(VARBINARY), parseTypeSignature("decimal(19,2)")));
Block block = createLongDecimalsBlock("11.11", "22.22", null, "33.33", "44.44");
DecimalType longDecimalType = DecimalType.createDecimalType(19);
assertAggregation(decimalAgg, expectedChecksum(longDecimalType, block), block);
}
use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.
the class TestChecksumAggregation method testBoolean.
@Test
public void testBoolean() {
InternalAggregationFunction booleanAgg = metadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction("checksum"), AGGREGATE, parseTypeSignature(VARBINARY), parseTypeSignature(BOOLEAN)));
Block block = createBooleansBlock(null, null, true, false, false);
assertAggregation(booleanAgg, expectedChecksum(BooleanType.BOOLEAN, block), block);
}
use of io.prestosql.spi.function.Signature in project boostkit-bigdata by kunpengcompute.
the class DataIoAdapter method extractCountAggregation.
private void extractCountAggregation(Type prestoType, String expressionName, Map<String, AggregationInfo.AggregateFunction> aggregationMap) {
List<RowExpression> arguments = new ArrayList<>();
Signature signature = new Signature(QualifiedObjectName.valueOfDefaultFunction("count"), AGGREGATE, BIGINT.getTypeSignature());
if (!expressionName.equals("count(1)")) {
int aggProjectionId = fieldMap.get(expressionName);
RowExpression rowExpression = new InputReferenceExpression(aggProjectionId, prestoType);
arguments.add(rowExpression);
signature = new Signature(QualifiedObjectName.valueOfDefaultFunction("count"), AGGREGATE, BIGINT.getTypeSignature(), prestoType.getTypeSignature());
}
FunctionHandle functionHandle = new BuiltInFunctionHandle(signature);
CallExpression callExpression = new CallExpression("count", functionHandle, BIGINT, arguments, Optional.empty());
aggregationMap.put(String.format("%s_%s", "count", columnOrder), new AggregationInfo.AggregateFunction(callExpression, false));
}
use of io.prestosql.spi.function.Signature in project boostkit-bigdata by kunpengcompute.
the class DataIoAdapter method extractSumMaxMinAggregation.
private void extractSumMaxMinAggregation(Type prestoType, String expressionName, Map<String, AggregationInfo.AggregateFunction> aggregationMap) {
String operatorName = expressionName.split("\\(")[0];
List<RowExpression> arguments = new ArrayList<>();
Type returnType = NdpUtils.transAggRetType(prestoType);
if (operatorName.equals("sum")) {
columnTypesList.add(NdpUtils.transAggDecodeType(returnType));
} else {
columnTypesList.add(NdpUtils.transAggDecodeType(prestoType));
}
FunctionHandle functionHandle = new BuiltInFunctionHandle(new Signature(QualifiedObjectName.valueOfDefaultFunction(operatorName), AGGREGATE, prestoType.getTypeSignature(), prestoType.getTypeSignature()));
int aggProjectionId = fieldMap.get(expressionName);
RowExpression rowExpression = new InputReferenceExpression(aggProjectionId, prestoType);
arguments.add(rowExpression);
CallExpression callExpression = new CallExpression(operatorName, functionHandle, returnType, arguments, Optional.empty());
aggregationMap.put(String.format("%s_%s", operatorName, columnOrder), new AggregationInfo.AggregateFunction(callExpression, false));
}
use of io.prestosql.spi.function.Signature in project boostkit-bigdata by kunpengcompute.
the class DataIoAdapter method getExpression.
private RowExpression getExpression(Expression filterExpression) {
RowExpression resRowExpression = null;
List<Expression> rightExpressions = new ArrayList<>();
ExpressionOperator expressionOperType = ExpressionOperator.valueOf(filterExpression.getClass().getSimpleName());
Expression left;
Expression right;
String operatorName;
switch(expressionOperType) {
case Or:
case And:
return reverseExpressionTree(filterExpression);
case Not:
Signature notSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("not"), FunctionKind.SCALAR, new TypeSignature("boolean"), new TypeSignature("boolean"));
RowExpression tempRowExpression = getExpression(((Not) filterExpression).child());
List<RowExpression> notArguments = new ArrayList<>();
notArguments.add(tempRowExpression);
return new CallExpression("not", new BuiltInFunctionHandle(notSignature), BOOLEAN, notArguments, Optional.empty());
case EqualTo:
if (((EqualTo) filterExpression).left() instanceof Literal) {
rightExpressions.add(((EqualTo) filterExpression).left());
left = ((EqualTo) filterExpression).right();
} else {
rightExpressions.add(((EqualTo) filterExpression).right());
left = ((EqualTo) filterExpression).left();
}
return getRowExpression(left, "equal", rightExpressions);
case IsNotNull:
Signature isnullSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("not"), FunctionKind.SCALAR, new TypeSignature("boolean"), new TypeSignature("boolean"));
RowExpression isnullRowExpression = getRowExpression(((IsNotNull) filterExpression).child(), "is_null", null);
List<RowExpression> isnullArguments = new ArrayList<>();
isnullArguments.add(isnullRowExpression);
return new CallExpression("not", new BuiltInFunctionHandle(isnullSignature), BOOLEAN, isnullArguments, Optional.empty());
case IsNull:
return getRowExpression(((IsNull) filterExpression).child(), "is_null", null);
case LessThan:
if (((LessThan) filterExpression).left() instanceof Literal) {
rightExpressions.add(((LessThan) filterExpression).left());
left = ((LessThan) filterExpression).right();
operatorName = "greater_than";
} else {
rightExpressions.add(((LessThan) filterExpression).right());
left = ((LessThan) filterExpression).left();
operatorName = "less_than";
}
return getRowExpression(left, operatorName, rightExpressions);
case GreaterThan:
if (((GreaterThan) filterExpression).left() instanceof Literal) {
rightExpressions.add(((GreaterThan) filterExpression).left());
left = ((GreaterThan) filterExpression).right();
operatorName = "less_than";
} else {
rightExpressions.add(((GreaterThan) filterExpression).right());
left = ((GreaterThan) filterExpression).left();
operatorName = "greater_than";
}
return getRowExpression(left, operatorName, rightExpressions);
case GreaterThanOrEqual:
if (((GreaterThanOrEqual) filterExpression).left() instanceof Literal) {
rightExpressions.add(((GreaterThanOrEqual) filterExpression).left());
left = ((GreaterThanOrEqual) filterExpression).right();
operatorName = "less_than_or_equal";
} else {
rightExpressions.add(((GreaterThanOrEqual) filterExpression).right());
left = ((GreaterThanOrEqual) filterExpression).left();
operatorName = "greater_than_or_equal";
}
return getRowExpression(left, operatorName, rightExpressions);
case LessThanOrEqual:
if (((LessThanOrEqual) filterExpression).left() instanceof Literal) {
rightExpressions.add(((LessThanOrEqual) filterExpression).left());
left = ((LessThanOrEqual) filterExpression).right();
operatorName = "greater_than_or_equal";
} else {
rightExpressions.add(((LessThanOrEqual) filterExpression).right());
left = ((LessThanOrEqual) filterExpression).left();
operatorName = "less_than_or_equal";
}
return getRowExpression(left, operatorName, rightExpressions);
case In:
List<Expression> rightExpression = JavaConverters.seqAsJavaList(((In) filterExpression).list());
return getRowExpression(((In) filterExpression).value(), "in", rightExpression);
case HiveSimpleUDF:
return getRowExpression(filterExpression, ((HiveSimpleUDF) filterExpression).name(), rightExpressions);
default:
return resRowExpression;
}
}
Aggregations