use of io.trino.sql.tree.Statement in project trino by trinodb.
the class TreeAssertions method assertFormattedSql.
public static void assertFormattedSql(SqlParser sqlParser, ParsingOptions parsingOptions, Node expected) {
String formatted = formatSql(expected);
// verify round-trip of formatting already-formatted SQL
Statement actual = parseFormatted(sqlParser, parsingOptions, formatted, expected);
assertEquals(formatSql(actual), formatted);
// compare parsed tree with parsed tree of formatted SQL
if (!actual.equals(expected)) {
// simplify finding the non-equal part of the tree
assertListEquals(linearizeTree(actual), linearizeTree(expected));
}
assertEquals(actual, expected);
}
use of io.trino.sql.tree.Statement in project trino by trinodb.
the class TestAnalyzer method analyze.
private Analysis analyze(Session clientSession, @Language("SQL") String query, AccessControl accessControl) {
return transaction(transactionManager, accessControl).singleStatement().readUncommitted().execute(clientSession, session -> {
Analyzer analyzer = createAnalyzer(session, accessControl);
Statement statement = SQL_PARSER.createStatement(query, new ParsingOptions(new FeaturesConfig().isParseDecimalLiteralsAsDouble() ? AS_DOUBLE : AS_DECIMAL));
return analyzer.analyze(statement);
});
}
use of io.trino.sql.tree.Statement in project trino by trinodb.
the class QueryRewriter method rewriteCreateTableAsSelect.
private Query rewriteCreateTableAsSelect(Connection connection, Query query, CreateTableAsSelect statement) throws SQLException, QueryRewriteException {
QualifiedName temporaryTableName = generateTemporaryTableName(statement.getName());
Statement rewritten = new CreateTableAsSelect(temporaryTableName, statement.getQuery(), statement.isNotExists(), statement.getProperties(), statement.isWithData(), statement.getColumnAliases(), Optional.empty());
String createTableAsSql = formatSql(rewritten);
String checksumSql = checksumSql(getColumns(connection, statement), temporaryTableName);
String dropTableSql = dropTableSql(temporaryTableName);
return new Query(query.getCatalog(), query.getSchema(), ImmutableList.of(createTableAsSql), checksumSql, ImmutableList.of(dropTableSql), query.getUsername(), query.getPassword(), query.getSessionProperties());
}
use of io.trino.sql.tree.Statement in project trino by trinodb.
the class QueryRewriter method rewriteInsertQuery.
private Query rewriteInsertQuery(Connection connection, Query query, Insert statement) throws SQLException, QueryRewriteException {
QualifiedName temporaryTableName = generateTemporaryTableName(statement.getTarget());
Statement createTemporaryTable = new CreateTable(temporaryTableName, ImmutableList.of(new LikeClause(statement.getTarget(), Optional.of(INCLUDING))), true, ImmutableList.of(), Optional.empty());
String createTemporaryTableSql = formatSql(createTemporaryTable);
String insertSql = formatSql(new Insert(new Table(temporaryTableName), statement.getColumns(), statement.getQuery()));
String checksumSql = checksumSql(getColumnsForTable(connection, query.getCatalog(), query.getSchema(), statement.getTarget().toString()), temporaryTableName);
String dropTableSql = dropTableSql(temporaryTableName);
return new Query(query.getCatalog(), query.getSchema(), ImmutableList.of(createTemporaryTableSql, insertSql), checksumSql, ImmutableList.of(dropTableSql), query.getUsername(), query.getPassword(), query.getSessionProperties());
}
use of io.trino.sql.tree.Statement in project trino by trinodb.
the class TestPrepareTask method testPrepareInvalidStatement.
@Test
public void testPrepareInvalidStatement() {
Statement statement = new Execute(identifier("foo"), emptyList());
String sqlString = "PREPARE my_query FROM EXECUTE foo";
assertTrinoExceptionThrownBy(() -> executePrepare("my_query", statement, sqlString, TEST_SESSION)).hasErrorCode(NOT_SUPPORTED).hasMessage("Invalid statement type for prepared statement: EXECUTE");
}
Aggregations