Search in sources :

Example 11 with SqlScalarFunction

use of io.prestosql.metadata.SqlScalarFunction in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testMultiScalarParse.

@Test
public void testMultiScalarParse() {
    Signature expectedSignature1 = new Signature(QualifiedObjectName.valueOfDefaultFunction("static_method_scalar_1"), FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
    Signature expectedSignature2 = new Signature(QualifiedObjectName.valueOfDefaultFunction("static_method_scalar_2"), FunctionKind.SCALAR, BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinitions(MultiScalarFunction.class);
    assertEquals(functions.size(), 2);
    ParametricScalar scalar1 = (ParametricScalar) functions.stream().filter(signature -> signature.getSignature().equals(expectedSignature1)).collect(toImmutableList()).get(0);
    ParametricScalar scalar2 = (ParametricScalar) functions.stream().filter(signature -> signature.getSignature().equals(expectedSignature2)).collect(toImmutableList()).get(0);
    assertImplementationCount(scalar1, 1, 0, 0);
    assertImplementationCount(scalar2, 1, 0, 0);
    assertEquals(scalar1.getSignature(), expectedSignature1);
    assertTrue(scalar1.isDeterministic());
    assertFalse(scalar1.isHidden());
    assertEquals(scalar1.getDescription(), "Simple scalar with single implementation based on method 1");
    assertEquals(scalar2.getSignature(), expectedSignature2);
    assertFalse(scalar2.isDeterministic());
    assertTrue(scalar2.isHidden());
    assertEquals(scalar2.getDescription(), "Simple scalar with single implementation based on method 2");
}
Also used : BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) Slice(io.airlift.slice.Slice) FunctionKind(io.prestosql.spi.function.FunctionKind) StandardTypes(io.prestosql.spi.type.StandardTypes) Assert.assertEquals(org.testng.Assert.assertEquals) LiteralParameters(io.prestosql.spi.function.LiteralParameters) Test(org.testng.annotations.Test) BoundVariables(io.prestosql.metadata.BoundVariables) TypeParameter(io.prestosql.spi.function.TypeParameter) USE_BOXED_TYPE(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.USE_BOXED_TYPE) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) ParametricScalarImplementationChoice(io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) IsNull(io.prestosql.spi.function.IsNull) LiteralParameter(io.prestosql.spi.function.LiteralParameter) ImmutableList(com.google.common.collect.ImmutableList) RETURN_NULL_ON_NULL(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.RETURN_NULL_ON_NULL) USE_NULL_FLAG(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.USE_NULL_FLAG) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Description(io.prestosql.spi.function.Description) Type(io.prestosql.spi.type.Type) Signature(io.prestosql.spi.function.Signature) TypeImplementationDependency(io.prestosql.operator.annotations.TypeImplementationDependency) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Assert.assertFalse(org.testng.Assert.assertFalse) Block(io.prestosql.spi.block.Block) ImmutableSet(com.google.common.collect.ImmutableSet) ImplementationDependency(io.prestosql.operator.annotations.ImplementationDependency) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) Metadata(io.prestosql.metadata.Metadata) Signature.typeVariable(io.prestosql.spi.function.Signature.typeVariable) ScalarFunction(io.prestosql.spi.function.ScalarFunction) ScalarFromAnnotationsParser(io.prestosql.operator.scalar.annotations.ScalarFromAnnotationsParser) List(java.util.List) SqlType(io.prestosql.spi.function.SqlType) ArgumentProperty.valueTypeArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty) Assert.assertTrue(org.testng.Assert.assertTrue) SqlNullable(io.prestosql.spi.function.SqlNullable) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 12 with SqlScalarFunction

use of io.prestosql.metadata.SqlScalarFunction in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testSimpleInjectionScalarParse.

