Search in sources :

Example 51 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class TestRowExpressionSerde method getJsonCodec.

private JsonCodec<RowExpression> getJsonCodec() throws Exception {
    Module module = binder -> {
        binder.install(new JsonModule());
        binder.install(new HandleJsonModule());
        configBinder(binder).bindConfig(FeaturesConfig.class);
        FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
        binder.bind(TypeManager.class).toInstance(functionAndTypeManager);
        jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
        newSetBinder(binder, Type.class);
        binder.bind(BlockEncodingSerde.class).to(BlockEncodingManager.class).in(Scopes.SINGLETON);
        newSetBinder(binder, BlockEncoding.class);
        jsonBinder(binder).addSerializerBinding(Block.class).to(BlockJsonSerde.Serializer.class);
        jsonBinder(binder).addDeserializerBinding(Block.class).to(BlockJsonSerde.Deserializer.class);
        jsonCodecBinder(binder).bindJsonCodec(RowExpression.class);
    };
    Bootstrap app = new Bootstrap(ImmutableList.of(module));
    Injector injector = app.doNotInitializeLogging().quiet().initialize();
    return injector.getInstance(new Key<JsonCodec<RowExpression>>() {
    });
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) WarningCollector(com.facebook.presto.spi.WarningCollector) Module(com.google.inject.Module) JsonCodec(com.facebook.airlift.json.JsonCodec) MetadataManager(com.facebook.presto.metadata.MetadataManager) SqlToRowExpressionTranslator(com.facebook.presto.sql.relational.SqlToRowExpressionTranslator) Key(com.google.inject.Key) BlockEncoding(com.facebook.presto.common.block.BlockEncoding) RowExpressionOptimizer(com.facebook.presto.sql.relational.RowExpressionOptimizer) Test(org.testng.annotations.Test) Float.floatToIntBits(java.lang.Float.floatToIntBits) Expressions.constant(com.facebook.presto.sql.relational.Expressions.constant) Expressions.specialForm(com.facebook.presto.sql.relational.Expressions.specialForm) IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) Map(java.util.Map) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) Multibinder.newSetBinder(com.google.inject.multibindings.Multibinder.newSetBinder) JsonModule(com.facebook.airlift.json.JsonModule) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Collections.emptyList(java.util.Collections.emptyList) BeforeClass(org.testng.annotations.BeforeClass) JsonBinder.jsonBinder(com.facebook.airlift.json.JsonBinder.jsonBinder) VarcharType(com.facebook.presto.common.type.VarcharType) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) AS_DOUBLE(com.facebook.presto.sql.parser.ParsingOptions.DecimalLiteralTreatment.AS_DOUBLE) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) Slice(io.airlift.slice.Slice) TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) Assert.assertEquals(org.testng.Assert.assertEquals) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) Expressions.call(com.facebook.presto.sql.relational.Expressions.call) JsonCodecBinder.jsonCodecBinder(com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder) DATE(com.facebook.presto.common.type.DateType.DATE) REAL(com.facebook.presto.common.type.RealType.REAL) BlockJsonSerde(com.facebook.presto.block.BlockJsonSerde) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) Assert.assertThrows(org.testng.Assert.assertThrows) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) TypeManager(com.facebook.presto.common.type.TypeManager) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) ArrayType(com.facebook.presto.common.type.ArrayType) HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog) Type(com.facebook.presto.common.type.Type) SUBSCRIPT(com.facebook.presto.common.function.OperatorType.SUBSCRIPT) RowExpression(com.facebook.presto.spi.relation.RowExpression) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) Language(org.intellij.lang.annotations.Language) OperatorType(com.facebook.presto.common.function.OperatorType) Scopes(com.google.inject.Scopes) NodeRef(com.facebook.presto.sql.tree.NodeRef) Injector(com.google.inject.Injector) OPTIMIZED(com.facebook.presto.spi.relation.ExpressionOptimizer.Level.OPTIMIZED) Scope(com.facebook.presto.sql.analyzer.Scope) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) ExpressionAnalyzer(com.facebook.presto.sql.analyzer.ExpressionAnalyzer) Expression(com.facebook.presto.sql.tree.Expression) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) ROW_CONSTRUCTOR(com.facebook.presto.spi.relation.SpecialFormExpression.Form.ROW_CONSTRUCTOR) Assert.assertTrue(org.testng.Assert.assertTrue) ConfigBinder.configBinder(com.facebook.airlift.configuration.ConfigBinder.configBinder) Block(com.facebook.presto.common.block.Block) PlanBuilder.expression(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.expression) RowType(com.facebook.presto.common.type.RowType) Metadata(com.facebook.presto.metadata.Metadata) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) RowExpression(com.facebook.presto.spi.relation.RowExpression) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) JsonModule(com.facebook.airlift.json.JsonModule) VarcharType(com.facebook.presto.common.type.VarcharType) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) OperatorType(com.facebook.presto.common.function.OperatorType) RowType(com.facebook.presto.common.type.RowType) JsonCodec(com.facebook.airlift.json.JsonCodec) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) Module(com.google.inject.Module) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) JsonModule(com.facebook.airlift.json.JsonModule) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) BlockEncoding(com.facebook.presto.common.block.BlockEncoding)

