use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class TestLimitQueryDeterminismAnalyzer method assertAnalyzerQuery.
private static void assertAnalyzerQuery(MockPrestoAction prestoAction, String expectedQuery) {
Statement expectedStatement = sqlParser.createStatement(expectedQuery, PARSING_OPTIONS);
Statement actualStatement = prestoAction.getLastStatement();
assertEquals(formatSql(actualStatement, Optional.empty()), formatSql(expectedStatement, Optional.empty()));
}
use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class TestSqlFormatter method assetQuery.
private void assetQuery(String query) {
SqlParser parser = new SqlParser();
Statement statement = parser.createStatement(query, new ParsingOptions());
String formattedQuery = getFormattedSql(statement, parser, Optional.empty());
assertEquals(formattedQuery, query);
}
use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class TestPrepareTask method testPrepareInvalidStatement.
@Test
public void testPrepareInvalidStatement() {
Statement statement = new Execute(identifier("foo"), emptyList());
String sqlString = "PREPARE my_query FROM EXECUTE foo";
try {
executePrepare("my_query", statement, sqlString, TEST_SESSION);
fail("expected exception");
} catch (PrestoException e) {
assertEquals(e.getErrorCode(), NOT_SUPPORTED.toErrorCode());
assertEquals(e.getMessage(), "Invalid statement type for prepared statement: EXECUTE");
}
}
use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class CreateViewTask method execute.
@Override
public ListenableFuture<?> execute(CreateView statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
QualifiedObjectName name = createQualifiedObjectName(session, statement, statement.getName());
accessControl.checkCanCreateView(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), name);
String sql = getFormattedSql(statement.getQuery(), sqlParser, Optional.of(parameters));
Analysis analysis = analyzeStatement(statement, session, metadata, accessControl, parameters, warningCollector);
List<ViewColumn> columns = analysis.getOutputDescriptor(statement.getQuery()).getVisibleFields().stream().map(field -> new ViewColumn(field.getName().get(), field.getType())).collect(toImmutableList());
List<ColumnMetadata> columnMetadata = columns.stream().map(column -> new ColumnMetadata(column.getName(), column.getType())).collect(toImmutableList());
ConnectorTableMetadata viewMetadata = new ConnectorTableMetadata(toSchemaTableName(name), columnMetadata);
// use DEFINER security by default
Optional<String> owner = Optional.of(session.getUser());
if (statement.getSecurity().orElse(null) == INVOKER) {
owner = Optional.empty();
}
String data = codec.toJson(new ViewDefinition(sql, session.getCatalog(), session.getSchema(), columns, owner, !owner.isPresent()));
metadata.createView(session, name.getCatalogName(), viewMetadata, data, statement.isReplace());
return immediateFuture(null);
}
use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class Analyzer method analyzeSemantic.
public Analysis analyzeSemantic(Statement statement, boolean isDescribe) {
Statement rewrittenStatement = StatementRewrite.rewrite(session, metadata, sqlParser, queryExplainer, statement, parameters, accessControl, warningCollector);
Analysis analysis = new Analysis(rewrittenStatement, parameters, isDescribe);
StatementAnalyzer analyzer = new StatementAnalyzer(analysis, metadata, sqlParser, accessControl, session, warningCollector);
analyzer.analyze(rewrittenStatement, Optional.empty());
analyzeForUtilizedColumns(analysis, analysis.getStatement());
return analysis;
}
Aggregations