use of io.trino.sql.planner.plan.WindowNode.Specification in project trino by trinodb.
the class SetOperationNodeTranslator method appendCounts.
private WindowNode appendCounts(UnionNode sourceNode, List<Symbol> originalColumns, List<Symbol> markers, List<Symbol> countOutputs, Symbol rowNumberSymbol) {
ImmutableMap.Builder<Symbol, WindowNode.Function> functions = ImmutableMap.builder();
WindowNode.Frame defaultFrame = new WindowNode.Frame(ROWS, UNBOUNDED_PRECEDING, Optional.empty(), Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
for (int i = 0; i < markers.size(); i++) {
Symbol output = countOutputs.get(i);
functions.put(output, new WindowNode.Function(countFunction, ImmutableList.of(markers.get(i).toSymbolReference()), defaultFrame, false));
}
functions.put(rowNumberSymbol, new WindowNode.Function(rowNumberFunction, ImmutableList.of(), defaultFrame, false));
return new WindowNode(idAllocator.getNextId(), sourceNode, new Specification(originalColumns, Optional.empty()), functions.buildOrThrow(), Optional.empty(), ImmutableSet.of(), 0);
}
use of io.trino.sql.planner.plan.WindowNode.Specification 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());
}
Aggregations