Search in sources :

Example 6 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class DecimalOperators method decimalAddOperator.

private static SqlScalarFunction decimalAddOperator() {
    TypeSignature decimalLeftSignature = parseTypeSignature("decimal(a_precision, a_scale)", ImmutableSet.of("a_precision", "a_scale"));
    TypeSignature decimalRightSignature = parseTypeSignature("decimal(b_precision, b_scale)", ImmutableSet.of("b_precision", "b_scale"));
    TypeSignature decimalResultSignature = parseTypeSignature("decimal(r_precision, r_scale)", ImmutableSet.of("r_precision", "r_scale"));
    Signature signature = Signature.builder().kind(SCALAR).operatorType(ADD).longVariableConstraints(longVariableExpression("r_precision", "min(38, max(a_precision - a_scale, b_precision - b_scale) + max(a_scale, b_scale) + 1)"), longVariableExpression("r_scale", "max(a_scale, b_scale)")).argumentTypes(decimalLeftSignature, decimalRightSignature).returnType(decimalResultSignature).build();
    return SqlScalarFunction.builder(DecimalOperators.class, ADD).signature(signature).deterministic(true).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("addShortShortShort").withExtraParameters(DecimalOperators::calculateShortRescaleParameters)).implementation(methodsGroup -> methodsGroup.methods("addShortShortLong", "addLongLongLong", "addShortLongLong", "addLongShortLong").withExtraParameters(DecimalOperators::calculateLongRescaleParameters))).build();
}
Also used : ADD(io.prestosql.spi.function.OperatorType.ADD) SCALAR(io.prestosql.spi.function.FunctionKind.SCALAR) LiteralParameters(io.prestosql.spi.function.LiteralParameters) DecimalType(io.prestosql.spi.type.DecimalType) Math.abs(java.lang.Math.abs) UnscaledDecimal128Arithmetic.unscaledDecimal(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.unscaledDecimal) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode) DIVISION_BY_ZERO(io.prestosql.spi.StandardErrorCode.DIVISION_BY_ZERO) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) IsNull(io.prestosql.spi.function.IsNull) ScalarOperator(io.prestosql.spi.function.ScalarOperator) INDETERMINATE(io.prestosql.spi.function.OperatorType.INDETERMINATE) OperatorType(io.prestosql.spi.function.OperatorType) BigInteger(java.math.BigInteger) PolymorphicScalarFunctionBuilder(io.prestosql.metadata.PolymorphicScalarFunctionBuilder) Long.signum(java.lang.Long.signum) MULTIPLY(io.prestosql.spi.function.OperatorType.MULTIPLY) UnscaledDecimal128Arithmetic(io.prestosql.spi.type.UnscaledDecimal128Arithmetic) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) Decimals.longTenToNth(io.prestosql.spi.type.Decimals.longTenToNth) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) List(java.util.List) UnscaledDecimal128Arithmetic.divideRoundUp(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.divideRoundUp) SqlType(io.prestosql.spi.function.SqlType) TypeSignature(io.prestosql.spi.type.TypeSignature) MODULUS(io.prestosql.spi.function.OperatorType.MODULUS) HASH_CODE(io.prestosql.spi.function.OperatorType.HASH_CODE) DIVIDE(io.prestosql.spi.function.OperatorType.DIVIDE) Slice(io.airlift.slice.Slice) StandardTypes(io.prestosql.spi.type.StandardTypes) UnscaledDecimal128Arithmetic.throwIfOverflows(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.throwIfOverflows) SpecializeContext(io.prestosql.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext) NUMERIC_VALUE_OUT_OF_RANGE(io.prestosql.spi.StandardErrorCode.NUMERIC_VALUE_OUT_OF_RANGE) Decimals(io.prestosql.spi.type.Decimals) UnscaledDecimal128Arithmetic.isZero(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.isZero) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) SignatureBuilder(io.prestosql.spi.function.SignatureBuilder) Math.toIntExact(java.lang.Math.toIntExact) Signature(io.prestosql.spi.function.Signature) Signature.longVariableExpression(io.prestosql.spi.function.Signature.longVariableExpression) UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong) XX_HASH_64(io.prestosql.spi.function.OperatorType.XX_HASH_64) XxHash64(io.airlift.slice.XxHash64) Decimals.encodeUnscaledValue(io.prestosql.spi.type.Decimals.encodeUnscaledValue) SUBTRACT(io.prestosql.spi.function.OperatorType.SUBTRACT) Integer.max(java.lang.Integer.max) UnscaledDecimal128Arithmetic.remainder(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.remainder) NEGATION(io.prestosql.spi.function.OperatorType.NEGATION) UnscaledDecimal128Arithmetic.rescale(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.rescale) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature)

