Search in sources :

Example 56 with ConnectorTableMetadata

use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.

the class TestMemoryMetadata method tableAlreadyExists.

@Test
public void tableAlreadyExists() {
    assertNoTables();
    SchemaTableName test1Table = new SchemaTableName("default", "test1");
    SchemaTableName test2Table = new SchemaTableName("default", "test2");
    metadata.createTable(SESSION, new ConnectorTableMetadata(test1Table, ImmutableList.of()), false);
    assertTrinoExceptionThrownBy(() -> metadata.createTable(SESSION, new ConnectorTableMetadata(test1Table, ImmutableList.of()), false)).hasErrorCode(ALREADY_EXISTS).hasMessage("Table [default.test1] already exists");
    ConnectorTableHandle test1TableHandle = metadata.getTableHandle(SESSION, test1Table);
    metadata.createTable(SESSION, new ConnectorTableMetadata(test2Table, ImmutableList.of()), false);
    assertTrinoExceptionThrownBy(() -> metadata.renameTable(SESSION, test1TableHandle, test2Table)).hasErrorCode(ALREADY_EXISTS).hasMessage("Table [default.test2] already exists");
}
Also used : SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 57 with ConnectorTableMetadata

use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.

the class TestMemoryMetadata method testCreateTableAndViewInNotExistSchema.

@Test
public void testCreateTableAndViewInNotExistSchema() {
    assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default"));
    SchemaTableName table1 = new SchemaTableName("test1", "test_schema_table1");
    assertTrinoExceptionThrownBy(() -> metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(table1, ImmutableList.of(), ImmutableMap.of()), Optional.empty(), NO_RETRIES)).hasErrorCode(NOT_FOUND).hasMessage("Schema test1 not found");
    assertNull(metadata.getTableHandle(SESSION, table1));
    SchemaTableName view2 = new SchemaTableName("test2", "test_schema_view2");
    assertTrinoExceptionThrownBy(() -> metadata.createView(SESSION, view2, testingViewDefinition("aaa"), false)).hasErrorCode(NOT_FOUND).hasMessage("Schema test2 not found");
    assertNull(metadata.getTableHandle(SESSION, view2));
    SchemaTableName view3 = new SchemaTableName("test3", "test_schema_view3");
    assertTrinoExceptionThrownBy(() -> metadata.createView(SESSION, view3, testingViewDefinition("bbb"), true)).hasErrorCode(NOT_FOUND).hasMessage("Schema test3 not found");
    assertNull(metadata.getTableHandle(SESSION, view3));
    assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default"));
}
Also used : SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 58 with ConnectorTableMetadata

use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.

the class TestRaptorMetadata method testInvalidTemporalColumn.

@Test(expectedExceptions = TrinoException.class, expectedExceptionsMessageRegExp = "Temporal column does not exist: foo")
public void testInvalidTemporalColumn() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(TEMPORAL_COLUMN_PROPERTY, "foo"));
    metadata.createTable(SESSION, ordersTable, false);
    fail("Expected createTable to fail");
}
Also used : ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 59 with ConnectorTableMetadata

use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.

the class TestRaptorMetadata method assertTableEqual.

