Github user jaceklaskowski commented on a diff in the pull request: https://github.com/apache/spark/pull/14410#discussion_r73051607 --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala --- @@ -1457,6 +1457,59 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { } } + test("saveAsTable(CTAS) when the source DataFrame is built on a Hive table") { + val tableName = "tab1" + withTable(tableName) { + sql(s"CREATE TABLE $tableName stored as SEQUENCEFILE as select 1 as key, 'abc' as value") + val df = sql(s"select key, value as value from $tableName") + + val message = intercept[AnalysisException] { + df.write.mode("append").saveAsTable(tableName) + }.getMessage + assert(message.contains( + "saveAsTable() for Hive tables is not supported yet. " + + "Please use insertInto() as an alternative")) + } + } + + test("saveAsTable(CTAS) and insertInto when the source DataFrame is built on Data Source") { + val tableName = "tab1" + withTable(tableName) { + val schema = StructType( + StructField("key", IntegerType, nullable = false) :: + StructField("value", IntegerType, nullable = true) :: Nil) + val row = Row(3, 4) + val df = spark.createDataFrame(sparkContext.parallelize(row :: Nil), schema) + + df.write.format("json").mode("overwrite").saveAsTable(tableName) + df.write.format("json").mode("append").saveAsTable(tableName) + checkAnswer( + sql(s"SELECT key, value FROM $tableName"), + Row(3, 4) :: Row(3, 4) :: Nil + ) + + (1 to 2).map { i => (i, i) }.toDF("key", "value").write.insertInto(tableName) + checkAnswer( + sql(s"SELECT key, value FROM $tableName"), + Row(1, 1) :: Row(2, 2) :: Row(3, 4) :: Row(3, 4) :: Nil + ) + } + } + + test("insertInto when the source DataFrame is built on a Hive table") { + val tableName = "tab1" + withTable(tableName) { + sql(s"CREATE TABLE $tableName stored as SEQUENCEFILE as select 1 as key, 'abc' as value") + val df = sql(s"select key, value as value from $tableName") --- End diff -- Is there a reason why you're using lowercase variant of the query in `sql` while `CREATE TABLE` above is uppercase? It seems inconsistent.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org