use of io.prestosql.spi.type.TypeSignature 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;
}
}
use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.
the class NdpUdfExpressions method createNdpSubscript.
private void createNdpSubscript(GetArrayItem expression, PrestoExpressionInfo prestoExpressionInfo, Map<String, Integer> fieldMap) {
String signatureName = NdpUdfEnum.SUBSCRIPT.getSignatureName();
Type strType = NdpUtils.transOlkDataType(expression.child().dataType(), true);
Type ordinalType = NdpUtils.transOlkDataType(expression.ordinal().dataType(), true);
Type returnType = NdpUtils.transOlkDataType(expression.dataType(), true);
List<RowExpression> rowArguments = new ArrayList<>();
checkAttributeReference(expression.child(), prestoExpressionInfo, fieldMap, strType, rowArguments);
// The presto`s array subscript is initially 1.
int argumentValue = Integer.parseInt(((Literal) expression.ordinal()).value().toString()) + 1;
rowArguments.add(NdpUtils.transArgumentData(Integer.toString(argumentValue), ordinalType));
Signature signature = new Signature(QualifiedObjectName.valueOfDefaultFunction(NdpUdfEnum.SUBSCRIPT.getOperatorName()), FunctionKind.SCALAR, new TypeSignature(returnType.toString()), new TypeSignature(strType.toString()), new TypeSignature(ordinalType.toString()));
RowExpression resExpression = new CallExpression(signatureName, new BuiltInFunctionHandle(signature), returnType, rowArguments);
prestoExpressionInfo.setReturnType(returnType);
prestoExpressionInfo.setPrestoRowExpression(resExpression);
}
use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.
the class NdpUdfExpressions method createNdpInstr.
private void createNdpInstr(StringInstr expression, PrestoExpressionInfo prestoExpressionInfo, Map<String, Integer> fieldMap) {
String signatureName = NdpUdfEnum.INSTR.getSignatureName();
Type strType = NdpUtils.transOlkDataType(expression.str().dataType(), true);
Type substrType = NdpUtils.transOlkDataType(expression.substr().dataType(), true);
Type returnType = NdpUtils.transOlkDataType(expression.dataType(), true);
List<RowExpression> rowArguments = new ArrayList<>();
checkAttributeReference(expression.str(), prestoExpressionInfo, fieldMap, strType, rowArguments);
rowArguments.add(NdpUtils.transArgumentData(expression.substr().toString(), substrType));
Signature signature = new Signature(QualifiedObjectName.valueOfDefaultFunction(NdpUdfEnum.INSTR.getOperatorName()), FunctionKind.SCALAR, new TypeSignature(returnType.toString()), new TypeSignature(strType.toString()), new TypeSignature(substrType.toString()));
RowExpression resExpression = new CallExpression(signatureName, new BuiltInFunctionHandle(signature), returnType, rowArguments);
prestoExpressionInfo.setReturnType(returnType);
prestoExpressionInfo.setPrestoRowExpression(resExpression);
}
use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.
the class NdpUdfExpressions method createHiveSimpleUdf.
private void createHiveSimpleUdf(Expression hiveSimpleUDFExpression, PrestoExpressionInfo prestoExpressionInfo, Map<String, Integer> fieldMap) {
String signatureName = ((HiveSimpleUDF) hiveSimpleUDFExpression).name();
List<Expression> hiveSimpleUdf = JavaConverters.seqAsJavaList(hiveSimpleUDFExpression.children());
Type returnType = NdpUtils.transOlkDataType(hiveSimpleUDFExpression.dataType(), true);
List<RowExpression> rowArguments = new ArrayList<>();
Type strTypeCandidate = returnType;
for (Expression hiveUdf : hiveSimpleUdf) {
strTypeCandidate = NdpUtils.transOlkDataType(hiveUdf.dataType(), true);
checkAttributeReference(hiveUdf, prestoExpressionInfo, fieldMap, strTypeCandidate, rowArguments);
}
Signature signature = new Signature(QualifiedObjectName.valueOfDefaultFunction(signatureName), FunctionKind.SCALAR, new TypeSignature(returnType.toString()), new TypeSignature(strTypeCandidate.toString()));
RowExpression resExpression = new CallExpression(signatureName.toLowerCase(Locale.ENGLISH), new BuiltInFunctionHandle(signature), returnType, rowArguments);
prestoExpressionInfo.setReturnType(returnType);
prestoExpressionInfo.setPrestoRowExpression(resExpression);
}
use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.
the class NdpUdfExpressions method createNdpSingleParameter.
/**
* Used to create UDF with only a single parameter
*/
private void createNdpSingleParameter(NdpUdfEnum udfEnum, Expression expression, Expression childExpression, PrestoExpressionInfo prestoExpressionInfo, Map<String, Integer> fieldMap) {
String signatureName = udfEnum.getSignatureName();
Type childType = NdpUtils.transOlkDataType(childExpression.dataType(), true);
Type returnType = NdpUtils.transOlkDataType(expression.dataType(), true);
List<RowExpression> rowArguments = new ArrayList<>();
checkAttributeReference(childExpression, prestoExpressionInfo, fieldMap, childType, rowArguments);
Signature signature = new Signature(QualifiedObjectName.valueOfDefaultFunction(udfEnum.getOperatorName()), FunctionKind.SCALAR, new TypeSignature(returnType.toString()), new TypeSignature(childType.toString()));
RowExpression resExpression = new CallExpression(signatureName, new BuiltInFunctionHandle(signature), returnType, rowArguments);
prestoExpressionInfo.setReturnType(returnType);
prestoExpressionInfo.setPrestoRowExpression(resExpression);
}
Aggregations