use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class PlanPrinter method formatAggregation.
public static String formatAggregation(Aggregation aggregation) {
StringBuilder builder = new StringBuilder();
String arguments = Joiner.on(", ").join(aggregation.getArguments());
if (aggregation.getArguments().isEmpty() && "count".equalsIgnoreCase(aggregation.getResolvedFunction().getSignature().getName())) {
arguments = "*";
}
if (aggregation.isDistinct()) {
arguments = "DISTINCT " + arguments;
}
builder.append(aggregation.getResolvedFunction().getSignature().getName()).append('(').append(arguments);
aggregation.getOrderingScheme().ifPresent(orderingScheme -> builder.append(' ').append(orderingScheme.getOrderBy().stream().map(input -> input + " " + orderingScheme.getOrdering(input)).collect(joining(", "))));
builder.append(')');
aggregation.getFilter().ifPresent(expression -> builder.append(" FILTER (WHERE ").append(expression).append(")"));
aggregation.getMask().ifPresent(symbol -> builder.append(" (mask = ").append(symbol).append(")"));
return builder.toString();
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class MockRemoteTaskFactory method createTableScanTask.
public MockRemoteTask createTableScanTask(TaskId taskId, InternalNode newNode, List<Split> splits, PartitionedSplitCountTracker partitionedSplitCountTracker) {
Symbol symbol = new Symbol("column");
PlanNodeId sourceId = new PlanNodeId("sourceId");
PlanFragment testFragment = new PlanFragment(new PlanFragmentId("test"), TableScanNode.newInstance(sourceId, TEST_TABLE_HANDLE, ImmutableList.of(symbol), ImmutableMap.of(symbol, new TestingColumnHandle("column")), false, Optional.empty()), ImmutableMap.of(symbol, VARCHAR), SOURCE_DISTRIBUTION, ImmutableList.of(sourceId), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(symbol)), ungroupedExecution(), StatsAndCosts.empty(), Optional.empty());
ImmutableMultimap.Builder<PlanNodeId, Split> initialSplits = ImmutableMultimap.builder();
for (Split sourceSplit : splits) {
initialSplits.put(sourceId, sourceSplit);
}
return createRemoteTask(TEST_SESSION, taskId, newNode, testFragment, initialSplits.build(), createInitialEmptyOutputBuffers(BROADCAST), partitionedSplitCountTracker, ImmutableSet.of(), true);
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestFilterStatsRule method testUnestimatableFunction.
@Test
public void testUnestimatableFunction() {
// can't estimate function and default filter factor is turned off
ComparisonExpression unestimatableExpression = new ComparisonExpression(Operator.EQUAL, new TestingFunctionResolution().functionCallBuilder(QualifiedName.of("sin")).addArgument(DOUBLE, new SymbolReference("i1")).build(), new DoubleLiteral("1"));
tester().assertStatsFor(pb -> pb.filter(unestimatableExpression, pb.values(pb.symbol("i1"), pb.symbol("i2"), pb.symbol("i3")))).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(10).addSymbolStatistics(new Symbol("i1"), SymbolStatsEstimate.builder().setLowValue(1).setHighValue(10).setDistinctValuesCount(5).setNullsFraction(0).build()).addSymbolStatistics(new Symbol("i2"), SymbolStatsEstimate.builder().setLowValue(0).setHighValue(3).setDistinctValuesCount(4).setNullsFraction(0).build()).addSymbolStatistics(new Symbol("i3"), SymbolStatsEstimate.builder().setLowValue(10).setHighValue(15).setDistinctValuesCount(4).setNullsFraction(0.1).build()).build()).check(PlanNodeStatsAssertion::outputRowsCountUnknown);
// can't estimate function, but default filter factor is turned on
defaultFilterTester.assertStatsFor(pb -> pb.filter(unestimatableExpression, pb.values(pb.symbol("i1"), pb.symbol("i2"), pb.symbol("i3")))).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(10).addSymbolStatistics(new Symbol("i1"), SymbolStatsEstimate.builder().setLowValue(1).setHighValue(10).setDistinctValuesCount(5).setNullsFraction(0).build()).addSymbolStatistics(new Symbol("i2"), SymbolStatsEstimate.builder().setLowValue(0).setHighValue(3).setDistinctValuesCount(4).setNullsFraction(0).build()).addSymbolStatistics(new Symbol("i3"), SymbolStatsEstimate.builder().setLowValue(10).setHighValue(15).setDistinctValuesCount(4).setNullsFraction(0.1).build()).build()).check(check -> check.outputRowsCount(9).symbolStats("i1", assertion -> assertion.lowValue(1).highValue(10).dataSizeUnknown().distinctValuesCount(5).nullsFraction(0)).symbolStats("i2", assertion -> assertion.lowValue(0).highValue(3).dataSizeUnknown().distinctValuesCount(4).nullsFraction(0)).symbolStats("i3", assertion -> assertion.lowValue(10).highValue(15).dataSizeUnknown().distinctValuesCount(4).nullsFraction(0.1)));
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestJoinStatsRule method testJoinComplementStats.
@Test
public void testJoinComplementStats() {
PlanNodeStatsEstimate expected = planNodeStats(LEFT_ROWS_COUNT * (LEFT_JOIN_COLUMN_NULLS + LEFT_JOIN_COLUMN_NON_NULLS / 4), symbolStatistics(LEFT_JOIN_COLUMN, 0.0, 20.0, LEFT_JOIN_COLUMN_NULLS / (LEFT_JOIN_COLUMN_NULLS + LEFT_JOIN_COLUMN_NON_NULLS / 4), 5), LEFT_OTHER_COLUMN_STATS);
PlanNodeStatsEstimate actual = JOIN_STATS_RULE.calculateJoinComplementStats(Optional.empty(), ImmutableList.of(new EquiJoinClause(new Symbol(LEFT_JOIN_COLUMN), new Symbol(RIGHT_JOIN_COLUMN))), LEFT_STATS, RIGHT_STATS, TYPES);
assertEquals(actual, expected);
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestJoinStatsRule method testRightJoinComplementStats.
@Test
public void testRightJoinComplementStats() {
PlanNodeStatsEstimate expected = NORMALIZER.normalize(planNodeStats(RIGHT_ROWS_COUNT * RIGHT_JOIN_COLUMN_NULLS, symbolStatistics(RIGHT_JOIN_COLUMN, NaN, NaN, 1.0, 0), RIGHT_OTHER_COLUMN_STATS), TYPES);
PlanNodeStatsEstimate actual = JOIN_STATS_RULE.calculateJoinComplementStats(Optional.empty(), ImmutableList.of(new EquiJoinClause(new Symbol(RIGHT_JOIN_COLUMN), new Symbol(LEFT_JOIN_COLUMN))), RIGHT_STATS, LEFT_STATS, TYPES);
assertEquals(actual, expected);
}
Aggregations