Skip to content

Add Enhanced Ingestion Mode to genddl Tool - #92

Open
ron-daniel1 wants to merge 12 commits into
prestodb:mainfrom
ron-daniel1:pbench-ingestion
Open

Add Enhanced Ingestion Mode to genddl Tool#92
ron-daniel1 wants to merge 12 commits into
prestodb:mainfrom
ron-daniel1:pbench-ingestion

Conversation

@ron-daniel1

Copy link
Copy Markdown

Adds enhanced ingestion mode to cmd/genddl for generating TPC-DS data
ingestion SQL files.

Key Features:

  • Two-stage ingestion: separate source (CSV/TEXTFILE) and target (Parquet) tables
  • Catalog support: multi-catalog environments with source/target catalogs
  • Format handling: CSV with CAST/NULLIF, TEXTFILE with direct SELECT
  • Engine support: Presto (WITH clause) and Spark (USING iceberg + TBLPROPERTIES)
  • Correct schema syntax: CREATE SCHEMA catalog.schema WITH (location = 's3a://...')

Files Changed:

New Templates:

  • create_source_table.sql.tmpl - Source table DDL (CSV/TEXTFILE)
  • create_target_table.sql.tmpl - Target table DDL (Parquet)

Modified: main.go

Schema struct additions:

  • Mode string - Detects "enhanced_ingestion" vs legacy mode
  • SourceFileFormat string - "CSV" or "TEXTFILE"
  • SourceSchema, TargetSchema string - Separate schema names
  • SourceCatalog, TargetCatalog string - Multi-catalog support
  • S3SourceLocation, S3TargetLocation string - Separate S3 paths
  • Engine string - "presto" or "spark" for engine-specific syntax

New functions:

  • isEnhancedIngestionMode() - Mode detection helper
  • generateSourceTable() - Generates 1a-create-source-*.sql
  • generateTargetTable() - Generates 1b-create-target-*.sql

Modified functions:

  • loadSchemas() - In enhanced mode, generates only specified catalog type
    (iceberg=true → Iceberg only) instead of all 4 variants
  • generateSchemaFromDef() - Routes to enhanced or legacy generation logic
    based on mode
  • Run() - Orchestrates enhanced vs legacy workflow

Modified: insert_table.sql.tmpl

  • Added conditional CAST/NULLIF for CSV: CAST(NULLIF(column, '') AS type)
  • Added direct SELECT * for TEXTFILE format
  • Added catalog-qualified table references: source_catalog.source_schema.table

Testing:
✅ All 10 tests pass
✅ Backward compatible - legacy mode unchanged
✅ Generated examples match golden files

Usage:
Enhanced: go run main.go genddl config_enhanced_ingestion.json
Legacy: go run main.go genddl config.json (unchanged)

@ron-daniel1
ron-daniel1 requested a review from ethanyzhang as a code owner May 29, 2026 06:56
@ron-daniel1

Copy link
Copy Markdown
Author

Fix provided in PR:
Fixed typo: p_response_targe → p_response_target in 6 SQL files
Fixed partition column positioning for Iceberg tables in golden files
Fixed Go formatting with gofmt on main.go and main_test.go
Upgraded go version: go 1.26.2 → go 1.26.3

Comment thread cmd/genddl/main.go Outdated
Comment thread cmd/genddl/create_target_table.sql.tmpl Outdated
Comment thread cmd/genddl/main.go Outdated
Comment thread cmd/genddl/main_test.go
Comment thread cmd/genddl/config_enhanced_ingestion.json Outdated
Comment thread cmd/genddl/create_source_table.sql.tmpl Outdated
Comment thread cmd/genddl/create_target_table.sql.tmpl Outdated
@ron-daniel1
ron-daniel1 requested a review from yabinma June 4, 2026 09:26

@yabinma yabinma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ron-daniel1 for adding/updating the PR. LGTM.

@ethanyzhang ethanyzhang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few correctness/robustness notes on the enhanced ingestion mode, posted inline. (Nice work — the legacy path looks cleanly preserved.)

Comment thread cmd/genddl/main.go
SourceFileFormat string `json:"source_file_format"` // "CSV" or "TEXTFILE"
SourceCatalog string `json:"source_catalog"` // Source catalog name (optional)
TargetCatalog string `json:"target_catalog"` // Target catalog name (optional)
Engine string `json:"engine"` // "presto" or "spark"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

engine is accepted as "presto"/"spark" and defaulted to presto at L397, but nothing ever branches on it — grep for Engine, spark, USING, TBLPROPERTIES finds no references in any template or code path. A config with "engine": "spark" silently emits the same Presto CREATE SCHEMA ... WITH (...), USE catalog.schema, and Presto-style table DDL, contradicting the PR description's claim of Spark support (USING iceberg + TBLPROPERTIES). Suggest either rejecting non-presto engines in loadSchemas for now, or implementing the Spark template path in this PR.

{{- end }})
WITH (
external_location = '{{ $.S3SourceLocation }}/{{ .Name }}/',
{{- if eq $.SourceFileFormat "CSV" }}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source_file_format is unvalidated and case-sensitive. The source template treats anything != "CSV" as TEXTFILE, while insert generation (insert_table.sql.tmpl:24) treats anything != "TEXTFILE" as the CSV branch but only emits column expressions when the value is exactly "CSV". A lowercase "csv" therefore creates the source table as TEXTFILE and generates an INSERT with an empty SELECT column list (SELECT\nFROM ...) — invalid SQL, no error. Please validate source_file_format ∈ {CSV, TEXTFILE} in loadSchemas for enhanced mode.

SET SESSION {{ $key }}='{{ $value }}';
{{ end }}

{{- if .TargetSchema }}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This template selects enhanced vs legacy by checking .TargetSchema presence rather than .Mode. Combined with the lack of required-field validation in loadSchemas, an enhanced_ingestion config that omits target_schema runs the legacy insert branch (referencing .SchemaName, .UncompressedName, etc.) while main.go still routes through the enhanced source/target generators — producing mismatched, silently-wrong output. Suggest branching on .Mode and validating that source_schema/target_schema/s3_*_location are set up front.

Comment thread cmd/genddl/main.go
@@ -161,15 +183,22 @@ func generateSchemaFromDef(schema *Schema, defDir string, configDir string, outp
func generateCreateTable(schema *Schema, currDir string, outputDirs []string, step int) {
genSubSteps := !schema.Iceberg && schema.Partitioned

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genSubSteps is computed before the enhanced branch and the trailing if genSubSteps { generateAwsS3Mv...; generateAnalyze...; generateAwsS3Cp... } still fires in enhanced mode. An enhanced config with iceberg:false, partitioned:true would emit stray legacy 6b-s3-mv/6c-call-analyze/6d-s3-cp artifacts alongside the source/target files. Untested combo (all enhanced examples use iceberg:true), but the path is reachable and unintended — worth guarding with !schema.isEnhancedIngestionMode().

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.

3 participants