private static void assertTableEqual(ConnectorTableMetadata actual, ConnectorTableMetadata expected) {
    assertEquals(actual.getTable(), expected.getTable());
    List<ColumnMetadata> actualColumns = actual.getColumns().stream().filter(columnMetadata -> !columnMetadata.isHidden()).collect(Collectors.toList());
    List<ColumnMetadata> expectedColumns = expected.getColumns();
    assertEquals(actualColumns.size(), expectedColumns.size());
    for (int i = 0; i < actualColumns.size(); i++) {
        ColumnMetadata actualColumn = actualColumns.get(i);
        ColumnMetadata expectedColumn = expectedColumns.get(i);
        assertEquals(actualColumn.getName(), expectedColumn.getName());
        assertEquals(actualColumn.getType(), expectedColumn.getType());
    }
    assertEquals(actual.getProperties(), expected.getProperties());
}
Also used : TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Assertions.assertInstanceOf(io.airlift.testing.Assertions.assertInstanceOf) NodeManager(io.trino.spi.NodeManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) ORGANIZED_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.ORGANIZED_PROPERTY) AfterMethod(org.testng.annotations.AfterMethod) TrinoExceptionAssert.assertTrinoExceptionThrownBy(io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy) Ticker.systemTicker(com.google.common.base.Ticker.systemTicker) QueryAssertions.assertEqualsIgnoreOrder(io.trino.testing.QueryAssertions.assertEqualsIgnoreOrder) RaptorTableHandle(io.trino.plugin.raptor.legacy.RaptorTableHandle) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Handle(org.jdbi.v3.core.Handle) Map(java.util.Map) ViewColumn(io.trino.spi.connector.ConnectorViewDefinition.ViewColumn) ConnectorViewDefinition(io.trino.spi.connector.ConnectorViewDefinition) RaptorPartitioningHandle(io.trino.plugin.raptor.legacy.RaptorPartitioningHandle) DatabaseTesting.createTestingJdbi(io.trino.plugin.raptor.legacy.DatabaseTesting.createTestingJdbi) Assert.assertFalse(org.testng.Assert.assertFalse) RaptorSessionProperties(io.trino.plugin.raptor.legacy.RaptorSessionProperties) ImmutableSet(com.google.common.collect.ImmutableSet) TestingNodeManager(io.trino.testing.TestingNodeManager) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeMethod(org.testng.annotations.BeforeMethod) TrinoException(io.trino.spi.TrinoException) TableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder) Assert.assertNotNull(org.testng.Assert.assertNotNull) RaptorColumnHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle) RaptorMetadata(io.trino.plugin.raptor.legacy.RaptorMetadata) Collectors(java.util.stream.Collectors) NodeSupplier(io.trino.plugin.raptor.legacy.NodeSupplier) SchemaTableName(io.trino.spi.connector.SchemaTableName) DISTRIBUTION_NAME_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.DISTRIBUTION_NAME_PROPERTY) List(java.util.List) BIGINT(io.trino.spi.type.BigintType.BIGINT) SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) BUCKET_COUNT_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.BUCKET_COUNT_PROPERTY) Optional(java.util.Optional) DATE(io.trino.spi.type.DateType.DATE) TestDatabaseShardManager.createShardManager(io.trino.plugin.raptor.legacy.metadata.TestDatabaseShardManager.createShardManager) ConnectorTableLayout(io.trino.spi.connector.ConnectorTableLayout) ConnectorInsertTableHandle(io.trino.spi.connector.ConnectorInsertTableHandle) Assert.assertNull(org.testng.Assert.assertNull) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) Assert.assertEquals(org.testng.Assert.assertEquals) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) BUCKETED_ON_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.BUCKETED_ON_PROPERTY) OptionalInt(java.util.OptionalInt) OptionalLong(java.util.OptionalLong) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ColumnHandle(io.trino.spi.connector.ColumnHandle) ORDERING_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.ORDERING_PROPERTY) Jdbi(org.jdbi.v3.core.Jdbi) StorageManagerConfig(io.trino.plugin.raptor.legacy.storage.StorageManagerConfig) TRANSACTION_CONFLICT(io.trino.spi.StandardErrorCode.TRANSACTION_CONFLICT) Assert.fail(org.testng.Assert.fail) ConnectorSession(io.trino.spi.connector.ConnectorSession) SchemaDaoUtil.createTablesWithRetry(io.trino.plugin.raptor.legacy.metadata.SchemaDaoUtil.createTablesWithRetry) TEMPORAL_COLUMN_PROPERTY(io.trino.plugin.raptor.legacy.RaptorTableProperties.TEMPORAL_COLUMN_PROPERTY) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) TestingConnectorSession(io.trino.testing.TestingConnectorSession) Assert.assertTrue(org.testng.Assert.assertTrue) ColumnMetadata(io.trino.spi.connector.ColumnMetadata)

Example 60 with ConnectorTableMetadata

use of io.trino.spi.connector.ConnectorTableMetadata in project trino by trinodb.

the class TestRaptorMetadata method testTablePropertiesWithOrganization.

@Test
public void testTablePropertiesWithOrganization() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(ORDERING_PROPERTY, ImmutableList.of("orderdate", "custkey"), ORGANIZED_PROPERTY, true));
    metadata.createTable(SESSION, ordersTable, false);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    assertEquals(raptorTableHandle.getTableId(), 1);
    long tableId = raptorTableHandle.getTableId();
    MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
    // verify sort columns
    List<TableColumn> sortColumns = metadataDao.listSortColumns(tableId);
    assertTableColumnsEqual(sortColumns, ImmutableList.of(new TableColumn(DEFAULT_TEST_ORDERS, "orderdate", DATE, 4, 3, OptionalInt.empty(), OptionalInt.of(0), false), new TableColumn(DEFAULT_TEST_ORDERS, "custkey", BIGINT, 2, 1, OptionalInt.empty(), OptionalInt.of(1), false)));
    // verify organization
    assertTrue(metadataDao.getTableInformation(tableId).isOrganized());
    metadata.dropTable(SESSION, tableHandle);
}
Also used : RaptorTableHandle(io.trino.plugin.raptor.legacy.RaptorTableHandle) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)113 SchemaTableName (io.trino.spi.connector.SchemaTableName)69 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)62 Test (org.testng.annotations.Test)48 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)39 ConnectorSession (io.trino.spi.connector.ConnectorSession)35 ImmutableList (com.google.common.collect.ImmutableList)34 List (java.util.List)32 ImmutableMap (com.google.common.collect.ImmutableMap)31 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)30 ColumnHandle (io.trino.spi.connector.ColumnHandle)25 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)24 ConnectorOutputTableHandle (io.trino.spi.connector.ConnectorOutputTableHandle)20 Optional (java.util.Optional)20 TrinoException (io.trino.spi.TrinoException)19 Map (java.util.Map)19 Type (io.trino.spi.type.Type)18 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)17 Constraint (io.trino.spi.connector.Constraint)17 ImmutableSet (com.google.common.collect.ImmutableSet)16