Search in sources :

Example 6 with ParsingOptions

use of io.prestosql.sql.parser.ParsingOptions in project hetu-core by openlookeng.

the class TestImpalaSqlMigrate method setup.

@BeforeClass
public void setup() throws Exception {
    sqlParser = new SqlParser();
    parsingOptions = new ParsingOptions(DecimalLiteralTreatment.AS_DECIMAL);
    SessionProperties sessionProperties = new SessionProperties();
    sessionProperties.setSourceType(SqlSyntaxType.IMPALA);
    sessionProperties.setParsingOptions(false);
    sqlConverter = SqlConverterFactory.getSqlConverter(sessionProperties);
}
Also used : ParsingOptions(io.prestosql.sql.parser.ParsingOptions) SqlParser(io.prestosql.sql.parser.SqlParser) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with ParsingOptions

use of io.prestosql.sql.parser.ParsingOptions in project hetu-core by openlookeng.

the class ReloadCubeConsole method reload.

public boolean reload(String query, QueryRunner queryRunner, ClientOptions.OutputFormat outputFormat, Runnable schemaChanged, boolean usePager, boolean showProgress, Terminal terminal, PrintStream out, PrintStream errorChannel) throws UnsupportedEncodingException {
    SqlParser parser = new SqlParser();
    ReloadCube reloadCube = (ReloadCube) parser.createStatement(query, new ParsingOptions(ParsingOptions.DecimalLiteralTreatment.AS_DOUBLE));
    if (!checkCubeName(queryRunner, reloadCube, reloadCube.getCubeName())) {
        return false;
    }
    String cubeTableName = this.catalogName + "." + this.schemaName + "." + this.objectName;
    final Charset charset = StandardCharsets.UTF_8;
    ByteArrayOutputStream stringOutputStream = new ByteArrayOutputStream();
    String showCreateCubeQuery = "SHOW CREATE CUBE " + cubeTableName.toString();
    if (!console.runQuery(queryRunner, showCreateCubeQuery, ClientOptions.OutputFormat.CSV, schemaChanged, false, showProgress, terminal, new PrintStream(stringOutputStream, true, charset.name()), errorChannel)) {
        return false;
    }
    this.newQuery = stringOutputStream.toString().replace("\"\"", "\"").trim();
    this.newQuery = this.newQuery.substring(1, this.newQuery.length() - 1);
    String dropQuery = "DROP CUBE " + cubeTableName.toString();
    if (!console.runQuery(queryRunner, dropQuery, outputFormat, schemaChanged, usePager, showProgress, terminal, out, errorChannel)) {
        return false;
    }
    return true;
}
Also used : PrintStream(java.io.PrintStream) ParsingOptions(io.prestosql.sql.parser.ParsingOptions) SqlParser(io.prestosql.sql.parser.SqlParser) Charset(java.nio.charset.Charset) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ReloadCube(io.prestosql.sql.tree.ReloadCube)

Example 8 with ParsingOptions

use of io.prestosql.sql.parser.ParsingOptions in project hetu-core by openlookeng.

the class TestExpressionInterpreter method assertRoundTrip.

private static void assertRoundTrip(String expression) {
    ParsingOptions parsingOptions = createParsingOptions(TEST_SESSION);
    Expression parsed = SQL_PARSER.createExpression(expression, parsingOptions);
    String formatted = formatExpression(parsed, Optional.empty());
    assertEquals(parsed, SQL_PARSER.createExpression(formatted, parsingOptions));
}
Also used : ParsingUtil.createParsingOptions(io.prestosql.sql.ParsingUtil.createParsingOptions) ParsingOptions(io.prestosql.sql.parser.ParsingOptions) ExpressionFormatter.formatExpression(io.prestosql.sql.ExpressionFormatter.formatExpression) Expression(io.prestosql.sql.tree.Expression)

Example 9 with ParsingOptions

use of io.prestosql.sql.parser.ParsingOptions in project hetu-core by openlookeng.

the class TestHiveSqlMigrate method setup.

@BeforeClass
public void setup() throws Exception {
    sqlParser = new SqlParser();
    parsingOptions = new io.prestosql.sql.parser.ParsingOptions(DecimalLiteralTreatment.AS_DECIMAL);
    SessionProperties sessionProperties = new SessionProperties();
    sessionProperties.setSourceType(SqlSyntaxType.HIVE);
    sessionProperties.setParsingOptions(false);
    sqlConverter = SqlConverterFactory.getSqlConverter(sessionProperties);
}
Also used : SqlParser(io.prestosql.sql.parser.SqlParser) ParsingOptions(io.prestosql.sql.parser.ParsingOptions) BeforeClass(org.testng.annotations.BeforeClass)

Example 10 with ParsingOptions

use of io.prestosql.sql.parser.ParsingOptions in project hetu-core by openlookeng.

the class CubeOptimizer method rewriteFilterPredicate.

private Optional<RowExpression> rewriteFilterPredicate() {
    // rewrite the expression by removing source filter predicate as cube would not have those columns necessarily
    Expression queryPredicate = castToExpression(filterNode.getPredicate());
    if (cubeMetadata.getCubeFilter() == null || cubeMetadata.getCubeFilter().getSourceTablePredicate() == null) {
        // nothing more to do. just rewrite the symbol reference of the original predicate
        return Optional.of(castToRowExpression(rewriteSymbolReferenceToTargetMapping(queryPredicate)));
    }
    SqlParser sqlParser = new SqlParser();
    Expression cubeSourcePredicate = sqlParser.createExpression(cubeMetadata.getCubeFilter().getSourceTablePredicate(), new ParsingOptions());
    cubeSourcePredicate = rewriteIdentifiersWithSymbolReference(cubeSourcePredicate);
    Set<Symbol> sourceFilterPredicateColumns = SymbolsExtractor.extractUnique(cubeSourcePredicate);
    Expression modifiedPredicate = ExpressionUtils.filterConjuncts(queryPredicate, expr -> !sourceFilterPredicateColumns.containsAll(SymbolsExtractor.extractUnique(expr)));
    return Optional.ofNullable(modifiedPredicate.equals(BooleanLiteral.TRUE_LITERAL) ? null : castToRowExpression(rewriteSymbolReferenceToTargetMapping(modifiedPredicate)));
}
Also used : ConstantExpression(io.prestosql.spi.relation.ConstantExpression) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) ParsingOptions(io.prestosql.sql.parser.ParsingOptions) Symbol(io.prestosql.spi.plan.Symbol) SqlParser(io.prestosql.sql.parser.SqlParser)

Aggregations

ParsingOptions (io.prestosql.sql.parser.ParsingOptions)17 SqlParser (io.prestosql.sql.parser.SqlParser)10 Expression (io.prestosql.sql.tree.Expression)10 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)5 CubeFilter (io.hetu.core.spi.cube.CubeFilter)4 Symbol (io.prestosql.spi.plan.Symbol)4 OriginalExpressionUtils.castToExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression)4 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)4 ParsingException (io.prestosql.sql.parser.ParsingException)3 ExpressionDomainTranslator (io.prestosql.sql.planner.ExpressionDomainTranslator)3 TypeProvider (io.prestosql.sql.planner.TypeProvider)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CallExpression (io.prestosql.spi.relation.CallExpression)2 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)2 RowExpression (io.prestosql.spi.relation.RowExpression)2 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)2 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)2 BetweenPredicate (io.prestosql.sql.tree.BetweenPredicate)2 QualifiedName (io.prestosql.sql.tree.QualifiedName)2