You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by an...@apache.org on 2017/01/18 18:34:05 UTC

[1/2] incubator-trafodion git commit: TRAFODION-2442 timestamp/date comparison bug. And couple other fixes.

Repository: incubator-trafodion
Updated Branches:
  refs/heads/master d9e24949b -> bafb29a1f


TRAFODION-2442  timestamp/date comparison bug. And couple other fixes.

-- TRAFODION-2442 timestamp comparison with date returns incorrect results.
  that has been fixed. Date value is expanded to timestamp datatype and
  then compared.
  Fix is for timestamp/date comparison only.
  TIMESTAMP comparison to TIME, and DATE comparison to TIME is not allowed.

-- row length of aligned format tables is now calculated correctly and
  stored in metadata.

-- optimizer cost method for sort had a high limit of MEMORY_UNITS_SIZE
   default set to 20M. For large rows in the range of 10 Mb,
   this caused an overflow.
   Fix is to allocate space for MAXOF default and size of 2 rows.


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

Branch: refs/heads/master
Commit: fe46974da6feb2bf5ba675f1622b07b7ae503a01
Parents: 4261a9d
Author: Anoop Sharma <an...@esgyn.com>
Authored: Tue Jan 17 18:50:25 2017 +0000
Committer: Anoop Sharma <an...@esgyn.com>
Committed: Tue Jan 17 18:50:25 2017 +0000

----------------------------------------------------------------------
 core/sql/optimizer/BindItemExpr.cpp      | 21 +++++++++-
 core/sql/optimizer/costmethod.cpp        |  4 ++
 core/sql/regress/seabase/EXPECTED030     | 59 +++++++++++++++++++++++----
 core/sql/regress/seabase/EXPECTED032     | 17 +++++---
 core/sql/regress/seabase/TEST030         | 14 ++++++-
 core/sql/regress/seabase/TEST032         |  4 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 28 ++++++++++---
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp  | 11 +++++
 8 files changed, 134 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe46974d/core/sql/optimizer/BindItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindItemExpr.cpp b/core/sql/optimizer/BindItemExpr.cpp
index 654653e..bd30515 100644
--- a/core/sql/optimizer/BindItemExpr.cpp
+++ b/core/sql/optimizer/BindItemExpr.cpp
@@ -2424,6 +2424,25 @@ static ItemExpr * ItemExpr_handleIncompatibleComparison(
       tgtOpIndex = 1;
       conversion = 4;
     }
+    else
+    if ((type1.getTypeQualifier() == NA_DATETIME_TYPE) &&
+	(type2.getTypeQualifier() == NA_DATETIME_TYPE) &&
+        (type1.getPrecision() != type2.getPrecision()))
+    {
+      conversion = 8;
+      if (type1.getPrecision() == SQLDTCODE_TIMESTAMP)
+        {
+          // convert op2 to timestamp
+          srcOpIndex = 1;
+          tgtOpIndex = 0;
+        }
+      else
+        {
+          // convert op1 to timestamp
+          srcOpIndex = 0;
+          tgtOpIndex = 1;
+        }
+    }
 
     ItemExpr * newOp = NULL;
 
@@ -2524,7 +2543,7 @@ static ItemExpr * ItemExpr_handleIncompatibleComparison(
 	     (tgtOpIndex == 0 ? op1 : op2)->castToItemExpr()->getValueId().getType().newCopy(bindWA->wHeap()));
       newOp = newOp->bindNode(bindWA);
       break;
-      
+     
       default:
         break;
     }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe46974d/core/sql/optimizer/costmethod.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/costmethod.cpp b/core/sql/optimizer/costmethod.cpp
index e82ff7a..0e4b0c5 100644
--- a/core/sql/optimizer/costmethod.cpp
+++ b/core/sql/optimizer/costmethod.cpp
@@ -4931,6 +4931,10 @@ void CostMethodSort::cacheParameters(RelExpr* op,
   }
 
   Lng32 myRowLength = myVis().getRowLength();
+
+  // allocate space for atleast 2 rows
+  memoryLimit_ = MAXOF(memoryLimit_, 2 * myRowLength);
+
   sortKeyLength_ = sortKeyVis.getRowLength();
   sortRecLength_ = sortKeyLength_ + myRowLength;
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe46974d/core/sql/regress/seabase/EXPECTED030
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/EXPECTED030 b/core/sql/regress/seabase/EXPECTED030
index 68fab15..2cd9c1c 100644
--- a/core/sql/regress/seabase/EXPECTED030
+++ b/core/sql/regress/seabase/EXPECTED030
@@ -536,10 +536,11 @@ March 01, 2016, 10:11:12
 >>drop table if exists t030t1;
 
 --- SQL operation complete.