@Test
public void testSimpleInjectionScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("parametric_scalar_inject"), FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(SimpleInjectionScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 0, 0, 1);
    List<ParametricScalarImplementationChoice> parametricScalarImplementationChoices = scalar.getImplementations().getGenericImplementations().get(0).getChoices();
    assertEquals(parametricScalarImplementationChoices.size(), 1);
    List<ImplementationDependency> dependencies = parametricScalarImplementationChoices.get(0).getDependencies();
    assertEquals(dependencies.size(), 1);
    assertTrue(dependencies.get(0) instanceof LiteralImplementationDependency);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Parametric scalar with literal injected");
}
Also used : TypeImplementationDependency(io.prestosql.operator.annotations.TypeImplementationDependency) ImplementationDependency(io.prestosql.operator.annotations.ImplementationDependency) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalarImplementationChoice(io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 13 with SqlScalarFunction

use of io.prestosql.metadata.SqlScalarFunction in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testPartiallyFixedTypeParameterParse.

@Test
public void testPartiallyFixedTypeParameterParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("partially_fixed_type_parameter_scalar_function"), FunctionKind.SCALAR, ImmutableList.of(typeVariable("T1"), typeVariable("T2")), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(PartiallyFixedTypeParameterScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 0, 0, 1);
    List<ParametricScalarImplementationChoice> parametricScalarImplementationChoices = scalar.getImplementations().getGenericImplementations().get(0).getChoices();
    assertEquals(parametricScalarImplementationChoices.size(), 1);
    List<ImplementationDependency> dependencies = parametricScalarImplementationChoices.get(0).getDependencies();
    assertEquals(dependencies.size(), 1);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Parametric scalar that uses TypeParameter with partially fixed type");
}
Also used : TypeImplementationDependency(io.prestosql.operator.annotations.TypeImplementationDependency) ImplementationDependency(io.prestosql.operator.annotations.ImplementationDependency) LiteralImplementationDependency(io.prestosql.operator.annotations.LiteralImplementationDependency) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalarImplementationChoice(io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 14 with SqlScalarFunction

use of io.prestosql.metadata.SqlScalarFunction in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testHiddenScalarParse.

@Test
public void testHiddenScalarParse() {
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(HiddenScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertTrue(scalar.isDeterministic());
    assertTrue(scalar.isHidden());
}
Also used : ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 15 with SqlScalarFunction

use of io.prestosql.metadata.SqlScalarFunction in project hetu-core by openlookeng.

the class TestAnnotationEngineForScalars method testSingleImplementationScalarParse.

@Test
public void testSingleImplementationScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("single_implementation_parametric_scalar"), FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(SingleImplementationScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertFalse(scalar.isHidden());
    assertEquals(scalar.getDescription(), "Simple scalar with single implementation based on class");
    assertImplementationCount(scalar, 1, 0, 0);
    BuiltInScalarFunctionImplementation specialized = scalar.specialize(BoundVariables.builder().build(), 1, METADATA.getFunctionAndTypeManager());
    assertFalse(specialized.getInstanceFactory().isPresent());
    assertEquals(specialized.getArgumentProperty(0).getNullConvention(), RETURN_NULL_ON_NULL);
}
Also used : BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) ParametricScalar(io.prestosql.operator.scalar.ParametricScalar) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Aggregations

SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)18 Signature (io.prestosql.spi.function.Signature)16 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)15 Test (org.testng.annotations.Test)14 ParametricScalar (io.prestosql.operator.scalar.ParametricScalar)13 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 Slice (io.airlift.slice.Slice)5 IsNull (io.prestosql.spi.function.IsNull)5 LiteralParameters (io.prestosql.spi.function.LiteralParameters)5 SqlType (io.prestosql.spi.function.SqlType)5 StandardTypes (io.prestosql.spi.type.StandardTypes)5 XxHash64 (io.airlift.slice.XxHash64)4 PolymorphicScalarFunctionBuilder (io.prestosql.metadata.PolymorphicScalarFunctionBuilder)4 SpecializeContext (io.prestosql.metadata.PolymorphicScalarFunctionBuilder.SpecializeContext)3 ImplementationDependency (io.prestosql.operator.annotations.ImplementationDependency)3 LiteralImplementationDependency (io.prestosql.operator.annotations.LiteralImplementationDependency)3 TypeImplementationDependency (io.prestosql.operator.annotations.TypeImplementationDependency)3 ParametricScalarImplementationChoice (io.prestosql.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice)3 PrestoException (io.prestosql.spi.PrestoException)3