kaya-abdullah commented on code in PR #45309:
URL: https://github.com/apache/superset/pull/45309#discussion_r4279554943
##########
superset/sql/parse.py:
##########
@@ -2178,6 +2300,35 @@ def set_limit_value(
if not isinstance(self._parsed, exp.Query):
return
+ # Oracle only gained `FETCH FIRST` in 12c, and that is how sqlglot
+ # renders every Oracle limit, so on 10g and 11g a limited query fails
+ # with "ORA-00933: SQL command not properly ended". There, cap the rows
+ # by filtering the original query on `ROWNUM` from outside. `ROWNUM` is
+ # assigned after the inner `ORDER BY` runs, so the first `n` rows are
+ # still the top `n`. SQLAlchemy uses the same rewrite for pre-12c
+ # servers. Later releases keep `FETCH FIRST`, because the wrapper
rejects
+ # duplicate output column names (ORA-00918) that `FETCH FIRST` accepts.
+ if method == LimitMethod.WRAP_ROWNUM:
+ inner = self._parsed.copy()
+ # Keep CTEs at statement level rather than inside the derived
table.
+ cte = inner.args.pop("with_", None)
+ _deduplicate_oracle_output_names(inner)
Review Comment:
Star projections are left as they are because their column names aren't
known without the table schema. Such a query fails the same way on 11g today,
since `FETCH FIRST` isn't available there; aliasing the columns avoids it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]