Skip to content

Commit e6b77b5

Browse files
committed
[py] pretty SQL compilation errors
Display SQL compliation errors in a pretty format. Also use `pretty-errors` library that improves how errors are presented in general. Fixes: #1842 Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
1 parent 6268d67 commit e6b77b5

5 files changed

Lines changed: 60 additions & 9 deletions

File tree

python/feldera/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
from feldera.rest.feldera_client import FelderaClient
22
from feldera.pipeline import Pipeline
33
from feldera.pipeline_builder import PipelineBuilder
4+
5+
import pretty_errors
6+
7+
pretty_errors.configure(
8+
line_number_first=True,
9+
)

python/feldera/rest/feldera_client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,16 @@ def __wait_for_compilation(self, name: str):
8888
if status == "Success":
8989
return p
9090
elif status not in wait:
91-
# TODO: return a more detailed error message
91+
# error handling for SQL compilation errors
92+
if isinstance(status, dict):
93+
sql_errors = status.get("SqlError")
94+
if sql_errors:
95+
err_msg = f"Pipeline {name} failed to compile:\n"
96+
for sql_error in sql_errors:
97+
err_msg += f"{sql_error['error_type']}\n{sql_error['message']}\n"
98+
err_msg += f"Code snippet:\n{sql_error['snippet']}"
99+
raise RuntimeError(err_msg)
100+
92101
raise RuntimeError(f"The program failed to compile: {status}")
93102

94103
logging.debug("still compiling %s, waiting for 100 more milliseconds", name)

python/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies = [
2727
"pandas",
2828
"typing-extensions",
2929
"numpy<2",
30+
"pretty-errors",
3031
]
3132
[project.urls]
3233
Homepage = "https://www.feldera.com"

python/tests/test_pipeline_builder.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,19 +252,31 @@ def test_df_without_columns(self):
252252
pipeline.delete()
253253

254254
def test_sql_error(self):
255-
TBL_NAME = "student"
255+
pipeline_name = "sql_error"
256256

257257
sql = f"""
258-
CREATE TABLE {TBL_NAME} (
259-
id INT,
260-
name STRING
261-
);
258+
CREATE TABLE student(
259+
id INT,
260+
name STRING
261+
);
262262
263-
CREATE VIEW s AS SELECT * FROM blah;
263+
CREATE VIEW s AS SELECT * FROM blah;
264264
"""
265265

266-
with self.assertRaises(Exception):
267-
PipelineBuilder(TEST_CLIENT, name="sql_error", sql=sql).create_or_replace()
266+
expected = f"""
267+
Pipeline {pipeline_name} failed to compile:
268+
Error in SQL statement
269+
Object 'blah' not found
270+
Code snippet:
271+
6|CREATE VIEW s AS SELECT * FROM blah;
272+
^^^^""".strip()
273+
274+
with self.assertRaises(Exception) as err:
275+
PipelineBuilder(TEST_CLIENT, name=pipeline_name, sql=sql).create_or_replace()
276+
277+
got_err: str = err.exception.args[0].strip()
278+
279+
assert expected == got_err
268280

269281
pipeline = Pipeline.get("sql_error", TEST_CLIENT)
270282
pipeline.delete()

python/uv.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)