use of io.trino.sql.tree.CreateTable in project trino by trinodb.
the class TestCreateTableTask method testCreateLikeWithProperties.
@Test
public void testCreateLikeWithProperties() {
CreateTable statement = getCreatleLikeStatement(true);
CreateTableTask createTableTask = new CreateTableTask(plannerContext, new AllowAllAccessControl(), columnPropertyManager, tablePropertyManager);
getFutureValue(createTableTask.internalExecute(statement, testSession, List.of(), output -> {
}));
assertEquals(metadata.getCreateTableCallCount(), 1);
assertThat(metadata.getReceivedTableMetadata().get(0).getColumns()).isEqualTo(PARENT_TABLE.getColumns());
assertThat(metadata.getReceivedTableMetadata().get(0).getProperties()).isEqualTo(PARENT_TABLE.getProperties());
}
use of io.trino.sql.tree.CreateTable in project trino by trinodb.
the class TestCreateTableTask method testCreateTableNotExistsFalse.
@Test
public void testCreateTableNotExistsFalse() {
CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition(identifier("a"), toSqlType(BIGINT), true, emptyList(), Optional.empty())), false, ImmutableList.of(), Optional.empty());
CreateTableTask createTableTask = new CreateTableTask(plannerContext, new AllowAllAccessControl(), columnPropertyManager, tablePropertyManager);
assertTrinoExceptionThrownBy(() -> getFutureValue(createTableTask.internalExecute(statement, testSession, emptyList(), output -> {
}))).hasErrorCode(ALREADY_EXISTS).hasMessage("Table already exists");
assertEquals(metadata.getCreateTableCallCount(), 1);
}
use of io.trino.sql.tree.CreateTable in project trino by trinodb.
the class TestCreateTableTask method testCreateTableWithMaterializedViewPropertyFails.
@Test
public void testCreateTableWithMaterializedViewPropertyFails() {
CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition(identifier("a"), toSqlType(BIGINT), true, emptyList(), Optional.empty())), false, ImmutableList.of(new Property(new Identifier("foo"), new StringLiteral("bar"))), Optional.empty());
CreateTableTask createTableTask = new CreateTableTask(plannerContext, new AllowAllAccessControl(), columnPropertyManager, tablePropertyManager);
assertTrinoExceptionThrownBy(() -> getFutureValue(createTableTask.internalExecute(statement, testSession, emptyList(), output -> {
}))).hasErrorCode(INVALID_TABLE_PROPERTY).hasMessage("Catalog 'catalog' table property 'foo' does not exist");
assertEquals(metadata.getCreateTableCallCount(), 0);
}
use of io.trino.sql.tree.CreateTable in project trino by trinodb.
the class TestCreateTableTask method testCreateLikeDenyPermission.
@Test
public void testCreateLikeDenyPermission() {
CreateTable statement = getCreatleLikeStatement(false);
TestingAccessControlManager accessControl = new TestingAccessControlManager(transactionManager, new EventListenerManager(new EventListenerConfig()));
accessControl.deny(privilege("parent_table", SELECT_COLUMN));
CreateTableTask createTableTask = new CreateTableTask(plannerContext, accessControl, columnPropertyManager, tablePropertyManager);
assertThatThrownBy(() -> getFutureValue(createTableTask.internalExecute(statement, testSession, List.of(), output -> {
}))).isInstanceOf(AccessDeniedException.class).hasMessageContaining("Cannot reference columns of table");
}
use of io.trino.sql.tree.CreateTable in project trino by trinodb.
the class TestCreateTableTask method testCreateTableNotExistsTrue.
@Test
public void testCreateTableNotExistsTrue() {
CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition(identifier("a"), toSqlType(BIGINT), true, emptyList(), Optional.empty())), true, ImmutableList.of(), Optional.empty());
CreateTableTask createTableTask = new CreateTableTask(plannerContext, new AllowAllAccessControl(), columnPropertyManager, tablePropertyManager);
getFutureValue(createTableTask.internalExecute(statement, testSession, emptyList(), output -> {
}));
assertEquals(metadata.getCreateTableCallCount(), 1);
}
Aggregations