use of io.trino.sql.tree.DoubleLiteral in project trino by trinodb.
the class TestComparisonStatsCalculator method symbolToLiteralGreaterThanStats.
@Test
public void symbolToLiteralGreaterThanStats() {
// Simple case
assertCalculate(new ComparisonExpression(GREATER_THAN, new SymbolReference("y"), new DoubleLiteral("2.5"))).outputRowsCount(// all rows minus nulls times range coverage (50%)
250.0).symbolStats("y", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(10.0).lowValue(2.5).highValue(5.0).nullsFraction(0.0);
});
// Literal on the edge of symbol range (whole range included)
assertCalculate(new ComparisonExpression(GREATER_THAN, new SymbolReference("x"), new DoubleLiteral("-10.0"))).outputRowsCount(// all rows minus nulls times range coverage (100%)
750.0).symbolStats("x", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(40.0).lowValue(-10.0).highValue(10.0).nullsFraction(0.0);
});
// Literal on the edge of symbol range (whole range excluded)
assertCalculate(new ComparisonExpression(GREATER_THAN, new SymbolReference("x"), new DoubleLiteral("10.0"))).outputRowsCount(// all rows minus nulls divided by NDV (one value from edge is included as approximation)
18.75).symbolStats("x", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(1.0).lowValue(10.0).highValue(10.0).nullsFraction(0.0);
});
// Literal range out of symbol range
assertCalculate(new ComparisonExpression(GREATER_THAN, new SymbolReference("y"), new DoubleLiteral("10.0"))).outputRowsCount(// all rows minus nulls times range coverage (0%)
0.0).symbolStats("y", symbolAssert -> {
symbolAssert.averageRowSize(0.0).distinctValuesCount(0.0).emptyRange().nullsFraction(1.0);
});
// Literal in left open range
assertCalculate(new ComparisonExpression(GREATER_THAN, new SymbolReference("leftOpen"), new DoubleLiteral("0.0"))).outputRowsCount(// all rows minus nulls times range coverage (25% - heuristic)
225.0).symbolStats("leftOpen", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(// (25% heuristic)
12.5).lowValue(0.0).highValue(15.0).nullsFraction(0.0);
});
// Literal in right open range
assertCalculate(new ComparisonExpression(GREATER_THAN, new SymbolReference("rightOpen"), new DoubleLiteral("0.0"))).outputRowsCount(// all rows minus nulls times range coverage (50% - heuristic)
450.0).symbolStats("rightOpen", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(// (50% heuristic)
25.0).lowValue(0.0).highValueUnknown().nullsFraction(0.0);
});
// Literal in unknown range
assertCalculate(new ComparisonExpression(GREATER_THAN, new SymbolReference("unknownRange"), new DoubleLiteral("0.0"))).outputRowsCount(// all rows minus nulls times range coverage (50% - heuristic)
450.0).symbolStats("unknownRange", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(// (50% heuristic)
25.0).lowValue(0.0).highValueUnknown().nullsFraction(0.0);
});
// Literal in empty range
assertCalculate(new ComparisonExpression(GREATER_THAN, new SymbolReference("emptyRange"), new DoubleLiteral("0.0"))).outputRowsCount(0.0).symbolStats("emptyRange", equalTo(emptyRangeStats));
}
use of io.trino.sql.tree.DoubleLiteral in project trino by trinodb.
the class TestComparisonStatsCalculator method symbolToLiteralEqualStats.
@Test
public void symbolToLiteralEqualStats() {
// Simple case
assertCalculate(new ComparisonExpression(EQUAL, new SymbolReference("y"), new DoubleLiteral("2.5"))).outputRowsCount(// all rows minus nulls divided by distinct values count
25.0).symbolStats("y", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(1.0).lowValue(2.5).highValue(2.5).nullsFraction(0.0);
});
// Literal on the edge of symbol range
assertCalculate(new ComparisonExpression(EQUAL, new SymbolReference("x"), new DoubleLiteral("10.0"))).outputRowsCount(// all rows minus nulls divided by distinct values count
18.75).symbolStats("x", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(1.0).lowValue(10.0).highValue(10.0).nullsFraction(0.0);
});
// Literal out of symbol range
assertCalculate(new ComparisonExpression(EQUAL, new SymbolReference("y"), new DoubleLiteral("10.0"))).outputRowsCount(// all rows minus nulls divided by distinct values count
0.0).symbolStats("y", symbolAssert -> {
symbolAssert.averageRowSize(0.0).distinctValuesCount(0.0).emptyRange().nullsFraction(1.0);
});
// Literal in left open range
assertCalculate(new ComparisonExpression(EQUAL, new SymbolReference("leftOpen"), new DoubleLiteral("2.5"))).outputRowsCount(// all rows minus nulls divided by distinct values count
18.0).symbolStats("leftOpen", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(1.0).lowValue(2.5).highValue(2.5).nullsFraction(0.0);
});
// Literal in right open range
assertCalculate(new ComparisonExpression(EQUAL, new SymbolReference("rightOpen"), new DoubleLiteral("-2.5"))).outputRowsCount(// all rows minus nulls divided by distinct values count
18.0).symbolStats("rightOpen", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(1.0).lowValue(-2.5).highValue(-2.5).nullsFraction(0.0);
});
// Literal in unknown range
assertCalculate(new ComparisonExpression(EQUAL, new SymbolReference("unknownRange"), new DoubleLiteral("0.0"))).outputRowsCount(// all rows minus nulls divided by distinct values count
18.0).symbolStats("unknownRange", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(1.0).lowValue(0.0).highValue(0.0).nullsFraction(0.0);
});
// Literal in empty range
assertCalculate(new ComparisonExpression(EQUAL, new SymbolReference("emptyRange"), new DoubleLiteral("0.0"))).outputRowsCount(0.0).symbolStats("emptyRange", equalTo(emptyRangeStats));
// Column with values not representable as double (unknown range)
assertCalculate(new ComparisonExpression(EQUAL, new SymbolReference("varchar"), new StringLiteral("blah"))).outputRowsCount(// all rows minus nulls divided by distinct values count
18.0).symbolStats("varchar", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(1.0).lowValue(NEGATIVE_INFINITY).highValue(POSITIVE_INFINITY).nullsFraction(0.0);
});
}
use of io.trino.sql.tree.DoubleLiteral in project trino by trinodb.
the class TestMergeProjectWithValues method testNonDeterministicValues.
@Test
public void testNonDeterministicValues() {
FunctionCall randomFunction = new FunctionCall(tester().getMetadata().resolveFunction(tester().getSession(), QualifiedName.of("random"), ImmutableList.of()).toQualifiedName(), ImmutableList.of());
tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> p.project(Assignments.of(p.symbol("rand"), expression("rand")), p.valuesOfExpressions(ImmutableList.of(p.symbol("rand")), ImmutableList.of(new Row(ImmutableList.of(randomFunction)))))).matches(values(ImmutableList.of("rand"), ImmutableList.of(ImmutableList.of(randomFunction))));
// ValuesNode has multiple rows
tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> p.project(Assignments.of(p.symbol("output"), expression("value")), p.valuesOfExpressions(ImmutableList.of(p.symbol("value")), ImmutableList.of(new Row(ImmutableList.of(new NullLiteral())), new Row(ImmutableList.of(randomFunction)), new Row(ImmutableList.of(new ArithmeticUnaryExpression(MINUS, randomFunction))))))).matches(values(ImmutableList.of("output"), ImmutableList.of(ImmutableList.of(new NullLiteral()), ImmutableList.of(randomFunction), ImmutableList.of(new ArithmeticUnaryExpression(MINUS, randomFunction)))));
// ValuesNode has multiple non-deterministic outputs
tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> p.project(Assignments.of(p.symbol("x"), expression("-a"), p.symbol("y"), expression("b")), p.valuesOfExpressions(ImmutableList.of(p.symbol("a"), p.symbol("b")), ImmutableList.of(new Row(ImmutableList.of(new DoubleLiteral("1e0"), randomFunction)), new Row(ImmutableList.of(randomFunction, new NullLiteral())), new Row(ImmutableList.of(new ArithmeticUnaryExpression(MINUS, randomFunction), new NullLiteral())))))).matches(values(ImmutableList.of("x", "y"), ImmutableList.of(ImmutableList.of(new ArithmeticUnaryExpression(MINUS, new DoubleLiteral("1e0")), randomFunction), ImmutableList.of(new ArithmeticUnaryExpression(MINUS, randomFunction), new NullLiteral()), ImmutableList.of(new ArithmeticUnaryExpression(MINUS, new ArithmeticUnaryExpression(MINUS, randomFunction)), new NullLiteral()))));
}
use of io.trino.sql.tree.DoubleLiteral in project trino by trinodb.
the class TestSqlParser method testDouble.
@Test
public void testDouble() {
assertExpression("123E7", new DoubleLiteral("123E7"));
assertExpression("123.E7", new DoubleLiteral("123E7"));
assertExpression("123.0E7", new DoubleLiteral("123E7"));
assertExpression("123E+7", new DoubleLiteral("123E7"));
assertExpression("123E-7", new DoubleLiteral("123E-7"));
assertExpression("123.456E7", new DoubleLiteral("123.456E7"));
assertExpression("123.456E+7", new DoubleLiteral("123.456E7"));
assertExpression("123.456E-7", new DoubleLiteral("123.456E-7"));
assertExpression(".4E42", new DoubleLiteral(".4E42"));
assertExpression(".4E+42", new DoubleLiteral(".4E42"));
assertExpression(".4E-42", new DoubleLiteral(".4E-42"));
}
use of io.trino.sql.tree.DoubleLiteral in project trino by trinodb.
the class TestComparisonStatsCalculator method symbolToLiteralLessThanStats.
@Test
public void symbolToLiteralLessThanStats() {
// Simple case
assertCalculate(new ComparisonExpression(LESS_THAN, new SymbolReference("y"), new DoubleLiteral("2.5"))).outputRowsCount(// all rows minus nulls times range coverage (50%)
250.0).symbolStats("y", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(10.0).lowValue(0.0).highValue(2.5).nullsFraction(0.0);
});
// Literal on the edge of symbol range (whole range included)
assertCalculate(new ComparisonExpression(LESS_THAN, new SymbolReference("x"), new DoubleLiteral("10.0"))).outputRowsCount(// all rows minus nulls times range coverage (100%)
750.0).symbolStats("x", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(40.0).lowValue(-10.0).highValue(10.0).nullsFraction(0.0);
});
// Literal on the edge of symbol range (whole range excluded)
assertCalculate(new ComparisonExpression(LESS_THAN, new SymbolReference("x"), new DoubleLiteral("-10.0"))).outputRowsCount(// all rows minus nulls divided by NDV (one value from edge is included as approximation)
18.75).symbolStats("x", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(1.0).lowValue(-10.0).highValue(-10.0).nullsFraction(0.0);
});
// Literal range out of symbol range
assertCalculate(new ComparisonExpression(LESS_THAN, new SymbolReference("y"), new DoubleLiteral("-10.0"))).outputRowsCount(// all rows minus nulls times range coverage (0%)
0.0).symbolStats("y", symbolAssert -> {
symbolAssert.averageRowSize(0.0).distinctValuesCount(0.0).emptyRange().nullsFraction(1.0);
});
// Literal in left open range
assertCalculate(new ComparisonExpression(LESS_THAN, new SymbolReference("leftOpen"), new DoubleLiteral("0.0"))).outputRowsCount(// all rows minus nulls times range coverage (50% - heuristic)
450.0).symbolStats("leftOpen", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(// (50% heuristic)
25.0).lowValueUnknown().highValue(0.0).nullsFraction(0.0);
});
// Literal in right open range
assertCalculate(new ComparisonExpression(LESS_THAN, new SymbolReference("rightOpen"), new DoubleLiteral("0.0"))).outputRowsCount(// all rows minus nulls times range coverage (25% - heuristic)
225.0).symbolStats("rightOpen", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(// (25% heuristic)
12.5).lowValue(-15.0).highValue(0.0).nullsFraction(0.0);
});
// Literal in unknown range
assertCalculate(new ComparisonExpression(LESS_THAN, new SymbolReference("unknownRange"), new DoubleLiteral("0.0"))).outputRowsCount(// all rows minus nulls times range coverage (50% - heuristic)
450.0).symbolStats("unknownRange", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(// (50% heuristic)
25.0).lowValueUnknown().highValue(0.0).nullsFraction(0.0);
});
// Literal in empty range
assertCalculate(new ComparisonExpression(LESS_THAN, new SymbolReference("emptyRange"), new DoubleLiteral("0.0"))).outputRowsCount(0.0).symbolStats("emptyRange", equalTo(emptyRangeStats));
}
Aggregations