use of org.apache.iceberg.types.Types.StructType in project hive by apache.
the class IcebergInternalRecordWrapper method converter.
private static Function<Object, Object> converter(Type type) {
switch(type.typeId()) {
case TIMESTAMP:
return timestamp -> DateTimeUtil.timestamptzFromMicros((Long) timestamp);
case STRUCT:
IcebergInternalRecordWrapper wrapper = new IcebergInternalRecordWrapper(type.asStructType(), type.asStructType());
return struct -> wrapper.wrap((StructLike) struct);
case LIST:
if (Type.TypeID.STRUCT.equals(type.asListType().elementType().typeId())) {
StructType listElementSchema = type.asListType().elementType().asStructType();
Function<Type, IcebergInternalRecordWrapper> createWrapper = t -> new IcebergInternalRecordWrapper(listElementSchema, listElementSchema);
return list -> {
return ((List<?>) list).stream().map(item -> createWrapper.apply(type).wrap((StructLike) item)).collect(Collectors.toList());
};
}
break;
default:
}
return null;
}
use of org.apache.iceberg.types.Types.StructType in project hive by apache.
the class ClusteredWriter method write.
@Override
public void write(T row, PartitionSpec spec, StructLike partition) {
if (!spec.equals(currentSpec)) {
if (currentSpec != null) {
closeCurrentWriter();
completedSpecIds.add(currentSpec.specId());
completedPartitions.clear();
}
if (completedSpecIds.contains(spec.specId())) {
String errorCtx = String.format("spec %s", spec);
throw new IllegalStateException(NOT_CLUSTERED_ROWS_ERROR_MSG_TEMPLATE + errorCtx);
}
StructType partitionType = spec.partitionType();
this.currentSpec = spec;
this.partitionComparator = Comparators.forType(partitionType);
this.completedPartitions = StructLikeSet.create(partitionType);
// copy the partition key as the key object may be reused
this.currentPartition = StructCopy.copy(partition);
this.currentWriter = newWriter(currentSpec, currentPartition);
} else if (partition != currentPartition && partitionComparator.compare(partition, currentPartition) != 0) {
closeCurrentWriter();
completedPartitions.add(currentPartition);
if (completedPartitions.contains(partition) && !hasBucketTransform(currentSpec)) {
String errorCtx = String.format("partition '%s' in spec %s", spec.partitionToPath(partition), spec);
throw new IllegalStateException(NOT_CLUSTERED_ROWS_ERROR_MSG_TEMPLATE + errorCtx);
}
// copy the partition key as the key object may be reused
this.currentPartition = StructCopy.copy(partition);
this.currentWriter = newWriter(currentSpec, currentPartition);
}
currentWriter.write(row);
}
Aggregations