{"record":{"id":"5a5d708178bb5d0e","repo":"pathwaycom/pathway","slug":"parsing-query-failed","errorCode":null,"errorMessage":"parsing {query} failed","messagePattern":"parsing (.+?) failed","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/sql/__init__.py","lineNumber":77,"sourceCode":"    - INTERSECT does not support INTERSECT ALL.\n    - COALESCE, IFNULL are not supported.\n    - FULL JOIN and NATURAL JOIN are not supported.\n    - CAST is not supported\n\n    '''\n\n    with optional_imports(\"sql\"):\n        import sqlglot\n        import sqlglot.expressions as sql_expr\n        from sqlglot.errors import OptimizeError\n        from sqlglot.optimizer import qualify_columns\n\n        from pathway.internals.sql.processing import _run\n\n    kwargs = {name: tab.copy() for name, tab in kwargs.items()}\n    root: sql_expr.Expression = sqlglot.parse_one(query)\n    if root is None:\n        raise RuntimeError(f\"parsing {query} failed\")\n    try:\n        root = qualify_columns.qualify_columns(\n            root,\n            {name: tab.schema.typehints() for name, tab in kwargs.items()},\n        )\n    except OptimizeError:\n        pass\n    tab, _ = _run(root, kwargs)\n    return tab\n","sourceCodeStart":59,"sourceCodeEnd":87,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/sql/__init__.py#L59-L87","documentation":"Pathway's SQL engine (pathway.sql / pw.sql) parses the query with sqlglot.parse_one. If sqlglot returns None — which happens for an empty or whitespace-only query string — the wrapper raises RuntimeError('parsing {query} failed'). This is a pre-execution failure: the query never reaches Pathway's SQL-to-table translation.","triggerScenarios":"Calling pw.sql(query) or pathway.internals.sql with query=\"\" or query that is only whitespace/comments; a f-string or templating bug that interpolates to an empty string; passing None-like input after string concatenation.","commonSituations":"Dynamically assembled SQL where a WHERE/SELECT clause variable is empty; config-driven query strings with a missing value; trailing whitespace-only strings from user input.","solutions":["Validate the query is non-empty and contains at least one SQL statement before calling pw.sql","Log/print the exact query string right before the call to catch templating bugs","If the query is user-supplied, reject blank input early with a clear error"],"exampleFix":"# before\ntab = pw.sql(query)  # query == \"\" -> RuntimeError\n\n# after\nif not query or not query.strip():\n    raise ValueError(\"SQL query is empty\")\ntab = pw.sql(query)","handlingStrategy":"validation","validationCode":"def is_runnable_sql(query: str) -> bool:\n    return bool(query and query.strip())","typeGuard":"def assert_nonempty_query(query: str) -> None:\n    if not query or not query.strip():\n        raise ValueError(\"SQL query is empty\")","tryCatchPattern":"try:\n    tab = pw.sql(query)\nexcept RuntimeError as e:\n    if \"parsing\" in str(e):\n        raise ValueError(f\"Bad SQL query: {query!r}\") from e\n    raise","preventionTips":["Log the assembled query string before executing","Unit-test dynamic query builders with empty-input cases"],"tags":["sql","validation","pathway"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}