trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sure...@apache.org
Subject [1/3] incubator-trafodion git commit: [TRAFODION-2247] upsert on altered aligned format table with missing columns inserts incorrect values
Date Wed, 05 Oct 2016 00:56:57 GMT
Repository: incubator-trafodion
Updated Branches:
  refs/heads/master d223ed9c6 -> 392cb6a71


[TRAFODION-2247] upsert on altered aligned format table with missing columns inserts incorrect
values

While generating mergeInsertExpr or updateExpr, the added columns were not considered. This
resulted
in incorrect relative offset value in the expressions in case of aligned row format and the
row got
corrupted.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/4d31d6e2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/4d31d6e2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/4d31d6e2

Branch: refs/heads/master
Commit: 4d31d6e21c54b976a97eeeba3694003744838718
Parents: 70f7fc0
Author: selvaganesang <selva.govindarajan@esgyn.com>
Authored: Fri Sep 30 23:37:28 2016 +0000
Committer: selvaganesang <selva.govindarajan@esgyn.com>
Committed: Sat Oct 1 00:29:05 2016 +0000

----------------------------------------------------------------------
 core/sql/generator/GenRelUpdate.cpp             | 150 ++-----------------
 core/sql/regress/seabase/EXPECTED020            |  22 +++
 core/sql/regress/seabase/TEST020                |  10 ++
 .../phoenix/end2end/MultiCfQueryExecTest.java   |   9 --
 .../end2end/SaltedTableUpsertSelectTest.java    |   2 +-
 5 files changed, 47 insertions(+), 146 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4d31d6e2/core/sql/generator/GenRelUpdate.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenRelUpdate.cpp b/core/sql/generator/GenRelUpdate.cpp
index e5fac6c..5713181 100644
--- a/core/sql/generator/GenRelUpdate.cpp
+++ b/core/sql/generator/GenRelUpdate.cpp
@@ -292,141 +292,6 @@ static short genUpdExpr(
   return 0;
 }
 
