|
8 | 8 |
|
9 | 9 | from felderize.config import Config |
10 | 10 | from felderize.models import TranslationResult |
11 | | -from felderize.translator import translate_spark_to_feldera |
| 11 | +from felderize.translator import split_combined_sql, translate_spark_to_feldera |
12 | 12 |
|
13 | 13 |
|
14 | 14 | @click.group() |
@@ -44,6 +44,31 @@ def translate( |
44 | 44 | _print_result(result) |
45 | 45 |
|
46 | 46 |
|
| 47 | +@cli.command("translate-file") |
| 48 | +@click.argument("sql_file", type=click.Path(exists=True)) |
| 49 | +@click.option("--validate", is_flag=True, help="Validate against Feldera instance") |
| 50 | +@click.option("--json-output", is_flag=True, help="Output as JSON") |
| 51 | +@click.option("--no-docs", is_flag=True, help="Disable Feldera doc inclusion in prompt") |
| 52 | +def translate_file(sql_file: str, validate: bool, json_output: bool, no_docs: bool): |
| 53 | + """Translate a single combined Spark SQL file (schema + views) to Feldera SQL.""" |
| 54 | + config = Config.from_env() |
| 55 | + combined_sql = Path(sql_file).read_text() |
| 56 | + schema_sql, query_sql = split_combined_sql(combined_sql) |
| 57 | + |
| 58 | + result = translate_spark_to_feldera( |
| 59 | + schema_sql, |
| 60 | + query_sql, |
| 61 | + config, |
| 62 | + validate=validate, |
| 63 | + include_docs=not no_docs, |
| 64 | + ) |
| 65 | + |
| 66 | + if json_output: |
| 67 | + click.echo(json.dumps(result.to_dict(), indent=2)) |
| 68 | + else: |
| 69 | + _print_result(result) |
| 70 | + |
| 71 | + |
47 | 72 | @cli.command() |
48 | 73 | @click.argument("data_dir", type=click.Path(exists=True)) |
49 | 74 | @click.option("--validate", is_flag=True, help="Validate against Feldera instance") |
|
0 commit comments