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