use of com.facebook.presto.hive.metastore.Table in project presto by prestodb.
the class HiveMetadata method getNewTableLayout.
@Override
public Optional<ConnectorNewTableLayout> getNewTableLayout(ConnectorSession session, ConnectorTableMetadata tableMetadata) {
Optional<HiveBucketProperty> bucketProperty = getBucketProperty(tableMetadata.getProperties());
if (!bucketProperty.isPresent()) {
return Optional.empty();
}
if (!bucketWritingEnabled) {
throw new PrestoException(NOT_SUPPORTED, "Writing to bucketed Hive table has been temporarily disabled");
}
List<String> bucketedBy = bucketProperty.get().getBucketedBy();
Map<String, HiveType> hiveTypeMap = tableMetadata.getColumns().stream().collect(toMap(ColumnMetadata::getName, column -> toHiveType(typeTranslator, column.getType())));
return Optional.of(new ConnectorNewTableLayout(new HivePartitioningHandle(connectorId, bucketProperty.get().getBucketCount(), bucketedBy.stream().map(hiveTypeMap::get).collect(toList())), bucketedBy));
}
use of com.facebook.presto.hive.metastore.Table in project presto by prestodb.
the class HiveMetadata method getViews.
@Override
public Map<SchemaTableName, ConnectorViewDefinition> getViews(ConnectorSession session, SchemaTablePrefix prefix) {
ImmutableMap.Builder<SchemaTableName, ConnectorViewDefinition> views = ImmutableMap.builder();
List<SchemaTableName> tableNames;
if (prefix.getTableName() != null) {
tableNames = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName()));
} else {
tableNames = listViews(session, prefix.getSchemaName());
}
for (SchemaTableName schemaTableName : tableNames) {
Optional<Table> table = metastore.getTable(schemaTableName.getSchemaName(), schemaTableName.getTableName());
if (table.isPresent() && HiveUtil.isPrestoView(table.get())) {
views.put(schemaTableName, new ConnectorViewDefinition(schemaTableName, Optional.ofNullable(table.get().getOwner()), decodeViewData(table.get().getViewOriginalText().get())));
}
}
return views.build();
}
use of com.facebook.presto.hive.metastore.Table in project presto by prestodb.
the class HiveMetadata method columnMetadataGetter.
private static Function<HiveColumnHandle, ColumnMetadata> columnMetadataGetter(Table table, TypeManager typeManager) {
ImmutableList.Builder<String> columnNames = ImmutableList.builder();
table.getPartitionColumns().stream().map(Column::getName).forEach(columnNames::add);
table.getDataColumns().stream().map(Column::getName).forEach(columnNames::add);
List<String> allColumnNames = columnNames.build();
if (allColumnNames.size() > Sets.newHashSet(allColumnNames).size()) {
throw new PrestoException(HIVE_INVALID_METADATA, format("Hive metadata for table %s is invalid: Table descriptor contains duplicate columns", table.getTableName()));
}
List<Column> tableColumns = table.getDataColumns();
ImmutableMap.Builder<String, Optional<String>> builder = ImmutableMap.builder();
for (Column field : concat(tableColumns, table.getPartitionColumns())) {
if ((field.getComment() != null) && !Optional.of("from deserializer").equals(field.getComment())) {
builder.put(field.getName(), field.getComment());
} else {
builder.put(field.getName(), Optional.empty());
}
}
// add hidden columns
builder.put(PATH_COLUMN_NAME, Optional.empty());
if (table.getStorage().getBucketProperty().isPresent()) {
builder.put(BUCKET_COLUMN_NAME, Optional.empty());
}
Map<String, Optional<String>> columnComment = builder.build();
return handle -> new ColumnMetadata(handle.getName(), typeManager.getType(handle.getTypeSignature()), columnComment.get(handle.getName()).orElse(null), columnExtraInfo(handle.isPartitionKey()), handle.isHidden());
}
use of com.facebook.presto.hive.metastore.Table in project presto by prestodb.
the class HivePartitionManager method getTable.
private Table getTable(SemiTransactionalHiveMetastore metastore, SchemaTableName tableName) {
Optional<Table> target = metastore.getTable(tableName.getSchemaName(), tableName.getTableName());
if (!target.isPresent()) {
throw new TableNotFoundException(tableName);
}
Table table = target.get();
String protectMode = table.getParameters().get(ProtectMode.PARAMETER_NAME);
if (protectMode != null && getProtectModeFromString(protectMode).offline) {
throw new TableOfflineException(tableName, false, null);
}
String prestoOffline = table.getParameters().get(PRESTO_OFFLINE);
if (!isNullOrEmpty(prestoOffline)) {
throw new TableOfflineException(tableName, true, prestoOffline);
}
return table;
}
use of com.facebook.presto.hive.metastore.Table in project presto by prestodb.
the class FileHiveMetastore method setTablePrivileges.
private synchronized void setTablePrivileges(String principalName, PrincipalType principalType, String databaseName, String tableName, Collection<HivePrivilegeInfo> privileges) {
requireNonNull(principalName, "principalName is null");
requireNonNull(principalType, "principalType is null");
requireNonNull(databaseName, "databaseName is null");
requireNonNull(tableName, "tableName is null");
requireNonNull(privileges, "privileges is null");
try {
Table table = getRequiredTable(databaseName, tableName);
Path permissionsDirectory = getPermissionsDirectory(table);
metadataFileSystem.mkdirs(permissionsDirectory);
if (!metadataFileSystem.isDirectory(permissionsDirectory)) {
throw new PrestoException(HIVE_METASTORE_ERROR, "Could not create permissions directory");
}
Path permissionFilePath = getPermissionsPath(permissionsDirectory, principalName, principalType);
List<PermissionMetadata> permissions = privileges.stream().map(PermissionMetadata::new).collect(toList());
writeFile("permissions", permissionFilePath, permissionsCodec, permissions, true);
} catch (IOException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
}
Aggregations