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