leaves12138 commented on code in PR #7952:
URL: https://github.com/apache/paimon/pull/7952#discussion_r3308125695


##########
paimon-python/pypaimon/read/split_read.py:
##########
@@ -650,6 +652,17 @@ def _build_merge_function(self):
                 value_arity=self.value_arity,
                 nullables=[f.type.nullable for f in self.value_fields],
             )
+        if engine == MergeEngine.AGGREGATE:
+            field_aggregators = build_field_aggregators(
+                self.value_fields,
+                self.trimmed_primary_key,
+                self.table.options,
+            )
+            return AggregateMergeFunction(
+                key_arity=len(self.trimmed_primary_key),
+                value_arity=self.value_arity,
+                field_aggregators=field_aggregators,
+            )

Review Comment:
   This should use the full table primary key list, not `trimmed_primary_key`. 
`read_type`/`value_fields` still contains partition columns, while 
`trimmed_primary_key` removes partition columns from the heap key. If a primary 
key column is also a partition column and a table-wide default aggregator is 
configured, that PK value is treated as a normal value field and gets 
aggregated.
   
   Minimal repro on this PR:
   
   ```python
   schema = pa.schema([
       pa.field('p', pa.int64(), nullable=False),
       pa.field('id', pa.int64(), nullable=False),
       pa.field('v', pa.int64()),
   ])
   Schema.from_pyarrow_schema(
       schema,
       primary_keys=['p', 'id'],
       partition_keys=['p'],
       options={
           'bucket': '1',
           'merge-engine': 'aggregation',
           'fields.default-aggregate-function': 'sum',
       },
   )
   # write {'p': 1, 'id': 1, 'v': 10}, then {'p': 1, 'id': 1, 'v': 20}
   ```
   
   Expected read result is `{'p': 1, 'id': 1, 'v': 30}`, but pypaimon currently 
returns `{'p': 2, 'id': 1, 'v': 30}` because field `p` falls through to the 
default `sum` aggregator. Java builds `AggregateMergeFunction` with 
`tableSchema.primaryKeys()` for the same reason. Please pass 
`self.table.primary_keys` here and add an e2e test covering a partition key 
that is also part of the primary key with 
`fields.default-aggregate-function=sum`.
   



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