Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.apache.spark.sql.catalyst.expressions.Attribute
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.execution.SparkPlan
import org.apache.spark.sql.hive.client.HiveClientImpl
import org.apache.spark.sql.util.SchemaUtils

/**
* Command for writing the results of `query` to file system.
Expand Down Expand Up @@ -61,6 +62,10 @@ case class InsertIntoHiveDirCommand(

override def run(sparkSession: SparkSession, child: SparkPlan): Seq[Row] = {
assert(storage.locationUri.nonEmpty)
SchemaUtils.checkColumnNameDuplication(
outputColumnNames,
s"when inserting into ${storage.locationUri.get}",
sparkSession.sessionState.conf.caseSensitiveAnalysis)

val hiveTable = HiveClientImpl.toHiveTable(CatalogTable(
identifier = TableIdentifier(storage.locationUri.get.toString, Some("default")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.apache.spark.sql.{QueryTest, _}
import org.apache.spark.sql.catalyst.parser.ParseException
import org.apache.spark.sql.catalyst.plans.logical.InsertIntoTable
import org.apache.spark.sql.hive.test.TestHiveSingleton
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.test.SQLTestUtils
import org.apache.spark.sql.types._
import org.apache.spark.util.Utils
Expand Down Expand Up @@ -750,4 +751,27 @@ class InsertSuite extends QueryTest with TestHiveSingleton with BeforeAndAfter
}
}
}

Seq("LOCAL", "").foreach { local =>
Seq(true, false).foreach { caseSensitivity =>
Seq("orc", "parquet").foreach { format =>
test(s"SPARK-25389 INSERT OVERWRITE $local DIRECTORY ... STORED AS with duplicated names" +
s"(caseSensitivity=$caseSensitivity, format=$format)") {
withTempDir { dir =>
withSQLConf(SQLConf.CASE_SENSITIVE.key -> s"$caseSensitivity") {
val m = intercept[AnalysisException] {
sql(
s"""
|INSERT OVERWRITE $local DIRECTORY '${dir.toURI}'
|STORED AS $format
|SELECT 'id', 'id2' ${if (caseSensitivity) "id" else "ID"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we miss a comma after 'id2'?

Copy link
Member Author

@dongjoon-hyun dongjoon-hyun Sep 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id2 is value and the following one appends alias; id or ID.

""".stripMargin)
}.getMessage
assert(m.contains("Found duplicate column(s) when inserting into"))
}
}
}
}
}
}
}