use of io.trino.sql.tree.DoubleLiteral in project trino by trinodb.
the class TestComparisonStatsCalculator method symbolToLiteralNotEqualStats.
@Test
public void symbolToLiteralNotEqualStats() {
// Simple case
assertCalculate(new ComparisonExpression(NOT_EQUAL, new SymbolReference("y"), new DoubleLiteral("2.5"))).outputRowsCount(// all rows minus nulls multiplied by ((distinct values - 1) / distinct values)
475.0).symbolStats("y", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(19.0).lowValue(0.0).highValue(5.0).nullsFraction(0.0);
});
// Literal on the edge of symbol range
assertCalculate(new ComparisonExpression(NOT_EQUAL, new SymbolReference("x"), new DoubleLiteral("10.0"))).outputRowsCount(// all rows minus nulls multiplied by ((distinct values - 1) / distinct values)
731.25).symbolStats("x", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(39.0).lowValue(-10.0).highValue(10.0).nullsFraction(0.0);
});
// Literal out of symbol range
assertCalculate(new ComparisonExpression(NOT_EQUAL, new SymbolReference("y"), new DoubleLiteral("10.0"))).outputRowsCount(// all rows minus nulls
500.0).symbolStats("y", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(19.0).lowValue(0.0).highValue(5.0).nullsFraction(0.0);
});
// Literal in left open range
assertCalculate(new ComparisonExpression(NOT_EQUAL, new SymbolReference("leftOpen"), new DoubleLiteral("2.5"))).outputRowsCount(// all rows minus nulls multiplied by ((distinct values - 1) / distinct values)
882.0).symbolStats("leftOpen", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(49.0).lowValueUnknown().highValue(15.0).nullsFraction(0.0);
});
// Literal in right open range
assertCalculate(new ComparisonExpression(NOT_EQUAL, new SymbolReference("rightOpen"), new DoubleLiteral("-2.5"))).outputRowsCount(// all rows minus nulls divided by distinct values count
882.0).symbolStats("rightOpen", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(49.0).lowValue(-15.0).highValueUnknown().nullsFraction(0.0);
});
// Literal in unknown range
assertCalculate(new ComparisonExpression(NOT_EQUAL, new SymbolReference("unknownRange"), new DoubleLiteral("0.0"))).outputRowsCount(// all rows minus nulls divided by distinct values count
882.0).symbolStats("unknownRange", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(49.0).lowValueUnknown().highValueUnknown().nullsFraction(0.0);
});
// Literal in empty range
assertCalculate(new ComparisonExpression(NOT_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(NOT_EQUAL, new SymbolReference("varchar"), new StringLiteral("blah"))).outputRowsCount(// all rows minus nulls divided by distinct values count
882.0).symbolStats("varchar", symbolAssert -> {
symbolAssert.averageRowSize(4.0).distinctValuesCount(49.0).lowValueUnknown().highValueUnknown().nullsFraction(0.0);
});
}
use of io.trino.sql.tree.DoubleLiteral in project trino by trinodb.
the class TestDereferencePushDown method testDereferencePushdownJoin.
@Test
public void testDereferencePushdownJoin() {
// dereference pushdown + constant folding
assertPlan("WITH t(msg) AS (VALUES ROW(CAST(ROW(1, 2.0) AS ROW(x BIGINT, y DOUBLE))))" + "SELECT b.msg.x " + "FROM t a, t b " + "WHERE a.msg.y = b.msg.y", output(project(ImmutableMap.of("b_x", expression("b_x")), filter("a_y = b_y", values(ImmutableList.of("b_x", "b_y", "a_y"), ImmutableList.of(ImmutableList.of(new GenericLiteral("BIGINT", "1"), new DoubleLiteral("2e0"), new DoubleLiteral("2e0"))))))));
assertPlan("WITH t(msg) AS (VALUES ROW(CAST(ROW(1, 2.0) AS ROW(x BIGINT, y DOUBLE))))" + "SELECT a.msg.y " + "FROM t a JOIN t b ON a.msg.y = b.msg.y " + "WHERE a.msg.x > BIGINT '5'", output(ImmutableList.of("a_y"), join(INNER, ImmutableList.of(), values("a_y"), values())));
assertPlan("WITH t(msg) AS (VALUES ROW(CAST(ROW(1, 2.0) AS ROW(x BIGINT, y DOUBLE))))" + "SELECT b.msg.x " + "FROM t a JOIN t b ON a.msg.y = b.msg.y " + "WHERE a.msg.x + b.msg.x < BIGINT '10'", output(ImmutableList.of("b_x"), join(INNER, ImmutableList.of(), project(filter("a_y = 2e0", values(ImmutableList.of("a_y"), ImmutableList.of(ImmutableList.of(new DoubleLiteral("2e0")))))), project(filter("b_y = 2e0", values(ImmutableList.of("b_x", "b_y"), ImmutableList.of(ImmutableList.of(new GenericLiteral("BIGINT", "1"), new DoubleLiteral("2e0")))))))));
}
use of io.trino.sql.tree.DoubleLiteral in project trino by trinodb.
the class TestSqlParser method testNumbers.
@Test
public void testNumbers() {
assertExpression("9223372036854775807", new LongLiteral("9223372036854775807"));
assertInvalidExpression("9223372036854775808", "Invalid numeric literal: 9223372036854775808");
assertExpression("-9223372036854775808", new LongLiteral("-9223372036854775808"));
assertInvalidExpression("-9223372036854775809", "Invalid numeric literal: -9223372036854775809");
assertExpression("1E5", new DoubleLiteral("1E5"));
assertExpression("1E-5", new DoubleLiteral("1E-5"));
assertExpression(".1E5", new DoubleLiteral(".1E5"));
assertExpression(".1E-5", new DoubleLiteral(".1E-5"));
assertExpression("1.1E5", new DoubleLiteral("1.1E5"));
assertExpression("1.1E-5", new DoubleLiteral("1.1E-5"));
assertExpression("-1E5", new DoubleLiteral("-1E5"));
assertExpression("-1E-5", new DoubleLiteral("-1E-5"));
assertExpression("-.1E5", new DoubleLiteral("-.1E5"));
assertExpression("-.1E-5", new DoubleLiteral("-.1E-5"));
assertExpression("-1.1E5", new DoubleLiteral("-1.1E5"));
assertExpression("-1.1E-5", new DoubleLiteral("-1.1E-5"));
assertExpression(".1", new DecimalLiteral(".1"));
assertExpression("1.2", new DecimalLiteral("1.2"));
assertExpression("-1.2", new DecimalLiteral("-1.2"));
}
Aggregations