use of io.crate.sql.tree.CreateView in project crate by crate.
the class ViewAnalyzer method analyze.
public CreateViewStmt analyze(CreateView createView, CoordinatorTxnCtx txnCtx) {
RelationName name = RelationName.of(createView.name(), txnCtx.sessionContext().searchPath().currentSchema());
name.ensureValidForRelationCreation();
if (BlobSchemaInfo.NAME.equals(name.schema())) {
throw new UnsupportedOperationException("Creating a view in the \"blob\" schema is not supported");
}
AnalyzedRelation query;
String formattedQuery;
try {
formattedQuery = SqlFormatter.formatSql(createView.query());
} catch (Exception e) {
throw new UnsupportedOperationException("Invalid query used in CREATE VIEW. Query: " + createView.query());
}
try {
// Analyze the formatted Query to make sure the formatting didn't mess it up in any way.
query = relationAnalyzer.analyze((Query) SqlParser.createStatement(formattedQuery), txnCtx, ParamTypeHints.EMPTY);
} catch (Exception e) {
throw new UnsupportedOperationException("Invalid query used in CREATE VIEW. " + e.getMessage() + ". Query: " + formattedQuery);
}
if (query.outputs().stream().map(f -> Symbols.pathFromSymbol(f).sqlFqn()).distinct().count() != query.outputs().size()) {
throw new IllegalArgumentException("Query in CREATE VIEW must not have duplicate column names");
}
return new CreateViewStmt(name, query, createView.query(), createView.replaceExisting(), txnCtx.sessionContext().sessionUser());
}
Aggregations