Search in sources :

Example 21 with TypeSignature

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;
    }
}
Also used : TypeSignature(io.prestosql.spi.type.TypeSignature) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) CallExpression(io.prestosql.spi.relation.CallExpression) Expression(org.apache.spark.sql.catalyst.expressions.Expression) NamedExpression(org.apache.spark.sql.catalyst.expressions.NamedExpression) InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) Literal(org.apache.spark.sql.catalyst.expressions.Literal) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 22 with TypeSignature

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);
}
Also used : Type(io.prestosql.spi.type.Type) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 23 with TypeSignature

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);
}
Also used : Type(io.prestosql.spi.type.Type) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 24 with TypeSignature

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);
}
Also used : Type(io.prestosql.spi.type.Type) TypeSignature(io.prestosql.spi.type.TypeSignature) CallExpression(io.prestosql.spi.relation.CallExpression) Expression(org.apache.spark.sql.catalyst.expressions.Expression) InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) HiveSimpleUDF(org.apache.spark.sql.hive.HiveSimpleUDF) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 25 with TypeSignature

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);
}
Also used : Type(io.prestosql.spi.type.Type) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression)

Aggregations

TypeSignature (io.prestosql.spi.type.TypeSignature)79 Signature (io.prestosql.spi.function.Signature)36 Type (io.prestosql.spi.type.Type)27 Test (org.testng.annotations.Test)24 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)22 ImmutableList (com.google.common.collect.ImmutableList)18 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)18 CallExpression (io.prestosql.spi.relation.CallExpression)18 PrestoException (io.prestosql.spi.PrestoException)17 List (java.util.List)14 RowExpression (io.prestosql.spi.relation.RowExpression)12 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)11 RowType (io.prestosql.spi.type.RowType)11 ArrayList (java.util.ArrayList)11 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)10 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)10 ArrayType (io.prestosql.spi.type.ArrayType)10 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)10 HashSet (java.util.HashSet)10 Domain (io.prestosql.spi.predicate.Domain)9