This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 12d2e1d3 feat(datafusion): support partitions in create_global_index 
(#1428)
12d2e1d3 is described below

commit 12d2e1d31da2fadf58b951703487a5cfc2b813ff
Author: Jingsong Lee <[email protected]>
AuthorDate: Tue Nov 17 13:31:10 2026 +0800

    feat(datafusion): support partitions in create_global_index (#1428)
---
 crates/integrations/datafusion/src/procedures.rs   |  13 ++-
 crates/integrations/datafusion/tests/procedures.rs | 110 +++++++++++++++++++++
 docs/src/sql.md                                    |  28 +++++-
 3 files changed, 149 insertions(+), 2 deletions(-)

diff --git a/crates/integrations/datafusion/src/procedures.rs 
b/crates/integrations/datafusion/src/procedures.rs
index 7ee17421..ac64ad3a 100644
--- a/crates/integrations/datafusion/src/procedures.rs
+++ b/crates/integrations/datafusion/src/procedures.rs
@@ -226,7 +226,13 @@ fn declared_parameters(proc_name: &str) -> Option<&'static 
[&'static str]> {
         "rename_branch" => &["table", "from_branch", "to_branch"],
         "delete_branch" => &["table", "branch"],
         "fast_forward" => &["table", "branch"],
-        "create_global_index" => &["table", "index_column", "index_type", 
"options"],
+        "create_global_index" => &[
+            "table",
+            "index_column",
+            "index_type",
+            "partitions",
+            "options",
+        ],
         "drop_global_index" => &[
             "table",
             "index_column",
@@ -1271,6 +1277,11 @@ async fn proc_create_global_index(
     if let Some(options) = args.get("options") {
         builder.with_options(parse_key_value_options(options)?);
     }
+    if let Some(partitions) = args.get("partitions") {
+        builder
+            .with_partition_filter(parse_partitions(&table, partitions)?)
+            .map_err(to_datafusion_error)?;
+    }
     builder.execute().await.map_err(to_datafusion_error)?;
     ok_result(ctx)
 }
diff --git a/crates/integrations/datafusion/tests/procedures.rs 
b/crates/integrations/datafusion/tests/procedures.rs
index 70243a7c..8892dfa2 100644
--- a/crates/integrations/datafusion/tests/procedures.rs
+++ b/crates/integrations/datafusion/tests/procedures.rs
@@ -1575,6 +1575,116 @@ async fn global_index_entries(
         .collect()
 }
 
+#[tokio::test]
+async fn test_create_global_index_partitions_select_and_extend_coverage() {
+    for (column, index_type) in [("id", "btree"), ("name", "full-text")] {
+        let (tmp, sql_context, table) =
+            setup_partitioned_global_index_table("create_partitions", 
false).await;
+        exec(
+            &sql_context,
+            "INSERT INTO paimon.test_db.create_partitions (id, dt, name, hr) 
VALUES \
+             (1, DATE '2026-10-10', 'alpha', 1), (2, DATE '2026-10-10', 
'beta', 2), \
+             (3, DATE '2026-10-11', 'gamma', 1), (4, DATE '2026-10-11', 
'delta', 2), \
+             (5, DATE '2026-10-12', 'epsilon', 1), (6, NULL, 'zeta', 1)",
+        )
+        .await;
+        let call = format!(
+            "CALL paimon.sys.create_global_index(\
+             `table` => 'test_db.create_partitions', `index_column` => 
'{column}', \
+             `index_type` => '{index_type}'"
+        );
+        let selected_call =
+            format!("{call}, partitions => ' dt = 2026-10-10, hr = 01 ; 
hr=2,dt=2026-10-11 ')");
+        exec(&sql_context, &selected_call).await;
+        let selected = global_index_entries(&table).await;
+        let mut partitions = selected
+            .values()
+            .map(|entry| {
+                assert_eq!(entry.index_file.index_type, index_type);
+                assert_eq!(entry.index_file.row_count, 1);
+                let row = 
paimon::spec::BinaryRow::from_serialized_bytes(&entry.partition).unwrap();
+                (row.get_int(0).unwrap(), row.get_int(1).unwrap())
+            })
+            .collect::<Vec<_>>();
+        partitions.sort_unstable();
+        let day = |text: &str| {
+            (chrono::NaiveDate::parse_from_str(text, "%Y-%m-%d").unwrap()
+                - chrono::DateTime::UNIX_EPOCH.date_naive())
+            .num_days() as i32
+        };
+        assert_eq!(
+            partitions,
+            vec![(1, day("2026-10-10")), (2, day("2026-10-11"))]
+        );
+
+        // Rebuilding covered partitions or selecting no data must not commit.
+        let before = table_files(tmp.path());
+        exec(&sql_context, &selected_call).await;
+        exec(
+            &sql_context,
+            &format!("{call}, partitions => 'dt=2026-10-09')"),
+        )
+        .await;
+        assert_eq!(table_files(tmp.path()), before, "{index_type}");
+
+        exec(
+            &sql_context,
+            &format!("{call}, partitions => 'dt=__DEFAULT_PARTITION__')"),
+        )
+        .await;
+        let with_null = global_index_entries(&table).await;
+        assert_eq!(with_null.len(), 3);
+        assert!(with_null.values().any(|entry| {
+            let row = 
paimon::spec::BinaryRow::from_serialized_bytes(&entry.partition).unwrap();
+            row.get_int(0).unwrap() == 1 && row.is_null_at(1)
+        }));
+
+        // Omitting the filter fills remaining partitions and preserves 
existing files.
+        exec(&sql_context, &format!("{call})")).await;
+        let all = global_index_entries(&table).await;
+        assert_eq!(all.len(), 6);
+        for (file, entry) in with_null {
+            assert_eq!(all.get(&file), Some(&entry));
+        }
+    }
+}
+
+#[tokio::test]
+async fn 
test_create_global_index_partitions_reject_invalid_filters_without_writes() {
+    let (tmp, sql_context, _) =
+        setup_partitioned_global_index_table("create_invalid_partitions", 
false).await;
+    let before = table_files(tmp.path());
+    for (argument, message) in [
+        ("'dt'", "Expected key=value"),
+        ("'id=1'", "not a partition column"),
+        ("'dt=2026-02-30'", "Invalid partitions value"),
+        ("'hr=1,hr=2'", "Duplicate partition column"),
+        ("'dt='", "Empty partitions value"),
+        ("NULL", "NULL"),
+    ] {
+        assert_sql_error(
+            &sql_context,
+            &format!(
+                "CALL sys.create_global_index(table => 
'test_db.create_invalid_partitions', \
+                 index_column => 'id', partitions => {argument})"
+            ),
+            message,
+        )
+        .await;
+        assert_eq!(table_files(tmp.path()), before, "{argument}");
+    }
+    let (tmp, sql_context) = 
setup_btree_global_index_table("create_unpartitioned").await;
+    let before = table_files(tmp.path());
+    assert_sql_error(
+        &sql_context,
+        "CALL sys.create_global_index(table => 'test_db.create_unpartitioned', 
\
+         index_column => 'id', partitions => 'dt=2026-10-10')",
+        "unpartitioned table",
+    )
+    .await;
+    assert_eq!(table_files(tmp.path()), before);
+}
+
 #[tokio::test]
 async fn 
test_drop_global_index_partitions_preserve_other_partitions_and_definitions() {
     let day = |text: &str| {
diff --git a/docs/src/sql.md b/docs/src/sql.md
index 175f036f..0122c958 100644
--- a/docs/src/sql.md
+++ b/docs/src/sql.md
@@ -1682,6 +1682,10 @@ offset and must not be passed directly as an epoch 
timestamp.
 
 Build and commit a global index for a table column.
 
+As in Paimon's Flink SQL and Spark SQL integrations, global indexes are created
+through `CALL sys.create_global_index`. `CREATE INDEX ... ON ...` DDL is not
+supported.
+
 To maintain indexes synchronously after writes, declare columns through options
 such as `global-index.btree.index-columns='id'`. Maintenance runs by default
 when `write-only=false`; see
@@ -1725,6 +1729,26 @@ CALL sys.create_global_index(
 );
 ```
 
+Set `partitions` to build indexes only for matching partitions. As in Flink SQL
+and Spark SQL, `,` combines constraints with AND and `;` combines alternatives
+with OR. Omitted partition keys are unrestricted; omitting `partitions` builds
+all partitions. Values are parsed using each partition column's type, and the
+table's `partition.default-name` selects NULL values. Invalid filters and
+partition filters on unpartitioned tables are rejected before files are 
written.
+
+```sql
+CALL sys.create_global_index(
+  table => 'paimon.my_db.my_table',
+  index_column => 'id',
+  index_type => 'btree',
+  partitions => 'dt=2026-10-10,hr=1;dt=2026-10-11,hr=2'
+);
+```
+
+Index coverage outside the selected partitions is preserved. If the selected
+data is already indexed and unchanged, or no data matches, no snapshot is
+committed.
+
 `index_type` defaults to `btree`. It is case-insensitive and surrounding
 whitespace is ignored. BTree and bitmap global indexes support scalar columns.
 Multivalue global indexes support `ARRAY` columns whose element type is 
supported
@@ -2014,7 +2038,9 @@ when `N` is zero. `dry_run` defaults to `false`; an 
explicit `false` or an
 omitted argument performs the drop and returns `OK`. Other values are rejected.
 The preview uses the latest snapshot at the time of the call; concurrent 
changes
 can affect the number of files matched by a later drop. Reads retain the usual
-local-cache behavior. Partition filtering is not supported by this procedure.
+local-cache behavior. The optional `partitions` argument uses the same filter
+syntax as [create_global_index](#create_global_index) and restricts the drop to
+matching partitions.
 
 ### compact
 

Reply via email to