You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by liancheng <gi...@git.apache.org> on 2016/05/10 10:49:36 UTC

[GitHub] spark pull request: [SPARK-14127][SQL] "DESC ": Extracts sc...
GitHub user liancheng opened a pull request:

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

    [SPARK-14127][SQL] "DESC <table>": Extracts schema information from table properties for data source tables

    ## What changes were proposed in this pull request?
    
    This is a follow-up of #12934 and #12844. This PR adds a set of utility methods in `DDLUtils` to help extract schema information (user-defined schema, partition columns, and bucketing information) from data source table properties. These utility methods are then used in `DescribeTableCommand` to refine output for data source tables. Before this PR, the aforementioned schema information are only shown as table properties, which are hard to read.
    
    Sample output:
    
    ```
    +----------------------------+---------------------------------------------------------+-------+
    |col_name                    |data_type                                                |comment|
    +----------------------------+---------------------------------------------------------+-------+
    |a                           |bigint                                                   |       |
    |b                           |bigint                                                   |       |
    |c                           |bigint                                                   |       |
    |d                           |bigint                                                   |       |
    |# Partition Information     |                                                         |       |
    |# col_name                  |                                                         |       |
    |d                           |                                                         |       |
    |                            |                                                         |       |
    |# Detailed Table Information|                                                         |       |
    |Database:                   |default                                                  |       |
    |Owner:                      |lian                                                     |       |
    |Create Time:                |Tue May 10 03:20:34 PDT 2016                             |       |
    |Last Access Time:           |Wed Dec 31 16:00:00 PST 1969                             |       |
    |Location:                   |file:/Users/lian/local/src/spark/workspace-a/target/...  |       |
    |Table Type:                 |MANAGED                                                  |       |
    |Table Parameters:           |                                                         |       |
    |  rawDataSize               |-1                                                       |       |
    |  numFiles                  |1                                                        |       |
    |  transient_lastDdlTime     |1462875634                                               |       |
    |  totalSize                 |684                                                      |       |
    |  spark.sql.sources.provider|parquet                                                  |       |
    |  EXTERNAL                  |FALSE                                                    |       |
    |  COLUMN_STATS_ACCURATE     |false                                                    |       |
    |  numRows                   |-1                                                       |       |
    |                            |                                                         |       |
    |# Storage Information       |                                                         |       |
    |SerDe Library:              |org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe       |       |
    |InputFormat:                |org.apache.hadoop.mapred.SequenceFileInputFormat         |       |
    |OutputFormat:               |org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat|       |
    |Compressed:                 |No                                                       |       |
    |Num Buckets:                |2                                                        |       |
    |Bucket Columns:             |[b]                                                      |       |
    |Sort Columns:               |[c]                                                      |       |
    |Storage Desc Parameters:    |                                                         |       |
    |  path                      |file:/Users/lian/local/src/spark/workspace-a/target/...  |       |
    |  serialization.format      |1                                                        |       |
    +----------------------------+---------------------------------------------------------+-------+
    ```
    
    ## How was this patch tested?
    
    Test cases are added in `HiveDDLSuite` to check command output.

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

    $ git pull https://github.com/liancheng/spark spark-14127-extract-schema-info

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

    https://github.com/apache/spark/pull/13025.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 #13025
    
