use of com.amazonaws.services.glue.model.Order 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;
}
use of com.amazonaws.services.glue.model.Order in project alluxio by Alluxio.
the class GlueUtils method toProto.
/**
* Convert the Glue Storage Descriptor and Translator information to Storage.
*
* @param sd the glue storage descriptor
* @param translator the glue translator
* @return storage proto
* @throws IOException
*/
public static Storage toProto(StorageDescriptor sd, PathTranslator translator) throws IOException {
if (sd == null) {
return Storage.getDefaultInstance();
}
String serDe = sd.getSerdeInfo() == null ? null : sd.getSerdeInfo().getSerializationLibrary();
Map<String, String> serdeLibMap = sd.getSerdeInfo() == null ? null : sd.getSerdeInfo().getParameters();
StorageFormat.Builder formatBuilder = StorageFormat.newBuilder().setInputFormat(sd.getInputFormat()).setOutputFormat(sd.getOutputFormat());
if (serdeLibMap != null) {
formatBuilder.putAllSerdelibParameters(serdeLibMap);
}
if (serDe != null) {
// Check SerDe info
formatBuilder.setSerde(serDe);
}
alluxio.grpc.table.layout.hive.Storage.Builder storageBuilder = alluxio.grpc.table.layout.hive.Storage.newBuilder();
List<String> bucketColumn = sd.getBucketColumns() == null ? Collections.emptyList() : sd.getBucketColumns();
List<Order> orderList = sd.getSortColumns();
List<SortingColumn> sortingColumns;
if (orderList == null) {
sortingColumns = Collections.emptyList();
} else {
sortingColumns = orderList.stream().map(order -> SortingColumn.newBuilder().setColumnName(order.getColumn()).setOrder(order.getSortOrder() == 1 ? SortingColumn.SortingOrder.ASCENDING : SortingColumn.SortingOrder.DESCENDING).build()).collect(Collectors.toList());
}
return storageBuilder.setStorageFormat(formatBuilder.build()).setLocation(translator.toAlluxioPath(sd.getLocation())).setBucketProperty(HiveBucketProperty.newBuilder().setBucketCount(sd.getNumberOfBuckets()).addAllBucketedBy(bucketColumn).addAllSortedBy(sortingColumns).build()).setSkewed(sd.getSkewedInfo() != null && (sd.getSkewedInfo().getSkewedColumnNames()) != null && !sd.getSkewedInfo().getSkewedColumnNames().isEmpty()).putAllSerdeParameters(sd.getParameters()).build();
}
Aggregations