Search in sources :

Example 6 with ColumnMetadata

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

the class TestDataCenterMetadata method getTableMetadata.

@Test
public void getTableMetadata() {
    ImmutableList.Builder builder = new ImmutableList.Builder();
    builder.add(new ColumnMetadata("orderkey", BIGINT)).add(new ColumnMetadata("custkey", BIGINT)).add(new ColumnMetadata("orderstatus", createVarcharType(1))).add(new ColumnMetadata("totalprice", DOUBLE)).add(new ColumnMetadata("orderdate", DATE)).add(new ColumnMetadata("orderpriority", createVarcharType(15))).add(new ColumnMetadata("clerk", createVarcharType(15))).add(new ColumnMetadata("shippriority", INTEGER)).add(new ColumnMetadata("comment", createVarcharType(79)));
    // known table
    ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(SESSION, NUMBERS_TABLE_HANDLE);
    assertEquals(tableMetadata.getTable(), new SchemaTableName("tiny", "orders"));
    assertEquals(tableMetadata.getColumns(), builder.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) Test(org.testng.annotations.Test)

Example 7 with ColumnMetadata

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

the class TestJdbcMetadata method getTableMetadata.

@Test
public void getTableMetadata() {
    // known table
    ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(SESSION, tableHandle);
    assertEquals(tableMetadata.getTable(), new SchemaTableName("example", "numbers"));
    assertEquals(tableMetadata.getColumns(), ImmutableList.of(// primary key is not null in H2
    new ColumnMetadata("text", VARCHAR, false, null, null, false, emptyMap()), new ColumnMetadata("text_short", createVarcharType(32)), new ColumnMetadata("value", BIGINT)));
    // escaping name patterns
    JdbcTableHandle specialTableHandle = metadata.getTableHandle(SESSION, new SchemaTableName("exa_ple", "num_ers"));
    ConnectorTableMetadata specialTableMetadata = metadata.getTableMetadata(SESSION, specialTableHandle);
    assertEquals(specialTableMetadata.getTable(), new SchemaTableName("exa_ple", "num_ers"));
    assertEquals(specialTableMetadata.getColumns(), ImmutableList.of(// primary key is not null in H2
    new ColumnMetadata("te_t", VARCHAR, false, null, null, false, emptyMap()), new ColumnMetadata("va%ue", BIGINT)));
    // unknown tables should produce null
    unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("u", "numbers"), null, "unknown", "unknown"));
    unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("example", "numbers"), null, "example", "unknown"));
    unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("example", "numbers"), null, "unknown", "numbers"));
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 8 with ColumnMetadata

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

the class TestCachingJdbcMetadata method getTableMetadata.

@Test
public void getTableMetadata() throws SQLException, InterruptedException {
    // add cachingtable
    database.getConnection().createStatement().execute("CREATE SCHEMA cachingschema");
    database.getConnection().createStatement().execute("CREATE TABLE cachingschema.cachingtable(id varchar primary key)");
    ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(session, metadata.getTableHandle(session, cachingSchemaTableName));
    assertEquals(tableMetadata.getTable(), cachingSchemaTableName);
    assertEquals(tableMetadata.getColumns(), ImmutableList.of(new ColumnMetadata("id", VARCHAR, false, null, null, false, emptyMap())));
    database.getConnection().createStatement().execute("ALTER TABLE cachingschema.cachingtable ADD COLUMN value VARCHAR(50)");
    // wait for cache to expire
    Thread.sleep(CACHE_TTL + 50);
    assertEquals(metadata.getTableMetadata(session, metadata.getTableHandle(session, cachingSchemaTableName)).getColumns(), ImmutableList.of(// primary key is not null in H2
    new ColumnMetadata("id", VARCHAR, false, null, null, false, emptyMap()), new ColumnMetadata("value", createVarcharType(50))));
    // known table
    tableMetadata = metadata.getTableMetadata(session, tableHandle);
    assertEquals(tableMetadata.getTable(), new SchemaTableName("example", "numbers"));
    assertEquals(tableMetadata.getColumns(), ImmutableList.of(// primary key is not null in H2
    new ColumnMetadata("text", VARCHAR, false, null, null, false, emptyMap()), new ColumnMetadata("text_short", createVarcharType(32)), new ColumnMetadata("value", BIGINT)));
    // escaping name patterns
    ConnectorTableHandle specialTableHandle = metadata.getTableHandle(session, new SchemaTableName("exa_ple", "num_ers"));
    ConnectorTableMetadata specialTableMetadata = metadata.getTableMetadata(session, specialTableHandle);
    assertEquals(specialTableMetadata.getTable(), new SchemaTableName("exa_ple", "num_ers"));
    assertEquals(specialTableMetadata.getColumns(), ImmutableList.of(// primary key is not null in H2
    new ColumnMetadata("te_t", VARCHAR, false, null, null, false, emptyMap()), new ColumnMetadata("va%ue", BIGINT)));
    // unknown tables should produce null
    unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("unknown", "unknown"), null, "unknown", "unknown"));
    unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("example", "unknown"), null, "example", "unknown"));
    unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("unknown", "numbers"), null, "unknown", "numbers"));
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 9 with ColumnMetadata

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

