Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 657510219 -> f9eaa7675


[TRAFODION-2121] add support of HIVE data type of DECIMAL


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

Branch: refs/heads/master
Commit: ad6c2f3eecde12fa50c95a1b8f22b53fb4534625
Parents: 81a455e
Author: Liu Ming <[email protected]>
Authored: Sat Jul 23 23:58:56 2016 +0000
Committer: Liu Ming <[email protected]>
Committed: Sat Jul 23 23:58:56 2016 +0000

----------------------------------------------------------------------
 core/sql/executor/ExExeUtilGet.cpp       |  2 +-
 core/sql/executor/hiveHook.cpp           |  4 +--
 core/sql/optimizer/NATable.cpp           | 52 +++++++++++++++++++++++++--
 core/sql/regress/hive/EXPECTED005        | 12 +++----
 core/sql/regress/hive/TEST005_a.hive.sql |  8 +++--
 core/sql/regress/hive/tbl_type.data      |  2 +-
 6 files changed, 66 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ad6c2f3e/core/sql/executor/ExExeUtilGet.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/ExExeUtilGet.cpp 
b/core/sql/executor/ExExeUtilGet.cpp
index 645d381..90a8d06 100644
--- a/core/sql/executor/ExExeUtilGet.cpp
+++ b/core/sql/executor/ExExeUtilGet.cpp
@@ -5253,7 +5253,7 @@ short ExExeUtilHiveMDaccessTcb::work()
                infoCol->colScale = 0;
                str_pad(infoCol->dtQualifier, 28, ' ');
                infoCol->dtStartField = 1;
