You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by ja...@apache.org on 2020/01/06 14:14:47 UTC

[carbondata] branch master updated: [CARBONDATA-3652] Make insert and select table columns equal

This is an automated email from the ASF dual-hosted git repository.

jackylk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/carbondata.git


The following commit(s) were added to refs/heads/master by this push:
     new 868ece6  [CARBONDATA-3652] Make insert and select table columns equal
868ece6 is described below

commit 868ece61ec2ac20d7b55cd75ae8473dab03f3c84
Author: 沈洪 <yu...@alipay.com>
AuthorDate: Fri Jan 3 19:41:06 2020 +0800

    [CARBONDATA-3652] Make insert and select table columns equal
    
    Why is this PR needed?
    
    Described in https://issues.apache.org/jira/browse/CARBONDATA-3652
    
    What changes were proposed in this PR?
    
    Insert and select table columns should equal.
    
    Does this PR introduce any user interface change?
    
    No
    
    Is any new testcase added?
    
    Yes
    
    This closesd #3559
---
 .../allqueries/InsertIntoCarbonTableTestCase.scala         | 14 ++++++++++++++
 .../org/apache/spark/sql/hive/CarbonAnalysisRules.scala    |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/allqueries/InsertIntoCarbonTableTestCase.scala b/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/allqueries/InsertIntoCarbonTableTestCase.scala
index fb1c801..8cca047 100644
--- a/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/allqueries/InsertIntoCarbonTableTestCase.scala
+++ b/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/allqueries/InsertIntoCarbonTableTestCase.scala
@@ -381,6 +381,18 @@ class InsertIntoCarbonTableTestCase extends QueryTest with BeforeAndAfterAll {
     assert(sql("show segments for table show_insert").collect().length == 1)
   }
 
+  test("insert and select table column number not equal") {
+    sql("DROP TABLE IF EXISTS table1")
+    sql("DROP TABLE IF EXISTS table2")
+    sql("create table table1 (col1 string, col2 string) partitioned by(pt string) stored by 'carbondata'")
+    sql("create table table2 (t2_c1 string, t2_c2 string, t2_c3 string) partitioned by(pt string)")
+    sql("insert overwrite table table2 partition(pt=20200101) values('v11', 'v12', 'v13')")
+    val e = intercept[Exception] {
+      sql("insert into table1 select * from table2")
+    }
+    assert(e.getMessage.contains("number of columns are different"))
+  }
+
   override def afterAll {
     sql("drop table if exists load")
     sql("drop table if exists inser")
@@ -402,6 +414,8 @@ class InsertIntoCarbonTableTestCase extends QueryTest with BeforeAndAfterAll {
     sql("DROP TABLE IF EXISTS show_insert")
     sql("drop table if exists OverwriteTable_t1")
     sql("drop table if exists OverwriteTable_t2")
+    sql("drop table if exists table1")
+    sql("drop table if exists table2")
 
     if (timeStampPropOrig != null) {
       CarbonProperties.getInstance()
diff --git a/integration/spark2/src/main/scala/org/apache/spark/sql/hive/CarbonAnalysisRules.scala b/integration/spark2/src/main/scala/org/apache/spark/sql/hive/CarbonAnalysisRules.scala
index 0c6b5aa..5323293 100644
--- a/integration/spark2/src/main/scala/org/apache/spark/sql/hive/CarbonAnalysisRules.scala
+++ b/integration/spark2/src/main/scala/org/apache/spark/sql/hive/CarbonAnalysisRules.scala
@@ -285,7 +285,7 @@ case class CarbonPreInsertionCasts(sparkSession: SparkSession) extends Rule[Logi
     }
     // In spark, PreprocessTableInsertion rule has below cast logic.
     // It was missed in carbon when implemented insert into rules.
-    var newChildOutput = if (child.output.size >= carbonDSRelation.carbonRelation.output.size) {
+    var newChildOutput = if (child.output.size == carbonDSRelation.carbonRelation.output.size) {
       val expectedOutput = carbonDSRelation.carbonRelation.output
       child.output.zip(expectedOutput).map {
         case (actual, expected) =>