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)));
}
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));
}
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);
}
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>>() {
});
}
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));
}
Aggregations