|
17 | 17 |
|
18 | 18 | package org.apache.spark.sql |
19 | 19 |
|
20 | | -import org.apache.spark.sql.sources.QueryPlanningException |
21 | | - |
22 | 20 | import scala.language.postfixOps |
23 | 21 |
|
24 | 22 | import org.apache.spark.sql.functions._ |
25 | 23 | import org.apache.spark.sql.types._ |
26 | 24 | import org.apache.spark.sql.test.{ExamplePointUDT, ExamplePoint} |
27 | 25 |
|
28 | | - |
29 | 26 | class DataFrameSuite extends QueryTest { |
30 | 27 | import org.apache.spark.sql.TestData._ |
31 | 28 |
|
@@ -764,24 +761,35 @@ class DataFrameSuite extends QueryTest { |
764 | 761 | assert(!f.getMessage.contains("column2")) |
765 | 762 | } |
766 | 763 |
|
767 | | - test("SPARK-6941: Better Error Message for inserting into RDD-based Table") { |
| 764 | + test("SPARK-6941: Better error message for inserting into RDD-based Table") { |
768 | 765 | val df = Seq(Tuple1(1)).toDF("col") |
769 | | - df.registerTempTable("rdd_base") |
| 766 | + val insertion = Seq(Tuple1(2)).toDF("col") |
770 | 767 |
|
771 | | - df.write.parquet("tmp_parquet") |
| 768 | + // pass case: parquet table (HadoopFsRelation) |
| 769 | + df.write.mode(SaveMode.Overwrite).parquet("tmp_parquet") |
772 | 770 | val pdf = ctx.read.parquet("tmp_parquet") |
773 | 771 | pdf.registerTempTable("parquet_base") |
| 772 | + insertion.write.insertInto("parquet_base") |
774 | 773 |
|
775 | | - df.write.json("tmp_json") |
| 774 | + // pass case: json table (InsertableRelation) |
| 775 | + df.write.mode(SaveMode.Overwrite).json("tmp_json") |
776 | 776 | val jdf = ctx.read.json("tmp_json") |
777 | 777 | jdf.registerTempTable("json_base") |
| 778 | + insertion.write.mode(SaveMode.Overwrite).insertInto("json_base") |
778 | 779 |
|
779 | | - val insertion = Seq(Tuple1(2)).toDF("col") |
780 | | - val e = intercept[QueryPlanningException] { |
| 780 | + // error cases: insert into a RDD |
| 781 | + df.registerTempTable("rdd_base") |
| 782 | + val e1 = intercept[AnalysisException] { |
781 | 783 | insertion.write.insertInto("rdd_base") |
782 | 784 | } |
783 | | - assert(e.getMessage.contains("Attempt to insert into a RDD-based table")) |
784 | | - insertion.write.insertInto("parquet_base") |
785 | | - insertion.write.mode(SaveMode.Overwrite).insertInto("json_base") |
| 785 | + assert(e1.getMessage.contains("Attempt to insert into a RDD-based table")) |
| 786 | + |
| 787 | + // error case: insert into a RDD based on data source |
| 788 | + val indirectDS = pdf.select("col").filter($"col" > 5) |
| 789 | + indirectDS.registerTempTable("indirect_ds") |
| 790 | + val e2 = intercept[AnalysisException] { |
| 791 | + insertion.write.insertInto("indirect_ds") |
| 792 | + } |
| 793 | + assert(e2.getMessage.contains("Attempt to insert into a RDD-based table")) |
786 | 794 | } |
787 | 795 | } |
0 commit comments