use of io.prestosql.sql.parser.SqlParser in project hetu-core by openlookeng.
the class PlanBuilder method rowExpression.
public RowExpression rowExpression(String sql) {
Expression expression = expression(sql);
Map<NodeRef<Expression>, Type> expressionTypes = ExpressionAnalyzer.analyzeExpressions(TEST_SESSION, metadata, new SqlParser(), getTypes(), ImmutableList.of(expression), ImmutableList.of(), WarningCollector.NOOP, false).getExpressionTypes();
return SqlToRowExpressionTranslator.translate(expression, SCALAR, expressionTypes, ImmutableMap.of(), metadata.getFunctionAndTypeManager(), TEST_SESSION, false);
}
use of io.prestosql.sql.parser.SqlParser in project hetu-core by openlookeng.
the class CubeFinishOperator method mergePredicates.
private CubeFilter mergePredicates(CubeFilter existing, String newPredicateString) {
String sourceTablePredicate = existing == null ? null : existing.getSourceTablePredicate();
if (newPredicateString == null && sourceTablePredicate == null) {
return null;
} else if (newPredicateString == null) {
return new CubeFilter(sourceTablePredicate, null);
}
SqlParser sqlParser = new SqlParser();
Expression newPredicate = sqlParser.createExpression(newPredicateString, new ParsingOptions());
if (!updateMetadata.isOverwrite() && existing != null && existing.getCubePredicate() != null) {
newPredicate = ExpressionUtils.or(sqlParser.createExpression(existing.getCubePredicate(), new ParsingOptions()), newPredicate);
}
// Merge new data predicate with existing predicate string
CubeRangeCanonicalizer canonicalizer = new CubeRangeCanonicalizer(metadata, session, types);
newPredicate = canonicalizer.mergePredicates(newPredicate);
String formatExpression = newPredicate.equals(BooleanLiteral.TRUE_LITERAL) ? null : ExpressionFormatter.formatExpression(newPredicate, Optional.empty());
return formatExpression == null && sourceTablePredicate == null ? null : new CubeFilter(sourceTablePredicate, formatExpression);
}
use of io.prestosql.sql.parser.SqlParser in project hetu-core by openlookeng.
the class AbstractTestQueryFramework method init.
@BeforeClass
public void init() throws Exception {
queryRunner = queryRunnerSupplier.get();
h2QueryRunner = new H2QueryRunner();
sqlParser = new SqlParser();
}
use of io.prestosql.sql.parser.SqlParser in project hetu-core by openlookeng.
the class TestShadowing method testInsert.
@Test
public void testInsert() throws Exception {
handle.execute("CREATE TABLE \"test_insert_table\" (a BIGINT, b DOUBLE, c VARCHAR)");
SqlParser parser = new SqlParser();
Query query = new Query(CATALOG, SCHEMA, ImmutableList.of(), "INSERT INTO test_insert_table (b, a, c) values (1.1, 1, 'a'), (2.0, 2, 'b'), (3.1, 3, 'c')", ImmutableList.of(), null, null, ImmutableMap.of());
QueryRewriter rewriter = new QueryRewriter(parser, URL, QualifiedName.of("other_catalog", "other_schema", "tmp_"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), 1, new Duration(10, SECONDS));
Query rewrittenQuery = rewriter.shadowQuery(query);
assertEquals(rewrittenQuery.getPreQueries().size(), 2);
CreateTable createTable = (CreateTable) parser.createStatement(rewrittenQuery.getPreQueries().get(0));
assertEquals(createTable.getName().getParts().size(), 3);
assertEquals(createTable.getName().getPrefix().get(), QualifiedName.of("other_catalog", "other_schema"));
assertTrue(createTable.getName().getSuffix().startsWith("tmp_"));
assertFalse(createTable.getName().getSuffix().contains("test_insert_table"));
Insert insert = (Insert) parser.createStatement(rewrittenQuery.getPreQueries().get(1));
assertEquals(insert.getTarget(), createTable.getName());
assertEquals(insert.getColumns(), Optional.of(ImmutableList.of(identifier("b"), identifier("a"), identifier("c"))));
Table table = new Table(createTable.getName());
SingleColumn columnA = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new Identifier("A"))));
SingleColumn columnB = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new FunctionCall(QualifiedName.of("round"), ImmutableList.of(new Identifier("B"), new LongLiteral("1"))))));
SingleColumn columnC = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new Identifier("C"))));
Select select = new Select(false, ImmutableList.of(columnA, columnB, columnC));
QuerySpecification querySpecification = new QuerySpecification(select, Optional.of(table), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
assertEquals(parser.createStatement(rewrittenQuery.getQuery()), new io.prestosql.sql.tree.Query(Optional.empty(), querySpecification, Optional.empty(), Optional.empty(), Optional.empty()));
assertEquals(rewrittenQuery.getPostQueries().size(), 1);
assertEquals(parser.createStatement(rewrittenQuery.getPostQueries().get(0)), new DropTable(createTable.getName(), true));
}
Aggregations