Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10733#discussion_r49819690
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/CreateViewAsSelect.scala
 ---
    @@ -44,26 +47,36 @@ private[hive] case class CreateViewAsSelect(
       override def run(sqlContext: SQLContext): Seq[Row] = {
         val hiveContext = sqlContext.asInstanceOf[HiveContext]
     
    -    if (hiveContext.catalog.tableExists(tableIdentifier)) {
    -      if (allowExisting) {
    +    hiveContext.catalog.tableExists(tableIdentifier) match {
    +      case true if allowExisting =>
             // view already exists, will do nothing, to keep consistent with 
Hive
    -      } else if (orReplace) {
    -        hiveContext.catalog.client.alertView(prepareTable())
    -      } else {
    +
    +      case true if orReplace =>
    +        hiveContext.catalog.client.alertView(prepareTable(sqlContext))
    +
    +      case true =>
             throw new AnalysisException(s"View $tableIdentifier already 
exists. " +
               "If you want to update the view definition, please use ALTER 
VIEW AS or " +
               "CREATE OR REPLACE VIEW AS")
    -      }
    -    } else {
    -      hiveContext.catalog.client.createView(prepareTable())
    +
    +      case false =>
    +        hiveContext.catalog.client.createView(prepareTable(sqlContext))
         }
     
         Seq.empty[Row]
       }
     
    -  private def prepareTable(): HiveTable = {
    -    // setup column types according to the schema of child.
    -    val schema = if (tableDesc.schema == Nil) {
    +  private def prepareTable(sqlContext: SQLContext): HiveTable = {
    +    val expandedText = if (sqlContext.conf.canonicalView) {
    +      rebuildViewQueryString(sqlContext).getOrElse(expandViewText)
    +    } else {
    +      expandViewText
    +    }
    +    tableDesc.copy(schema = viewSchema, viewText = Some(expandedText))
    +  }
    +
    +  private def viewSchema: Seq[HiveColumn] = {
    --- End diff --
    
    Should we inline this?


---
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.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to