You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zhengruifeng (via GitHub)" <gi...@apache.org> on 2024/07/15 11:40:17 UTC

[PR] [SPARK-48897][PYTHON][CONNECT] Make `from_xml` support StructType schema [spark]

zhengruifeng opened a new pull request, #47355:
URL: https://github.com/apache/spark/pull/47355

   ### What changes were proposed in this pull request?
   Make `from_xml` support StructType schema
   
   ### Why are the changes needed?
   StructType schema was supported in Spark Classic, but not in Spark Connect
   
   to address https://github.com/apache/spark/pull/43680#discussion_r1385332357
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   before:
   ```
   from pyspark.sql.types import StructType, LongType
   import pyspark.sql.functions as sf
   data = [(1, '''<p><a>1</a></p>''')]
   df = spark.createDataFrame(data, ("key", "value"))
   
   schema = StructType().add("a", LongType())
   df.select(sf.from_xml(df.value, schema)).show()
   
   ---------------------------------------------------------------------------
   AnalysisException                         Traceback (most recent call last)
   Cell In[1], line 7
   ...
   AnalysisException: [PARSE_SYNTAX_ERROR] Syntax error at or near '{'. SQLSTATE: 42601
   
   JVM stacktrace:
   org.apache.spark.sql.AnalysisException
   	at org.apache.spark.sql.catalyst.parser.ParseException.withCommand(parsers.scala:278)
   	at org.apache.spark.sql.catalyst.parser.AbstractParser.parse(parsers.scala:98)
   	at org.apache.spark.sql.catalyst.parser.AbstractParser.parseDataType(parsers.scala:40)
   	at org.apache.spark.sql.types.DataType$.$anonfun$fromDDL$1(DataType.scala:126)
   	at org.apache.spark.sql.types.DataType$.parseTypeWithFallback(DataType.scala:145)
   	at org.apache.spark.sql.types.DataType$.fromDDL(DataType.scala:127)
   ```
   
   after:
   ```
   +---------------+
   |from_xml(value)|
   +---------------+
   |            {1}|
   +---------------+
   
   ```
   
   ### How was this patch tested?
   added doctest
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   no


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-48897][PYTHON][CONNECT] Make `from_xml` support StructType schema [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #47355:
URL: https://github.com/apache/spark/pull/47355#discussion_r1678555974


##########
python/pyspark/sql/functions/builtin.py:
##########
@@ -16303,7 +16303,21 @@ def from_xml(
     >>> df.select(sf.from_xml(df.value, schema).alias("xml")).collect()
     [Row(xml=Row(a=1))]
 
-    Example 2: Parsing XML with :class:`ArrayType` in schema
+    Example 2: Parsing XML with a :class:`StructType` schema

Review Comment:
   sure



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-48897][PYTHON][CONNECT] Make `from_xml` support StructType schema [spark]

Posted by "sandip-db (via GitHub)" <gi...@apache.org>.
sandip-db commented on code in PR #47355:
URL: https://github.com/apache/spark/pull/47355#discussion_r1678084898


##########
python/pyspark/sql/functions/builtin.py:
##########
@@ -16303,7 +16303,21 @@ def from_xml(
     >>> df.select(sf.from_xml(df.value, schema).alias("xml")).collect()
     [Row(xml=Row(a=1))]
 
-    Example 2: Parsing XML with :class:`ArrayType` in schema
+    Example 2: Parsing XML with a :class:`StructType` schema

Review Comment:
   Also, can you please enable tests [here](https://github.com/apache/spark/blob/master/python/pyspark/sql/tests/connect/test_connect_function.py#L1911-L1915)



##########
python/pyspark/sql/functions/builtin.py:
##########
@@ -16303,7 +16303,21 @@ def from_xml(
     >>> df.select(sf.from_xml(df.value, schema).alias("xml")).collect()
     [Row(xml=Row(a=1))]
 
-    Example 2: Parsing XML with :class:`ArrayType` in schema
+    Example 2: Parsing XML with a :class:`StructType` schema

Review Comment:
   Thanks for fixing this. Can you please reuse the existing jira #SPARK-45190?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-45190][SPARK-48897][PYTHON][CONNECT] Make `from_xml` support StructType schema [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #47355: [SPARK-45190][SPARK-48897][PYTHON][CONNECT] Make `from_xml` support StructType schema
URL: https://github.com/apache/spark/pull/47355


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-45190][SPARK-48897][PYTHON][CONNECT] Make `from_xml` support StructType schema [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #47355:
URL: https://github.com/apache/spark/pull/47355#issuecomment-2230046850

   Merged to master.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-48897][PYTHON][CONNECT] Make `from_xml` support StructType schema [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #47355:
URL: https://github.com/apache/spark/pull/47355#issuecomment-2228300983

   also cc @sandip-db 


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-48897][PYTHON][CONNECT] Make `from_xml` support StructType schema [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #47355:
URL: https://github.com/apache/spark/pull/47355#discussion_r1678555085


##########
python/pyspark/sql/functions/builtin.py:
##########
@@ -16303,7 +16303,21 @@ def from_xml(
     >>> df.select(sf.from_xml(df.value, schema).alias("xml")).collect()
     [Row(xml=Row(a=1))]
 
-    Example 2: Parsing XML with :class:`ArrayType` in schema
+    Example 2: Parsing XML with a :class:`StructType` schema

Review Comment:
   sure, I was not aware of that ticket, will also add it to the title



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org