voonhous opened a new issue, #20782:
URL: https://github.com/apache/hudi/issues/20782

   ### Problem
   The Spark record-level index lookup turns a filter literal into a record key 
with `lit.value.toString`, the literal's Catalyst internal value 
(`getSimpleLiteralGenerator` and `getComplexKeyLiteralGenerator` in 
`hudi-spark-common/.../RecordLevelIndexSupport.scala:182-188`). The writer 
builds the record key through 
`HoodieAvroUtils.convertValueForAvroLogicalTypes`, so the two disagree for some 
key field types. With 
`hoodie.datasource.write.keygenerator.consistent.logical.timestamp.enabled=false`
 (the default):
   
   | Record key field | Writer key | Spark lookup key |
   |---|---|---|
   | timestamp-micros | epoch micros | epoch micros (match) |
   | timestamp-millis | epoch millis | epoch micros |
   | date | `2024-01-01` | epoch day, e.g. `19723` |
   
   With the setting on, the writer key for timestamps is 
`java.sql.Timestamp.toString()`, which matches neither.
   
   `getAttributeLiteralTuple` (line 321) does not check the attribute's type, 
so any `key = literal` filter is used. When no looked-up key is found, 
`computeCandidateFileNames` (lines 58-70) returns an empty candidate set rather 
than `None`, which prunes every file slice.
   
   ### Expected impact
   From reading the code; not yet reproduced. On a table with the record-level 
index enabled and keyed by a date or timestamp-millis field, `SELECT ... WHERE 
<key> = <literal>` with data skipping on returns no rows even when matching 
rows exist.
   
   ### To confirm
   A Spark SQL test on a table keyed by a `DATE` column, and one keyed by a 
timestamp-millis field (written through an Avro schema, since Spark writes 
timestamps as micros), with the record-level index built: compare the query 
result with `hoodie.enable.data.skipping` on and off.
   
   ### Direction
   Build the lookup key with the writer's conversion, from the key field's 
schema type and the consistent-logical-timestamp setting, or skip record-level 
index pruning for key fields whose literal cannot be converted. The Trino 
connector builds keys the writer's way in #20757.
   


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