Skip to content

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

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

concaf wants to merge 7 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

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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

…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.
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.
@concaf
concaf force-pushed the fix/snowflake-flat-array-format branch from 7a22f1e to 70824e0 Compare September 6, 2026 11:32
Drop all fallback paths that read the old single-object format
(ConvertedFile, ChunksFile, EmbeddingsFile). All controllers now
only read and write the new flat array format (ConvertedRow,
ChunkRow, EmbeddingRow). Old-format files will fail to parse and
trigger re-processing into the new format.
Remove readConvertedFile and readChunksFile helpers that were not in
the original code. Inline the retrieve+unmarshal logic in each caller,
matching the original code structure with only the type swap.
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