spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Zommerfelds (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SPARK-15642) Metadata gets lost when selecting a field of a StructType
Date Sat, 11 Feb 2017 17:48:42 GMT

    [ https://issues.apache.org/jira/browse/SPARK-15642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15862467#comment-15862467
] 

Christian Zommerfelds commented on SPARK-15642:
-----------------------------------------------

Problem is still present in Spark 2.2.0-snapshot. This issues is *not* in progress. It just
shows that because I submitted a pull request to demonstrate the bug.

> Metadata gets lost when selecting a field of a StructType
> ---------------------------------------------------------
>
>                 Key: SPARK-15642
>                 URL: https://issues.apache.org/jira/browse/SPARK-15642
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 1.6.0, 1.6.1, 2.2.0
>            Reporter: Christian Zommerfelds
>
> Hi,
> When working with Data Frames, sometimes I find myself needing to write a function that
creates multiple columns. Since that is not directly possible, I create a function that returns
a StructType, and then call select() to assign the fields to different columns. However, I
noticed that the metadata gets lost when I do that.
> Example: (Python)
> {code}
> In: schema = StructType([StructField('foo', StructType([
>     StructField('features', ArrayType(IntegerType())),
>     StructField('label', DoubleType(), False,
>                 {'ml_attr': {'type': 'nominal', 'vals': ['0.0', '1.0']}}
>     )
> ]))])
> In: df = sqlContext.createDataFrame([Row(foo=Row(features=[1,2], label=0.0)), Row(foo=Row(features=[3,4],
label=1.0))], schema)
> In: df.schema.fields[0].dataType.fields[1].metadata
> Out: {'ml_attr': {'type': 'nominal', 'vals': ['0.0', '1.0']}}
> In: df2 = df.select(df.foo['label'])
> In: df2.schema.fields[0].metadata
> Out: {}
> {code}
> Expected: same metadata (ml_attrib...)
> My work around is to create a new Data Frame from RDD, because as far as I know PySpark
doesn't support adding metadata once the DF is created (should I create another issue for
that?). Work around example:
> {code}
> In: df3 = sqlContext.createDataFrame(df2.rdd, StructType([schema.fields[0].dataType.fields[1]]))
> In: df3.schema.fields[0].metadata
> Out: {'ml_attr': {'type': 'nominal', 'vals': ['0.0', '1.0']}}
> {code}
> I am not sure if this affects the Scala API. (EDIT: yes it does. See test case at https://github.com/apache/spark/pull/13467/files)
> Let me know if I can provide any other information.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

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


Mime
View raw message