Search in sources :

Example 11 with FunctionAndTypeManager

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

the class TestRealAverageAggregation method setUp.

@BeforeClass
public void setUp() {
    FunctionAndTypeManager functionAndTypeManager = MetadataManager.createTestMetadataManager().getFunctionAndTypeManager();
    avgFunction = functionAndTypeManager.getAggregateFunctionImplementation(functionAndTypeManager.lookupFunction("avg", fromTypes(REAL)));
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) BeforeClass(org.testng.annotations.BeforeClass)

Example 12 with FunctionAndTypeManager

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

the class TestIllegalMethodAggregation method testIllegalMethod.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "In differential_entropy UDF, invalid method: no_such_method")
public void testIllegalMethod() {
    FunctionAndTypeManager functionAndTypeManager = MetadataManager.createTestMetadataManager().getFunctionAndTypeManager();
    InternalAggregationFunction function = functionAndTypeManager.getAggregateFunctionImplementation(functionAndTypeManager.lookupFunction("differential_entropy", fromTypes(BIGINT, DOUBLE, DOUBLE, VARCHAR, DOUBLE, DOUBLE)));
    aggregation(function, createLongsBlock(200), createDoublesBlock(0.1), createDoublesBlock(0.2), createStringsBlock("no_such_method"), createDoublesBlock(0.0), createDoublesBlock(1.0));
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 13 with FunctionAndTypeManager

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

the class TestInCodeGenerator method testBigint.

@Test
public void testBigint() {
    FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
    List<RowExpression> values = new ArrayList<>();
    values.add(constant(Integer.MAX_VALUE + 1L, BIGINT));
    values.add(constant(Integer.MIN_VALUE - 1L, BIGINT));
    values.add(constant(3L, BIGINT));
    assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
    values.add(constant(null, BIGINT));
    assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
    values.add(new CallExpression(CAST.name(), functionAndTypeManager.lookupCast(CAST, DOUBLE.getTypeSignature(), BIGINT.getTypeSignature()), BIGINT, Collections.singletonList(constant(12345678901234.0, DOUBLE))));
    assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
    for (long i = 6; i <= 32; ++i) {
        values.add(constant(i, BIGINT));
    }
    assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
    values.add(constant(33L, BIGINT));
    assertEquals(checkSwitchGenerationCase(BIGINT, values), SET_CONTAINS);
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) ArrayList(java.util.ArrayList) RowExpression(com.facebook.presto.spi.relation.RowExpression) CallExpression(com.facebook.presto.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 14 with FunctionAndTypeManager

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

the class TestHiveSplit method getJsonCodec.

private JsonCodec<HiveSplit> 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(HiveSplit.class);
    };
    Bootstrap app = new Bootstrap(ImmutableList.of(module));
    Injector injector = app.doNotInitializeLogging().quiet().initialize();
    HandleResolver handleResolver = injector.getInstance(HandleResolver.class);
    handleResolver.addConnectorName("hive", new HiveHandleResolver());
    return injector.getInstance(new Key<JsonCodec<HiveSplit>>() {
    });
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) Module(com.google.inject.Module) JsonCodec(com.facebook.airlift.json.JsonCodec) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) NO_PREFERENCE(com.facebook.presto.spi.schedule.NodeSelectionStrategy.NO_PREFERENCE) Column(com.facebook.presto.hive.metastore.Column) REGULAR(com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR) Key(com.google.inject.Key) BlockEncoding(com.facebook.presto.common.block.BlockEncoding) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) NO_CACHE_REQUIREMENT(com.facebook.presto.hive.CacheQuotaRequirement.NO_CACHE_REQUIREMENT) OptionalInt(java.util.OptionalInt) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) JsonCodecBinder.jsonCodecBinder(com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder) BlockJsonSerde(com.facebook.presto.block.BlockJsonSerde) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) ImmutableList(com.google.common.collect.ImmutableList) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) TypeManager(com.facebook.presto.common.type.TypeManager) Map(java.util.Map) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) Multibinder.newSetBinder(com.google.inject.multibindings.Multibinder.newSetBinder) HIVE_LONG(com.facebook.presto.hive.HiveType.HIVE_LONG) Type(com.facebook.presto.common.type.Type) JsonModule(com.facebook.airlift.json.JsonModule) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) Storage(com.facebook.presto.hive.metastore.Storage) ImmutableSet(com.google.common.collect.ImmutableSet) StorageFormat(com.facebook.presto.hive.metastore.StorageFormat) ImmutableMap(com.google.common.collect.ImmutableMap) HostAddress(com.facebook.presto.spi.HostAddress) Set(java.util.Set) JsonBinder.jsonBinder(com.facebook.airlift.json.JsonBinder.jsonBinder) Instant(java.time.Instant) Scopes(com.google.inject.Scopes) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) Injector(com.google.inject.Injector) HIVE_STRING(com.facebook.presto.hive.HiveType.HIVE_STRING) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Optional(java.util.Optional) ConfigBinder.configBinder(com.facebook.airlift.configuration.ConfigBinder.configBinder) Block(com.facebook.presto.common.block.Block) SplitWeight(com.facebook.presto.spi.SplitWeight) HandleResolver(com.facebook.presto.metadata.HandleResolver) HandleResolver(com.facebook.presto.metadata.HandleResolver) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) JsonModule(com.facebook.airlift.json.JsonModule) Type(com.facebook.presto.common.type.Type) 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 15 with FunctionAndTypeManager

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

the class TestArraySqlFunctions method testArrayFrequencyVarchar.

@Test
public void testArrayFrequencyVarchar() {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    MapType type = new MapType(VARCHAR, INTEGER, methodHandle(TestRowType.class, "throwUnsupportedOperation"), methodHandle(TestRowType.class, "throwUnsupportedOperation"));
    TypeSignature typeSignature = TypeSignature.parseTypeSignature(type.getDisplayName());
    assertFunction("array_frequency(cast(null as array(varchar)))", functionAndTypeManager.getType(typeSignature), null);
    assertFunction("array_frequency(cast(array[] as array(varchar)))", functionAndTypeManager.getType(typeSignature), ImmutableMap.of());
    assertFunction("array_frequency(array[cast(null as varchar), cast(null as varchar), cast(null as varchar)])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of());
    assertFunction("array_frequency(array[varchar 'z', cast(null as varchar)])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of("z", 1));
    assertFunction("array_frequency(array[varchar 'a', cast(null as varchar), varchar 'b', cast(null as varchar), cast(null as varchar) ])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of("a", 1, "b", 1));
    assertFunction("array_frequency(array[varchar 'a', varchar 'b', varchar 'a', varchar 'a', varchar 'a'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of("a", 4, "b", 1));
    assertFunction("array_frequency(array[varchar 'a', varchar 'b', varchar 'a', varchar 'b', varchar 'c'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of("a", 2, "b", 2, "c", 1));
    assertFunction("array_frequency(array[varchar 'y', varchar 'p'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of("p", 1, "y", 1));
    assertFunction("array_frequency(array[varchar 'a', varchar 'a', varchar 'p'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of("p", 1, "a", 2));
    assertFunction("array_frequency(array[varchar 'z'])", functionAndTypeManager.getType(typeSignature), ImmutableMap.of("z", 1));
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) TestRowType(com.facebook.presto.common.type.TestRowType) MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

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