presto-main/src/main/java/io/prestosql/execution/CreateViewTask.java/CreateViewTask/execute
class CreateViewTask:    @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.toSecurityContext(), name);

        String sql = getFormattedSql(statement.getQuery(), sqlParser);

        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().getTypeId()))
                .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);
    }