allisonwang-db commented on code in PR #45486:
URL: https://github.com/apache/spark/pull/45486#discussion_r1534794771


##########
python/pyspark/sql/connect/plan.py:
##########
@@ -2408,6 +2408,46 @@ def __repr__(self) -> str:
         return f"{self._function_name}({', '.join([str(arg) for arg in 
self._arguments])})"
 
 
+class PythonDataSource:
+    """Represents a user-defined Python data source."""
+    def __init__(self, data_source: Type, python_ver: str):
+        self._data_source = data_source
+        self._python_ver = python_ver
+
+    def to_plan(self, session: "SparkConnectClient") -> proto.PythonDataSource:
+        ds = proto.PythonDataSource()
+        ds.command = CloudPickleSerializer().dumps(self._data_source)
+        ds.python_ver = self._python_ver
+        return ds
+
+
+class CommonInlineUserDefinedDataSource(LogicalPlan):
+    """Logical plan object for a user-defined data source"""
+
+    def __init__(self, name: str, data_source: PythonDataSource) -> None:
+        super().__init__(None)
+        self._name = name
+        self._data_source = data_source
+
+    def plan(self, session: "SparkConnectClient") -> proto.Relation:
+        plan = self._create_proto_relation()
+        plan.common_inline_user_defined_data_source.name = self._name
+        
plan.common_inline_user_defined_data_source.python_data_source.CopyFrom(
+            self._data_source.to_plan(session)
+        )
+        return plan
+
+    def to_data_source_proto(
+        self, session: "SparkConnectClient"
+    ) -> "proto.CommonInlineUserDefinedDataSource":
+        plan = proto.CommonInlineUserDefinedDataSource()
+        plan.name = self._name
+        plan.python_data_source.CopyFrom(
+            cast(proto.PythonDataSource, self._data_source.to_plan(session))  
# type: ignore[arg-type]

Review Comment:
   Good catch I think we don't need this cast here.



-- 
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]

Reply via email to