Repository: trafodion
Updated Branches:
  refs/heads/master 7677846ac -> ce62bc52d


[TRAFODION-3147] support sys_guid function


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

Branch: refs/heads/master
Commit: 6ad70a36245a6dacedda0d8740c7d84cff5bf707
Parents: 0db94ea
Author: Liu Ming <ovis_p...@sina.com>
Authored: Sat Jul 21 11:03:49 2018 -0400
Committer: Liu Ming <ovis_p...@sina.com>
Committed: Sat Jul 21 11:03:49 2018 -0400

----------------------------------------------------------------------
 core/sql/common/OperTypeEnum.h     |  1 +
 core/sql/exp/exp_clause.cpp        |  2 ++
 core/sql/exp/exp_function.cpp      |  6 ++++++
 core/sql/generator/GenItemFunc.cpp |  1 +
 core/sql/optimizer/ItemExpr.cpp    |  2 ++
 core/sql/optimizer/SynthType.cpp   |  5 +++++
 core/sql/parser/ParKeyWords.cpp    |  1 +
 core/sql/parser/sqlparser.y        | 13 +++++++++++--
 8 files changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/6ad70a36/core/sql/common/OperTypeEnum.h
----------------------------------------------------------------------
diff --git a/core/sql/common/OperTypeEnum.h b/core/sql/common/OperTypeEnum.h
index 135264c..f3114ca 100644
--- a/core/sql/common/OperTypeEnum.h
+++ b/core/sql/common/OperTypeEnum.h
@@ -728,6 +728,7 @@ enum OperatorTypeEnum {
                         ITM_ANY_CAST = 2457,
 
                         ITM_UNIQUE_ID = 2458,
+                        ITM_UNIQUE_ID_SYS_GUID = 2459,
 
                        // Do not do any conversion. Just interpret source as 
the specified type.
                         ITM_CAST_TYPE,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/6ad70a36/core/sql/exp/exp_clause.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_clause.cpp b/core/sql/exp/exp_clause.cpp
index ffd8b27..0b918e5 100644
--- a/core/sql/exp/exp_clause.cpp
+++ b/core/sql/exp/exp_clause.cpp
@@ -506,6 +506,7 @@ ex_clause::ex_clause(clause_type type,
          setClassID(FUNC_QUERYID_EXTRACT);
          break;
        case ITM_UNIQUE_ID:
+       case ITM_UNIQUE_ID_SYS_GUID:
        case ITM_UNIQUE_SHORT_ID:
          setClassID(FUNC_UNIQUE_ID);
          break;
@@ -1508,6 +1509,7 @@ const char * getOperTypeEnumAsString(Int16 
/*OperatorTypeEnum*/ ote)
 
     case ITM_LAST_ITEM_OP: return "ITM_LAST_ITEM_OP";
     case ITM_UNIQUE_ID: return "ITM_UNIQUE_ID";
+    case ITM_UNIQUE_ID_SYS_GUID: return "ITM_UNIQUE_ID_SYS_GUID";
     case ITM_UNIQUE_SHORT_ID: return "ITM_UNIQUE_SHORT_ID";
     case ITM_ROWNUM: return "ITM_ROWNUM";
     case ITM_HBASE_COLUMN_LOOKUP: return "ITM_HBASE_COLUMN_LOOKUP";

http://git-wip-us.apache.org/repos/asf/trafodion/blob/6ad70a36/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index 4a936cb..9aba9b1 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -6924,6 +6924,12 @@ ex_expr::exp_return_type ExFunctionUniqueId::eval(char 
*op_data[],
     uuid_unparse(uu, str);
     str_cpy_all(result, str, 36);
   }
+  else if(getOperType() == ITM_UNIQUE_ID_SYS_GUID)
+  {
+    uuid_t uu;
+    uuid_generate( uu ); 
+    str_cpy_all(result, (char*)&uu,sizeof(uu));
+  }
   else //at present , it must be ITM_UUID_SHORT_ID
   { 
     Int64 uniqueUID;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/6ad70a36/core/sql/generator/GenItemFunc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenItemFunc.cpp 
b/core/sql/generator/GenItemFunc.cpp
index 60a8f19..ca4d625 100644
--- a/core/sql/generator/GenItemFunc.cpp
+++ b/core/sql/generator/GenItemFunc.cpp
@@ -665,6 +665,7 @@ short BuiltinFunction::codeGen(Generator * generator)
     break;
 
     case ITM_UNIQUE_ID:
+    case ITM_UNIQUE_ID_SYS_GUID:
     case ITM_UNIQUE_SHORT_ID:
       {
        function_clause =

http://git-wip-us.apache.org/repos/asf/trafodion/blob/6ad70a36/core/sql/optimizer/ItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp
index 920d2f4..57604b5 100644
--- a/core/sql/optimizer/ItemExpr.cpp
+++ b/core/sql/optimizer/ItemExpr.cpp
@@ -7627,6 +7627,8 @@ const NAString BuiltinFunction::getText() const
       return "unique_short_id";
     case ITM_UNIQUE_ID:
       return "unique_id";
+    case ITM_UNIQUE_ID_SYS_GUID:
+      return "sys_guid";
     case ITM_HBASE_COLUMN_LOOKUP:
       return "hbase_column_lookup";
     case ITM_HBASE_COLUMNS_DISPLAY:

http://git-wip-us.apache.org/repos/asf/trafodion/blob/6ad70a36/core/sql/optimizer/SynthType.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/SynthType.cpp b/core/sql/optimizer/SynthType.cpp
index f993aa6..f43526b 100644
--- a/core/sql/optimizer/SynthType.cpp
+++ b/core/sql/optimizer/SynthType.cpp
@@ -1347,6 +1347,11 @@ const NAType *BuiltinFunction::synthesizeType()
         //please check the ExFunctionUniqueId::eval if the size is changed
        retType = new HEAP SQLChar(HEAP, 36, FALSE);
       }
+    case ITM_UNIQUE_ID_SYS_GUID:
+      {
+        //please check the ExFunctionUniqueId::eval if the size is changed
+       retType = new HEAP SQLChar(HEAP, 16, FALSE);
+      }
       break;
     case ITM_UNIQUE_SHORT_ID:
       {

http://git-wip-us.apache.org/repos/asf/trafodion/blob/6ad70a36/core/sql/parser/ParKeyWords.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/ParKeyWords.cpp b/core/sql/parser/ParKeyWords.cpp
index 0a152ce..d2a8d1c 100644
--- a/core/sql/parser/ParKeyWords.cpp
+++ b/core/sql/parser/ParKeyWords.cpp
@@ -1069,6 +1069,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("SYNONYM",            TOK_SYNONYM,     POTANS_|RESWORD_),
   ParKeyWord("SYNONYMS",           TOK_SYNONYMS,    NONRESTOKEN_),
   ParKeyWord("SYSDATE",            TOK_SYSDATE,     NONRESTOKEN_),
+  ParKeyWord("SYS_GUID",           TOK_SYS_GUID,     NONRESTOKEN_),
   ParKeyWord("SYSTEM",             TOK_SYSTEM,      NONRESTOKEN_),
   ParKeyWord("SYSTIMESTAMP",            TOK_SYSTIMESTAMP,     NONRESTOKEN_),
   ParKeyWord("SYSTEM_USER",        IDENTIFIER,      ANS_|RESWORD_),

http://git-wip-us.apache.org/repos/asf/trafodion/blob/6ad70a36/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 0fd04a1..107c53b 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -729,6 +729,7 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %token <tokval> TOK_INOUT
 %token <tokval> TOK_INSTR
 %token <tokval> TOK_NOT_IN
+%token <tokval> TOK_SYS_GUID
 %token <tokval> TOK_INCLUSIVE
 %token <tokval> TOK_INDICATOR
 %token <tokval> TOK_INITIALIZATION // MV 
@@ -8708,10 +8709,18 @@ datetime_value_function : TOK_CURDATE '(' ')'
                                    ItemExpr * ie = new (PARSERHEAP()) 
UnixTimestamp($3);
                                    $$ = new (PARSERHEAP()) Cast(ie, type);
                                }
+    | TOK_SYS_GUID '(' ')'
+              {
+                  ItemExpr * uniqueId =  new (PARSERHEAP()) 
BuiltinFunction(ITM_UNIQUE_ID_SYS_GUID, PARSERHEAP());
+                  ItemExpr *conv = new (PARSERHEAP()) 
ConvertHex(ITM_CONVERTTOHEX, uniqueId);
+                  NAType * type;
+                  type = new (PARSERHEAP())
+                       SQLVarChar(PARSERHEAP() , 32, FALSE);
+                  $$ = new (PARSERHEAP()) Cast(conv,type);
+              }
     | TOK_UUID '(' ')'
               {
                   ItemExpr * uniqueId =  new (PARSERHEAP()) 
BuiltinFunction(ITM_UNIQUE_ID, PARSERHEAP());
-                  //ItemExpr *conv = new (PARSERHEAP()) 
ConvertHex(ITM_CONVERTTOHEX, uniqueId);
                   NAType * type;
                   type = new (PARSERHEAP())
                        SQLVarChar(PARSERHEAP() , 36, FALSE);
@@ -8720,7 +8729,6 @@ datetime_value_function : TOK_CURDATE '(' ')'
     | TOK_UUID_SHORT '(' ')'
               {
                   ItemExpr * uniqueId =  new (PARSERHEAP()) 
BuiltinFunction(ITM_UNIQUE_SHORT_ID, PARSERHEAP());
-                  //ItemExpr *conv = new (PARSERHEAP()) 
ConvertHex(ITM_CONVERTTOHEX, uniqueId);
                   NAType * type;
                   type = new (PARSERHEAP())
                        SQLVarChar(PARSERHEAP() , 36, FALSE);
@@ -34512,6 +34520,7 @@ nonreserved_func_word:  TOK_ABS
                        //                      | TOK_UPSERT
                       | TOK_UNIQUE_ID
                       | TOK_UUID
+                      | TOK_SYS_GUID
                      | TOK_USERNAMEINTTOEXT
                       | TOK_VARIANCE
                       | TOK_WEEK

Reply via email to