Search in sources :

Example 96 with Signature

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);
}
Also used : TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) BlockAssertions.createShortDecimalsBlock(io.prestosql.block.BlockAssertions.createShortDecimalsBlock) BlockAssertions.createLongDecimalsBlock(io.prestosql.block.BlockAssertions.createLongDecimalsBlock) Block(io.prestosql.spi.block.Block) BlockAssertions.createStringsBlock(io.prestosql.block.BlockAssertions.createStringsBlock) BlockAssertions.createArrayBigintBlock(io.prestosql.block.BlockAssertions.createArrayBigintBlock) BlockAssertions.createBooleansBlock(io.prestosql.block.BlockAssertions.createBooleansBlock) BlockAssertions.createDoublesBlock(io.prestosql.block.BlockAssertions.createDoublesBlock) BlockAssertions.createLongsBlock(io.prestosql.block.BlockAssertions.createLongsBlock) DecimalType(io.prestosql.spi.type.DecimalType) Test(org.testng.annotations.Test)

Example 97 with Signature

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);
}
Also used : TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) BlockAssertions.createShortDecimalsBlock(io.prestosql.block.BlockAssertions.createShortDecimalsBlock) BlockAssertions.createLongDecimalsBlock(io.prestosql.block.BlockAssertions.createLongDecimalsBlock) Block(io.prestosql.spi.block.Block) BlockAssertions.createStringsBlock(io.prestosql.block.BlockAssertions.createStringsBlock) BlockAssertions.createArrayBigintBlock(io.prestosql.block.BlockAssertions.createArrayBigintBlock) BlockAssertions.createBooleansBlock(io.prestosql.block.BlockAssertions.createBooleansBlock) BlockAssertions.createDoublesBlock(io.prestosql.block.BlockAssertions.createDoublesBlock) BlockAssertions.createLongsBlock(io.prestosql.block.BlockAssertions.createLongsBlock) Test(org.testng.annotations.Test)

Example 98 with Signature

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));
}
Also used : InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) AggregationInfo(com.huawei.boostkit.omnidata.model.AggregationInfo) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) FunctionHandle(io.prestosql.spi.function.FunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 99 with Signature

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));
}
Also used : InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) RowDecodeType(com.huawei.boostkit.omnidata.decode.type.RowDecodeType) RowType(io.prestosql.spi.type.RowType) Type(io.prestosql.spi.type.Type) DecodeType(com.huawei.boostkit.omnidata.decode.type.DecodeType) BigintType(io.prestosql.spi.type.BigintType) LongDecodeType(com.huawei.boostkit.omnidata.decode.type.LongDecodeType) DoubleType(io.prestosql.spi.type.DoubleType) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) AggregationInfo(com.huawei.boostkit.omnidata.model.AggregationInfo) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) FunctionHandle(io.prestosql.spi.function.FunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 100 with Signature

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

Aggregations

Signature (io.prestosql.spi.function.Signature)230 Test (org.testng.annotations.Test)186 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)184 TypeSignature (io.prestosql.spi.type.TypeSignature)93 InternalAggregationFunction (io.prestosql.operator.aggregation.InternalAggregationFunction)69 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)41 CallExpression (io.prestosql.spi.relation.CallExpression)35 Type (io.prestosql.spi.type.Type)23 RowExpression (io.prestosql.spi.relation.RowExpression)20 Block (io.prestosql.spi.block.Block)18 ArrayList (java.util.ArrayList)17 ImmutableList (com.google.common.collect.ImmutableList)15 SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)15 MapType (io.prestosql.spi.type.MapType)14 ImmutableSet (com.google.common.collect.ImmutableSet)12 Slice (io.airlift.slice.Slice)12 ParametricAggregation (io.prestosql.operator.aggregation.ParametricAggregation)11 BuiltInScalarFunctionImplementation (io.prestosql.spi.function.BuiltInScalarFunctionImplementation)11 AggregationImplementation (io.prestosql.operator.aggregation.AggregationImplementation)10 AggregationMetadata (io.prestosql.operator.aggregation.AggregationMetadata)10