-               infoCol->dtEndField = 6;
+               infoCol->dtEndField = 3;
               }
            }
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ad6c2f3e/core/sql/executor/hiveHook.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/hiveHook.cpp b/core/sql/executor/hiveHook.cpp
index 7e05763..1fc032a 100644
--- a/core/sql/executor/hiveHook.cpp
+++ b/core/sql/executor/hiveHook.cpp
@@ -375,7 +375,7 @@ struct hive_column_desc* populateColumns(HiveMetaData *md, 
Int32 cdID,
         return NULL;
       
       NAText typeStr;
-      if(!extractValueStr(md, tblStr, pos, "type:", ",", 
+      if(!extractValueStr(md, tblStr, pos, "type:", ", comment", 
                           typeStr, "populateColumns::type:###"))
         return NULL;
       
@@ -436,7 +436,7 @@ struct hive_pkey_desc* populatePartitionKey(HiveMetaData 
*md, Int32 tblID,
       NAText nameStr = tblStr->substr(foundB, pos-foundB);
       
       NAText typeStr;
-      if(!extractValueStr(md, tblStr, pos, "type:", ",", 
+      if(!extractValueStr(md, tblStr, pos, "type:", ", comment", 
                           typeStr, "populatePartitionKeys::type:###"))
         return NULL;
       

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ad6c2f3e/core/sql/optimizer/NATable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NATable.cpp b/core/sql/optimizer/NATable.cpp
index afdfaa0..ad6bf86 100644
--- a/core/sql/optimizer/NATable.cpp
+++ b/core/sql/optimizer/NATable.cpp
@@ -3631,9 +3631,9 @@ NAType* getSQColTypeForHive(const char* hiveType, 
NAMemory* heap)
     memset(maxLen, 0, 32);
     int i=0,j=0;
     int copyit = 0;
-
+    int lenStr = strlen(hiveType);
     //get length
-    for(i = 0; i < strlen(hiveType) ; i++)
+    for(i = 0; i < lenStr ; i++)
     {
       if(hiveType[i] == '(') //start
       {
@@ -3676,6 +3676,54 @@ NAType* getSQColTypeForHive(const char* hiveType, 
NAMemory* heap)
                                    CharInfo::IMPLICIT);
   } 
 
+  if ( !strncmp(hiveType, "decimal", 7) )
+  {
+    Int16 i=0, pstart=0, pend=0, sstart=0, send=0, p=0, s = 0;
+    Int16 hiveTypeLen = strlen(hiveType);
+    char pstr[16], sstr[16];
+    memset(pstr,0,sizeof(pstr));
+    memset(sstr,0,sizeof(sstr));
+
+    for( i = 0; i < hiveTypeLen; i++ )
+    {
+      if(hiveType[i] == '(' )
+      {
+        pstart = i+1;
+      }
+      else if(hiveType[i] == ',')
+      {
+        pend = i;
+        sstart = i+1;
+      }
+      else if(hiveType[i] == ')')
+      {
+        send = i;
+      }
+      else
+       continue;
+    }
+    if(pend - pstart > 0)
+    {
+      strncpy(pstr,hiveType+pstart, pend-pstart);
+      p=atoi(pstr);
+    }
+    if(send - sstart > 0)
+    {
+      strncpy(sstr,hiveType+sstart,send-sstart);
+      s=atoi(sstr);
+    }
+
+    if( (p>0) && (s>0) )
+    {
+      return new (heap) SQLDecimal( p, s, TRUE, TRUE);
+    }
+    else
+    {
+      return new (heap) SQLDecimal( 10, 0, TRUE, TRUE);
+    }
+
+  }
+
   return NULL;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ad6c2f3e/core/sql/regress/hive/EXPECTED005
----------------------------------------------------------------------
diff --git a/core/sql/regress/hive/EXPECTED005 
b/core/sql/regress/hive/EXPECTED005
index 75a64aa..38c91d0 100644
--- a/core/sql/regress/hive/EXPECTED005
+++ b/core/sql/regress/hive/EXPECTED005
@@ -434,10 +434,10 @@ ID           CHAPTER                    ENGLISH           
         TRANSLATOR
 >>
 >>select * from tbl_type;
 
-TINT  SM      I            BIG                   STR                        F  
              D                          T                           DT         
 VC
-----  ------  -----------  --------------------  -------------------------  
---------------  -------------------------  --------------------------  
----------  ----------------------------------------
+TINT  SM      I            BIG                   STR                        F  
              D                          T                           DT         
 VC                                        D10          D18
+----  ------  -----------  --------------------  -------------------------  
---------------  -------------------------  --------------------------  
----------  ----------------------------------------  -----------  ----------
 
- 101     202          203                   204  two hundred                 
2.0000000E+002   2.00000000000000000E+002  2022-02-02 22:22:22.222222  
2022-02-02  varchar                                 
+ 101     202          203                   204  two hundred                 
2.0000000E+002   2.00000000000000000E+002  2022-02-02 22:22:22.222222  
2022-02-02  varchar                                    1234567890   123456.11
 
 --- 1 row(s) selected.
 >>insert into tbl_type_temp select * from tbl_type;
@@ -445,10 +445,10 @@ TINT  SM      I            BIG                   STR      
                  F
 --- 1 row(s) inserted.
 >>select * from tbl_type_temp;
 
-TINT  SM      I            BIG                   STR                        F  
              D                          T                           DT         
 VC
-----  ------  -----------  --------------------  -------------------------  
---------------  -------------------------  --------------------------  
----------  ----------------------------------------
+TINT  SM      I            BIG                   STR                        F  
              D                          T                           DT         
 VC                                        D10          D18
+----  ------  -----------  --------------------  -------------------------  
---------------  -------------------------  --------------------------  
----------  ----------------------------------------  -----------  ----------
 
- 101     202          203                   204  two hundred                 
2.0000000E+002   2.00000000000000000E+002  2022-02-02 22:22:22.222222  
2022-02-02  varchar                                 
+ 101     202          203                   204  two hundred                 
2.0000000E+002   2.00000000000000000E+002  2022-02-02 22:22:22.222222  
2022-02-02  varchar                                    1234567890   123456.11
 
 --- 1 row(s) selected.
 >>

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ad6c2f3e/core/sql/regress/hive/TEST005_a.hive.sql
----------------------------------------------------------------------
diff --git a/core/sql/regress/hive/TEST005_a.hive.sql 
b/core/sql/regress/hive/TEST005_a.hive.sql
index b151a79..10949dc 100644
--- a/core/sql/regress/hive/TEST005_a.hive.sql
+++ b/core/sql/regress/hive/TEST005_a.hive.sql
@@ -138,7 +138,9 @@ create external table tbl_type
      d           double,
      t           timestamp,
      dt          date,
-     vc          varchar(10)
+     vc          varchar(10),
+     d10         decimal,
+     d18         decimal(8,2)
 )
 row format delimited fields terminated by '|'
 location '/user/hive/exttables/tbl_type';
@@ -155,7 +157,9 @@ create table tbl_type_temp
      d           double,
      t           timestamp,
      dt          date,
-     vc          varchar(10)
+     vc          varchar(10),
+     d10         decimal,
+     d18         decimal(8,2)
 )
 row format delimited fields terminated by '|';
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/ad6c2f3e/core/sql/regress/hive/tbl_type.data
----------------------------------------------------------------------
diff --git a/core/sql/regress/hive/tbl_type.data 
b/core/sql/regress/hive/tbl_type.data
index 99c4827..9e56472 100644
--- a/core/sql/regress/hive/tbl_type.data
+++ b/core/sql/regress/hive/tbl_type.data
@@ -1 +1 @@
-101|202|203|204|two hundred|2E2|2E+002|2022-02-02 
22:22:22.222222|2022-02-02|varchar
+101|202|203|204|two hundred|2E2|2E+002|2022-02-02 
22:22:22.222222|2022-02-02|varchar|1234567890|123456.11

Reply via email to