Search in sources :

Example 1 with SCALAR

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

the class DecimalOperators method decimalDivideOperator.

private static SqlScalarFunction decimalDivideOperator() {
    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"));
    // we extend target precision by b_scale. This is upper bound on how much division result will grow.
    // pessimistic case is a / 0.0000001
    // if scale of divisor is greater than scale of dividend we extend scale further as we
    // want result scale to be maximum of scales of divisor and dividend.
    Signature signature = Signature.builder().kind(SCALAR).operatorType(DIVIDE).longVariableConstraints(longVariableExpression("r_precision", "min(38, a_precision + b_scale + max(b_scale - a_scale, 0))"), longVariableExpression("r_scale", "max(a_scale, b_scale)")).argumentTypes(decimalLeftSignature, decimalRightSignature).returnType(decimalResultSignature).build();
    return SqlScalarFunction.builder(DecimalOperators.class, DIVIDE).signature(signature).deterministic(true).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("divideShortShortShort", "divideShortLongShort", "divideLongShortShort", "divideShortShortLong", "divideLongLongLong", "divideShortLongLong", "divideLongShortLong").withExtraParameters(DecimalOperators::divideRescaleFactor))).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 2 with SCALAR

use of io.prestosql.spi.function.FunctionKind.SCALAR 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 3 with SCALAR

use of io.prestosql.spi.function.FunctionKind.SCALAR 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 4 with SCALAR

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

the class TestPolymorphicScalarFunction method testSelectsMultipleChoiceWithBlockPosition.

@Test
public void testSelectsMultipleChoiceWithBlockPosition() throws Throwable {
    Signature signature = Signature.builder().kind(SCALAR).operatorType(IS_DISTINCT_FROM).argumentTypes(DECIMAL_SIGNATURE, DECIMAL_SIGNATURE).returnType(parseTypeSignature(BOOLEAN)).build();
    SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(signature).deterministic(true).calledOnNullInput(IS_DISTINCT_FROM.isCalledOnNullInput()).choice(choice -> choice.argumentProperties(valueTypeArgumentProperty(USE_NULL_FLAG), valueTypeArgumentProperty(USE_NULL_FLAG)).implementation(methodsGroup -> methodsGroup.methods("shortShort", "longLong"))).choice(choice -> choice.argumentProperties(valueTypeArgumentProperty(BLOCK_AND_POSITION), valueTypeArgumentProperty(BLOCK_AND_POSITION)).implementation(methodsGroup -> methodsGroup.methodWithExplicitJavaTypes("blockPositionLongLong", asList(Optional.of(Slice.class), Optional.of(Slice.class))).methodWithExplicitJavaTypes("blockPositionShortShort", asList(Optional.of(long.class), Optional.of(long.class))))).build();
    BuiltInScalarFunctionImplementation functionImplementation = function.specialize(SHORT_DECIMAL_BOUND_VARIABLES, 2, METADATA.getFunctionAndTypeManager());
    assertEquals(functionImplementation.getAllChoices().size(), 2);
    assertEquals(functionImplementation.getAllChoices().get(0).getArgumentProperties(), Collections.nCopies(2, valueTypeArgumentProperty(USE_NULL_FLAG)));
    assertEquals(functionImplementation.getAllChoices().get(1).getArgumentProperties(), Collections.nCopies(2, valueTypeArgumentProperty(BLOCK_AND_POSITION)));
    Block block1 = new LongArrayBlock(0, Optional.empty(), new long[0]);
    Block block2 = new LongArrayBlock(0, Optional.empty(), new long[0]);
    assertFalse((boolean) functionImplementation.getAllChoices().get(1).getMethodHandle().invoke(block1, 0, block2, 0));
    functionImplementation = function.specialize(LONG_DECIMAL_BOUND_VARIABLES, 2, METADATA.getFunctionAndTypeManager());
    assertTrue((boolean) functionImplementation.getAllChoices().get(1).getMethodHandle().invoke(block1, 0, block2, 0));
}
Also used : ADD(io.prestosql.spi.function.OperatorType.ADD) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) BLOCK_AND_POSITION(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.BLOCK_AND_POSITION) Slice(io.airlift.slice.Slice) StandardTypes(io.prestosql.spi.type.StandardTypes) SCALAR(io.prestosql.spi.function.FunctionKind.SCALAR) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) VARCHAR_TO_BIGINT_RETURN_VALUE(io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) Slices(io.airlift.slice.Slices) USE_NULL_FLAG(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.USE_NULL_FLAG) Math.toIntExact(java.lang.Math.toIntExact) Signature(io.prestosql.spi.function.Signature) Signature.comparableWithVariadicBound(io.prestosql.spi.function.Signature.comparableWithVariadicBound) Assert.assertFalse(org.testng.Assert.assertFalse) Block(io.prestosql.spi.block.Block) VARCHAR(io.prestosql.spi.type.StandardTypes.VARCHAR) ImmutableSet(com.google.common.collect.ImmutableSet) BOOLEAN(io.prestosql.spi.type.StandardTypes.BOOLEAN) ImmutableMap(com.google.common.collect.ImmutableMap) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) IS_DISTINCT_FROM(io.prestosql.spi.function.OperatorType.IS_DISTINCT_FROM) MAX_SHORT_PRECISION(io.prestosql.spi.type.Decimals.MAX_SHORT_PRECISION) ArgumentProperty.valueTypeArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) VARCHAR_TO_VARCHAR_RETURN_VALUE(io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE) TypeSignature(io.prestosql.spi.type.TypeSignature) Collections(java.util.Collections) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) Block(io.prestosql.spi.block.Block) Test(org.testng.annotations.Test)

