Search in sources :

Example 6 with TypeDeserializer

use of io.trino.type.TypeDeserializer in project trino by trinodb.

the class TestIcebergColumnHandle method testRoundTrip.

private void testRoundTrip(IcebergColumnHandle expected) {
    ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
    objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new TypeDeserializer(TESTING_TYPE_MANAGER)));
    JsonCodec<IcebergColumnHandle> codec = new JsonCodecFactory(objectMapperProvider).jsonCodec(IcebergColumnHandle.class);
    String json = codec.toJson(expected);
    IcebergColumnHandle actual = codec.fromJson(json);
    assertEquals(actual, expected);
    assertEquals(actual.getBaseColumnIdentity(), expected.getBaseColumnIdentity());
    assertEquals(actual.getBaseType(), expected.getBaseType());
    assertEquals(actual.getQualifiedName(), expected.getQualifiedName());
    assertEquals(actual.getName(), expected.getName());
    assertEquals(actual.getColumnIdentity(), expected.getColumnIdentity());
    assertEquals(actual.getId(), actual.getId());
    assertEquals(actual.getType(), expected.getType());
    assertEquals(actual.getComment(), expected.getComment());
}
Also used : RowType(io.trino.spi.type.RowType) Type(io.trino.spi.type.Type) ArrayType(io.trino.spi.type.ArrayType) TypeDeserializer(io.trino.type.TypeDeserializer) JsonCodecFactory(io.airlift.json.JsonCodecFactory) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider)

Example 7 with TypeDeserializer

use of io.trino.type.TypeDeserializer in project trino by trinodb.

the class TestPatternRecognitionNodeSerialization method testAggregationValuePointerRoundtrip.

@Test
public void testAggregationValuePointerRoundtrip() {
    ObjectMapperProvider provider = new ObjectMapperProvider();
    provider.setJsonSerializers(ImmutableMap.of(Expression.class, new ExpressionSerialization.ExpressionSerializer()));
    provider.setJsonDeserializers(ImmutableMap.of(Expression.class, new ExpressionSerialization.ExpressionDeserializer(new SqlParser()), Type.class, new TypeDeserializer(TESTING_TYPE_MANAGER)));
    provider.setKeyDeserializers(ImmutableMap.of(TypeSignature.class, new TypeSignatureKeyDeserializer()));
    JsonCodec<ValuePointer> codec = new JsonCodecFactory(provider).jsonCodec(ValuePointer.class);
    ResolvedFunction countFunction = createTestMetadataManager().resolveFunction(TEST_SESSION, QualifiedName.of("count"), ImmutableList.of());
    assertJsonRoundTrip(codec, new AggregationValuePointer(countFunction, new AggregatedSetDescriptor(ImmutableSet.of(), false), ImmutableList.of(), new Symbol("classifier"), new Symbol("match_number")));
    ResolvedFunction maxFunction = createTestMetadataManager().resolveFunction(TEST_SESSION, QualifiedName.of("max"), fromTypes(BIGINT));
    assertJsonRoundTrip(codec, new AggregationValuePointer(maxFunction, new AggregatedSetDescriptor(ImmutableSet.of(new IrLabel("A"), new IrLabel("B")), true), ImmutableList.of(new NullLiteral()), new Symbol("classifier"), new Symbol("match_number")));
}
Also used : IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) ResolvedFunction(io.trino.metadata.ResolvedFunction) Symbol(io.trino.sql.planner.Symbol) SqlParser(io.trino.sql.parser.SqlParser) AggregationValuePointer(io.trino.sql.planner.rowpattern.AggregationValuePointer) ScalarValuePointer(io.trino.sql.planner.rowpattern.ScalarValuePointer) ValuePointer(io.trino.sql.planner.rowpattern.ValuePointer) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) AggregationValuePointer(io.trino.sql.planner.rowpattern.AggregationValuePointer) Type(io.trino.spi.type.Type) TypeSignature(io.trino.spi.type.TypeSignature) AggregatedSetDescriptor(io.trino.sql.planner.rowpattern.AggregatedSetDescriptor) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) IfExpression(io.trino.sql.tree.IfExpression) Expression(io.trino.sql.tree.Expression) TypeDeserializer(io.trino.type.TypeDeserializer) JsonCodecFactory(io.airlift.json.JsonCodecFactory) NullLiteral(io.trino.sql.tree.NullLiteral) TypeSignatureKeyDeserializer(io.trino.type.TypeSignatureKeyDeserializer) Test(org.testng.annotations.Test)

Aggregations

JsonCodecFactory (io.airlift.json.JsonCodecFactory)7 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)7 Type (io.trino.spi.type.Type)7 TypeDeserializer (io.trino.type.TypeDeserializer)7 Test (org.testng.annotations.Test)5 TypeSignature (io.trino.spi.type.TypeSignature)3 SqlParser (io.trino.sql.parser.SqlParser)3 Symbol (io.trino.sql.planner.Symbol)3 IrLabel (io.trino.sql.planner.rowpattern.ir.IrLabel)3 ArithmeticUnaryExpression (io.trino.sql.tree.ArithmeticUnaryExpression)3 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)3 Expression (io.trino.sql.tree.Expression)3 IfExpression (io.trino.sql.tree.IfExpression)3 NullLiteral (io.trino.sql.tree.NullLiteral)3 ResolvedFunction (io.trino.metadata.ResolvedFunction)2 VarcharType.createVarcharType (io.trino.spi.type.VarcharType.createVarcharType)2 Measure (io.trino.sql.planner.plan.PatternRecognitionNode.Measure)2 ExpressionAndValuePointers (io.trino.sql.planner.rowpattern.LogicalIndexExtractor.ExpressionAndValuePointers)2 ScalarValuePointer (io.trino.sql.planner.rowpattern.ScalarValuePointer)2 TypeSignatureKeyDeserializer (io.trino.type.TypeSignatureKeyDeserializer)2