Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
046f795
[migrations] Spark-to-Feldera migration tool PoC.
wilmaontherun Mar 16, 2026
bb1b24c
[ci] apply automatic fixes
feldera-bot Mar 16, 2026
871d79c
Intermediate progress based on Mihai's comments.
wilmaontherun Mar 19, 2026
e856080
fixed comments on skills
wilmaontherun Mar 19, 2026
b672679
Fixed all comments before we refactor skills
wilmaontherun Mar 19, 2026
3d8536f
Merge skills
wilmaontherun Mar 19, 2026
219f8b7
Fixed the rest of the code w.r.t. new skill file
wilmaontherun Mar 19, 2026
83d7731
Revised doc indexing
wilmaontherun Mar 19, 2026
98f7dee
merged skills
wilmaontherun Mar 19, 2026
56bd911
add --verbose flag, translate-file, combined demos, and Feldera PK/qu…
wilmaontherun Mar 19, 2026
b10f7a4
more demo files
wilmaontherun Mar 19, 2026
7d56201
revised samples and skills
wilmaontherun Mar 20, 2026
9e17a33
[ci] apply automatic fixes
feldera-bot Mar 20, 2026
3a75739
add --compiler option, fix no-compiler handling, improve example list…
wilmaontherun Mar 20, 2026
ab4f746
[ci] apply automatic fixes
feldera-bot Mar 20, 2026
6672146
fixed readme
wilmaontherun Mar 20, 2026
9975f33
[ci] apply automatic fixes
feldera-bot Mar 20, 2026
14e7cc6
Add --model option, remove OpenAI support and hardcoded compiler path
wilmaontherun Mar 20, 2026
7ac2fb9
Use sqlparse for SQL splitting, fix README inconsistencies
wilmaontherun Mar 20, 2026
6655f7c
Add prompt caching and rate limit retry; skip examples on first pass
wilmaontherun Mar 20, 2026
8fa1210
Clean up code quality: fix imports, types, and consistency issues
wilmaontherun Mar 21, 2026
4358104
Fix spark_skills.md inconsistencies
wilmaontherun Mar 24, 2026
80a5e7f
[ci] apply automatic fixes
feldera-bot Mar 24, 2026
7da4c30
Verify and fix spark_skills.md against Apache Spark SQL reference
wilmaontherun Mar 24, 2026
589406c
Overhaul spark/data/samples: fix errors, add new patterns, remove tri…
wilmaontherun Mar 24, 2026
b53a97a
Fix skills inconsistencies: QUARTER unsupported, contains/binary, pmo…
wilmaontherun Mar 25, 2026
05388f9
Rename misnamed sample files to match their content
wilmaontherun Mar 25, 2026
643ba2b
Improve and expand sample demos
wilmaontherun Mar 25, 2026
d1b0c95
Fix demo files: remove unsupported patterns, add dates and arithmetic…
wilmaontherun Mar 25, 2026
d7057b9
Fix aggregations and arithmetic demos to use only supported Feldera f…
wilmaontherun Mar 25, 2026
b438037
split_part skill & base_url config
anandbraman Mar 27, 2026
aaf02dd
Update AVG(integer) rule: rewrite to AVG(CAST(col AS DOUBLE)) for int…
wilmaontherun Mar 30, 2026
9de37f9
Untrack known_unsupported.yaml (ignored by .gitignore)
wilmaontherun Mar 30, 2026
e088426
Add dialect subcommand structure: felderize spark <cmd>
wilmaontherun Mar 30, 2026
d596584
Move data/skills one level above spark/ to felderize root
wilmaontherun Mar 30, 2026
d5bf6e0
Move skills file to spark/skills/
wilmaontherun Mar 30, 2026
e714f19
Address review comments: lateral aliases, size/CARDINALITY, JSON, sem…
wilmaontherun Mar 30, 2026
621dd95
Merge branch 'gh-readonly-queue/main/pr-5953-63f28bb9543f28137c91d7a2…
wilmaontherun Mar 30, 2026
a84c82f
Reorganize spark_skills.md: fix section placement and add missing ent…
wilmaontherun Mar 31, 2026
06b7bc6
Fix and improve spark_skills.md translation rules
wilmaontherun Apr 2, 2026
425d5ab
Reorganize spark_skills.md: structured subsections with emoji markers
wilmaontherun Apr 2, 2026
2b98d4e
Verify spark_skills.md claims against test evidence; fix errors found
wilmaontherun Apr 2, 2026
4faca22
Fix skills: STDDEV rewrite rule, GBD-REGEX-ESCAPE for RLIKE, CAST(num…
wilmaontherun Apr 2, 2026
c1f740d
README: note that Spark is current dialect, more planned
wilmaontherun Apr 2, 2026
d8a1ed6
[ci] apply automatic fixes
feldera-bot Apr 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[ci] apply automatic fixes
Signed-off-by: feldera-bot <feldera-bot@feldera.com>
  • Loading branch information
feldera-bot committed Mar 16, 2026
commit bb1b24c5488b400eda94b387e48b14d37ab661d3
30 changes: 24 additions & 6 deletions python/felderize/spark/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ def cli():
@click.option("--validate", is_flag=True, help="Validate against Feldera instance")
@click.option("--json-output", is_flag=True, help="Output as JSON")
@click.option("--no-docs", is_flag=True, help="Disable Feldera doc inclusion in prompt")
def translate(schema_file: str, query_file: str, validate: bool, json_output: bool, no_docs: bool):
def translate(
schema_file: str, query_file: str, validate: bool, json_output: bool, no_docs: bool
):
"""Translate a single Spark SQL schema + query pair to Feldera SQL."""
config = Config.from_env()
schema_sql = Path(schema_file).read_text()
query_sql = Path(query_file).read_text()

result = translate_spark_to_feldera(
schema_sql, query_sql, config, validate=validate, include_docs=not no_docs,
schema_sql,
query_sql,
config,
validate=validate,
include_docs=not no_docs,
)

if json_output:
Expand Down Expand Up @@ -70,7 +76,11 @@ def batch(data_dir: str, validate: bool, output_dir: str | None, no_docs: bool):

click.echo(f"Translating {name}...", err=True)
result = translate_spark_to_feldera(
schema_sql, query_sql, config, validate=validate, include_docs=not no_docs,
schema_sql,
query_sql,
config,
validate=validate,
include_docs=not no_docs,
)
results[name] = result.to_dict()

Expand Down Expand Up @@ -98,7 +108,11 @@ def batch(data_dir: str, validate: bool, output_dir: str | None, no_docs: bool):

@cli.command()
@click.argument("name", required=False)
@click.option("--validate/--no-validate", default=True, help="Validate against Feldera instance (default: on)")
@click.option(
"--validate/--no-validate",
default=True,
help="Validate against Feldera instance (default: on)",
)
@click.option("--json-output", is_flag=True, help="Output as JSON")
@click.option("--no-docs", is_flag=True, help="Disable Feldera doc inclusion in prompt")
def example(name: str | None, validate: bool, json_output: bool, no_docs: bool):
Expand All @@ -124,7 +138,7 @@ def example(name: str | None, validate: bool, json_output: bool, no_docs: bool):
for ex_name, (sf, qf) in pairs.items():
schema_preview = sf.read_text().strip().split("\n")[0]
click.echo(f" {ex_name:20s} {schema_preview}")
click.echo(f"\nRun one with: felderize example <name>")
click.echo("\nRun one with: felderize example <name>")
return

if name not in pairs:
Expand All @@ -143,7 +157,11 @@ def example(name: str | None, validate: bool, json_output: bool, no_docs: bool):

config = Config.from_env()
result = translate_spark_to_feldera(
schema_sql, query_sql, config, validate=validate, include_docs=not no_docs,
schema_sql,
query_sql,
config,
validate=validate,
include_docs=not no_docs,
)

if json_output:
Expand Down
88 changes: 68 additions & 20 deletions python/felderize/spark/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,88 @@
_CATEGORIES: dict[str, list[str]] = {
Comment thread
wilmaontherun marked this conversation as resolved.
Outdated
"types": [], # Always matched
"string": [
r"\bUPPER\b", r"\bLOWER\b", r"\bTRIM\b", r"\bCONCAT\b",
r"\bSUBSTRING\b", r"\bREPLACE\b", r"\bLIKE\b", r"\bREGEXP\b",
r"\bLENGTH\b", r"\bINITCAP\b", r"\bREVERSE\b", r"\bREPEAT\b",
r"\bSPLIT\b", r"\bLPAD\b", r"\bRPAD\b",
r"\bUPPER\b",
r"\bLOWER\b",
r"\bTRIM\b",
r"\bCONCAT\b",
r"\bSUBSTRING\b",
r"\bREPLACE\b",
r"\bLIKE\b",
r"\bREGEXP\b",
r"\bLENGTH\b",
r"\bINITCAP\b",
r"\bREVERSE\b",
r"\bREPEAT\b",
r"\bSPLIT\b",
r"\bLPAD\b",
r"\bRPAD\b",
],
"datetime": [
r"\bDATE\b", r"\bTIMESTAMP\b", r"\bINTERVAL\b", r"\bYEAR\b",
r"\bMONTH\b", r"\bDAY\b", r"\bHOUR\b", r"\bEXTRACT\b",
r"\bDATE_ADD\b", r"\bDATE_SUB\b", r"\bDATEDIFF\b",
r"\bDATE_TRUNC\b", r"\bCURRENT_DATE\b", r"\bCURRENT_TIMESTAMP\b",
r"\bDATE\b",
r"\bTIMESTAMP\b",
r"\bINTERVAL\b",
r"\bYEAR\b",
r"\bMONTH\b",
r"\bDAY\b",
r"\bHOUR\b",
r"\bEXTRACT\b",
r"\bDATE_ADD\b",
r"\bDATE_SUB\b",
r"\bDATEDIFF\b",
r"\bDATE_TRUNC\b",
r"\bCURRENT_DATE\b",
r"\bCURRENT_TIMESTAMP\b",
],
"json": [
r"\bJSON\b", r"\bPARSE_JSON\b", r"\bVARIANT\b",
r"\bget_json_object\b", r"\bfrom_json\b", r"\bjson_tuple\b",
r"\bJSON\b",
r"\bPARSE_JSON\b",
r"\bVARIANT\b",
r"\bget_json_object\b",
r"\bfrom_json\b",
r"\bjson_tuple\b",
r"\bTO_JSON\b",
],
"aggregates": [
r"\bCOUNT\b", r"\bSUM\b", r"\bAVG\b", r"\bGROUP\s+BY\b",
r"\bHAVING\b", r"\bOVER\s*\(", r"\bROW_NUMBER\b", r"\bRANK\b",
r"\bLAG\b", r"\bLEAD\b", r"\bWINDOW\b",
r"\bCOUNT\b",
r"\bSUM\b",
r"\bAVG\b",
r"\bGROUP\s+BY\b",
r"\bHAVING\b",
r"\bOVER\s*\(",
r"\bROW_NUMBER\b",
r"\bRANK\b",
r"\bLAG\b",
r"\bLEAD\b",
r"\bWINDOW\b",
],
"array": [
r"\bARRAY\b", r"\bEXPLODE\b", r"\bUNNEST\b",
r"\barray_contains\b", r"\bsort_array\b", r"\barray_distinct\b",
r"\bCARDINALITY\b", r"\bsize\s*\(",
r"\bARRAY\b",
r"\bEXPLODE\b",
r"\bUNNEST\b",
r"\barray_contains\b",
r"\bsort_array\b",
r"\barray_distinct\b",
r"\bCARDINALITY\b",
r"\bsize\s*\(",
],
"map": [r"\bMAP\s*<", r"\bMAP\s*\(", r"\bmap_keys\b", r"\bmap_values\b"],
"decimal": [
r"\bDECIMAL\b", r"\bNUMERIC\b", r"\bROUND\b", r"\bCEIL\b",
r"\bFLOOR\b", r"\bTRUNCATE\b",
r"\bDECIMAL\b",
r"\bNUMERIC\b",
r"\bROUND\b",
r"\bCEIL\b",
r"\bFLOOR\b",
r"\bTRUNCATE\b",
],
"float": [
r"\bFLOAT\b", r"\bDOUBLE\b", r"\bPOWER\b", r"\bSQRT\b",
r"\bLOG\b", r"\bLN\b", r"\bSIN\b", r"\bCOS\b",
r"\bFLOAT\b",
r"\bDOUBLE\b",
r"\bPOWER\b",
r"\bSQRT\b",
r"\bLOG\b",
r"\bLN\b",
r"\bSIN\b",
r"\bCOS\b",
],
"casts": [r"\bCAST\s*\(", r"::"],
"comparisons": [r"\bBETWEEN\b", r"\bCASE\s+WHEN\b", r"\bCOALESCE\b", r"\bNULLIF\b"],
Expand Down
4 changes: 1 addition & 3 deletions python/felderize/spark/skills.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import os
from pathlib import Path

import yaml
Expand Down Expand Up @@ -77,8 +76,7 @@ def build_system_prompt(
prompt += (
"\n\n## Validated Translation Examples\n\n"
"These examples were validated against the Feldera compiler. "
"Follow the same patterns.\n\n"
+ examples_text
"Follow the same patterns.\n\n" + examples_text
)
if with_docs:
docs_text = load_docs(spark_sql, docs_dir)
Expand Down
47 changes: 37 additions & 10 deletions python/felderize/spark/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,22 @@ def _translate_once(
raw = client.translate(system_prompt, repair_prompt)
try:
data = _parse_response(raw)
result.feldera_schema = _as_str(data.get("feldera_schema", result.feldera_schema))
result.feldera_query = _as_str(data.get("feldera_query", result.feldera_query))
result.feldera_schema = _as_str(
data.get("feldera_schema", result.feldera_schema)
)
result.feldera_query = _as_str(
data.get("feldera_query", result.feldera_query)
)
result.unsupported = _as_list(data.get("unsupported", result.unsupported))
result.warnings = _as_list(data.get("warnings", result.warnings))
result.explanations = _as_list(data.get("explanations", result.explanations))
result.explanations = _as_list(
data.get("explanations", result.explanations)
)
full_sql = result.feldera_schema + "\n\n" + result.feldera_query
except (json.JSONDecodeError, KeyError):
result.warnings.append(f"Repair attempt {attempt + 1} produced invalid JSON")
result.warnings.append(
f"Repair attempt {attempt + 1} produced invalid JSON"
)

# Final validation after all retries
errors = validate_sql(full_sql, config.feldera_compiler or None)
Expand All @@ -143,7 +151,9 @@ def _translate_once(
result.status = Status.UNSUPPORTED if result.unsupported else Status.SUCCESS
else:
result.status = Status.ERROR
result.warnings.extend([f"Still failing after {max_retries} repairs: {e}" for e in errors])
result.warnings.extend(
[f"Still failing after {max_retries} repairs: {e}" for e in errors]
)

return result

Expand All @@ -164,21 +174,38 @@ def translate_spark_to_feldera(

# First pass: skills + examples only (no docs)
system_prompt = build_system_prompt(
skills_dir, docs_dir=docs_dir_path, spark_sql=combined_sql, with_docs=False,
skills_dir,
docs_dir=docs_dir_path,
spark_sql=combined_sql,
with_docs=False,
)
result = _translate_once(
schema_sql, query_sql, config, client, system_prompt, validate, max_retries,
schema_sql,
query_sql,
config,
client,
system_prompt,
validate,
max_retries,
)

# If first pass failed and docs are enabled, retry with docs
if result.status == Status.ERROR and include_docs:
print("Retrying with Feldera docs...", file=sys.stderr)
system_prompt_with_docs = build_system_prompt(
skills_dir, docs_dir=docs_dir_path, spark_sql=combined_sql, with_docs=True,
skills_dir,
docs_dir=docs_dir_path,
spark_sql=combined_sql,
with_docs=True,
)
result = _translate_once(
schema_sql, query_sql, config, client, system_prompt_with_docs,
validate, max_retries,
schema_sql,
query_sql,
config,
client,
system_prompt_with_docs,
validate,
max_retries,
)
if result.status != Status.ERROR:
result.warnings.append("Resolved with docs fallback")
Expand Down
Loading