->>create table t030t1 (a date, b char(30), c varchar(30));
+>>create table t030t1 (a date, b char(30), c varchar(30), d timestamp);
 
 --- SQL operation complete.
->>insert into t030t1 values (date '2016-03-01', '2016-03-01', '2016-03-01');
+>>insert into t030t1 values (date '2016-03-01', '2016-03-01', '2016-03-01', 
++>           timestamp '2017-01-13 13:13:13');
 
 --- 1 row(s) inserted.
 >>
@@ -577,13 +578,41 @@ March 01, 2016, 10:11:12
 --- 1 row(s) selected.
 >>select * from t030t1 where to_date(c, 'YYYY-MM-DD') = DATE '2016-03-01';
 
-A           B                               C
-----------  ------------------------------  ------------------------------
+A           B                               C                               D
+----------  ------------------------------  ------------------------------  --------------------------
 
-2016-03-01  2016-03-01                      2016-03-01                    
+2016-03-01  2016-03-01                      2016-03-01                      2017-01-13 13:13:13.000000
 
 --- 1 row(s) selected.
 >>
+>>select case when timestamp '2017-01-13 13:13:13' > date '2017-01-13' then 'pass' else 'fail' end from dual;
+
+(EXPR)
+------
+
+pass  
+
+--- 1 row(s) selected.
+>>select case when timestamp '2017-01-13 13:13:13' > date '2017-01-14' then 'pass' else 'fail' end from dual;
+
+(EXPR)
+------
+
+fail  
+
+--- 1 row(s) selected.
+>>select * from t030t1 where d > date '2017-01-13';
+
+A           B                               C                               D
+----------  ------------------------------  ------------------------------  --------------------------
+
+2016-03-01  2016-03-01                      2016-03-01                      2017-01-13 13:13:13.000000
+
+--- 1 row(s) selected.
+>>select * from t030t1 where d > date '2017-01-14';
+
+--- 0 row(s) selected.
+>>
 >>-- negative tests
 >>select to_date('2016-03-01', 'YYYYMM-DD') from (values(1)) x(a);
 
@@ -673,10 +702,10 @@ A           B                               C
 --- 0 row(s) selected.
 >>select * from t030t1 where to_date(c, 'YYYY-MM-DD') = '2016-03-01';
 
-A           B                               C
-----------  ------------------------------  ------------------------------
+A           B                               C                               D
+----------  ------------------------------  ------------------------------  --------------------------
 
-2016-03-01  2016-03-01                      2016-03-01                    
+2016-03-01  2016-03-01                      2016-03-01                      2017-01-13 13:13:13.000000
 
 --- 1 row(s) selected.
 >>select to_date('01.03.2016:10:11:12', 'DD.MM.YYYY:HH24:MI:SS') from (values(1)) x(a);
@@ -761,4 +790,18 @@ A           B                               C
 *** ERROR[8822] The statement was not prepared.
 
 >>
+>>-- cannot compare timestamp to time, or date to time
+>>select case when timestamp '2017-01-17 10:10:10' > time '10:10:10' then 'pass' else 'fail' end from dual;
+
+*** ERROR[4041] Type TIMESTAMP(0) cannot be compared with type TIME(0).
+
+*** ERROR[8822] The statement was not prepared.
+
+>>select case when date '2017-01-17' > time '10:10:10' then 'pass' else 'fail' end from dual;
+
+*** ERROR[4041] Type DATE cannot be compared with type TIME(0).
+
+*** ERROR[8822] The statement was not prepared.
+
+>>
 >>log;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe46974d/core/sql/regress/seabase/EXPECTED032
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/EXPECTED032 b/core/sql/regress/seabase/EXPECTED032
index 6658d3a..5a4aa97 100644
--- a/core/sql/regress/seabase/EXPECTED032
+++ b/core/sql/regress/seabase/EXPECTED032
@@ -15,7 +15,7 @@
 >>invoke t032t1;
 
 -- Definition of Trafodion table TRAFODION.SCH.T032T1
