Search in sources :

Example 21 with QualifiedName

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());
}
Also used : Statement(io.trino.sql.tree.Statement) QualifiedName(io.trino.sql.tree.QualifiedName) CreateTableAsSelect(io.trino.sql.tree.CreateTableAsSelect)

Example 22 with QualifiedName

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());
}
Also used : LikeClause(io.trino.sql.tree.LikeClause) DropTable(io.trino.sql.tree.DropTable) CreateTable(io.trino.sql.tree.CreateTable) Table(io.trino.sql.tree.Table) Statement(io.trino.sql.tree.Statement) QualifiedName(io.trino.sql.tree.QualifiedName) CreateTable(io.trino.sql.tree.CreateTable) Insert(io.trino.sql.tree.Insert)

Example 23 with QualifiedName

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));
}
Also used : ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) SetSession(io.trino.sql.tree.SetSession) QualifiedName(io.trino.sql.tree.QualifiedName)

Example 24 with QualifiedName

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);
}
Also used : QualifiedName(io.trino.sql.tree.QualifiedName) Test(org.testng.annotations.Test)

Example 25 with QualifiedName

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
}
Also used : QualifiedName(io.trino.sql.tree.QualifiedName) Test(org.testng.annotations.Test)

Aggregations

QualifiedName (io.trino.sql.tree.QualifiedName)42 Test (org.testng.annotations.Test)29 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)7 FunctionCall (io.trino.sql.tree.FunctionCall)7 Identifier (io.trino.sql.tree.Identifier)7 ImmutableList (com.google.common.collect.ImmutableList)4 AllColumns (io.trino.sql.tree.AllColumns)4 Test (org.junit.jupiter.api.Test)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 MetadataManager.createTestMetadataManager (io.trino.metadata.MetadataManager.createTestMetadataManager)3 ResolvedFunction (io.trino.metadata.ResolvedFunction)3 ASC_NULLS_LAST (io.trino.spi.connector.SortOrder.ASC_NULLS_LAST)3 BIGINT (io.trino.spi.type.BigintType.BIGINT)3 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)3 TypeSignatureProvider.fromTypes (io.trino.sql.analyzer.TypeSignatureProvider.fromTypes)3 OrderingScheme (io.trino.sql.planner.OrderingScheme)3 PlanMatchPattern.functionCall (io.trino.sql.planner.assertions.PlanMatchPattern.functionCall)3 PlanMatchPattern.patternRecognition (io.trino.sql.planner.assertions.PlanMatchPattern.patternRecognition)3 PlanMatchPattern.specification (io.trino.sql.planner.assertions.PlanMatchPattern.specification)3