You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hivemall.apache.org by "Charles Pritchard (JIRA)" <ji...@apache.org> on 2017/07/03 04:28:00 UTC

[jira] [Commented] (HIVEMALL-61) Support a function to convert a comma-separated string into typed data and vice versa

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

Charles Pritchard commented on HIVEMALL-61:
-------------------------------------------

Along these lines, I'm looking for a function to cast an array from ANY to a primitive, such as a string to an integer. Brickhaus has cast_array as a UDF.

> Support a function to convert a comma-separated string into typed data and vice versa
> -------------------------------------------------------------------------------------
>
>                 Key: HIVEMALL-61
>                 URL: https://issues.apache.org/jira/browse/HIVEMALL-61
>             Project: Hivemall
>          Issue Type: New Feature
>            Reporter: Takeshi Yamamuro
>            Priority: Minor
>
> Currently, spark does not have this features (IMO this feature will not appear as first-class ones in Spark) it is useful for ETL before ML processing.
> e.x.)
> {code}
> scala> val ds1 = Seq("""1,abc""").toDS()
> ds1: org.apache.spark.sql.Dataset[String] = [value: string]
> scala> val schema = new StructType().add("a", IntegerType).add("b", StringType)
> schema: org.apache.spark.sql.types.StructType = StructType(StructField(a,IntegerType,true), StructField(b,StringType,true))
> scala> val ds2 = ds1.select(from_csv($"value", schema))
> ds2: org.apache.spark.sql.DataFrame = [csvtostruct(value): struct<a: int, b: string>]
> scala> ds2.printSchema
> root
>  |-- csvtostruct(value): struct (nullable = true)
>  |    |-- a: integer (nullable = true)
>  |    |-- b: string (nullable = true)
> scala> ds2.show
> +------------------+
> |csvtostruct(value)|
> +------------------+
> |           [1,abc]|
> +------------------+
> {code}
> A related discussion is here: https://github.com/apache/spark/pull/13300#issuecomment-261962773



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)