Search in sources :

Example 6 with NullLiteral

use of com.facebook.presto.sql.tree.NullLiteral 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 7 with NullLiteral

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

the class TestScalarStatsCalculator method testFunctionCall.

@Test
public void testFunctionCall() {
    assertCalculate(new FunctionCall(QualifiedName.of("length"), ImmutableList.of(new Cast(new NullLiteral(), "VARCHAR(10)")))).distinctValuesCount(0.0).lowValueUnknown().highValueUnknown().nullsFraction(1.0);
    assertCalculate(new FunctionCall(QualifiedName.of("length"), ImmutableList.of(new SymbolReference("x"))), PlanNodeStatsEstimate.unknown(), TypeProvider.viewOf(ImmutableMap.of("x", createVarcharType(2)))).distinctValuesCountUnknown().lowValueUnknown().highValueUnknown().nullsFractionUnknown();
}
Also used : Cast(com.facebook.presto.sql.tree.Cast) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) NullLiteral(com.facebook.presto.sql.tree.NullLiteral) Test(org.testng.annotations.Test)

Example 8 with NullLiteral

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

the class TestSqlParser method testCoalesce.

@Test
public void testCoalesce() {
    assertInvalidExpression("coalesce()", "The 'coalesce' function must have at least two arguments");
    assertInvalidExpression("coalesce(5)", "The 'coalesce' function must have at least two arguments");
    assertInvalidExpression("coalesce(1, 2) filter (where true)", "FILTER not valid for 'coalesce' function");
    assertInvalidExpression("coalesce(1, 2) OVER ()", "OVER clause not valid for 'coalesce' function");
    assertExpression("coalesce(13, 42)", new CoalesceExpression(new LongLiteral("13"), new LongLiteral("42")));
    assertExpression("coalesce(6, 7, 8)", new CoalesceExpression(new LongLiteral("6"), new LongLiteral("7"), new LongLiteral("8")));
    assertExpression("coalesce(13, null)", new CoalesceExpression(new LongLiteral("13"), new NullLiteral()));
    assertExpression("coalesce(null, 13)", new CoalesceExpression(new NullLiteral(), new LongLiteral("13")));
    assertExpression("coalesce(null, null)", new CoalesceExpression(new NullLiteral(), new NullLiteral()));
}
Also used : LongLiteral(com.facebook.presto.sql.tree.LongLiteral) CoalesceExpression(com.facebook.presto.sql.tree.CoalesceExpression) NullLiteral(com.facebook.presto.sql.tree.NullLiteral) Test(org.testng.annotations.Test)

Example 9 with NullLiteral

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

the class TestSqlParser method testIf.

@Test
public void testIf() {
    assertExpression("if(true, 1, 0)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("1"), new LongLiteral("0")));
    assertExpression("if(true, 3, null)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("3"), new NullLiteral()));
    assertExpression("if(false, null, 4)", new IfExpression(new BooleanLiteral("false"), new NullLiteral(), new LongLiteral("4")));
    assertExpression("if(false, null, null)", new IfExpression(new BooleanLiteral("false"), new NullLiteral(), new NullLiteral()));
    assertExpression("if(true, 3)", new IfExpression(new BooleanLiteral("true"), new LongLiteral("3"), null));
    assertInvalidExpression("IF(true)", "Invalid number of arguments for 'if' function");
    assertInvalidExpression("IF(true, 1, 0) FILTER (WHERE true)", "FILTER not valid for 'if' function");
    assertInvalidExpression("IF(true, 1, 0) OVER()", "OVER clause not valid for 'if' function");
}
Also used : IfExpression(com.facebook.presto.sql.tree.IfExpression) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) BooleanLiteral(com.facebook.presto.sql.tree.BooleanLiteral) NullLiteral(com.facebook.presto.sql.tree.NullLiteral) Test(org.testng.annotations.Test)

Aggregations

NullLiteral (com.facebook.presto.sql.tree.NullLiteral)9 Cast (com.facebook.presto.sql.tree.Cast)5 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)5 Test (org.testng.annotations.Test)5 Expression (com.facebook.presto.sql.tree.Expression)4 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)3 BooleanLiteral (com.facebook.presto.sql.tree.BooleanLiteral)2 DoubleLiteral (com.facebook.presto.sql.tree.DoubleLiteral)2 GenericLiteral (com.facebook.presto.sql.tree.GenericLiteral)2 IfExpression (com.facebook.presto.sql.tree.IfExpression)2 NullIfExpression (com.facebook.presto.sql.tree.NullIfExpression)2 StringLiteral (com.facebook.presto.sql.tree.StringLiteral)2 Session (com.facebook.presto.Session)1 SystemSessionProperties (com.facebook.presto.SystemSessionProperties)1 SystemSessionProperties.isPrintStatsForNonJoinQuery (com.facebook.presto.SystemSessionProperties.isPrintStatsForNonJoinQuery)1 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)1 Block (com.facebook.presto.common.block.Block)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 CharType (com.facebook.presto.common.type.CharType)1