Search in sources :

Example 26 with StringLiteral

use of com.facebook.presto.sql.tree.StringLiteral in project presto by prestodb.

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).variableStats(new VariableReferenceExpression(Optional.empty(), "y", DOUBLE), 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).variableStats(new VariableReferenceExpression(Optional.empty(), "x", DOUBLE), 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).variableStats(new VariableReferenceExpression(Optional.empty(), "y", DOUBLE), 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).variableStats(new VariableReferenceExpression(Optional.empty(), "leftOpen", DOUBLE), 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).variableStats(new VariableReferenceExpression(Optional.empty(), "rightOpen", DOUBLE), 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).variableStats(new VariableReferenceExpression(Optional.empty(), "unknownRange", DOUBLE), 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).variableStats(new VariableReferenceExpression(Optional.empty(), "emptyRange", DOUBLE), 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).variableStats(new VariableReferenceExpression(Optional.empty(), "varchar", VarcharType.createVarcharType(10)), symbolAssert -> {
        symbolAssert.averageRowSize(4.0).distinctValuesCount(49.0).lowValueUnknown().highValueUnknown().nullsFraction(0.0);
    });
}
Also used : ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) DoubleLiteral(com.facebook.presto.sql.tree.DoubleLiteral) Test(org.testng.annotations.Test)

Example 27 with StringLiteral

use of com.facebook.presto.sql.tree.StringLiteral in project presto by prestodb.

the class TestScalarStatsCalculator method testLiteral.

@Test
public void testLiteral() {
    assertCalculate(new GenericLiteral("TINYINT", "7")).distinctValuesCount(1.0).lowValue(7).highValue(7).nullsFraction(0.0);
    assertCalculate(new GenericLiteral("SMALLINT", "8")).distinctValuesCount(1.0).lowValue(8).highValue(8).nullsFraction(0.0);
    assertCalculate(new GenericLiteral("INTEGER", "9")).distinctValuesCount(1.0).lowValue(9).highValue(9).nullsFraction(0.0);
    assertCalculate(new GenericLiteral("BIGINT", Long.toString(Long.MAX_VALUE))).distinctValuesCount(1.0).lowValue(Long.MAX_VALUE).highValue(Long.MAX_VALUE).nullsFraction(0.0);
    assertCalculate(new DoubleLiteral("7.5")).distinctValuesCount(1.0).lowValue(7.5).highValue(7.5).nullsFraction(0.0);
    assertCalculate(new DecimalLiteral("75.5")).distinctValuesCount(1.0).lowValue(75.5).highValue(75.5).nullsFraction(0.0);
    assertCalculate(new StringLiteral("blah")).distinctValuesCount(1.0).lowValueUnknown().highValueUnknown().nullsFraction(0.0);
    assertCalculate(new NullLiteral()).distinctValuesCount(0.0).lowValueUnknown().highValueUnknown().nullsFraction(1.0);
}
Also used : StringLiteral(com.facebook.presto.sql.tree.StringLiteral) DecimalLiteral(com.facebook.presto.sql.tree.DecimalLiteral) DoubleLiteral(com.facebook.presto.sql.tree.DoubleLiteral) NullLiteral(com.facebook.presto.sql.tree.NullLiteral) GenericLiteral(com.facebook.presto.sql.tree.GenericLiteral) Test(org.testng.annotations.Test)

Example 28 with StringLiteral

use of com.facebook.presto.sql.tree.StringLiteral in project presto by prestodb.

the class TestExpressionInterpreter method assertLike.

private static void assertLike(byte[] value, String pattern, boolean expected) {
    Expression predicate = new LikePredicate(rawStringLiteral(Slices.wrappedBuffer(value)), new StringLiteral(pattern), Optional.empty());
    assertEquals(evaluate(predicate, true), expected);
}
Also used : StringLiteral(com.facebook.presto.sql.tree.StringLiteral) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) CallExpression(com.facebook.presto.spi.relation.CallExpression) SpecialFormExpression(com.facebook.presto.spi.relation.SpecialFormExpression) LambdaDefinitionExpression(com.facebook.presto.spi.relation.LambdaDefinitionExpression) ExpressionFormatter.formatExpression(com.facebook.presto.sql.ExpressionFormatter.formatExpression) InputReferenceExpression(com.facebook.presto.spi.relation.InputReferenceExpression) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) Expression(com.facebook.presto.sql.tree.Expression) LikePredicate(com.facebook.presto.sql.tree.LikePredicate)

Example 29 with StringLiteral

use of com.facebook.presto.sql.tree.StringLiteral in project presto by prestodb.

the class TestSqlParser method testPosition.

@Test
public void testPosition() {
    assertExpression("position('a' in 'b')", new FunctionCall(QualifiedName.of("strpos"), ImmutableList.of(new StringLiteral("b"), new StringLiteral("a"))));
    assertExpression("position('a' in ('b'))", new FunctionCall(QualifiedName.of("strpos"), ImmutableList.of(new StringLiteral("b"), new StringLiteral("a"))));
}
Also used : StringLiteral(com.facebook.presto.sql.tree.StringLiteral) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 30 with StringLiteral

use of com.facebook.presto.sql.tree.StringLiteral in project presto by prestodb.

the class TestSqlParser method testSetSession.

@Test
public void testSetSession() {
    assertStatement("SET SESSION foo = 'bar'", new SetSession(QualifiedName.of("foo"), new StringLiteral("bar")));
    assertStatement("SET SESSION foo.bar = 'baz'", new SetSession(QualifiedName.of("foo", "bar"), new StringLiteral("baz")));
    assertStatement("SET SESSION foo.bar.boo = 'baz'", new SetSession(QualifiedName.of("foo", "bar", "boo"), new StringLiteral("baz")));
    assertStatement("SET SESSION foo.bar = 'ban' || 'ana'", new SetSession(QualifiedName.of("foo", "bar"), new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(new StringLiteral("ban"), new StringLiteral("ana")))));
}
Also used : SetSession(com.facebook.presto.sql.tree.SetSession) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Aggregations

StringLiteral (com.facebook.presto.sql.tree.StringLiteral)35 Test (org.testng.annotations.Test)25 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)19 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)15 DoubleLiteral (com.facebook.presto.sql.tree.DoubleLiteral)9 Query (com.facebook.presto.sql.tree.Query)8 QueryUtil.quotedIdentifier (com.facebook.presto.sql.QueryUtil.quotedIdentifier)7 QueryUtil.simpleQuery (com.facebook.presto.sql.QueryUtil.simpleQuery)7 Expression (com.facebook.presto.sql.tree.Expression)7 Identifier (com.facebook.presto.sql.tree.Identifier)7 WithQuery (com.facebook.presto.sql.tree.WithQuery)7 AllColumns (com.facebook.presto.sql.tree.AllColumns)6 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)6 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)5 BooleanLiteral (com.facebook.presto.sql.tree.BooleanLiteral)5 GenericLiteral (com.facebook.presto.sql.tree.GenericLiteral)5 Property (com.facebook.presto.sql.tree.Property)5 Session (com.facebook.presto.Session)4 ArrayConstructor (com.facebook.presto.sql.tree.ArrayConstructor)4 QuerySpecification (com.facebook.presto.sql.tree.QuerySpecification)4