use of io.prestosql.sql.parser.SqlParser in project hetu-core by openlookeng.
the class CreateViewTask method execute.
@Override
public ListenableFuture<?> execute(CreateView statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
Session session = stateMachine.getSession();
QualifiedObjectName name = createQualifiedObjectName(session, statement, statement.getName());
accessControl.checkCanCreateView(session.getRequiredTransactionId(), session.getIdentity(), name);
String sql = getFormattedSql(statement.getQuery(), sqlParser, Optional.of(parameters));
Analysis analysis = analyzeStatement(statement, session, metadata, accessControl, parameters, stateMachine.getWarningCollector());
List<ViewColumn> columns = analysis.getOutputDescriptor(statement.getQuery()).getVisibleFields().stream().map(field -> new ViewColumn(field.getName().get(), field.getType().getTypeSignature())).collect(toImmutableList());
// use DEFINER security by default
Optional<String> owner = Optional.of(session.getUser());
if (statement.getSecurity().orElse(null) == INVOKER) {
owner = Optional.empty();
}
ConnectorViewDefinition definition = new ConnectorViewDefinition(sql, session.getCatalog(), session.getSchema(), columns, owner, !owner.isPresent());
metadata.createView(session, name, definition, statement.isReplace());
return immediateFuture(null);
}
use of io.prestosql.sql.parser.SqlParser 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.SqlParser in project hetu-core by openlookeng.
the class LogicalPlanner method arePredicatesOverlapping.
private boolean arePredicatesOverlapping(Expression inputNewDataPredicate, CubeMetadata cubeMetadata) {
// Cannot do this check inside StatementAnalyzer because predicate expressions have not been rewritten by then.
Expression newDataPredicate = inputNewDataPredicate;
TypeProvider types = planSymbolAllocator.getTypes();
newDataPredicate = ExpressionUtils.rewriteIdentifiersToSymbolReferences(newDataPredicate);
ExpressionDomainTranslator.ExtractionResult decomposedNewDataPredicate = ExpressionDomainTranslator.fromPredicate(metadata, session, newDataPredicate, types);
if (cubeMetadata.getCubeStatus() == CubeStatus.INACTIVE) {
// Inactive cubes are empty. So inserts should be allowed.
return false;
}
CubeFilter cubeFilter = cubeMetadata.getCubeFilter();
if (cubeFilter == null || cubeFilter.getCubePredicate() == null) {
// Means Cube was created for entire dataset.
return true;
}
SqlParser sqlParser = new SqlParser();
Expression cubePredicateAsExpr = sqlParser.createExpression(cubeFilter.getCubePredicate(), createParsingOptions(session));
cubePredicateAsExpr = ExpressionUtils.rewriteIdentifiersToSymbolReferences(cubePredicateAsExpr);
ExpressionDomainTranslator.ExtractionResult decomposedCubePredicate = ExpressionDomainTranslator.fromPredicate(metadata, session, cubePredicateAsExpr, types);
return decomposedCubePredicate.getTupleDomain().overlaps(decomposedNewDataPredicate.getTupleDomain());
}
use of io.prestosql.sql.parser.SqlParser in project hetu-core by openlookeng.
the class TestWindowNode method getJsonCodec.
private JsonCodec<WindowNode> getJsonCodec() throws Exception {
Module module = binder -> {
SqlParser sqlParser = new SqlParser();
TypeManager typeManager = new TestingTypeManager();
binder.install(new JsonModule());
binder.install(new HandleJsonModule());
binder.bind(SqlParser.class).toInstance(sqlParser);
binder.bind(TypeManager.class).toInstance(typeManager);
configBinder(binder).bindConfig(FeaturesConfig.class);
newSetBinder(binder, Type.class);
jsonBinder(binder).addSerializerBinding(Slice.class).to(SliceSerializer.class);
jsonBinder(binder).addDeserializerBinding(Slice.class).to(SliceDeserializer.class);
jsonBinder(binder).addDeserializerBinding(Type.class).to(TestingTypeDeserializer.class);
jsonBinder(binder).addSerializerBinding(Expression.class).to(Serialization.ExpressionSerializer.class);
jsonBinder(binder).addDeserializerBinding(Expression.class).to(Serialization.ExpressionDeserializer.class);
jsonBinder(binder).addDeserializerBinding(FunctionCall.class).to(Serialization.FunctionCallDeserializer.class);
jsonBinder(binder).addKeySerializerBinding(VariableReferenceExpression.class).to(Serialization.VariableReferenceExpressionSerializer.class);
jsonBinder(binder).addKeyDeserializerBinding(VariableReferenceExpression.class).to(Serialization.VariableReferenceExpressionDeserializer.class);
jsonCodecBinder(binder).bindJsonCodec(WindowNode.class);
};
Bootstrap app = new Bootstrap(ImmutableList.of(module));
Injector injector = app.strictConfig().doNotInitializeLogging().quiet().initialize();
return injector.getInstance(new Key<JsonCodec<WindowNode>>() {
});
}
use of io.prestosql.sql.parser.SqlParser 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);
}
Aggregations