use of com.facebook.presto.sql.tree.CreateView in project presto by prestodb.
the class CreateViewTask method execute.
@Override
public ListenableFuture<?> execute(CreateView statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
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);
List<ViewColumn> columns = analysis.getOutputDescriptor(statement.getQuery()).getVisibleFields().stream().map(field -> new ViewColumn(field.getName().get(), field.getType())).collect(toImmutableList());
String data = codec.toJson(new ViewDefinition(sql, session.getCatalog(), session.getSchema(), columns, Optional.of(session.getUser())));
metadata.createView(session, name, data, statement.isReplace());
return immediateFuture(null);
}
use of com.facebook.presto.sql.tree.CreateView in project presto by prestodb.
the class TestSqlParser method testCreateView.
@Test
public void testCreateView() throws Exception {
assertStatement("CREATE VIEW a AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false));
assertStatement("CREATE OR REPLACE VIEW a AS SELECT * FROM t", new CreateView(QualifiedName.of("a"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), true));
}
Aggregations