Example 5 with SCALAR

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

the class TestPolymorphicScalarFunction method testSameLiteralInArgumentsAndReturnValue.

@Test
public void testSameLiteralInArgumentsAndReturnValue() throws Throwable {
    Signature signature = Signature.builder().name("foo").kind(SCALAR).returnType(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))).argumentTypes(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))).build();
    SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(signature).deterministic(true).calledOnNullInput(FOO_IS_CALL_ON_NUL_INPUT).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("varcharToVarchar"))).build();
    BuiltInScalarFunctionImplementation functionImplementation = function.specialize(BOUND_VARIABLES, 1, METADATA.getFunctionAndTypeManager());
    Slice slice = (Slice) functionImplementation.getMethodHandle().invoke(INPUT_SLICE);
    assertEquals(slice, VARCHAR_TO_VARCHAR_RETURN_VALUE);
}
Also used : ADD(io.prestosql.spi.function.OperatorType.ADD) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) BLOCK_AND_POSITION(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.BLOCK_AND_POSITION) Slice(io.airlift.slice.Slice) StandardTypes(io.prestosql.spi.type.StandardTypes) SCALAR(io.prestosql.spi.function.FunctionKind.SCALAR) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) VARCHAR_TO_BIGINT_RETURN_VALUE(io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) Slices(io.airlift.slice.Slices) USE_NULL_FLAG(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.USE_NULL_FLAG) Math.toIntExact(java.lang.Math.toIntExact) Signature(io.prestosql.spi.function.Signature) Signature.comparableWithVariadicBound(io.prestosql.spi.function.Signature.comparableWithVariadicBound) Assert.assertFalse(org.testng.Assert.assertFalse) Block(io.prestosql.spi.block.Block) VARCHAR(io.prestosql.spi.type.StandardTypes.VARCHAR) ImmutableSet(com.google.common.collect.ImmutableSet) BOOLEAN(io.prestosql.spi.type.StandardTypes.BOOLEAN) ImmutableMap(com.google.common.collect.ImmutableMap) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) IS_DISTINCT_FROM(io.prestosql.spi.function.OperatorType.IS_DISTINCT_FROM) MAX_SHORT_PRECISION(io.prestosql.spi.type.Decimals.MAX_SHORT_PRECISION) ArgumentProperty.valueTypeArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) VARCHAR_TO_VARCHAR_RETURN_VALUE(io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE) TypeSignature(io.prestosql.spi.type.TypeSignature) Collections(java.util.Collections) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) Slice(io.airlift.slice.Slice) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) Test(org.testng.annotations.Test)

Aggregations

SCALAR (io.prestosql.spi.function.FunctionKind.SCALAR)9 TypeSignature (io.prestosql.spi.type.TypeSignature)9 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 Slice (io.airlift.slice.Slice)8 ADD (io.prestosql.spi.function.OperatorType.ADD)8 Signature (io.prestosql.spi.function.Signature)8 StandardTypes (io.prestosql.spi.type.StandardTypes)7 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)7 Math.toIntExact (java.lang.Math.toIntExact)7 PrestoException (io.prestosql.spi.PrestoException)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Slices (io.airlift.slice.Slices)4 XxHash64 (io.airlift.slice.XxHash64)4 MetadataManager.createTestMetadataManager (io.prestosql.metadata.MetadataManager.createTestMetadataManager)4 PolymorphicScalarFunctionBuilder (io.prestosql.metadata.PolymorphicScalarFunctionBuilder)4 SpecializeContext (io.prestosql.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext)4 SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)4 VARCHAR_TO_BIGINT_RETURN_VALUE (io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE)4 VARCHAR_TO_VARCHAR_RETURN_VALUE (io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE)4