JingsongLi commented on code in PR #10983:
URL: https://github.com/apache/paimon/pull/10983#discussion_r4478910489


##########
paimon-core/src/main/java/org/apache/paimon/schema/SchemaValidation.java:
##########
@@ -1378,19 +1380,61 @@ private static void 
validateMergeFunctionFactory(TableSchema schema) {
             default:
         }
 
-        for (int i = 0; i < schema.logicalRowType().getFieldNames().size(); 
i++) {
-            String fieldName = schema.logicalRowType().getFieldNames().get(i);
-            String aggFuncName = options.fieldAggFunc(fieldName);
-            aggFuncName = aggFuncName == null ? options.fieldsDefaultFunc() : 
aggFuncName;
-            if (aggFuncName != null) {
-                FactoryUtil.discoverFactory(
-                        FieldAggregator.class.getClassLoader(),
-                        FieldAggregatorFactory.class,
-                        aggFuncName);
+        RowType rowType = schema.logicalRowType();
+        List<String> primaryKeys = schema.primaryKeys();
+        List<String> sequenceFields = options.sequenceField();
+        List<String> orderingFields = new ArrayList<>();
+        List<String> protectedFields = new ArrayList<>();
+        for (Map.Entry<String, String> entry : options.toMap().entrySet()) {
+            if (isSequenceGroupOption(entry.getKey())) {
+                
orderingFields.addAll(sequenceGroupOrderingFields(entry.getKey()));
+                
protectedFields.addAll(sequenceGroupProtectedFields(entry.getValue()));
+            }
+        }
+
+        for (int i = 0; i < rowType.getFieldNames().size(); i++) {
+            String fieldName = rowType.getFieldNames().get(i);
+            String aggFuncName =
+                    resolveAggFuncName(
+                            options,
+                            fieldName,
+                            primaryKeys,
+                            sequenceFields,
+                            orderingFields,
+                            protectedFields);
+            if (aggFuncName == null) {
+                continue;
             }
+            // Instantiate once so that type-incompatible configurations (e.g. 
'collect' on a
+            // non-array column) are rejected at DDL time instead of at 
read/write time.
+            FieldAggregatorFactory.create(

Review Comment:
   [P1] Keep valid historical projections readable after aggregate schema 
evolution
   
   `AbstractFileStoreTable.runtimeStore()` also runs this check, before the 
read projection is applied. I created a primary-key partial-update table with 
`label VARCHAR(16)` protected by `fields.seq.sequence-group=label`, wrote 
snapshot 1, and widened `label` to `STRING` while enabling `listagg` through 
ALTER. Both DDL operations succeed. A read of only `id` at snapshot 1 passes on 
the base and now fails before planning with `list agg column must be STRING ... 
VARCHAR(16)`, because time travel combines the old type with current options. 
The same eager check also blocks previously working projections on pre-upgrade 
tables with incompatible aggregators on unused columns. Please run the eager 
type check on CREATE/ALTER and preserve the runtime projection behavior for 
stored schemas. Add the historical projection as a regression test.



-- 
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]

Reply via email to