zhengruifeng commented on code in PR #38872:
URL: https://github.com/apache/spark/pull/38872#discussion_r1037857406
##########
python/pyspark/sql/connect/functions.py:
##########
@@ -14,29 +14,81 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-from pyspark.sql.connect.column import Column, LiteralExpression,
ColumnReference
+from pyspark.sql.connect.column import (
+ Column,
+ Expression,
+ LiteralExpression,
+ ColumnReference,
+ UnresolvedFunction,
+)
-from typing import Any, TYPE_CHECKING
+from typing import Any, TYPE_CHECKING, Union, List
if TYPE_CHECKING:
from pyspark.sql.connect._typing import ColumnOrName
+
# TODO(SPARK-40538) Add support for the missing PySpark functions.
def _to_col(col: "ColumnOrName") -> Column:
return col if isinstance(col, Column) else column(col)
-def col(x: str) -> Column:
- return Column(ColumnReference(x))
+def _invoke_function(name: str, *args: Union[Column, Expression]) -> Column:
+ """
+ Simple wrapper function that converts the arguments into the appropriate
types.
+ Parameters
+ ----------
+ name Name of the function to be called.
+ args The list of arguments.
+
+ Returns
+ -------
+ :class:`UnresolvedFunction`
+ """
+ expressions: List[Expression] = []
+ for arg in args:
+ assert isinstance(arg, (Column, Expression))
+ if isinstance(arg, Column):
+ expressions.append(arg._expr)
+ else:
+ expressions.append(arg)
+ return Column(UnresolvedFunction(name, expressions))
+
+
+def _invoke_function_over_columns(name: str, *cols: "ColumnOrName") -> Column:
+ """
+ Invokes n-ary JVM function identified by name
+ and wraps the result with :class:`~pyspark.sql.Column`.
+ """
+ _cols = [_to_col(c) for c in cols]
+ return _invoke_function(name, *_cols)
+
+
+def _invoke_binary_math_function(name: str, col1: Any, col2: Any) -> Column:
+ """
+ Invokes binary JVM math function identified by name
Review Comment:
good catch, will update
--
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]