Skip to content

Fix Snowflake external table 0-row bug with flat JSON array format - #328

Draft
concaf wants to merge 4 commits into
redhat-data-and-ai:mainfrom
concaf:fix/snowflake-flat-array-format
Draft

Fix Snowflake external table 0-row bug with flat JSON array format#328
concaf wants to merge 4 commits into
redhat-data-and-ai:mainfrom
concaf:fix/snowflake-flat-array-format

Conversation

@concaf

@concaf concaf commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Snowflake's VARIANT type has a 16MB per-row limit. The current format writes each stage's output as a single JSON object per source document (e.g., 195MB for embeddings), which exceeds this limit and causes external tables to silently return 0 rows despite files being registered in EXTERNAL_TABLE_FILE_REGISTRATION_HISTORY.
  • Switch all pipeline stages (converted, chunks, embeddings) to output JSON arrays of flat row objects. With STRIP_OUTER_ARRAY=TRUE already set on the external tables, each array element becomes its own row (~10KB each), well under the 16MB limit.
  • Add new row types (ConvertedRow, ChunkRow, EmbeddingRow) and update all controllers to write the new format while reading both old and new formats for backward compatibility.

Companion DPO MR: Updates materialized views to read the flat row format (no more LATERAL FLATTEN needed).

Test plan

  • Deploy to sandbox and trigger a pipeline for a data product (e.g., aiftestgdrivear)
  • Verify select count(*) from <db>.staging.embeddings_ext_tbl returns > 0
  • Verify select count(*) from <db>.staging.chunks_ext_tbl returns > 0
  • Verify materialized views (EMBEDDINGS_MV, CHUNKS_MV, CONVERTED_MV) return correct data
  • Verify MCP tools (get_chunks, search) still work end-to-end
  • Test with an existing data product that has old-format files — verify re-processing generates new format

…y format

Snowflake's VARIANT type has a 16MB per-row limit. The current format writes
each stage's output as a single JSON object (e.g., 195MB for embeddings),
which exceeds this limit and causes external tables to silently return 0 rows
despite files being registered.

Switch all pipeline stages (converted, chunks, embeddings) to output JSON
arrays of flat row objects. With STRIP_OUTER_ARRAY=TRUE already configured
on the external tables, each array element becomes its own row, keeping
VARIANT values well under the 16MB limit.

All readers handle both old (single-object) and new (array) formats for
backward compatibility during migration.
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d2b983f2-4d69-4348-99b4-7f0c9e286704

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

concaf added 3 commits August 21, 2026 13:30
The nilerr linter flags cases where a non-nil error is returned as nil.
In these fallback unmarshal paths, returning nil error is intentional —
an unparseable file means it should be re-processed, not that the
reconciler failed.
The nilerr linter flags the return line, not the if line, so the
directive must be on the return statement to suppress the warning.
The nilerr linter does not fire on this line, so the nolint directive
triggers nolintlint for being unnecessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant