Search in sources :

Example 1 with StorageDescriptor

use of com.amazonaws.services.glue.model.StorageDescriptor in project presto by prestodb.

the class GlueInputConverter method convertStorage.

private static StorageDescriptor convertStorage(Storage storage, List<Column> columns) {
    if (storage.isSkewed()) {
        throw new IllegalArgumentException("Writing to skewed table/partition is not supported");
    }
    SerDeInfo serdeInfo = new SerDeInfo().withSerializationLibrary(storage.getStorageFormat().getSerDeNullable()).withParameters(storage.getSerdeParameters());
    StorageDescriptor sd = new StorageDescriptor();
    sd.setLocation(storage.getLocation());
    sd.setColumns(columns.stream().map(GlueInputConverter::convertColumn).collect(toList()));
    sd.setSerdeInfo(serdeInfo);
    sd.setInputFormat(storage.getStorageFormat().getInputFormatNullable());
    sd.setOutputFormat(storage.getStorageFormat().getOutputFormatNullable());
    sd.setParameters(ImmutableMap.of());
    Optional<HiveBucketProperty> bucketProperty = storage.getBucketProperty();
    if (bucketProperty.isPresent()) {
        sd.setNumberOfBuckets(bucketProperty.get().getBucketCount());
        sd.setBucketColumns(bucketProperty.get().getBucketedBy());
        if (!bucketProperty.get().getSortedBy().isEmpty()) {
            sd.setSortColumns(bucketProperty.get().getSortedBy().stream().map(column -> new Order().withColumn(column.getColumnName()).withSortOrder(column.getOrder().getHiveOrder())).collect(toImmutableList()));
        }
    }
    return sd;
}
Also used : Order(com.amazonaws.services.glue.model.Order) HiveBucketProperty(com.facebook.presto.hive.HiveBucketProperty) SerDeInfo(com.amazonaws.services.glue.model.SerDeInfo) StorageDescriptor(com.amazonaws.services.glue.model.StorageDescriptor)

Example 2 with StorageDescriptor

use of com.amazonaws.services.glue.model.StorageDescriptor in project presto by prestodb.

the class GlueToPrestoConverter method convertTable.

public static Table convertTable(com.amazonaws.services.glue.model.Table glueTable, String dbName) {
    requireNonNull(glueTable.getStorageDescriptor(), "Table StorageDescriptor is null");
    StorageDescriptor sd = glueTable.getStorageDescriptor();
    Table.Builder tableBuilder = Table.builder().setDatabaseName(dbName).setTableName(glueTable.getName()).setOwner(nullToEmpty(glueTable.getOwner())).setTableType(PrestoTableType.optionalValueOf(glueTable.getTableType()).orElse(EXTERNAL_TABLE)).setDataColumns(convertColumns(sd.getColumns())).setParameters(convertParameters(glueTable.getParameters())).setViewOriginalText(Optional.ofNullable(glueTable.getViewOriginalText())).setViewExpandedText(Optional.ofNullable(glueTable.getViewExpandedText()));
    if (glueTable.getPartitionKeys() != null) {
        tableBuilder.setPartitionColumns(convertColumns(glueTable.getPartitionKeys()));
    } else {
        tableBuilder.setPartitionColumns(ImmutableList.of());
    }
    new StorageConverter().setConvertedStorage(sd, tableBuilder.getStorageBuilder());
    return tableBuilder.build();
}
Also used : Table(com.facebook.presto.hive.metastore.Table) StorageDescriptor(com.amazonaws.services.glue.model.StorageDescriptor)

Aggregations

StorageDescriptor (com.amazonaws.services.glue.model.StorageDescriptor)2 Order (com.amazonaws.services.glue.model.Order)1 SerDeInfo (com.amazonaws.services.glue.model.SerDeInfo)1 HiveBucketProperty (com.facebook.presto.hive.HiveBucketProperty)1 Table (com.facebook.presto.hive.metastore.Table)1