Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10498#discussion_r48842647
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/DataFrameWriter.scala ---
    @@ -189,13 +220,47 @@ final class DataFrameWriter private[sql](df: 
DataFrame) {
             ifNotExists = false)).toRdd
       }
     
    -  private def normalizedParCols: Option[Seq[String]] = 
partitioningColumns.map { parCols =>
    -    parCols.map { col =>
    -      df.logicalPlan.output
    -        .map(_.name)
    -        .find(df.sqlContext.analyzer.resolver(_, col))
    -        .getOrElse(throw new AnalysisException(s"Partition column $col not 
found in existing " +
    -          s"columns (${df.logicalPlan.output.map(_.name).mkString(", 
")})"))
    +  private def normalizedParCols: Option[Seq[String]] = 
partitioningColumns.map { cols =>
    +    cols.map(normalize(_, "Partition"))
    +  }
    +
    +  private def normalizedBucketColNames: Option[Seq[String]] = 
bucketColumnNames.map { cols =>
    +    cols.map(normalize(_, "Bucketing"))
    +  }
    +
    +  private def normalizedSortColNames: Option[Seq[String]] = 
sortColumnNames.map { cols =>
    +    cols.map(normalize(_, "Sorting"))
    +  }
    +
    +  private def getBucketSpec: Option[BucketSpec] = {
    +    if (sortColumnNames.isDefined) {
    +      require(numBuckets.isDefined, "sortBy must be used together with 
bucketBy")
    +    }
    +
    +    for {
    +      n <- numBuckets
    +    } yield {
    +      require(n > 0, "Bucket number must be greater than 0.")
    +      BucketSpec(n, normalizedBucketColNames.get, 
normalizedSortColNames.getOrElse(Nil))
    +    }
    +  }
    +
    +  /**
    +   * The given column name may not be equal to any of the existing column 
names if we were in
    +   * case-insensitive context.  Normalize the given column name to the 
real one so that we don't
    +   * need to care about case sensitivity afterwards.
    +   */
    +  private def normalize(columnName: String, columnType: String): String = {
    +    val validColumnNames = df.logicalPlan.output.map(_.name)
    +    validColumnNames.find(df.sqlContext.analyzer.resolver(_, columnName))
    +      .getOrElse(throw new AnalysisException(s"$columnType column 
$columnName not found in " +
    +        s"existing columns (${validColumnNames.mkString(", ")})"))
    +  }
    +
    +  private def assertNotBucketed(): Unit = {
    +    if (numBuckets.isDefined || sortColumnNames.isDefined) {
    --- End diff --
    
    previous discussion: 
https://github.com/apache/spark/pull/10498#discussion_r48818408


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