SteNicholas commented on code in PR #1315:
URL: https://github.com/apache/paimon-rust/pull/1315#discussion_r4454175871


##########
crates/integrations/datafusion/src/merge_into/tests.rs:
##########
@@ -0,0 +1,920 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! MERGE INTO unit and behavioral tests.
+
+use super::*;
+use datafusion::sql::sqlparser::ast::Merge;
+use datafusion::sql::sqlparser::dialect::GenericDialect;
+use datafusion::sql::sqlparser::parser::Parser;
+use paimon::catalog::{Catalog, Identifier};
+use paimon::{CatalogOptions, FileSystemCatalog, Options};
+use tempfile::TempDir;
+
+use crate::SQLContext;
+
+#[tokio::test]
+async fn test_retry_limits_and_non_conflict_errors() {
+    use std::sync::atomic::{AtomicUsize, Ordering};
+
+    for (message, classify) in [
+        (
+            "Row ID conflict",
+            is_row_id_conflict as fn(&DataFusionError) -> bool,
+        ),
+        (
+            "Delete conflict",
+            is_delete_conflict as fn(&DataFusionError) -> bool,
+        ),
+    ] {
+        let attempts = AtomicUsize::new(0);
+        let result: DFResult<u64> = retry_on_conflict("MERGE INTO", classify, 
|| async {
+            attempts.fetch_add(1, Ordering::SeqCst);
+            Err(DataFusionError::External(Box::new(std::io::Error::other(
+                message,
+            ))))
+        })
+        .await;
+        assert_eq!(attempts.load(Ordering::SeqCst), 5);
+        let err = result.unwrap_err().to_string();
+        assert!(err.contains("after 5 retries"), "{err}");
+        assert!(err.contains(message), "{err}");
+
+        let attempts = AtomicUsize::new(0);
+        let result: DFResult<u64> = retry_on_conflict("MERGE INTO", classify, 
|| async {
+            attempts.fetch_add(1, Ordering::SeqCst);
+            Err(DataFusionError::Execution("unrelated failure".into()))
+        })
+        .await;
+        assert_eq!(attempts.load(Ordering::SeqCst), 1);
+        assert!(
+            matches!(result, Err(DataFusionError::Execution(message)) if 
message == "unrelated failure")
+        );
+        let overlapping_update = 
to_datafusion_error(paimon::Error::DataInvalid {
+            message: "For Data Evolution table, multiple MERGE INTO operations 
have encountered conflicts, updating the same file".into(),
+            source: None,
+        });
+        assert!(!classify(&overlapping_update));
+    }
+}
+
+async fn setup_sql_context() -> (TempDir, SQLContext, Arc<FileSystemCatalog>) {
+    let temp_dir = TempDir::new().unwrap();
+    let warehouse = format!("file://{}", temp_dir.path().display());
+    let mut options = Options::new();
+    options.set(CatalogOptions::WAREHOUSE, warehouse);
+    let catalog = Arc::new(FileSystemCatalog::new(options).unwrap());
+
+    let mut sql_context = SQLContext::new();
+    sql_context
+        .register_catalog("paimon", catalog.clone())
+        .await
+        .unwrap();
+    sql_context
+        .sql("CREATE SCHEMA paimon.test_db")
+        .await
+        .unwrap();
+
+    (temp_dir, sql_context, catalog)
+}
+
+async fn setup_data_evolution_table(name: &str) -> (TempDir, SQLContext, 
Table) {
+    let (tmp, sql_context, catalog) = setup_sql_context().await;
+
+    sql_context
+        .sql(&format!(
+            "CREATE TABLE paimon.test_db.{name} (id INT, name VARCHAR, value 
INT) WITH ('data-evolution.enabled' = 'true', 'row-tracking.enabled' = 'true')"
+        ))
+        .await
+        .unwrap();
+
+    sql_context
+        .sql(&format!(
+            "INSERT INTO paimon.test_db.{name} (id, name, value) VALUES (1, 
'alice', 10), (2, 'bob', 20), (3, 'charlie', 30)"
+        ))
+        .await
+        .unwrap()
+        .collect()
+        .await
+        .unwrap();
+
+    let table = catalog
+        .get_table(&Identifier::new("test_db", name))
+        .await
+        .unwrap();
+    let mut extra = std::collections::HashMap::new();
+    extra.insert("data-evolution.enabled".to_string(), "true".to_string());
+    extra.insert("row-tracking.enabled".to_string(), "true".to_string());
+    let de_table = table.copy_with_options(extra);
+
+    (tmp, sql_context, de_table)
+}
+
+// Exercise the native planner and provider while retaining these behavioral 
fixtures.
+async fn execute_merge_into(
+    ctx: &SQLContext,
+    merge: &Merge,
+    _table: Table,
+    _enable_ident_normalization: bool,

Review Comment:
   Nit: Could we remove the unused `_table` and `_enable_ident_normalization` 
parameters and update the callers? This helper now executes entirely through 
`ctx`, so passing a table with different options or `false` for normalization 
has no effect. Keeping these parameters could make future tests appear to cover 
settings they never actually exercise; normalization-specific tests should 
configure the context explicitly.



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