--- Definition current  Wed Sep 21 02:57:14 2016
+-- Definition current  Tue Jan 17 18:16:14 2017
 
   (
     A                                INT NO DEFAULT NOT NULL NOT DROPPABLE
@@ -140,7 +140,7 @@ B
 (EXPR)                        
 ------------------------------
 
-RANDOMVAL=323996797           
+RANDOMVAL=1210881081          
 
 --- 1 row(s) selected.
 >>select random() from (values(1)) x(a);
@@ -352,7 +352,7 @@ A            B     C            D           E         F
 
 --- 3 row(s) selected.
 >>
->>select * from (values(1)) x(a) where current_date = current_timestamp;
+>>select * from (values(1)) x(a) where current_date = cast(current_timestamp as date);
 
 A   
 ----
@@ -360,9 +360,14 @@ A
    1
 
 --- 1 row(s) selected.
->>select * from (values(1)) x(a) where current_timestamp(0) = current_timestamp(6);
+>>select * from (values(1)) x(a) where current_timestamp(0) = cast(current_timestamp(6) as timestamp(0));
 
---- 0 row(s) selected.
+A   
+----
+
+   1
+
+--- 1 row(s) selected.
 >>
 >>select cast(1e0 as interval year) from dual;
 
@@ -396,7 +401,7 @@ A
 >>invoke t032t2;
 
 -- Definition of Trafodion table TRAFODION.T032SCH.T032T2
--- Definition current  Wed Sep 21 02:57:30 2016
+-- Definition current  Tue Jan 17 18:16:25 2017
 
   (
     SYSKEY                           LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe46974d/core/sql/regress/seabase/TEST030
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/TEST030 b/core/sql/regress/seabase/TEST030
index 6a79973..f65648b 100644
--- a/core/sql/regress/seabase/TEST030
+++ b/core/sql/regress/seabase/TEST030
@@ -97,8 +97,9 @@ select extract (year from INTERVAL '97-02' YEAR TO MONTH) from (values (1)) as t
 select interval '8' year / 4 from dual;
 
 drop table if exists t030t1;
-create table t030t1 (a date, b char(30), c varchar(30));
-insert into t030t1 values (date '2016-03-01', '2016-03-01', '2016-03-01');
+create table t030t1 (a date, b char(30), c varchar(30), d timestamp);
+insert into t030t1 values (date '2016-03-01', '2016-03-01', '2016-03-01', 
+           timestamp '2017-01-13 13:13:13');
 
 select to_char(a, 'YYYYMMDD') from t030t1;
 select a (date, format 'YYYYMMDD') from t030t1;
@@ -106,6 +107,11 @@ select to_date(b, 'YYYY-MM-DD') from t030t1;
 select to_date(c, 'YYYY-MM-DD') from t030t1;
 select * from t030t1 where to_date(c, 'YYYY-MM-DD') = DATE '2016-03-01';
 
+select case when timestamp '2017-01-13 13:13:13' > date '2017-01-13' then 'pass' else 'fail' end from dual;
+select case when timestamp '2017-01-13 13:13:13' > date '2017-01-14' then 'pass' else 'fail' end from dual;
+select * from t030t1 where d > date '2017-01-13';
+select * from t030t1 where d > date '2017-01-14';
+
 -- negative tests
 select to_date('2016-03-01', 'YYYYMM-DD') from (values(1)) x(a);
 select to_date(DATE '2016-03-01', 'YYYY-MM-DD') from (values(1)) x(a);
@@ -140,4 +146,8 @@ select to_date(-12345678, '99:99:99:99') from (values(1)) x(a);
 select to_date(1e0, '99:99:99:99') from (values(1)) x(a);
 select to_date(1.2, '99:99:99:99') from (values(1)) x(a);
 
+-- cannot compare timestamp to time, or date to time
+select case when timestamp '2017-01-17 10:10:10' > time '10:10:10' then 'pass' else 'fail' end from dual;
+select case when date '2017-01-17' > time '10:10:10' then 'pass' else 'fail' end from dual;
+
 log;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe46974d/core/sql/regress/seabase/TEST032
----------------------------------------------------------------------
diff --git a/core/sql/regress/seabase/TEST032 b/core/sql/regress/seabase/TEST032
index c16fd8e..29d32db 100644
--- a/core/sql/regress/seabase/TEST032
+++ b/core/sql/regress/seabase/TEST032
@@ -94,8 +94,8 @@ insert into t032t1 values ('3', 3, 3, date '2016-08-15',  time '10:11:12',
                            timestamp '2016-08-15 10:11:12', 4e0);
 select * from t032t1;
 
-select * from (values(1)) x(a) where current_date = current_timestamp;
-select * from (values(1)) x(a) where current_timestamp(0) = current_timestamp(6);
+select * from (values(1)) x(a) where current_date = cast(current_timestamp as date);
+select * from (values(1)) x(a) where current_timestamp(0) = cast(current_timestamp(6) as timestamp(0));
 
 select cast(1e0 as interval year) from dual;
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe46974d/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index 0efc74b..523c729 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -4808,15 +4808,33 @@ short CmpSeabaseDDL::updateSeabaseMDTable(
         }
 
       rowDataLength += colInfo->length + (colInfo->nullable ? 1 : 0);
-      rowTotalLength +=  colInfo->length + (colInfo->nullable ? 1 : 0) +
-        keyLength +
-        sizeof(Int64)/*timestamp*/ +
-        (colInfo->hbaseColFam ? strlen(colInfo->hbaseColFam) : strlen(SEABASE_DEFAULT_COL_FAMILY)) +
-         (colInfo->hbaseColQual ? strlen(colInfo->hbaseColQual) : 2);
+
+      // compute HBase cell overhead.
+      // For each stored cell/column, overhead is:
+      //  timestamp, colFam, colQual, rowKey
+      // For aligned format tables, only one cell is stored.
+      // The overhead will be computed after exiting the 'for' loop.
+      if ((!tableInfo) || 
+          (tableInfo->rowFormat != COM_ALIGNED_FORMAT_TYPE))
+        {
+          rowTotalLength +=  colInfo->length + (colInfo->nullable ? 1 : 0) +
+            keyLength +
+            sizeof(Int64)/*timestamp*/ +
+            (colInfo->hbaseColFam ? strlen(colInfo->hbaseColFam) : strlen(SEABASE_DEFAULT_COL_FAMILY)) +
+            (colInfo->hbaseColQual ? strlen(colInfo->hbaseColQual) : 2);
+        }
 
       colInfo += 1;
     } // for
 
+  if (tableInfo && tableInfo->rowFormat == COM_ALIGNED_FORMAT_TYPE)
+    {
+      // one cell contains the aligned row
+      rowTotalLength = rowDataLength + keyLength +
+        sizeof(Int64)/*timestamp*/ +
+        strlen(SEABASE_DEFAULT_COL_FAMILY) + 2/* 2 bytes for col qual #1*/;
+    }
+
   if (useRWRS)
     {
       cliRC = rwrsCliInterface.rwrsClose();

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/fe46974d/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index 768e419..4e805a6 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@ -649,6 +649,17 @@ short CmpSeabaseDDL::createSeabaseTableExternal(
       if (retcode)
         return -1;
 
+      if (length > 1048576)
+        {
+          *CmpCommon::diags()
+            << DgSqlCode(-4247)
+            << DgInt0(length)
+            << DgInt1(1048576) 
+            << DgString0(naCol->getColName().data());
+          
+          return -1;
+        }
+
       colInfoArray[index].colName = naCol->getColName().data(); 
       colInfoArray[index].colNumber = index;
       colInfoArray[index].columnClass = COM_USER_COLUMN;


[2/2] incubator-trafodion git commit: Merge [TRAFODION-2442] PR-916 timestamp/date comparison bug. And couple other fixes

Posted by an...@apache.org.
Merge [TRAFODION-2442] PR-916 timestamp/date comparison bug. And couple other fixes


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

Branch: refs/heads/master
Commit: bafb29a1fd02c4f371ad2c1064107470d6ed4697
Parents: d9e2494 fe46974
Author: Anoop Sharma <an...@esgyn.com>
Authored: Wed Jan 18 18:33:46 2017 +0000
Committer: Anoop Sharma <an...@esgyn.com>
Committed: Wed Jan 18 18:33:46 2017 +0000

----------------------------------------------------------------------
 core/sql/optimizer/BindItemExpr.cpp      | 21 +++++++++-
 core/sql/optimizer/costmethod.cpp        |  4 ++
 core/sql/regress/seabase/EXPECTED030     | 59 +++++++++++++++++++++++----
 core/sql/regress/seabase/EXPECTED032     | 17 +++++---
 core/sql/regress/seabase/TEST030         | 14 ++++++-
 core/sql/regress/seabase/TEST032         |  4 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 28 ++++++++++---
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp  | 11 +++++
 8 files changed, 134 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/bafb29a1/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------