the class HBaseConnection method validateColumns.

private static void validateColumns(ConnectorTableMetadata meta) {
    // Check schema name
    if (!validateSchemaName(meta.getTable().getSchemaName(), meta.getProperties())) {
        throw new PrestoException(INVALID_TABLE_PROPERTY, "SchemaName needs to consistent with HBase schema");
    }
    // Check columns type
    Set<String> columns = new HashSet<>();
    for (ColumnMetadata column : meta.getColumns()) {
        checkTypeValidate(column.getType());
        // check not exists duplicate columns
        if (!columns.add(column.getName().toLowerCase(Locale.ENGLISH))) {
            throw new PrestoException(INVALID_TABLE_PROPERTY, "not support duplicate column names");
        }
    }
    Optional<Map<String, Pair<String, String>>> columnMapping = HBaseTableProperties.getColumnMapping(meta.getProperties());
    if (columnMapping.isPresent()) {
        // check no duplicates in the column mapping
        Set<String> mappings = new HashSet<>();
        for (Map.Entry<String, Pair<String, String>> entry : columnMapping.get().entrySet()) {
            if (!mappings.add(entry.getValue().getLeft() + "/" + entry.getValue().getRight())) {
                throw new PrestoException(INVALID_TABLE_PROPERTY, "Duplicate column family/qualifier pair detected in column mapping, check the value of column_mapping");
            }
        }
    } else {
        if (HBaseTableProperties.getHBaseTableName(meta.getProperties()).isPresent()) {
            // map to a HBase table without column_mapping
            throw new PrestoException(INVALID_TABLE_PROPERTY, "Column generation for mapping hbase tables is not supported, must specify column_mapping");
        }
    }
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) PrestoException(io.prestosql.spi.PrestoException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Pair(org.apache.commons.lang3.tuple.Pair)

Example 10 with ColumnMetadata

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

the class HBaseConnection method autoGenerateMapping.

private static Map<String, Pair<String, String>> autoGenerateMapping(List<ColumnMetadata> columns, Optional<Map<String, Set<String>>> groups) {
    Map<String, Pair<String, String>> mapping = new HashMap<>();
    // all columns in a single family
    final String familyConstant = "family";
    for (ColumnMetadata column : columns) {
        Optional<String> family = getColumnLocalityGroup(column.getName(), groups);
        mapping.put(column.getName(), Pair.of(family.orElse(familyConstant), column.getName()));
    }
    return mapping;
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)184 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)81 Test (org.testng.annotations.Test)73 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)65 PrestoException (io.prestosql.spi.PrestoException)64 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)64 ImmutableList (com.google.common.collect.ImmutableList)61 TestingConnectorSession (io.prestosql.testing.TestingConnectorSession)50 ImmutableMap (com.google.common.collect.ImmutableMap)49 TupleDomain (io.prestosql.spi.predicate.TupleDomain)49 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)48 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)46 HashMap (java.util.HashMap)43 List (java.util.List)42 Map (java.util.Map)41 Type (io.prestosql.spi.type.Type)38 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)37 ConnectorSplit (io.prestosql.spi.connector.ConnectorSplit)37 Optional (java.util.Optional)36 CounterStat (io.airlift.stats.CounterStat)34