GitHub user yhuai opened a pull request:

    https://github.com/apache/spark/pull/1346

    [WIP][SPARK-2179][SQL] Public API for DataTypes and Schema

    The current PR contains the following changes:
    * Expose `DataType`s in the sql package (internal details are private to 
sql).
    * Introduce `createSchemaRDD` to create a `SchemaRDD` from an `RDD` with a 
provided schema (represented by a `StructType`) and a provided function to 
construct `Row`,
    * Add a function `simpleString` to every `DataType`. Also, the schema 
represented by a `StructType` can be visualized by `printSchema`.
    
    An example of using `createSchemaRDD` is shown below.
    ```scala
    import org.apache.spark.sql._
    val sqlContext = new org.apache.spark.sql.SQLContext(sc)
    
    val schema =
      StructType(
        StructField("name", StringType, false) ::
        StructField("age", IntegerType, true) :: Nil)
    
    def createRow(record: String): Row = {
      val items = record.split(",")
      Row(items(0), items(1).trim.toInt)
    }
    
    val people = sc.textFile("examples/src/main/resources/people.txt")
    val peopleSchemaRDD = sqlContext.createSchemaRDD(people, schema, createRow)
    peopleSchemaRDD.printSchema
    // root
    // |-- name: string (nullable = false)
    // |-- age: integer (nullable = true)
    
    peopleSchemaRDD.registerAsTable("people")
    sqlContext.sql("select name from people").collect.foreach(println)
    ```
    
    I am currently working on the following things.
    * Move those general purpose functions introduced by the JSON support to 
the type system.
    * Add pre-defined `constructRow` functions to help users easily use 
`createSchemaRDD` (e.g. applying a schema to a JSON dataset).
    * Add a method to let user optionally validate the schema of a `SchemaRDD` 
by checking every row.
    * Add needed tests.
    
    JIRA: https://issues.apache.org/jira/browse/SPARK-2179

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/yhuai/spark dataTypeAndSchema

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/1346.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1346
    
----
commit 16be3e56e83a406af86b9e7f18059ec7a2595a9e
Author: Yin Huai <[email protected]>
Date:   2014-07-09T18:51:24Z

    This commit contains three changes:
    * Expose `DataType`s in the sql package (internal details are private to 
sql).
    * Introduce `createSchemaRDD` to create a `SchemaRDD` from an `RDD` with a 
provided schema (represented by a `StructType`) and a provided function to 
construct `Row`,
    * Add a function `simpleString` to every `DataType`. Also, the schema 
represented by a `StructType` can be visualized by `printSchema`.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to