use of io.trino.sql.tree.QualifiedName 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.QualifiedName 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.QualifiedName in project trino by trinodb.
the class TestSetSessionTask method testSetSessionWithParameters.
private void testSetSessionWithParameters(String property, Expression expression, String expectedValue, List<Expression> parameters) {
QualifiedName qualifiedPropName = QualifiedName.of(CATALOG_NAME, property);
QueryStateMachine stateMachine = QueryStateMachine.begin(Optional.empty(), format("set %s = 'old_value'", qualifiedPropName), Optional.empty(), TEST_SESSION, URI.create("fake://uri"), new ResourceGroupId("test"), false, transactionManager, accessControl, executor, metadata, WarningCollector.NOOP, Optional.empty());
getFutureValue(new SetSessionTask(plannerContext, accessControl, sessionPropertyManager).execute(new SetSession(qualifiedPropName, expression), stateMachine, parameters, WarningCollector.NOOP));
Map<String, String> sessionProperties = stateMachine.getSetSessionProperties();
assertEquals(sessionProperties, ImmutableMap.of(qualifiedPropName.toString(), expectedValue));
}
use of io.trino.sql.tree.QualifiedName in project trino by trinodb.
the class TestRenameViewTask method testRenameViewOnMaterializedView.
@Test
public void testRenameViewOnMaterializedView() {
QualifiedName viewName = qualifiedName("existing_materialized_view");
metadata.createMaterializedView(testSession, QualifiedObjectName.valueOf(viewName.toString()), someMaterializedView(), false, false);
assertTrinoExceptionThrownBy(() -> getFutureValue(executeRenameView(viewName, qualifiedName("existing_materialized_view_new")))).hasErrorCode(TABLE_NOT_FOUND).hasMessage("View '%s' does not exist, but a materialized view with that name exists. Did you mean ALTER MATERIALIZED VIEW catalog.schema.existing_materialized_view RENAME ...?", viewName);
}
use of io.trino.sql.tree.QualifiedName in project trino by trinodb.
the class TestDropViewTask method testDropNotExistingViewIfExists.
@Test
public void testDropNotExistingViewIfExists() {
QualifiedName viewName = qualifiedName("not_existing_view");
getFutureValue(executeDropView(viewName, true));
// no exception
}
Aggregations