Search in sources :

Example 6 with TypeRegistry

use of com.facebook.presto.type.TypeRegistry in project presto by prestodb.

the class TestFunctionRegistry method testExactMatchBeforeCoercion.

@Test
public void testExactMatchBeforeCoercion() {
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    boolean foundOperator = false;
    for (SqlFunction function : registry.listOperators()) {
        OperatorType operatorType = unmangleOperator(function.getSignature().getName());
        if (operatorType == OperatorType.CAST || operatorType == OperatorType.SATURATED_FLOOR_CAST) {
            continue;
        }
        if (!function.getSignature().getTypeVariableConstraints().isEmpty()) {
            continue;
        }
        if (function.getSignature().getArgumentTypes().stream().anyMatch(TypeSignature::isCalculated)) {
            continue;
        }
        Signature exactOperator = registry.resolveOperator(operatorType, resolveTypes(function.getSignature().getArgumentTypes(), typeManager));
        assertEquals(exactOperator, function.getSignature());
        foundOperator = true;
    }
    assertTrue(foundOperator);
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeSignature(com.facebook.presto.spi.type.TypeSignature) FunctionRegistry.getMagicLiteralFunctionSignature(com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeRegistry(com.facebook.presto.type.TypeRegistry) OperatorType(com.facebook.presto.spi.function.OperatorType) Test(org.testng.annotations.Test)

Example 7 with TypeRegistry

use of com.facebook.presto.type.TypeRegistry in project presto by prestodb.

the class TestSignature method testSerializationRoundTrip.

@Test
public void testSerializationRoundTrip() {
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(new TypeRegistry())));
    JsonCodec<Signature> codec = new JsonCodecFactory(objectMapperProvider, true).jsonCodec(Signature.class);
    Signature expected = new Signature("function", SCALAR, parseTypeSignature(StandardTypes.BIGINT), ImmutableList.of(parseTypeSignature(StandardTypes.BOOLEAN), parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.VARCHAR)));
    String json = codec.toJson(expected);
    Signature actual = codec.fromJson(json);
    assertEquals(actual.getName(), expected.getName());
    assertEquals(actual.getKind(), expected.getKind());
    assertEquals(actual.getReturnType(), expected.getReturnType());
    assertEquals(actual.getArgumentTypes(), expected.getArgumentTypes());
}
Also used : Type(com.facebook.presto.spi.type.Type) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) TypeRegistry(com.facebook.presto.type.TypeRegistry) JsonCodecFactory(io.airlift.json.JsonCodecFactory) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Test(org.testng.annotations.Test)

Example 8 with TypeRegistry

use of com.facebook.presto.type.TypeRegistry in project presto by prestodb.

the class MetadataManager method createTestingViewCodec.

private static JsonCodec<ViewDefinition> createTestingViewCodec() {
    ObjectMapperProvider provider = new ObjectMapperProvider();
    provider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(new TypeRegistry())));
    return new JsonCodecFactory(provider).jsonCodec(ViewDefinition.class);
}
Also used : OperatorType(com.facebook.presto.spi.function.OperatorType) Type(com.facebook.presto.spi.type.Type) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) TypeRegistry(com.facebook.presto.type.TypeRegistry) JsonCodecFactory(io.airlift.json.JsonCodecFactory) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider)

Example 9 with TypeRegistry

use of com.facebook.presto.type.TypeRegistry in project presto by prestodb.