Example 52 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class TestField method testMap.

@Test
public void testMap() {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    Type type = functionAndTypeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.of(VARCHAR.getTypeSignature()), TypeSignatureParameter.of(BIGINT.getTypeSignature())));
    Block expected = AccumuloRowSerializer.getBlockFromMap(type, ImmutableMap.of("a", 1L, "b", 2L, "c", 3L));
    Field f1 = new Field(expected, type);
    assertEquals(f1.getMap(), expected);
    assertEquals(f1.getObject(), expected);
    assertEquals(f1.getType(), type);
    assertEquals(f1.toString(), "MAP(ARRAY ['a','b','c'], ARRAY [1,2,3])");
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) Block(com.facebook.presto.common.block.Block) Test(org.testng.annotations.Test)

Example 53 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class AbstractTestAccumuloRowSerializer method testMap.

@Test
public void testMap() throws Exception {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance();
    Type type = functionAndTypeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.of(VARCHAR.getTypeSignature()), TypeSignatureParameter.of(BIGINT.getTypeSignature())));
    Map<Object, Object> expected = ImmutableMap.of("a", 1L, "b", 2L, "3", 3L);
    byte[] data = serializer.encode(type, AccumuloRowSerializer.getBlockFromMap(type, expected));
    Map<Object, Object> actual = serializer.decode(type, data);
    assertEquals(actual, expected);
    deserializeData(serializer, data);
    actual = AccumuloRowSerializer.getMapFromBlock(type, serializer.getMap(COLUMN_NAME, type));
    assertEquals(actual, expected);
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) Test(org.testng.annotations.Test)

Example 54 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class AbstractTestGeoAggregationFunctions method registerFunctions.

@BeforeClass
public void registerFunctions() {
    GeoPlugin plugin = new GeoPlugin();
    for (Type type : plugin.getTypes()) {
        functionAssertions.getFunctionAndTypeManager().addType(type);
    }
    functionAssertions.getMetadata().registerBuiltInFunctions(extractFunctions(plugin.getFunctions()));
    FunctionAndTypeManager functionAndTypeManager = functionAssertions.getMetadata().getFunctionAndTypeManager();
    function = functionAndTypeManager.getAggregateFunctionImplementation(functionAndTypeManager.lookupFunction(getFunctionName(), fromTypes(GEOMETRY)));
}
Also used : Type(com.facebook.presto.common.type.Type) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) GeoPlugin(com.facebook.presto.plugin.geospatial.GeoPlugin) BeforeClass(org.testng.annotations.BeforeClass)

Example 55 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class StatisticsAggregationPlanner method createAggregation.

private ColumnStatisticsAggregation createAggregation(String functionName, RowExpression input, Type inputType, Type outputType) {
    FunctionAndTypeManager functionAndTypeManager = metadata.getFunctionAndTypeManager();
    FunctionHandle functionHandle = functionAndTypeManager.lookupFunction(functionName, TypeSignatureProvider.fromTypes(ImmutableList.of(inputType)));
    Type resolvedType = metadata.getType(getOnlyElement(functionAndTypeManager.getFunctionMetadata(functionHandle).getArgumentTypes()));
    verify(resolvedType.equals(inputType), "resolved function input type does not match the input type: %s != %s", resolvedType, inputType);
    return new ColumnStatisticsAggregation(new AggregationNode.Aggregation(new CallExpression(input.getSourceLocation(), functionName, functionHandle, outputType, ImmutableList.of(input)), Optional.empty(), Optional.empty(), false, Optional.empty()), outputType);
}
Also used : TableStatisticType(com.facebook.presto.spi.statistics.TableStatisticType) Type(com.facebook.presto.common.type.Type) ColumnStatisticType(com.facebook.presto.spi.statistics.ColumnStatisticType) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) CallExpression(com.facebook.presto.spi.relation.CallExpression)

Aggregations

FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)62 Test (org.testng.annotations.Test)31 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)26 Type (com.facebook.presto.common.type.Type)24 RowExpression (com.facebook.presto.spi.relation.RowExpression)13 ImmutableList (com.google.common.collect.ImmutableList)13 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)12 CallExpression (com.facebook.presto.spi.relation.CallExpression)12 Block (com.facebook.presto.common.block.Block)11 ArrayType (com.facebook.presto.common.type.ArrayType)11 Optional (java.util.Optional)11 BeforeClass (org.testng.annotations.BeforeClass)11 Page (com.facebook.presto.common.Page)10 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)10 List (java.util.List)10 DBI (org.skife.jdbi.v2.DBI)8 Bootstrap (com.facebook.airlift.bootstrap.Bootstrap)6 JsonBinder.jsonBinder (com.facebook.airlift.json.JsonBinder.jsonBinder)6 JsonCodecBinder.jsonCodecBinder (com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder)6 JsonModule (com.facebook.airlift.json.JsonModule)6