----
commit 2eccb6e1dbcd47e89cbf5fcd5a79f3a65cee0672
Author: Cheng Lian <li...@databricks.com>
Date:   2016-05-10T10:36:01Z

    Extracts schema information from table properties for data source tables

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

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


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/13025#issuecomment-218141031
  
    Merged build finished. Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/13025#issuecomment-218123846
  
    **[Test build #58231 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/58231/consoleFull)** for PR 13025 at commit [`2eccb6e`](https://github.com/apache/spark/commit/2eccb6e1dbcd47e89cbf5fcd5a79f3a65cee0672).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/13025#issuecomment-218140793
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/58232/
    Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on the pull request:

    https://github.com/apache/spark/pull/13025#issuecomment-218204902
  
    LGTM. Merging to master and branch 2.0


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13025#discussion_r62698532
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala ---
    @@ -489,9 +486,83 @@ private[sql] object DDLUtils {
           case _ =>
         })
       }
    +
       def isTablePartitioned(table: CatalogTable): Boolean = {
    -    table.partitionColumns.size > 0 ||
    +    table.partitionColumns.nonEmpty ||
           table.properties.contains("spark.sql.sources.schema.numPartCols")
       }
    -}
     
    +  def getSchemaFromTableProperties(metadata: CatalogTable): Option[StructType] = {
    +    getSchemaFromTableProperties(metadata.properties)
    +  }
    +
    +  // A persisted data source table may not store its schema in the catalog. In this case, its schema
    +  // will be inferred at runtime when the table is referenced.
    +  def getSchemaFromTableProperties(props: Map[String, String]): Option[StructType] = {
    +    require(isDatasourceTable(props))
    +
    +    val schemaParts = for {
    +      numParts <- props.get("spark.sql.sources.schema.numParts").toSeq
    +      index <- 0 until numParts.toInt
    +    } yield props.getOrElse(
    +      s"spark.sql.sources.schema.part.$index",
    +      throw new AnalysisException(
    +        s"Corrupted schema in catalog: $numParts parts expected, but part $index is missing."
    +      )
    +    )
    +
    +    if (schemaParts.isEmpty) {
    +      None
    +    } else {
    +      Some(DataType.fromJson(schemaParts.mkString).asInstanceOf[StructType])
    +    }
    +  }
    --- End diff --
    
    There was a time when we only used `spark.sql.sources.schema`. Let's check this first and then check `spark.sql.sources.schema.numParts`. You can take a look at `HiveMetastoreCatalog`'s `cachedDataSourceTables`.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/13025#issuecomment-218140818
  
    **[Test build #58231 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/58231/consoleFull)** for PR 13025 at commit [`2eccb6e`](https://github.com/apache/spark/commit/2eccb6e1dbcd47e89cbf5fcd5a79f3a65cee0672).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/13025#issuecomment-218140790
  
    Merged build finished. Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/13025#issuecomment-218140575
  
    **[Test build #58232 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/58232/consoleFull)** for PR 13025 at commit [`54e2618`](https://github.com/apache/spark/commit/54e2618e441d7defe6de436cffe607b0ea24f46f).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/13025#issuecomment-218141035
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/58231/
    Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13025#discussion_r62699825
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala ---
    @@ -489,9 +486,83 @@ private[sql] object DDLUtils {
           case _ =>
         })
       }
    +
       def isTablePartitioned(table: CatalogTable): Boolean = {
    -    table.partitionColumns.size > 0 ||
    +    table.partitionColumns.nonEmpty ||
           table.properties.contains("spark.sql.sources.schema.numPartCols")
       }
    -}
     
    +  def getSchemaFromTableProperties(metadata: CatalogTable): Option[StructType] = {
    +    getSchemaFromTableProperties(metadata.properties)
    +  }
    +
    +  // A persisted data source table may not store its schema in the catalog. In this case, its schema
    +  // will be inferred at runtime when the table is referenced.
    +  def getSchemaFromTableProperties(props: Map[String, String]): Option[StructType] = {
    +    require(isDatasourceTable(props))
    +
    +    val schemaParts = for {
    +      numParts <- props.get("spark.sql.sources.schema.numParts").toSeq
    +      index <- 0 until numParts.toInt
    +    } yield props.getOrElse(
    +      s"spark.sql.sources.schema.part.$index",
    +      throw new AnalysisException(
    +        s"Corrupted schema in catalog: $numParts parts expected, but part $index is missing."
    +      )
    +    )
    +
    +    if (schemaParts.isEmpty) {
    +      None
    +    } else {
    +      Some(DataType.fromJson(schemaParts.mkString).asInstanceOf[StructType])
    +    }
    +  }
    --- End diff --
    
    I will make a commit to handle `spark.sql.sources.schema`. 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-14127][SQL] "DESC

": Extracts sc...Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/13025#issuecomment-218124867
  
    **[Test build #58232 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/58232/consoleFull)** for PR 13025 at commit [`54e2618`](https://github.com/apache/spark/commit/54e2618e441d7defe6de436cffe607b0ea24f46f).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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