in xtable-core/src/main/java/org/apache/xtable/delta/DeltaPartitionExtractor.java [119:180]
private List<InternalPartitionField> getInternalPartitionFields(
StructType partitionSchema, InternalSchema internalSchema) {
PeekingIterator<StructField> itr =
Iterators.peekingIterator(Arrays.stream(partitionSchema.fields()).iterator());
List<InternalPartitionField> partitionFields = new ArrayList<>(partitionSchema.fields().length);
while (itr.hasNext()) {
StructField currPartitionField = itr.peek();
if (!currPartitionField.metadata().contains(DELTA_GENERATION_EXPRESSION)) {
partitionFields.add(
InternalPartitionField.builder()
.sourceField(
SchemaFieldFinder.getInstance()
.findFieldByPath(internalSchema, currPartitionField.name()))
.transformType(PartitionTransformType.VALUE)
.build());
itr.next(); // consume the field.
} else {
// Partition contains generated expression.
// if it starts with year we should consume until we hit field with no generated expression
// or we hit a field with generated expression that is of cast or date format.
String expr = currPartitionField.metadata().getString(DELTA_GENERATION_EXPRESSION);
ParsedGeneratedExpr parsedGeneratedExpr =
ParsedGeneratedExpr.buildFromString(currPartitionField.name(), expr);
if (ParsedGeneratedExpr.GeneratedExprType.CAST == parsedGeneratedExpr.generatedExprType) {
partitionFields.add(
getPartitionWithDateTransform(
currPartitionField.name(), parsedGeneratedExpr, internalSchema));
itr.next(); // consume the field.
} else if (ParsedGeneratedExpr.GeneratedExprType.DATE_FORMAT
== parsedGeneratedExpr.generatedExprType) {
partitionFields.add(
getPartitionWithDateFormatTransform(
currPartitionField.name(), parsedGeneratedExpr, internalSchema));
itr.next(); // consume the field.
} else {
// consume until we hit field with no generated expression or generated expression
// that is not of type cast or date format.
List<ParsedGeneratedExpr> parsedGeneratedExprs = new ArrayList<>();
while (itr.hasNext()
&& currPartitionField.metadata().contains(DELTA_GENERATION_EXPRESSION)) {
expr = currPartitionField.metadata().getString(DELTA_GENERATION_EXPRESSION);
parsedGeneratedExpr =
ParsedGeneratedExpr.buildFromString(currPartitionField.name(), expr);
if (ParsedGeneratedExpr.GeneratedExprType.CAST == parsedGeneratedExpr.generatedExprType
|| ParsedGeneratedExpr.GeneratedExprType.DATE_FORMAT
== parsedGeneratedExpr.generatedExprType) {
break;
}
parsedGeneratedExprs.add(parsedGeneratedExpr);
itr.next(); // consume the field
if (itr.hasNext()) {
currPartitionField = itr.peek();
}
}
partitionFields.add(
getPartitionColumnsForHourOrDayOrMonthOrYear(parsedGeneratedExprs, internalSchema));
}
}
}
return partitionFields;
}