-static short genMergeInsertExpr(
-        Generator * generator, 
-        TableDesc * tableDesc,             // IN
-        const IndexDesc * indexDesc,       // IN
-        ValueIdArray &mergeInsertRecExprArray,  // IN
-        const Int32 mergeInsertKeyEncodeAtpIndex, // IN
-        const Int32 mergeInsertRowAtpIndex,       // IN
-        ex_expr** mergeInsertKeyEncodeExpr,     // OUT
-        ULng32 &mergeInsertKeyLen,       // OUT
-        ex_expr** mergeInsertExpr,        // OUT
-	ULng32 &mergeInsertRowLen, // OUT
-        ExpTupleDesc** mergeInsertRowTupleDesc)     // OUT fetched/updated RowTupleDesc,
-{
-  ExpGenerator * expGen = generator->getExpGenerator();
-
-  *mergeInsertKeyEncodeExpr = NULL;
-  mergeInsertKeyLen = 0;
-  *mergeInsertExpr = NULL;
-  mergeInsertRowLen = 0;
-
-  // Generate the update expression that will create the updated row
-  // given to DP2 at runtime.
-  ValueIdList mergeInsertRowVidList;
-  BaseColumn *updtCol       = NULL,
-             *fetchedCol    = NULL;
-  Lng32        updtColNum    = -1,
-              fetchedColNum = 0;
-  ItemExpr   *updtColVal    = NULL,
-             *castNode      = NULL;
-  CollIndex   recEntries    = mergeInsertRecExprArray.entries(),
-              colEntries    = indexDesc->getIndexColumns().entries(),
-              j             = 0;
-  NAColumnArray colArray;
-  NAColumn *col;
-
-  if (recEntries == 0)
-    return 0;
-
-  ExpTupleDesc::TupleDataFormat tupleFormat = 
-                   generator->getTableDataFormat( tableDesc->getNATable(), indexDesc);
-
-  NABoolean alignedFormat = (tupleFormat == ExpTupleDesc::SQLMX_ALIGNED_FORMAT);
-  
-  for (CollIndex ii = 0; ii < mergeInsertRecExprArray.entries(); ii++)
-    {
-      const ItemExpr *assignExpr = mergeInsertRecExprArray[ii].getItemExpr();
-
-      ValueId tgtValueId = assignExpr->child(0)->castToItemExpr()->getValueId();
-      ValueId srcValueId = assignExpr->child(1)->castToItemExpr()->getValueId();
-
-      // populate the colArray because this info is needed later to identify 
-      // the added columns. 
-      if ( alignedFormat )
-      {
-        col = tgtValueId.getNAColumn( TRUE );
-        if ( col != NULL )
-          colArray.insert( col );
-      }
-      
-      ItemExpr * ie = NULL;
-
-      ie = new(generator->wHeap())
-	    Cast(assignExpr->child(1), &tgtValueId.getType());
-     
-      ie->bindNode(generator->getBindWA());
-      mergeInsertRowVidList.insert(ie->getValueId());
-    }
-
-  // Tell the expression generator that we're coming in for an insert
-  // or an update.  This flag will be cleared in generateContigousMoveExpr.
-  if ( tupleFormat == ExpTupleDesc::SQLMX_FORMAT ||
-       tupleFormat == ExpTupleDesc::SQLMX_ALIGNED_FORMAT )
-    expGen->setForInsertUpdate( TRUE );
-
-  // Generate the insert expression
-  //
-  expGen->generateContiguousMoveExpr
-    (mergeInsertRowVidList,
-     // (IN) Don't add convert nodes, Cast's have already been done.
-     0,
-     // (IN) Destination Atp
-     1, 
-     // (IN) Destination Atp index
-     mergeInsertRowAtpIndex,
-     // (IN) Destination data format
-     tupleFormat,
-     // (OUT) Destination tuple length
-     mergeInsertRowLen,
-     // (OUT) Generated expression
-     mergeInsertExpr, 
-     // (OUT) Tuple descriptor for destination tuple
-     mergeInsertRowTupleDesc, 
-     // (IN) Tuple descriptor format
-     ExpTupleDesc::LONG_FORMAT,
-     NULL, NULL, 0, NULL, NULL,
-     &colArray); // colArray is needed to identify any added cols.
-  
-  // Assign attributes to the ASSIGN nodes of the newRecExpArray()
-  // This is not the same as the generateContiguousMoveExpr() call
-  // above since different valueId's are added to the mapTable.
-  // 
-  expGen->processValIdList(mergeInsertRecExprArray,
-			   tupleFormat,
-			   mergeInsertRowLen,
-			   1, 
-			   mergeInsertRowAtpIndex,
-			   mergeInsertRowTupleDesc,
-			   ExpTupleDesc::LONG_FORMAT,
-                           0,NULL,&colArray,
-                           !indexDesc->isClusteringIndex());
-
-
-  for (CollIndex i = 0; i < indexDesc->getIndexColumns().entries();
-       i++) 
-    {
-      generator->addMapInfo(
-	   (indexDesc->getIndexColumns())[i],
-	   generator->getMapInfo(mergeInsertRecExprArray[i])->getAttr()
-	   )->getAttr()->setAtp(0);
-    }
-  
-    ULng32 f;
-    expGen->generateKeyEncodeExpr(
-	 indexDesc,                              // describes the columns
-	 0,                                      // work Atp
-	 mergeInsertKeyEncodeAtpIndex,                // work Atp entry #3
-	 ExpTupleDesc::SQLMX_KEY_FORMAT,         // Tuple format
-	 mergeInsertKeyLen,                           // Key length
-	 mergeInsertKeyEncodeExpr,                    // Encode expression
-	 FALSE,                                  // don't optimize key encoding
-	 f);
-
-  return 0;
-}
-
 static short genUpdConstraintExpr(Generator *generator)
 {
   return 0;
@@ -470,6 +335,8 @@ static short genHbaseUpdOrInsertExpr(
   if (updRecExprArray.entries() > 0)
     listOfUpdatedColNames = new(space) Queue(space);
 
+  NAColumnArray colArray;
+  NAColumn *col;
 
   for (CollIndex ii = 0; ii < updRecExprArray.entries(); ii++)
     {
@@ -479,6 +346,15 @@ static short genHbaseUpdOrInsertExpr(
       ValueId tgtValueId = assignExpr->child(0)->castToItemExpr()->getValueId();
       ValueId srcValueId = assignExpr->child(1)->castToItemExpr()->getValueId();
 
+      // populate the colArray because this info is needed later to identify 
+      // the added columns. 
+      if ( isAligned )
+      {
+        col = tgtValueId.getNAColumn( TRUE );
+        if ( col != NULL )
+          colArray.insert( col );
+      }
+
       ItemExpr * ie = NULL;
 
       ie = new(generator->wHeap())
@@ -539,7 +415,9 @@ static short genHbaseUpdOrInsertExpr(
      updateRowLen,      // (OUT) Destination tuple length
      updateExpr,  // (OUT) Generated expression
      updateTupleDesc, // (OUT) Tuple descriptor for destination tuple
-     ExpTupleDesc::LONG_FORMAT);
+     ExpTupleDesc::LONG_FORMAT,
+     NULL, NULL, 0, NULL, NULL,
+     &colArray); // colArray is needed to identify any added cols.
   
   // Assign attributes to the ASSIGN nodes of the newRecExpArray()
   // This is not the same as the generateContiguousMoveExpr() call

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4d31d6e2/core/sql/regress/seabase/EXPECTED020
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/EXPECTED020 b/core/sql/regress/seabase/EXPECTED020
index 37c7b84..d452f19 100644
--- a/core/sql/regress/seabase/EXPECTED020
+++ b/core/sql/regress/seabase/EXPECTED020
@@ -3936,4 +3936,26 @@ C1           C2
 
 --- 2 row(s) selected.
 >>
+>>obey TEST020(trafodion_2247);
+>>create table test020t44(a char(15) not null primary key,b int)
++>attribute aligned format;
+
+--- SQL operation complete.
+>>alter table test020t44 add c int;
+
+--- SQL operation complete.
+>>cqd traf_upsert_mode 'merge';
+
+--- SQL operation complete.
+>>upsert into test020t44 (a,c) values ('AAAA', 2);
+
+--- 1 row(s) inserted.
+>>select * from test020t44;
+A                B            C          
+---------------  -----------  -----------
+
+AAAA                       ?            2
+
+--- 1 row(s) selected.
+>>
 >>log;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4d31d6e2/core/sql/regress/seabase/TEST020
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/TEST020 b/core/sql/regress/seabase/TEST020
index 6ae7718..6f68b54 100755
--- a/core/sql/regress/seabase/TEST020
+++ b/core/sql/regress/seabase/TEST020
@@ -40,6 +40,7 @@ obey TEST020(test_10_020913_3920);
 obey TEST020(test_10_030916_9668);
 obey TEST020(test_LP_1360493);
 obey TEST020(trafodion_1700_and_1847);
+obey TEST020(trafodion_2247);
 log;
 obey TEST020(clean_up);
 exit;
@@ -91,6 +92,7 @@ drop table test020t40 cascade;
 drop table test020t41 cascade;
 drop table test020t42 cascade;
 drop table test020t43 cascade;
+drop table test020t44;
 
 ?section tests
 create table  test020t1 (c1 int not null primary key,
@@ -919,3 +921,11 @@ upsert into test020t43 values (1,1);
 upsert into test020t43 (c1) values(1);
 select * from test020t43 ; 
 
+?section trafodion_2247
+create table test020t44(a char(15) not null primary key,b int) 
+attribute aligned format;
+alter table test020t44 add c int;
+cqd traf_upsert_mode 'merge';
+upsert into test020t44 (a,c) values ('AAAA', 2);
+select * from test020t44;
+

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4d31d6e2/tests/phx/src/test/java/org/trafodion/phoenix/end2end/MultiCfQueryExecTest.java
----------------------------------------------------------------------
diff --git a/tests/phx/src/test/java/org/trafodion/phoenix/end2end/MultiCfQueryExecTest.java
b/tests/phx/src/test/java/org/trafodion/phoenix/end2end/MultiCfQueryExecTest.java
index ee5b7e1..ae5e246 100644
--- a/tests/phx/src/test/java/org/trafodion/phoenix/end2end/MultiCfQueryExecTest.java
+++ b/tests/phx/src/test/java/org/trafodion/phoenix/end2end/MultiCfQueryExecTest.java
@@ -234,15 +234,6 @@ public class MultiCfQueryExecTest extends BaseTest {
 
         PreparedStatement statement;
 
-        // BEGIN TEMP: until jira TRAFODION-2247 is fixed.
-        // Remove the begin/end temp block after that
-        if (tgtTR()) {
-            dml = "control query default traf_upsert_mode 'REPLACE'";
-            statement = conn.prepareStatement(dml);
-            statement.execute();
-        }
-        // END TEMP:
-
         if (tgtPH()||tgtTR()) dml = "upsert into " +
         "MULTI_CF(" +
         "    ID, " +

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4d31d6e2/tests/phx/src/test/java/org/trafodion/phoenix/end2end/SaltedTableUpsertSelectTest.java
----------------------------------------------------------------------
diff --git a/tests/phx/src/test/java/org/trafodion/phoenix/end2end/SaltedTableUpsertSelectTest.java
b/tests/phx/src/test/java/org/trafodion/phoenix/end2end/SaltedTableUpsertSelectTest.java
index 7b98684..32f7bcc 100644
--- a/tests/phx/src/test/java/org/trafodion/phoenix/end2end/SaltedTableUpsertSelectTest.java
+++ b/tests/phx/src/test/java/org/trafodion/phoenix/end2end/SaltedTableUpsertSelectTest.java
@@ -236,7 +236,7 @@ public class SaltedTableUpsertSelectTest extends BaseTest {
             String query = null;
 
             PreparedStatement stmt;
-            // BEGIN TEMP: until jira TRAFODION-2247 is fixed.
+            // BEGIN TEMP: until jira TRAFODION-2254 is fixed.
             // Remove the begin/end temp block after that
             if (tgtTR()) {
                 query = "control query default traf_upsert_mode 'REPLACE'";


Mime
View raw message