zhengruifeng commented on code in PR #42938: URL: https://github.com/apache/spark/pull/42938#discussion_r1328198653
########## python/pyspark/sql/tests/connect/test_connect_function.py: ########## @@ -1821,6 +1821,111 @@ def test_json_functions(self): sdf.select(SF.to_json(SF.struct(SF.lit("a"), SF.lit("b")), {"mode": "FAILFAST"})), ) + def test_xml_functions(self): + query = """ + SELECT * FROM VALUES + ('<p><a>1</a></p>', '<p><a>1</a><a>2</a><a>3</a></p>', + '<p><a attr="s"><b>5.0</b></a></p>'), + ('<p><a>0</a></p>', '<p><a>4</a><a>5</a><a>6</a></p>', '<p><a attr="t"></a></p>') + AS tab(a, b, c) + """ + # +---------------+-------------------------------+---------------------------------+ + # | a| b| c| + # +---------------+-------------------------------+---------------------------------+ + # |<p><a>1</a></p>|<p><a>1</a><a>2</a><a>3</a></p>|<p><a attr="s"><b>5.0</b></a></p>| + # |<p><a>1</a></p>|<p><a>4</a><a>5</a><a>6</a></p>| <p><a attr="t"></a></p>| + # +---------------+-------------------------------+---------------------------------+ + + cdf = self.connect.sql(query) + sdf = self.spark.sql(query) + + # test from_xml + for schema in [ + "a INT", + # StructType([StructField("a", IntegerType())]), + # StructType([StructField("a", ArrayType(IntegerType()))]), Review Comment: are they supported? ########## python/pyspark/sql/tests/connect/test_connect_function.py: ########## @@ -1821,6 +1821,111 @@ def test_json_functions(self): sdf.select(SF.to_json(SF.struct(SF.lit("a"), SF.lit("b")), {"mode": "FAILFAST"})), ) + def test_xml_functions(self): + query = """ + SELECT * FROM VALUES + ('<p><a>1</a></p>', '<p><a>1</a><a>2</a><a>3</a></p>', + '<p><a attr="s"><b>5.0</b></a></p>'), + ('<p><a>0</a></p>', '<p><a>4</a><a>5</a><a>6</a></p>', '<p><a attr="t"></a></p>') + AS tab(a, b, c) + """ + # +---------------+-------------------------------+---------------------------------+ + # | a| b| c| + # +---------------+-------------------------------+---------------------------------+ + # |<p><a>1</a></p>|<p><a>1</a><a>2</a><a>3</a></p>|<p><a attr="s"><b>5.0</b></a></p>| + # |<p><a>1</a></p>|<p><a>4</a><a>5</a><a>6</a></p>| <p><a attr="t"></a></p>| + # +---------------+-------------------------------+---------------------------------+ + + cdf = self.connect.sql(query) + sdf = self.spark.sql(query) + + # test from_xml + for schema in [ + "a INT", + # StructType([StructField("a", IntegerType())]), + # StructType([StructField("a", ArrayType(IntegerType()))]), + ]: + self.compare_by_show( + cdf.select(CF.from_xml(cdf.a, schema)), + sdf.select(SF.from_xml(sdf.a, schema)), + ) + self.compare_by_show( + cdf.select(CF.from_xml("a", schema)), + sdf.select(SF.from_xml("a", schema)), + ) + self.compare_by_show( + cdf.select(CF.from_xml(cdf.a, schema, {"mode": "FAILFAST"})), + sdf.select(SF.from_xml(sdf.a, schema, {"mode": "FAILFAST"})), + ) + self.compare_by_show( + cdf.select(CF.from_xml("a", schema, {"mode": "FAILFAST"})), + sdf.select(SF.from_xml("a", schema, {"mode": "FAILFAST"})), + ) + + for schema in [ + "STRUCT<a: ARRAY<INT>>", + # StructType([StructField("a", ArrayType(IntegerType()))]), Review Comment: is this supported? -- 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-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org