HeartSaVioR commented on code in PR #54085:
URL: https://github.com/apache/spark/pull/54085#discussion_r2761864050


##########
python/pyspark/sql/datasource_internal.py:
##########
@@ -144,3 +141,28 @@ def read(
         self, input_partition: SimpleInputPartition  # type: ignore[override]
     ) -> Iterator[Tuple]:
         return self.simple_reader.readBetweenOffsets(input_partition.start, 
input_partition.end)
+
+
+class ReadLimitRegistry:
+    def __init__(self) -> None:
+        self._registry: Dict[str, Type[ReadLimit]] = {}
+        # Register built-in ReadLimit types
+        self.__register(ReadAllAvailable.type_name(), ReadAllAvailable)
+        self.__register(ReadMinRows.type_name(), ReadMinRows)
+        self.__register(ReadMaxRows.type_name(), ReadMaxRows)
+        self.__register(ReadMaxBytes.type_name(), ReadMaxBytes)
+
+    def __register(self, type_name: str, read_limit_type: Type["ReadLimit"]) 
-> None:
+        if type_name in self._registry:
+            raise PySparkException(f"ReadLimit type '{type_name}' is already 
registered.")
+
+        self._registry[type_name] = read_limit_type
+
+    def get(self, type_name: str, params: dict) -> ReadLimit:
+        read_limit_type = self._registry[type_name]

Review Comment:
   That's not expected to happen, but KeyError is definitely not preferable. 
I'll probably throw the better exception - if we have internal exception in 
PySpark than I'll use that.



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