Example 7 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class DecimalOperators method decimalMultiplyOperator.

private static SqlScalarFunction decimalMultiplyOperator() {
    TypeSignature decimalLeftSignature = parseTypeSignature("decimal(a_precision, a_scale)", ImmutableSet.of("a_precision", "a_scale"));
    TypeSignature decimalRightSignature = parseTypeSignature("decimal(b_precision, b_scale)", ImmutableSet.of("b_precision", "b_scale"));
    TypeSignature decimalResultSignature = parseTypeSignature("decimal(r_precision, r_scale)", ImmutableSet.of("r_precision", "r_scale"));
    Signature signature = Signature.builder().kind(SCALAR).operatorType(MULTIPLY).longVariableConstraints(longVariableExpression("r_precision", "min(38, a_precision + b_precision)"), longVariableExpression("r_scale", "a_scale + b_scale")).argumentTypes(decimalLeftSignature, decimalRightSignature).returnType(decimalResultSignature).build();
    return SqlScalarFunction.builder(DecimalOperators.class, MULTIPLY).signature(signature).deterministic(true).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("multiplyShortShortShort", "multiplyShortShortLong", "multiplyLongLongLong", "multiplyShortLongLong", "multiplyLongShortLong"))).build();
}
Also used : ADD(io.prestosql.spi.function.OperatorType.ADD) SCALAR(io.prestosql.spi.function.FunctionKind.SCALAR) LiteralParameters(io.prestosql.spi.function.LiteralParameters) DecimalType(io.prestosql.spi.type.DecimalType) Math.abs(java.lang.Math.abs) UnscaledDecimal128Arithmetic.unscaledDecimal(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.unscaledDecimal) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode) DIVISION_BY_ZERO(io.prestosql.spi.StandardErrorCode.DIVISION_BY_ZERO) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) IsNull(io.prestosql.spi.function.IsNull) ScalarOperator(io.prestosql.spi.function.ScalarOperator) INDETERMINATE(io.prestosql.spi.function.OperatorType.INDETERMINATE) OperatorType(io.prestosql.spi.function.OperatorType) BigInteger(java.math.BigInteger) PolymorphicScalarFunctionBuilder(io.prestosql.metadata.PolymorphicScalarFunctionBuilder) Long.signum(java.lang.Long.signum) MULTIPLY(io.prestosql.spi.function.OperatorType.MULTIPLY) UnscaledDecimal128Arithmetic(io.prestosql.spi.type.UnscaledDecimal128Arithmetic) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) Decimals.longTenToNth(io.prestosql.spi.type.Decimals.longTenToNth) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) List(java.util.List) UnscaledDecimal128Arithmetic.divideRoundUp(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.divideRoundUp) SqlType(io.prestosql.spi.function.SqlType) TypeSignature(io.prestosql.spi.type.TypeSignature) MODULUS(io.prestosql.spi.function.OperatorType.MODULUS) HASH_CODE(io.prestosql.spi.function.OperatorType.HASH_CODE) DIVIDE(io.prestosql.spi.function.OperatorType.DIVIDE) Slice(io.airlift.slice.Slice) StandardTypes(io.prestosql.spi.type.StandardTypes) UnscaledDecimal128Arithmetic.throwIfOverflows(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.throwIfOverflows) SpecializeContext(io.prestosql.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext) NUMERIC_VALUE_OUT_OF_RANGE(io.prestosql.spi.StandardErrorCode.NUMERIC_VALUE_OUT_OF_RANGE) Decimals(io.prestosql.spi.type.Decimals) UnscaledDecimal128Arithmetic.isZero(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.isZero) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) SignatureBuilder(io.prestosql.spi.function.SignatureBuilder) Math.toIntExact(java.lang.Math.toIntExact) Signature(io.prestosql.spi.function.Signature) Signature.longVariableExpression(io.prestosql.spi.function.Signature.longVariableExpression) UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.unscaledDecimalToUnscaledLong) XX_HASH_64(io.prestosql.spi.function.OperatorType.XX_HASH_64) XxHash64(io.airlift.slice.XxHash64) Decimals.encodeUnscaledValue(io.prestosql.spi.type.Decimals.encodeUnscaledValue) SUBTRACT(io.prestosql.spi.function.OperatorType.SUBTRACT) Integer.max(java.lang.Integer.max) UnscaledDecimal128Arithmetic.remainder(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.remainder) NEGATION(io.prestosql.spi.function.OperatorType.NEGATION) UnscaledDecimal128Arithmetic.rescale(io.prestosql.spi.type.UnscaledDecimal128Arithmetic.rescale) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature)

