Scan-plan reads prefetch Delta credentials and fail for masked native Iceberg tables

Aperta
#133 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
databases

Direzione di ricerca

Start in src/storage/uc_table_entry.cpp at the USE_IRC_SCAN_PLAN branch and inspect the existing offline scan-plan mock and live scan-plan fixture. Add regression coverage using a non-file storage location, then verify that the query succeeds through the /plan endpoint without a /delta/v1/ request and returns the masked result.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

When USE_IRC_SCAN_PLAN true is enabled, querying a native Iceberg table with a Unity Catalog column mask fails before the extension calls the server-side scan-planning endpoint.

UCTableEntry::GetScanFunction first calls TableInformation::RefreshCredentials. For a catalog-managed table, this requests credentials through the Unity Catalog Delta REST API:

/api/2.1/unity-catalog/delta/v1/catalogs/.../credentials

Databricks rejects that request for a table with fine-grained access controls because the Delta REST API does not support row filters or column masks. As a result, the intended Iceberg REST /plan request
is never made.

Removing the preliminary RefreshCredentials call allows the same query to use server-side scan planning successfully and returns the expected masked result.

Environment

  • DuckDB: v2.0.0-dev85598 (eb620c77f8)
  • unity_catalog: 91eff65972
  • delta: 1419d1616f
  • httpfs: 8103a11cc4
  • Platform: macOS ARM64
  • Databricks workspace with server-side scan planning enabled through Early Access
  • External data access enabled
  • Querying principal has EXTERNAL USE SCHEMA

The extensions were built from the current duckdb/unity_catalog main branch and statically linked.

Table setup

The source table is a native, catalog-managed Iceberg table:

  CREATE TABLE <catalog>.<schema>.masked_iceberg_table
  (
      col0 INT,
      col1 STRING
  )
  USING iceberg;

A Unity Catalog column mask was subsequently applied to col1.

The same principal can query the table successfully through Databricks SQL, where the expected masked value is returned.

Reproduction

Create the Unity Catalog secret:

  CREATE SECRET uc (
      TYPE unity_catalog,
      TOKEN '<redacted>',
      ENDPOINT 'https://<workspace-host>',
      AWS_REGION 'us-east-1'
  );

Attach the catalog with scan planning enabled:

  ATTACH '<catalog>' AS uc_catalog (
      TYPE unity_catalog,
      SECRET 'uc',
      DEFAULT_SCHEMA '<schema>',
      READ_ONLY,
      USE_IRC_SCAN_PLAN true
  );

Query the masked native Iceberg table:

  SELECT *
  FROM uc_catalog.<schema>.masked_iceberg_table;

Actual behavior

The extension lists the catalog metadata successfully, but then requests Delta table credentials:

  api.GetTableCredentials <catalog>.<schema>.masked_iceberg_table
  op=READ managed=1

The request is sent to:

  GET /api/2.1/unity-catalog/delta/v1/catalogs/<catalog>/schemas/<schema>/tables/masked_iceberg_table/credentials?operation=READ

Databricks returns:

  HTTP 403

  Table '<catalog>.<schema>.masked_iceberg_table' has row-level
  security or column masks applied. The Delta REST API (/delta/v1)
  does not support access to tables with fine-grained access control
  policies. [ErrorCode: 5118]

No api-irc.PlanTableScan request is made.

Expected behavior

When the scan-plan path is selected, the extension should call the Iceberg REST scan-planning endpoint without first requesting credentials from the Delta REST API:

  POST /api/2.1/unity-catalog/iceberg-rest/v1/catalogs/<catalog>/namespaces/<schema>/tables/masked_iceberg_table/plan

The scan-plan response supplies scoped, short-lived storage-credentials, which the extension already installs before binding the Parquet scan.

If scan planning fails and the table is Delta, the existing Delta fallback can obtain credentials when BuildDeltaScan is invoked.

Suspected cause

The scan-plan branch in src/storage/uc_table_entry.cpp currently begins with:

  if (table.catalog.ShouldTryScanPlan() && !lookup_info.GetAtClause()) {
      table.RefreshCredentials(context);
      auto bd = make_uniq<UCScanPlanBindData>();
      // ...
  }

RefreshCredentials calls UCAPI::GetTableCredentials, which selects the Delta credentials endpoint for a catalog-managed table.

This credential prefetch appears redundant for scan-plan reads:

  • UCAPI::PlanTableScan authenticates using the Unity Catalog token.
  • The scan-plan response contains storage-credentials.
  • UCScanPlanInitGlobal already creates scoped temporary secrets from those credentials before binding parquet_scan.
  • BuildDeltaScan independently calls RefreshCredentials, so the Delta fallback retains its existing credential behavior.

Validated workaround

I locally removed the preliminary call:

   if (table.catalog.ShouldTryScanPlan() && !lookup_info.GetAtClause()) {
  -    table.RefreshCredentials(context);
       auto bd = make_uniq<UCScanPlanBindData>();

After rebuilding:

  • The Delta credentials endpoint was no longer called before planning.
  • The extension called api-irc.PlanTableScan.
  • The query completed successfully through the Iceberg REST scan-plan path.
  • The result contained the expected policy-masked value.

Test coverage observation

The existing offline scan-plan mock uses a file:// storage location. That causes RefreshCredentials to return early, so it does not expose this behavior.

The live scan-plan fixture is a catalog-managed Delta table without fine-grained access controls, so the preliminary Delta credential request succeeds there.

A regression test could:

  1. Serve a mock table with:
    • data_source_format = "ICEBERG"
    • A non-file:// storage location
  2. Return local Parquet files from the mock /plan response.
  3. Execute a query with USE_IRC_SCAN_PLAN true.
  4. Assert that the query succeeds.
  5. Assert that no request containing /delta/v1/ was made.
  6. Assert that the /plan endpoint was called.
Lingua principale
Python
Stelle
111
Fork
50
Merge medio
1g 8h
PR unite (30g)
9

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di duckdb/unity_catalog

Tutte le issue di duckdb/unity_catalog

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.