use of io.prestosql.sql.tree.CreateView in project hetu-core by openlookeng.
the class TestSqlParser method testCreateView.
@Test
public void testCreateView() {
Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t")));
assertStatement("CREATE VIEW a AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.empty()));
assertStatement("CREATE OR REPLACE VIEW a AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, true, Optional.empty()));
assertStatement("CREATE VIEW a SECURITY DEFINER AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.of(CreateView.Security.DEFINER)));
assertStatement("CREATE VIEW a SECURITY INVOKER AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), query, false, Optional.of(CreateView.Security.INVOKER)));
assertStatement("CREATE VIEW bar.foo AS SELECT * FROM t", new CreateView(QualifiedName.of("bar", "foo"), query, false, Optional.empty()));
assertStatement("CREATE VIEW \"awesome view\" AS SELECT * FROM t", new CreateView(QualifiedName.of("awesome view"), query, false, Optional.empty()));
assertStatement("CREATE VIEW \"awesome schema\".\"awesome view\" AS SELECT * FROM t", new CreateView(QualifiedName.of("awesome schema", "awesome view"), query, false, Optional.empty()));
}
use of io.prestosql.sql.tree.CreateView 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);
}
Aggregations