use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class RaptorMetadata method getTableMetadata.
@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
RaptorTableHandle handle = (RaptorTableHandle) tableHandle;
SchemaTableName tableName = new SchemaTableName(handle.getSchemaName(), handle.getTableName());
List<TableColumn> tableColumns = dao.listTableColumns(handle.getTableId());
if (tableColumns.isEmpty()) {
throw new TableNotFoundException(tableName);
}
ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder();
SortedMap<Integer, String> bucketing = new TreeMap<>();
SortedMap<Integer, String> ordering = new TreeMap<>();
for (TableColumn column : tableColumns) {
if (column.isTemporal()) {
properties.put(TEMPORAL_COLUMN_PROPERTY, column.getColumnName());
}
column.getBucketOrdinal().ifPresent(bucketOrdinal -> bucketing.put(bucketOrdinal, column.getColumnName()));
column.getSortOrdinal().ifPresent(sortOrdinal -> ordering.put(sortOrdinal, column.getColumnName()));
}
if (!bucketing.isEmpty()) {
properties.put(BUCKETED_ON_PROPERTY, ImmutableList.copyOf(bucketing.values()));
}
if (!ordering.isEmpty()) {
properties.put(ORDERING_PROPERTY, ImmutableList.copyOf(ordering.values()));
}
handle.getBucketCount().ifPresent(bucketCount -> properties.put(BUCKET_COUNT_PROPERTY, bucketCount));
handle.getDistributionName().ifPresent(distributionName -> properties.put(DISTRIBUTION_NAME_PROPERTY, distributionName));
// Only display organization property if set
if (handle.isOrganized()) {
properties.put(ORGANIZED_PROPERTY, true);
}
List<ColumnMetadata> columns = tableColumns.stream().map(TableColumn::toColumnMetadata).collect(toCollection(ArrayList::new));
columns.add(hiddenColumn(SHARD_UUID_COLUMN_NAME, SHARD_UUID_COLUMN_TYPE));
columns.add(hiddenColumn(BUCKET_NUMBER_COLUMN_NAME, INTEGER));
return new ConnectorTableMetadata(tableName, columns, properties.build());
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class RedisMetadata method getColumnHandles.
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
RedisTableHandle redisTableHandle = convertTableHandle(tableHandle);
RedisTableDescription redisTableDescription = getDefinedTables().get(redisTableHandle.toSchemaTableName());
if (redisTableDescription == null) {
throw new TableNotFoundException(redisTableHandle.toSchemaTableName());
}
ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
int index = 0;
RedisTableFieldGroup key = redisTableDescription.getKey();
if (key != null) {
List<RedisTableFieldDescription> fields = key.getFields();
if (fields != null) {
for (RedisTableFieldDescription field : fields) {
columnHandles.put(field.getName(), field.getColumnHandle(connectorId, true, index));
index++;
}
}
}
RedisTableFieldGroup value = redisTableDescription.getValue();
if (value != null) {
List<RedisTableFieldDescription> fields = value.getFields();
if (fields != null) {
for (RedisTableFieldDescription field : fields) {
columnHandles.put(field.getName(), field.getColumnHandle(connectorId, false, index));
index++;
}
}
}
for (RedisInternalFieldDescription field : internalFieldDescriptions) {
columnHandles.put(field.getName(), field.getColumnHandle(connectorId, index, hideInternalColumns));
index++;
}
return columnHandles.build();
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class KafkaMetadata method getColumnHandles.
@SuppressWarnings("ValueOfIncrementOrDecrementUsed")
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
KafkaTableHandle kafkaTableHandle = convertTableHandle(tableHandle);
KafkaTopicDescription kafkaTopicDescription = tableDescriptions.get(kafkaTableHandle.toSchemaTableName());
if (kafkaTopicDescription == null) {
throw new TableNotFoundException(kafkaTableHandle.toSchemaTableName());
}
ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
int index = 0;
KafkaTopicFieldGroup key = kafkaTopicDescription.getKey();
if (key != null) {
List<KafkaTopicFieldDescription> fields = key.getFields();
if (fields != null) {
for (KafkaTopicFieldDescription kafkaTopicFieldDescription : fields) {
columnHandles.put(kafkaTopicFieldDescription.getName(), kafkaTopicFieldDescription.getColumnHandle(connectorId, true, index++));
}
}
}
KafkaTopicFieldGroup message = kafkaTopicDescription.getMessage();
if (message != null) {
List<KafkaTopicFieldDescription> fields = message.getFields();
if (fields != null) {
for (KafkaTopicFieldDescription kafkaTopicFieldDescription : fields) {
columnHandles.put(kafkaTopicFieldDescription.getName(), kafkaTopicFieldDescription.getColumnHandle(connectorId, false, index++));
}
}
}
for (KafkaInternalFieldDescription kafkaInternalFieldDescription : internalFieldDescriptions) {
columnHandles.put(kafkaInternalFieldDescription.getName(), kafkaInternalFieldDescription.getColumnHandle(connectorId, index++, hideInternalColumns));
}
return columnHandles.build();
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class MongoSession method getTableMetadata.
// Internal Schema management
private Document getTableMetadata(SchemaTableName schemaTableName) throws TableNotFoundException {
String schemaName = schemaTableName.getSchemaName();
String tableName = schemaTableName.getTableName();
MongoDatabase db = client.getDatabase(schemaName);
MongoCollection<Document> schema = db.getCollection(schemaCollection);
Document doc = schema.find(new Document(TABLE_NAME_KEY, tableName)).first();
if (doc == null) {
if (!collectionExists(db, tableName)) {
throw new TableNotFoundException(schemaTableName);
} else {
Document metadata = new Document(TABLE_NAME_KEY, tableName);
metadata.append(FIELDS_KEY, guessTableFields(schemaTableName));
schema.createIndex(new Document(TABLE_NAME_KEY, 1), new IndexOptions().unique(true));
schema.insertOne(metadata);
return metadata;
}
}
return doc;
}
use of com.facebook.presto.spi.TableNotFoundException in project presto by prestodb.
the class MongoSession method createTableMetadata.
private void createTableMetadata(SchemaTableName schemaTableName, List<MongoColumnHandle> columns) throws TableNotFoundException {
String schemaName = schemaTableName.getSchemaName();
String tableName = schemaTableName.getTableName();
MongoDatabase db = client.getDatabase(schemaName);
Document metadata = new Document(TABLE_NAME_KEY, tableName);
ArrayList<Document> fields = new ArrayList<>();
if (!columns.stream().anyMatch(c -> c.getName().equals("_id"))) {
fields.add(new MongoColumnHandle("_id", OBJECT_ID, true).getDocument());
}
fields.addAll(columns.stream().map(MongoColumnHandle::getDocument).collect(toList()));
metadata.append(FIELDS_KEY, fields);
MongoCollection<Document> schema = db.getCollection(schemaCollection);
schema.createIndex(new Document(TABLE_NAME_KEY, 1), new IndexOptions().unique(true));
schema.insertOne(metadata);
}
Aggregations