matko commented on code in PR #964:
URL: https://github.com/apache/datafusion-python/pull/964#discussion_r1932064792
##########
python/datafusion/context.py:
##########
@@ -534,12 +543,20 @@ def sql(self, query: str, options: SQLOptions | None =
None) -> DataFrame:
Args:
query: SQL query text.
options: If provided, the query will be validated against these
options.
+ named_dfs: When provided, used to replace parameterized query
variables
+ in the query string.
Returns:
DataFrame representation of the SQL query.
"""
+ if named_dfs:
+ for alias, df in named_dfs.items():
+ df_sql = f"({df.logical_plan().to_sql()})"
+ query = query.replace(f"{{{alias}}}", df_sql)
Review Comment:
There are some annoying unintended side effects to this approach. Imagine
the following query
```sql
SELECT * FROM {alias} WHERE val="a string that happens to contain {alias} in
it"
```
Since this code just replaces all occurences of `{alias}` with an sql query
it'll do so in the WHERE part as well.
As far as I can tell, there would be no way to escape `{alias}` in such a
way that the replacement does not occur.
This is obviously a contrived example, and it might be that this is
acceptable.
##########
src/functions.rs:
##########
@@ -282,6 +283,16 @@ fn find_window_fn(name: &str, ctx:
Option<PySessionContext>) -> PyResult<WindowF
return Ok(agg_fn);
}
+ // search default window functions
Review Comment:
It is not clear to me how this relates to the rest of the change.
--
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]