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");
}
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"));
}
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");
}
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());
}
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);
}
Aggregations