HyukjinKwon commented on code in PR #40741:
URL: https://github.com/apache/spark/pull/40741#discussion_r1163702110
##########
python/pyspark/sql/connect/session.py:
##########
@@ -395,13 +397,22 @@ def createDataFrame(
createDataFrame.__doc__ = PySparkSession.createDataFrame.__doc__
- def sql(self, sqlQuery: str, args: Optional[Dict[str, Any]] = None) ->
"DataFrame":
- cmd = SQL(sqlQuery, args)
- data, properties =
self.client.execute_command(cmd.command(self._client))
- if "sql_command_result" in properties:
- return
DataFrame.withPlan(CachedRelation(properties["sql_command_result"]), self)
- else:
- return DataFrame.withPlan(SQL(sqlQuery, args), self)
+ def sql(
+ self, sqlQuery: str, args: Optional[Dict[str, Any]] = None, **kwargs:
Any
+ ) -> "DataFrame":
+ formatter = SQLStringFormatter(self)
+ if len(kwargs) > 0:
+ sqlQuery = formatter.format(sqlQuery, **kwargs)
+ try:
+ cmd = SQL(sqlQuery, args, formatter.unresolvedColumns)
+ data, properties =
self.client.execute_command(cmd.command(self._client))
+ if "sql_command_result" in properties:
+ return
DataFrame.withPlan(CachedRelation(properties["sql_command_result"]), self)
+ else:
+ return DataFrame.withPlan(SQL(sqlQuery, args,
formatter.unresolvedColumns), self)
Review Comment:
I meant sth like this
```python
if "sql_command_result" in properties:
ret =
DataFrame.withPlan(CachedRelation(properties["sql_command_result"]), self)
else:
ret = DataFrame.withPlan(SQL(sqlQuery, args,
formatter.unresolvedColumns), self)
if len(kwargs) > 0:
ret.schema # Workaround to drop view blah blah blah by
trggering analysis. blah blah
return ret
```
--
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]