Search in sources :

Example 1 with TypeSignatureKeyDeserializer

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

the class TestPatternRecognitionNodeSerialization method testPatternRecognitionNodeRoundtrip.

@Test
public void testPatternRecognitionNodeRoundtrip() {
    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<PatternRecognitionNode> codec = new JsonCodecFactory(provider).jsonCodec(PatternRecognitionNode.class);
    ResolvedFunction rankFunction = createTestMetadataManager().resolveFunction(TEST_SESSION, QualifiedName.of("rank"), ImmutableList.of());
    // test remaining fields inside PatternRecognitionNode specific to pattern recognition:
    // windowFunctions, measures, commonBaseFrame, rowsPerMatch, skipToLabel, skipToPosition, initial, pattern, subsets, variableDefinitions
    PatternRecognitionNode node = new PatternRecognitionNode(new PlanNodeId("0"), new ValuesNode(new PlanNodeId("1"), 1), new Specification(ImmutableList.of(), Optional.empty()), Optional.empty(), ImmutableSet.of(), 0, ImmutableMap.of(new Symbol("rank"), new Function(rankFunction, ImmutableList.of(), new Frame(ROWS, CURRENT_ROW, Optional.empty(), Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), false)), ImmutableMap.of(new Symbol("measure"), new Measure(new ExpressionAndValuePointers(new NullLiteral(), ImmutableList.of(), ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of()), BOOLEAN)), Optional.of(new Frame(ROWS, CURRENT_ROW, Optional.empty(), Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty())), WINDOW, Optional.of(new IrLabel("B")), LAST, true, new IrConcatenation(ImmutableList.of(new IrLabel("A"), new IrLabel("B"), new IrLabel("C"))), ImmutableMap.of(new IrLabel("U"), ImmutableSet.of(new IrLabel("A"), new IrLabel("B")), new IrLabel("V"), ImmutableSet.of(new IrLabel("B"), new IrLabel("C"))), ImmutableMap.of(new IrLabel("B"), new ExpressionAndValuePointers(new NullLiteral(), ImmutableList.of(), ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of()), new IrLabel("C"), new ExpressionAndValuePointers(new NullLiteral(), ImmutableList.of(), ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of())));
    PatternRecognitionNode roundtripNode = codec.fromJson(codec.toJson(node));
    assertEquals(roundtripNode.getMeasures(), node.getMeasures());
    assertEquals(roundtripNode.getRowsPerMatch(), node.getRowsPerMatch());
    assertEquals(roundtripNode.getSkipToLabel(), node.getSkipToLabel());
    assertEquals(roundtripNode.getSkipToPosition(), node.getSkipToPosition());
    assertEquals(roundtripNode.isInitial(), node.isInitial());
    assertEquals(roundtripNode.getPattern(), node.getPattern());
    assertEquals(roundtripNode.getSubsets(), node.getSubsets());
    assertEquals(roundtripNode.getVariableDefinitions(), node.getVariableDefinitions());
}
Also used : IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) Frame(io.trino.sql.planner.plan.WindowNode.Frame) ResolvedFunction(io.trino.metadata.ResolvedFunction) Symbol(io.trino.sql.planner.Symbol) SqlParser(io.trino.sql.parser.SqlParser) Specification(io.trino.sql.planner.plan.WindowNode.Specification) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) IrConcatenation(io.trino.sql.planner.rowpattern.ir.IrConcatenation) ResolvedFunction(io.trino.metadata.ResolvedFunction) Function(io.trino.sql.planner.plan.WindowNode.Function) Type(io.trino.spi.type.Type) TypeSignature(io.trino.spi.type.TypeSignature) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) IfExpression(io.trino.sql.tree.IfExpression) Expression(io.trino.sql.tree.Expression) ExpressionAndValuePointers(io.trino.sql.planner.rowpattern.LogicalIndexExtractor.ExpressionAndValuePointers) Measure(io.trino.sql.planner.plan.PatternRecognitionNode.Measure) 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)

Example 2 with TypeSignatureKeyDeserializer

use of io.trino.type.TypeSignatureKeyDeserializer 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)2 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)2 ResolvedFunction (io.trino.metadata.ResolvedFunction)2 Type (io.trino.spi.type.Type)2 TypeSignature (io.trino.spi.type.TypeSignature)2 SqlParser (io.trino.sql.parser.SqlParser)2 Symbol (io.trino.sql.planner.Symbol)2 IrLabel (io.trino.sql.planner.rowpattern.ir.IrLabel)2 ArithmeticUnaryExpression (io.trino.sql.tree.ArithmeticUnaryExpression)2 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)2 Expression (io.trino.sql.tree.Expression)2 IfExpression (io.trino.sql.tree.IfExpression)2 NullLiteral (io.trino.sql.tree.NullLiteral)2 TypeDeserializer (io.trino.type.TypeDeserializer)2 TypeSignatureKeyDeserializer (io.trino.type.TypeSignatureKeyDeserializer)2 Test (org.testng.annotations.Test)2 Measure (io.trino.sql.planner.plan.PatternRecognitionNode.Measure)1 Frame (io.trino.sql.planner.plan.WindowNode.Frame)1 Function (io.trino.sql.planner.plan.WindowNode.Function)1 Specification (io.trino.sql.planner.plan.WindowNode.Specification)1