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");
}
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);
}
Aggregations