Search in sources :

Example 1 with ConnectorTableMetadata

use of io.prestosql.spi.connector.ConnectorTableMetadata in project hetu-core by openlookeng.

the class TpchMetadata method getTableMetadata.

private static ConnectorTableMetadata getTableMetadata(String schemaName, TpchTable<?> tpchTable, ColumnNaming columnNaming) {
    ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
    for (TpchColumn<? extends TpchEntity> column : tpchTable.getColumns()) {
        columns.add(new ColumnMetadata(columnNaming.getName(column), getPrestoType(column), false, null, null, false, emptyMap()));
    }
    columns.add(new ColumnMetadata(ROW_NUMBER_COLUMN_NAME, BIGINT, null, true));
    SchemaTableName tableName = new SchemaTableName(schemaName, tpchTable.getTableName());
    return new ConnectorTableMetadata(tableName, columns.build());
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata)

Example 2 with ConnectorTableMetadata

use of io.prestosql.spi.connector.ConnectorTableMetadata in project hetu-core by openlookeng.

the class TpcdsMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> tableColumns = ImmutableMap.builder();
    for (String schemaName : getSchemaNames(session, prefix.getSchema())) {
        for (Table tpcdsTable : Table.getBaseTables()) {
            if (prefix.getTable().map(tpcdsTable.getName()::equals).orElse(true)) {
                ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpcdsTable);
                tableColumns.put(new SchemaTableName(schemaName, tpcdsTable.getName()), tableMetadata.getColumns());
            }
        }
    }
    return tableColumns.build();
}
Also used : Table(com.teradata.tpcds.Table) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata)

Example 3 with ConnectorTableMetadata

use of io.prestosql.spi.connector.ConnectorTableMetadata in project hetu-core by openlookeng.

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);
    try {
        metadata.createTable(SESSION, new ConnectorTableMetadata(test1Table, ImmutableList.of()), false);
        fail("Should fail because table already exists");
    } catch (PrestoException ex) {
        assertEquals(ex.getErrorCode(), ALREADY_EXISTS.toErrorCode());
        assertEquals(ex.getMessage(), "Table [default.test1] already exists");
    }
    ConnectorTableHandle test1TableHandle = metadata.getTableHandle(SESSION, test1Table);
    metadata.createTable(SESSION, new ConnectorTableMetadata(test2Table, ImmutableList.of()), false);
    try {
        metadata.renameTable(SESSION, test1TableHandle, test2Table);
        fail("Should fail because table already exists");
    } catch (PrestoException ex) {
        assertEquals(ex.getErrorCode(), ALREADY_EXISTS.toErrorCode());
        assertEquals(ex.getMessage(), "Table [default.test2] already exists");
    }
}
Also used : PrestoException(io.prestosql.spi.PrestoException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 4 with ConnectorTableMetadata

use of io.prestosql.spi.connector.ConnectorTableMetadata in project hetu-core by openlookeng.

the class TestMemoryMetadata method testRenameTable.

@Test
public void testRenameTable() {
    SchemaTableName tableName = new SchemaTableName("test_schema", "test_table_to_be_renamed");
    metadata.createSchema(SESSION, "test_schema", ImmutableMap.of());
    ConnectorOutputTableHandle table = metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(tableName, ImmutableList.of(), ImmutableMap.of()), Optional.empty());
    metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());
    // rename table to schema which does not exist
    SchemaTableName invalidSchemaTableName = new SchemaTableName("test_schema_not_exist", "test_table_renamed");
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, tableName);
    Throwable throwable = expectThrows(SchemaNotFoundException.class, () -> metadata.renameTable(SESSION, tableHandle, invalidSchemaTableName));
    assertTrue(throwable.getMessage().equals("Schema test_schema_not_exist not found"));
    // rename table to same schema
    SchemaTableName sameSchemaTableName = new SchemaTableName("test_schema", "test_renamed");
    metadata.renameTable(SESSION, metadata.getTableHandle(SESSION, tableName), sameSchemaTableName);
    assertEquals(metadata.listTables(SESSION, Optional.of("test_schema")), ImmutableList.of(sameSchemaTableName));
}
Also used : ConnectorOutputTableHandle(io.prestosql.spi.connector.ConnectorOutputTableHandle) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 5 with ConnectorTableMetadata

use of io.prestosql.spi.connector.ConnectorTableMetadata in project hetu-core by openlookeng.

the class TestMemoryMetadata method tableIsCreatedAfterCommits.

@Test
public void tableIsCreatedAfterCommits() {
    assertNoTables();
    SchemaTableName schemaTableName = new SchemaTableName("default", "temp_table");
    ConnectorOutputTableHandle table = metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(schemaTableName, ImmutableList.of(), ImmutableMap.of()), Optional.empty());
    metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());
    List<SchemaTableName> tables = metadata.listTables(SESSION, Optional.empty());
    assertEquals(tables.size(), 1, "Expected only one table");
    assertEquals(tables.get(0).getTableName(), "temp_table", "Expected table with name 'temp_table'");
}
Also used : ConnectorOutputTableHandle(io.prestosql.spi.connector.ConnectorOutputTableHandle) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Aggregations

ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)81 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)50 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)49 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)30 Test (org.testng.annotations.Test)29 ImmutableList (com.google.common.collect.ImmutableList)26 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)26 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)24 ImmutableMap (com.google.common.collect.ImmutableMap)21 PrestoException (io.prestosql.spi.PrestoException)21 List (java.util.List)21 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)20 ConnectorOutputTableHandle (io.prestosql.spi.connector.ConnectorOutputTableHandle)17 TestingConnectorSession (io.prestosql.testing.TestingConnectorSession)16 Slice (io.airlift.slice.Slice)15 ArrayList (java.util.ArrayList)15 Constraint (io.prestosql.spi.connector.Constraint)14 Optional (java.util.Optional)14 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)13 TableNotFoundException (io.prestosql.spi.connector.TableNotFoundException)13