singhpk234 commented on code in PR #15268:
URL: https://github.com/apache/iceberg/pull/15268#discussion_r2784169839
##########
api/src/main/java/org/apache/iceberg/Schema.java:
##########
@@ -629,4 +631,30 @@ public static void checkCompatibility(Schema schema, int
formatVersion) {
formatVersion, Joiner.on("\n- ").join(problems.values())));
}
}
+
+ // indexes all fields from schemas, preferring field definitions from higher
schema IDs
Review Comment:
minor : may be ok to mention this is for cases like type promotion ?
##########
api/src/main/java/org/apache/iceberg/Schema.java:
##########
@@ -629,4 +631,30 @@ public static void checkCompatibility(Schema schema, int
formatVersion) {
formatVersion, Joiner.on("\n- ").join(problems.values())));
}
}
+
+ // indexes all fields from schemas, preferring field definitions from higher
schema IDs
+ public static Map<Integer, NestedField> indexFields(Collection<Schema>
schemas) {
+ if (schemas.size() == 1) {
+ Schema schema = Iterables.getOnlyElement(schemas);
+ return schema.lazyIdToField();
+ }
+
+ Map<Integer, NestedField> fields = Maps.newHashMap();
+ Set<Integer> seenSchemaIds = Sets.newHashSet();
+
+ for (Schema schema : sortByIdAsc(schemas)) {
+ if (!seenSchemaIds.contains(schema.schemaId())) {
Review Comment:
can we make it sorted set instead ?
##########
core/src/main/java/org/apache/iceberg/DeleteFileIndex.java:
##########
@@ -828,7 +855,8 @@ public List<Types.NestedField> equalityFields() {
if (equalityFields == null) {
List<Types.NestedField> fields = Lists.newArrayList();
for (int id : wrapped.equalityFieldIds()) {
- Types.NestedField field = spec.schema().findField(id);
+ Types.NestedField field = fieldLookup.apply(id);
+ Preconditions.checkArgument(field != null, "Cannot find field
for ID %s", id);
Review Comment:
[doubt] what would have been prev behaviour when the field was null in
`spec.schema()` was null ? did we failed later ?
##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/BaseReader.java:
##########
@@ -252,5 +251,40 @@ protected <V> V getOrLoad(String key, Supplier<V>
valueSupplier, long valueSize)
return cache.getOrLoad(table().name(), key, valueSupplier, valueSize);
}
}
+
+ // field lookup for serializable tables that assumes fetching historic
schemas is expensive
+ private static class FieldLookup implements Function<Integer,
Types.NestedField> {
+ private final Table table;
+
+ private volatile Map<Integer, Types.NestedField> historicSchemaFields;
+
+ private FieldLookup(Table table) {
+ this.table = table;
+ }
+
+ @Override
+ public Types.NestedField apply(Integer id) {
+ Types.NestedField field = table.schema().findField(id);
+ return field != null ? field : historicSchemaFields().get(id);
+ }
+
+ private Map<Integer, Types.NestedField> historicSchemaFields() {
+ if (historicSchemaFields == null) {
+ synchronized (this) {
+ if (historicSchemaFields == null) {
+ this.historicSchemaFields =
Schema.indexFields(historicSchemas(table));
+ }
+ }
+ }
+
+ return historicSchemaFields;
+ }
+
+ private static Collection<Schema> historicSchemas(Table table) {
+ return table.schemas().values().stream()
+ .filter(schema -> schema.schemaId() != table.schema().schemaId())
+ .collect(Collectors.toList());
+ }
+ }
Review Comment:
This would now require loading the TableMetadata on executor, which is
absolutely fine.
please ref check: https://github.com/apache/iceberg/pull/14944
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]