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