Search in sources :

Example 46 with StringLiteral

use of io.prestosql.sql.tree.StringLiteral in project hetu-core by openlookeng.

the class TestSetSessionTask method testSetSession.

@Test
public void testSetSession() {
    testSetSession(new StringLiteral("baz"), "baz");
    testSetSession(new FunctionCallBuilder(metadata).setName(QualifiedName.of("concat")).addArgument(VARCHAR, new StringLiteral("ban")).addArgument(VARCHAR, new StringLiteral("ana")).build(), "banana");
}
Also used : StringLiteral(io.prestosql.sql.tree.StringLiteral) FunctionCallBuilder(io.prestosql.sql.planner.FunctionCallBuilder) Test(org.testng.annotations.Test)

Example 47 with StringLiteral

use of io.prestosql.sql.tree.StringLiteral in project boostkit-bigdata by kunpengcompute.

the class OmniRowExpressionUtil method generateOmniExpr.

/**
 * Generates a RowExpression to ensure like query compatibility with omniruntime
 *
 * @param staticExpr Expression from openLookeng
 * @param translatedExpr RowExpression from staticFilter conversion
 * @return new Optional<RowExpression> with new, regex-syntax arguments for like
 * queries
 */
public static Optional<RowExpression> generateOmniExpr(Expression staticExpr, RowExpression translatedExpr) {
    // parse the expr
    if (staticExpr instanceof SearchedCaseExpression && translatedExpr instanceof SpecialForm) {
        return getWhenExpr((SearchedCaseExpression) staticExpr, (SpecialForm) translatedExpr);
    }
    if (translatedExpr instanceof SpecialForm) {
        SpecialForm specialExpr = (SpecialForm) translatedExpr;
        List<RowExpression> newArguments = new ArrayList<RowExpression>();
        for (int i = 0; i < specialExpr.getArguments().size(); i++) {
            RowExpression nestedExpr = specialExpr.getArguments().get(i);
            if (nestedExpr instanceof SpecialForm || nestedExpr instanceof CallExpression) {
                newArguments.add(generateOmniExpr((Expression) staticExpr.getChildren().get(i), nestedExpr).get());
            } else {
                newArguments.add(specialExpr.getArguments().get(i));
            }
        }
        Optional<RowExpression> newOmniFilter = Optional.of(new SpecialForm(specialExpr.getForm(), specialExpr.getType(), newArguments));
        return newOmniFilter;
    } else if (translatedExpr instanceof CallExpression) {
        CallExpression callExpr = (CallExpression) translatedExpr;
        List<RowExpression> newArguments = new ArrayList<RowExpression>();
        for (int i = 0; i < callExpr.getArguments().size(); i++) {
            RowExpression nestedExpr = callExpr.getArguments().get(i);
            if (nestedExpr instanceof SpecialForm || nestedExpr instanceof CallExpression) {
                newArguments.add(generateOmniExpr((Expression) staticExpr.getChildren().get(i), nestedExpr).get());
            } else {
                newArguments.add(callExpr.getArguments().get(i));
            }
        }
        Optional<RowExpression> newOmniFilter = Optional.of(new CallExpression(callExpr.getDisplayName(), callExpr.getFunctionHandle(), callExpr.getType(), newArguments));
        if ("LIKE".equals(((CallExpression) newOmniFilter.get()).getDisplayName().toUpperCase(Locale.ROOT))) {
            String sqlString = "";
            if (staticExpr.getChildren().get(1) instanceof Cast) {
                sqlString = ((StringLiteral) ((Cast) staticExpr.getChildren().get(1)).getExpression()).getValue();
            } else {
                sqlString = ((StringLiteral) staticExpr.getChildren().get(1)).getValue();
            }
            return generateLikeExpr(sqlString, newOmniFilter);
        }
        return newOmniFilter;
    }
    return Optional.of(translatedExpr);
}
Also used : Cast(io.prestosql.sql.tree.Cast) Optional(java.util.Optional) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) StringLiteral(io.prestosql.sql.tree.StringLiteral) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) CallExpression(io.prestosql.spi.relation.CallExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) LambdaDefinitionExpression(io.prestosql.spi.relation.LambdaDefinitionExpression) InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) CallExpression(io.prestosql.spi.relation.CallExpression) SpecialForm(io.prestosql.spi.relation.SpecialForm)

Aggregations

StringLiteral (io.prestosql.sql.tree.StringLiteral)47 Test (org.testng.annotations.Test)23 LongLiteral (io.prestosql.sql.tree.LongLiteral)20 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)15 FunctionCall (io.prestosql.sql.tree.FunctionCall)15 Identifier (io.prestosql.sql.tree.Identifier)15 Expression (io.prestosql.sql.tree.Expression)14 Property (io.prestosql.sql.tree.Property)12 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)9 ArithmeticUnaryExpression (io.prestosql.sql.tree.ArithmeticUnaryExpression)9 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)9 DoubleLiteral (io.prestosql.sql.tree.DoubleLiteral)9 IfExpression (io.prestosql.sql.tree.IfExpression)9 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)9 NotExpression (io.prestosql.sql.tree.NotExpression)9 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)9 SearchedCaseExpression (io.prestosql.sql.tree.SearchedCaseExpression)9 SimpleCaseExpression (io.prestosql.sql.tree.SimpleCaseExpression)9 SubqueryExpression (io.prestosql.sql.tree.SubqueryExpression)9 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)8