You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Ole André Schistad (Jira)" <ji...@apache.org> on 2024/10/03 10:15:00 UTC

[jira] [Updated] (SPARK-49865) Extend Spark XSD parser into PySpark

     [ https://issues.apache.org/jira/browse/SPARK-49865?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ole André Schistad updated SPARK-49865:
---------------------------------------
    Description: 
While PySpark does support XML parsing, it lacks a native XSD parser. Instead, you have to access the native Scala method {{XSDToSchema}} via the Spark Context.

This does work, but only if you are able to access the SparkContext object.  This is going to be a problem for users on Databricks, where Shared Clusters are required for many important features such as row-level security, since the Spark Context is not available from PySpark in this environment.

So I would like to request that the Apache Spark project implements a PySpark wrapper for the XSDToSchema Scala method. This should be a fairly quick and easy fix, as it is functionally the same as the existing PySpark function \{{from_ddl_schema}}

This is implemented in PySpark already, [https://github.com/apache/spark/blob/master/python/pyspark/sql/types.py:1903:]

 
{code:java}
def from_ddl_schema(type_str: str) -> DataType:
            return _parse_datatype_json_string(
                cast(JVMView, sc._jvm)
                .org.apache.spark.sql.types.StructType.fromDDL(type_str)
                .json()
            ) {code}
So for XSD:
{code:java}
def from_xsd_schema(type_str: str) -> DataType:
           return _parse_datatype_json_string(
                cast(JVMView, sc._jvm)
                .org.apache.spark.sql.execution.datasources.xml
                .XSDToSchema.read(type_str)
                .json()
            ) {code}
 

  was:
While PySpark does support XML parsing, it lacks a native XSD parser. Instead, you have to access the native Scala method {{XSDToSchema}} via the Spark Context.

This does work, but only if you are able to access the SparkContext object.  This is going to be a problem for users on Databricks, where Shared Clusters are required for many important features such as row-level security, since the Spark Context is not available from PySpark in this environment.

So I would like to request that the Apache Spark project implements a PySpark wrapper for the XSDToSchema Scala method. This should be a fairly quick and easy fix, as it is functionally the same as the existing PySpark function {{from_ddl_schema
}}

This is implemented in PySpark already, https://github.com/apache/spark/blob/master/python/pyspark/sql/types.py:1903:

 
{code:java}
def from_ddl_schema(type_str: str) -> DataType:
            return _parse_datatype_json_string(
                cast(JVMView, sc._jvm)
                .org.apache.spark.sql.types.StructType.fromDDL(type_str)
                .json()
            ) {code}
So for XSD:
{code:java}
def from_xsd_schema(type_str: str) -> DataType:
           return _parse_datatype_json_string(
                cast(JVMView, sc._jvm)
                .org.apache.spark.sql.execution.datasources.xml
                .XSDToSchema.read(type_str)
                .json()
            ) {code}
 


> Extend Spark XSD parser into PySpark
> ------------------------------------
>
>                 Key: SPARK-49865
>                 URL: https://issues.apache.org/jira/browse/SPARK-49865
>             Project: Spark
>          Issue Type: Wish
>          Components: PySpark
>    Affects Versions: 3.5.3
>            Reporter: Ole André Schistad
>            Priority: Major
>
> While PySpark does support XML parsing, it lacks a native XSD parser. Instead, you have to access the native Scala method {{XSDToSchema}} via the Spark Context.
> This does work, but only if you are able to access the SparkContext object.  This is going to be a problem for users on Databricks, where Shared Clusters are required for many important features such as row-level security, since the Spark Context is not available from PySpark in this environment.
> So I would like to request that the Apache Spark project implements a PySpark wrapper for the XSDToSchema Scala method. This should be a fairly quick and easy fix, as it is functionally the same as the existing PySpark function \{{from_ddl_schema}}
> This is implemented in PySpark already, [https://github.com/apache/spark/blob/master/python/pyspark/sql/types.py:1903:]
>  
> {code:java}
> def from_ddl_schema(type_str: str) -> DataType:
>             return _parse_datatype_json_string(
>                 cast(JVMView, sc._jvm)
>                 .org.apache.spark.sql.types.StructType.fromDDL(type_str)
>                 .json()
>             ) {code}
> So for XSD:
> {code:java}
> def from_xsd_schema(type_str: str) -> DataType:
>            return _parse_datatype_json_string(
>                 cast(JVMView, sc._jvm)
>                 .org.apache.spark.sql.execution.datasources.xml
>                 .XSDToSchema.read(type_str)
>                 .json()
>             ) {code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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