the class TestFunctionRegistry method testDuplicateFunctions.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "\\QFunction already registered: custom_add(bigint,bigint):bigint\\E")
public void testDuplicateFunctions() {
    List<SqlFunction> functions = new FunctionListBuilder().scalars(CustomFunctions.class).getFunctions().stream().filter(input -> input.getSignature().getName().equals("custom_add")).collect(toImmutableList());
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    registry.addFunctions(functions);
    registry.addFunctions(functions);
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) TypeManager(com.facebook.presto.spi.type.TypeManager) TIMESTAMP_WITH_TIME_ZONE(com.facebook.presto.spi.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE) TypeRegistry(com.facebook.presto.type.TypeRegistry) Assert.assertEquals(org.testng.Assert.assertEquals) ScalarFunctionImplementation(com.facebook.presto.operator.scalar.ScalarFunctionImplementation) Test(org.testng.annotations.Test) FunctionRegistry.mangleOperatorName(com.facebook.presto.metadata.FunctionRegistry.mangleOperatorName) Lists.transform(com.google.common.collect.Lists.transform) BlockEncodingSerde(com.facebook.presto.spi.block.BlockEncodingSerde) SCALAR(com.facebook.presto.metadata.FunctionKind.SCALAR) ImmutableList(com.google.common.collect.ImmutableList) FunctionRegistry.getMagicLiteralFunctionSignature(com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature) TypeSignatureProvider.fromTypeSignatures(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypeSignatures) Signature.typeVariable(com.facebook.presto.metadata.Signature.typeVariable) StandardTypes(com.facebook.presto.spi.type.StandardTypes) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) Assert.assertFalse(org.testng.Assert.assertFalse) Functions(com.google.common.base.Functions) ImmutableSet(com.google.common.collect.ImmutableSet) FunctionRegistry.unmangleOperator(com.facebook.presto.metadata.FunctionRegistry.unmangleOperator) HYPER_LOG_LOG(com.facebook.presto.spi.type.HyperLogLogType.HYPER_LOG_LOG) MethodHandles(java.lang.invoke.MethodHandles) Assert.fail(org.testng.Assert.fail) String.format(java.lang.String.format) CustomFunctions(com.facebook.presto.operator.scalar.CustomFunctions) TypeUtils.resolveTypes(com.facebook.presto.type.TypeUtils.resolveTypes) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) OperatorType(com.facebook.presto.spi.function.OperatorType) Assert.assertTrue(org.testng.Assert.assertTrue) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Collections(java.util.Collections) SqlType(com.facebook.presto.spi.function.SqlType) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeRegistry(com.facebook.presto.type.TypeRegistry) Test(org.testng.annotations.Test)

Example 10 with TypeRegistry

use of com.facebook.presto.type.TypeRegistry in project presto by prestodb.

the class TestFunctionRegistry method testListingHiddenFunctions.

@Test
public void testListingHiddenFunctions() throws Exception {
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    List<SqlFunction> functions = registry.list();
    List<String> names = transform(functions, input -> input.getSignature().getName());
    assertTrue(names.contains("length"), "Expected function names " + names + " to contain 'length'");
    assertTrue(names.contains("stddev"), "Expected function names " + names + " to contain 'stddev'");
    assertTrue(names.contains("rank"), "Expected function names " + names + " to contain 'rank'");
    assertFalse(names.contains("like"), "Expected function names " + names + " not to contain 'like'");
}
Also used : BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeRegistry(com.facebook.presto.type.TypeRegistry) Test(org.testng.annotations.Test)

Aggregations

TypeRegistry (com.facebook.presto.type.TypeRegistry)20 Test (org.testng.annotations.Test)12 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)10 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)9 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)9 BeforeMethod (org.testng.annotations.BeforeMethod)6 DBI (org.skife.jdbi.v2.DBI)5 FunctionRegistry.getMagicLiteralFunctionSignature (com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature)4 TypeManager (com.facebook.presto.spi.type.TypeManager)4 TestingNodeManager (com.facebook.presto.testing.TestingNodeManager)4 FunctionRegistry (com.facebook.presto.metadata.FunctionRegistry)3 Signature (com.facebook.presto.metadata.Signature)3 NodeSupplier (com.facebook.presto.raptor.NodeSupplier)3 MetadataDao (com.facebook.presto.raptor.metadata.MetadataDao)3 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)3 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)3 SchemaTableName (com.facebook.presto.spi.SchemaTableName)3 CallExpression (com.facebook.presto.sql.relational.CallExpression)3 ConstantExpression (com.facebook.presto.sql.relational.ConstantExpression)3 RowExpression (com.facebook.presto.sql.relational.RowExpression)3