zhengruifeng commented on code in PR #36640:
URL: https://github.com/apache/spark/pull/36640#discussion_r887627360


##########
python/pyspark/sql/session.py:
##########
@@ -611,8 +612,8 @@ def _inferSchema(
         :class:`pyspark.sql.types.StructType`
         """
         first = rdd.first()
-        if not first:
-            raise ValueError("The first row in RDD is empty, " "can not infer 
schema")
+        if isinstance(first, Sized) and len(first) == 0:

Review Comment:
   +1, the `first` job seems unnecessary:
   
   1, `if samplingRatio is None`, we should directly take first 100 non-None 
rows, check on the 100 rows and infer the schema;
   2, `if samplingRatio is not None`, the `_merge_type` job should be enough. 
If we need to check the count, we can add a `count` into `_merge_type`.



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