Example 8 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestFunctionAndTypeManager method testIdentityCast.

@Test
public void testIdentityCast() {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    FunctionHandle exactOperator = functionAndTypeManager.lookupCast(CastType.CAST, HYPER_LOG_LOG.getTypeSignature(), HYPER_LOG_LOG.getTypeSignature());
    assertEquals(exactOperator, new BuiltInFunctionHandle(new Signature(CAST.getFunctionName(), SCALAR, HYPER_LOG_LOG.getTypeSignature(), HYPER_LOG_LOG.getTypeSignature())));
}
Also used : FunctionAndTypeManager.createTestFunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) LiteralEncoder.getMagicLiteralFunctionSignature(io.prestosql.sql.planner.LiteralEncoder.getMagicLiteralFunctionSignature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) FunctionHandle(io.prestosql.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Example 9 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestFunctionAndTypeManager method testMagicLiteralFunction.

@Test
public void testMagicLiteralFunction() {
    Signature signature = getMagicLiteralFunctionSignature(TIMESTAMP_WITH_TIME_ZONE);
    assertEquals(signature.getNameSuffix(), "$literal$timestamp with time zone");
    assertEquals(signature.getArgumentTypes(), ImmutableList.of(parseTypeSignature(StandardTypes.BIGINT)));
    assertEquals(signature.getReturnType().getBase(), StandardTypes.TIMESTAMP_WITH_TIME_ZONE);
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    BuiltInFunctionHandle functionHandle = (BuiltInFunctionHandle) functionAndTypeManager.resolveFunction(TEST_SESSION.getTransactionId(), signature.getName(), fromTypeSignatures(signature.getArgumentTypes()));
    assertEquals(functionAndTypeManager.getFunctionMetadata(functionHandle).getArgumentTypes(), ImmutableList.of(parseTypeSignature(StandardTypes.BIGINT)));
    assertEquals(signature.getReturnType().getBase(), StandardTypes.TIMESTAMP_WITH_TIME_ZONE);
}
Also used : FunctionAndTypeManager.createTestFunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) LiteralEncoder.getMagicLiteralFunctionSignature(io.prestosql.sql.planner.LiteralEncoder.getMagicLiteralFunctionSignature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) Test(org.testng.annotations.Test)

Example 10 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestLiteralFunction method testLiteralFunction.

@Test
public void testLiteralFunction() {
    Signature signature = getLiteralFunctionSignature(TIMESTAMP_WITH_TIME_ZONE);
    assertEquals(signature.getName(), QualifiedObjectName.valueOfDefaultFunction("$literal$timestamp with time zone"));
    assertEquals(signature.getArgumentTypes(), ImmutableList.of(parseTypeSignature(StandardTypes.BIGINT)));
    assertEquals(signature.getReturnType().getBase(), StandardTypes.TIMESTAMP_WITH_TIME_ZONE);
    Signature function = ((BuiltInFunctionHandle) createTestMetadataManager().getFunctionAndTypeManager().resolveFunction(Optional.empty(), signature.getName(), fromTypeSignatures(signature.getArgumentTypes()))).getSignature();
    assertEquals(function.getArgumentTypes(), ImmutableList.of(parseTypeSignature(StandardTypes.BIGINT)));
    assertEquals(signature.getReturnType().getBase(), StandardTypes.TIMESTAMP_WITH_TIME_ZONE);
}
Also used : LiteralFunction.getLiteralFunctionSignature(io.prestosql.metadata.LiteralFunction.getLiteralFunctionSignature) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) Test(org.testng.annotations.Test)

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