jerry-024 commented on code in PR #309:
URL: https://github.com/apache/paimon-rust/pull/309#discussion_r3206098444
##########
crates/integrations/datafusion/src/sql_context.rs:
##########
@@ -275,6 +405,130 @@ impl SQLContext {
}
}
+ /// Handle SQL queries containing time-travel syntax (`VERSION AS OF` /
`TIMESTAMP AS OF`).
+ ///
+ /// DataFusion's default SQL parser does not support these clauses, so we:
+ /// 1. Extract the table name and version/timestamp value via regex
+ /// 2. Strip the time-travel clause from the SQL
+ /// 3. Create a `PaimonTableProvider` with the appropriate scan options
+ /// 4. Register it, execute the stripped SQL, then deregister
+ async fn handle_time_travel_query(&self, sql: &str) -> DFResult<DataFrame>
{
+ use crate::table::PaimonTableProvider;
+ use paimon::spec::{SCAN_TIMESTAMP_MILLIS_OPTION, SCAN_VERSION_OPTION};
+
+ let (table_name, options, clause_range) = if let Some(info) =
extract_version_as_of(sql) {
+ let options = HashMap::from([(SCAN_VERSION_OPTION.to_string(),
info.version)]);
+ (info.table_name, options, info.clause_range)
+ } else if let Some(info) = extract_timestamp_as_of(sql) {
+ let millis = Self::parse_timestamp_to_millis(&info.timestamp)?;
+ let options =
+ HashMap::from([(SCAN_TIMESTAMP_MILLIS_OPTION.to_string(),
millis.to_string())]);
+ (info.table_name, options, info.clause_range)
+ } else {
+ return Err(DataFusionError::Plan(
+ "Failed to parse time-travel clause in SQL".to_string(),
+ ));
+ };
+
+ // Resolve the table from our catalog and create a provider with scan
options
+ let table_ref: datafusion::common::TableReference =
table_name.as_str().into();
+ let (catalog, _catalog_name, identifier) =
self.resolve_table_name_from_ref(&table_ref)?;
+
+ let paimon_table = catalog
+ .get_table(&identifier)
Review Comment:
**P0 — Must fix (dynamic options bypass)**
`catalog.get_table(&identifier)` here loads the table directly from the
Paimon catalog, bypassing the normal `PaimonSchemaProvider` path. This means
session-scoped dynamic options set via `SET 'paimon.xxx' = ...` are **not
applied** to time-travel queries.
For example:
```sql
SET 'paimon.blob-as-descriptor' = 'true';
SELECT * FROM paimon.default.my_table VERSION AS OF 1; --
blob-as-descriptor NOT applied
```
The normal table loading path in `PaimonSchemaProvider::table()` applies
`dynamic_options` before creating the provider. Time-travel should do the same
— either pass `self.dynamic_options` to `copy_with_options` alongside the
time-travel options, or go through the schema provider.
--
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]