Repository: trafodion
Updated Branches:
  refs/heads/master 344cc3f2f -> 75c7b3954


[TRAFODION-2157] add MySQL function unix_timestamp,uuid,sleep


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

Branch: refs/heads/master
Commit: dbe4cac9c8e58c8dc9c6b86b5c473320df5c44c3
Parents: 9d88d08
Author: Liu Ming <ovis_p...@sina.com>
Authored: Wed Feb 14 08:57:58 2018 +0000
Committer: Liu Ming <ovis_p...@sina.com>
Committed: Wed Feb 14 08:57:58 2018 +0000

----------------------------------------------------------------------
 core/sql/common/OperTypeEnum.h         |   3 +
 core/sql/exp/ExpPackDefs.cpp           |  10 +++
 core/sql/exp/exp_clause.cpp            |  14 ++++
 core/sql/exp/exp_clause.h              |   4 +-
 core/sql/exp/exp_function.cpp          | 110 ++++++++++++++++++++++++++++
 core/sql/exp/exp_function.h            |  60 +++++++++++++++
 core/sql/generator/GenExpGenerator.cpp |   1 +
 core/sql/generator/GenItemFunc.cpp     |  16 ++++
 core/sql/optimizer/BindItemExpr.cpp    |  45 +++++++++++-
 core/sql/optimizer/GroupAttr.cpp       |   4 +-
 core/sql/optimizer/ItemExpr.cpp        |  22 ++++++
 core/sql/optimizer/ItemFunc.h          |  32 ++++++++
 core/sql/optimizer/OptItemExpr.cpp     |   1 +
 core/sql/optimizer/SynthType.cpp       |  14 ++++
 core/sql/parser/ParKeyWords.cpp        |   3 +
 core/sql/parser/sqlparser.y            |  53 +++++++++-----
 16 files changed, 371 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/common/OperTypeEnum.h
----------------------------------------------------------------------
diff --git a/core/sql/common/OperTypeEnum.h b/core/sql/common/OperTypeEnum.h
index c581fa9..af1d2ba 100644
--- a/core/sql/common/OperTypeEnum.h
+++ b/core/sql/common/OperTypeEnum.h
@@ -471,6 +471,9 @@ enum OperatorTypeEnum {
 
                         // Regular Expression
                         ITM_REGEXP = 2178,
+                       ITM_UNIX_TIMESTAMP = 2179,
+                       ITM_UUID_SHORT = 2180,
+                       ITM_SLEEP = 2181,
 
                         // numeric functions
                         ITM_ABS = 2200,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/exp/ExpPackDefs.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpPackDefs.cpp b/core/sql/exp/ExpPackDefs.cpp
index d924b9d..b8e6d6b 100644
--- a/core/sql/exp/ExpPackDefs.cpp
+++ b/core/sql/exp/ExpPackDefs.cpp
@@ -315,6 +315,16 @@ Long ExFunctionTokenStr::pack(void * space_)
   return packClause(space_, sizeof(ExFunctionTokenStr));
 }  
 
+Long ex_function_unixtime::pack(void * space_)
+{
+  return packClause(space_, sizeof(ex_function_unixtime));
+}  
+
+Long ex_function_sleep::pack(void * space_)
+{
+  return packClause(space_, sizeof(ex_function_sleep));
+}  
+
 Long ex_function_current::pack(void * space_)
 {
   return packClause(space_, sizeof(ex_function_current));

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/exp/exp_clause.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_clause.cpp b/core/sql/exp/exp_clause.cpp
index 796e2e5..0ad09d5 100644
--- a/core/sql/exp/exp_clause.cpp
+++ b/core/sql/exp/exp_clause.cpp
@@ -260,6 +260,12 @@ ex_clause::ex_clause(clause_type type,
        case ITM_LOWER_UNICODE:
          setClassID(FUNC_LOWER_UNICODE_ID);
          break;
+       case ITM_UNIX_TIMESTAMP:
+         setClassID(FUNC_UNIX_TIMESTAMP_ID);
+         break;
+       case ITM_SLEEP:
+         setClassID(FUNC_SLEEP_ID);
+         break;
        case ITM_CURRENT_TIMESTAMP:
          setClassID(FUNC_CURRENT_TIMESTAMP_ID);
          break;
@@ -756,6 +762,12 @@ char *ex_clause::findVTblPtr(short classID)
     case ex_clause::FUNC_LOWER_UNICODE_ID:
       GetVTblPtr(vtblPtr, ex_function_lower_unicode);
       break;
+    case ex_clause::FUNC_SLEEP_ID:
+      GetVTblPtr(vtblPtr, ex_function_sleep);
+      break;
+    case ex_clause::FUNC_UNIX_TIMESTAMP_ID:
+      GetVTblPtr(vtblPtr, ex_function_unixtime);
+      break;
     case ex_clause::FUNC_CURRENT_TIMESTAMP_ID:
       GetVTblPtr(vtblPtr, ex_function_current);
       break;
@@ -1196,6 +1208,8 @@ const char * getOperTypeEnumAsString(Int16 
/*OperatorTypeEnum*/ ote)
     case ITM_BETWEEN: return "ITM_BETWEEN";
     case ITM_LIKE: return "ITM_LIKE";
     case ITM_REGEXP: return "ITM_REGEXP";
+    case ITM_UNIX_TIMESTAMP: return "ITM_UNIX_TIMESTAMP";
+    case ITM_SLEEP: return "ITM_SLEEP";
     case ITM_CURRENT_TIMESTAMP: return "ITM_CURRENT_TIMESTAMP";
     case ITM_CURRENT_USER: return "ITM_CURRENT_USER";
     case ITM_SESSION_USER: return "ITM_SESSION_USER";

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/exp/exp_clause.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_clause.h b/core/sql/exp/exp_clause.h
index c5d8e79..fda7269 100644
--- a/core/sql/exp/exp_clause.h
+++ b/core/sql/exp/exp_clause.h
@@ -209,7 +209,9 @@ public:
     FUNC_JSON_ID             = 128,
     FUNC_AES_ENCRYPT         = 129,
     FUNC_AES_DECRYPT         = 130,
-    FUNC_REVERSE_ID         = 131
+    FUNC_REVERSE_ID         = 131,
+    FUNC_SLEEP_ID           = 132,
+    FUNC_UNIX_TIMESTAMP_ID = 133
   };
 
   // max number of operands (including result) in a clause.

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index 1f757fa..e5f975d 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -40,6 +40,7 @@
 
 
 #include <math.h>
+#include <unistd.h>
 #include <zlib.h>
 #include <openssl/md5.h>
 #include <openssl/sha.h>  
@@ -159,6 +160,8 @@ ex_function_trim_char::ex_function_trim_char(){};
 ExFunctionTokenStr::ExFunctionTokenStr(){};
 ExFunctionReverseStr::ExFunctionReverseStr(){};
 ex_function_current::ex_function_current(){};
+ex_function_unixtime::ex_function_unixtime(){};
+ex_function_sleep::ex_function_sleep(){};
 ex_function_unique_execute_id::ex_function_unique_execute_id(){};//Trigger -
 ex_function_get_triggers_status::ex_function_get_triggers_status(){};//Trigger 
-
 ex_function_get_bit_value_at::ex_function_get_bit_value_at(){};//Trigger -
@@ -435,6 +438,19 @@ ex_function_current::ex_function_current(OperatorTypeEnum 
oper_type,
   
 };
 
+ex_function_sleep::ex_function_sleep(OperatorTypeEnum oper_type, short 
numOperands,
+                                        Attributes ** attr, Space * space)
+: ex_function_clause(oper_type, numOperands, attr, space)
+{
+  
+};
+
+ex_function_unixtime::ex_function_unixtime(OperatorTypeEnum oper_type, short 
numOperands,
+                                        Attributes ** attr, Space * space)
+: ex_function_clause(oper_type, numOperands, attr, space)
+{
+  
+};
 //++ Triggers -
 ex_function_unique_execute_id::ex_function_unique_execute_id(OperatorTypeEnum 
oper_type,
                                         Attributes ** attr, Space * space)
@@ -2501,6 +2517,100 @@ ex_expr::exp_return_type 
ExFunctionReverseStr::eval(char *op_data[],
   return ex_expr::EXPR_OK;
 };
 
+ex_expr::exp_return_type ex_function_sleep::eval(char *op_data[],
+                                                  CollHeap* heap,
+                                                  ComDiagsArea** diagsArea)
+{
+   Int32 sec = 0;
+  switch (getOperand(1)->getDatatype())
+  {
+    case REC_BIN8_SIGNED:
+      sec = *(Int8 *)op_data[1] ;
+      if(sec < 0 )
+      {
+        ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+        *(*diagsArea) << DgString0("SLEEP");
+        return ex_expr::EXPR_ERROR;
+      }
+      sleep(sec);
+      *(Int64 *)op_data[0] = 1;
+      break;
+      
+    case REC_BIN16_SIGNED:
+      sec = *(short *)op_data[1] ; 
+      if(sec < 0 )
+      {
+        ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+        *(*diagsArea) << DgString0("SLEEP");
+        return ex_expr::EXPR_ERROR;
+      }
+      sleep(sec);
+      *(Int64 *)op_data[0] = 1;
+      break;
+      
+    case REC_BIN32_SIGNED:
+      *(Lng32 *)sec = labs(*(Lng32 *)op_data[1]);
+      if(sec < 0 )
+      {
+        ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+        *(*diagsArea) << DgString0("SLEEP");
+        return ex_expr::EXPR_ERROR;
+      }
+      sleep(sec);
+      *(Int64 *)op_data[0] = 1;
+      break;
+ 
+    case REC_BIN64_SIGNED:
+      sec = *(Int64 *)op_data[1];
+      if(sec < 0 )
+      {
+        ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+        *(*diagsArea) << DgString0("SLEEP");
+        return ex_expr::EXPR_ERROR;
+      }
+      sleep(sec);
+      *(Int64 *)op_data[0] = 1;
+      break;
+      
+    default:
+        ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+        *(*diagsArea) << DgString0("SLEEP");
+      return ex_expr::EXPR_ERROR;
+      break;
+  }
+  //get the seconds to sleep
+  return ex_expr::EXPR_OK;
+}
+
+ex_expr::exp_return_type ex_function_unixtime::eval(char *op_data[],
+                                                  CollHeap* heap,
+                                                  ComDiagsArea** diagsArea)
+{
+  char *opData = op_data[1];
+  //if there is input value
+  if(opData[0] != 0 &&  getNumOperands() == 2)
+  {
+    struct tm* ptr;
+    char* r = strptime(opData, "%Y-%m-%d %H:%M:%S", ptr);
+    if( r == NULL)
+    {
+        ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+        *(*diagsArea) << DgString0("UNIX_TIMESTAMP");
+      return ex_expr::EXPR_ERROR;
+    }
+    else
+      *(Int64 *)op_data[0] = mktime(ptr);
+
+  }
+  else
+  {
+    time_t seconds;  
+    seconds = time((time_t *)NULL);   
+    *(Int64 *)op_data[0] = seconds; 
+  }
+  return ex_expr::EXPR_OK;
+}
+
 ex_expr::exp_return_type ex_function_current::eval(char *op_data[],
                                                   CollHeap*,
                                                   ComDiagsArea**)

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/exp/exp_function.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.h b/core/sql/exp/exp_function.h
index 1f8732a..13b7185 100644
--- a/core/sql/exp/exp_function.h
+++ b/core/sql/exp/exp_function.h
@@ -1174,6 +1174,66 @@ public:
   // ---------------------------------------------------------------------
 };
 
+class  ex_function_sleep: public ex_function_clause {
+public:
+  ex_function_sleep(OperatorTypeEnum oper_type, short numOperands,
+                                Attributes ** attr,
+                                Space * space);
+  ex_function_sleep();
+
+
+  ex_expr::exp_return_type eval(char *op_data[], CollHeap*, 
+                                          ComDiagsArea** = 0);
+  Long pack(void *);
+
+  // ---------------------------------------------------------------------
+  // Redefinition of methods inherited from NAVersionedObject.
+  // ---------------------------------------------------------------------
+  virtual unsigned char getClassVersionID()
+  {
+    return 1;
+  }
+
+  virtual void populateImageVersionIDArray()
+  {
+    setImageVersionID(2,getClassVersionID());
+    ex_function_clause::populateImageVersionIDArray();
+  }
+
+  virtual short getClassSize() { return (short)sizeof(*this); }
+  // ---------------------------------------------------------------------
+};
+
+class  ex_function_unixtime: public ex_function_clause {
+public:
+  ex_function_unixtime(OperatorTypeEnum oper_type, short num,
+                                Attributes ** attr,
+                                Space * space);
+  ex_function_unixtime();
+
+
+  ex_expr::exp_return_type eval(char *op_data[], CollHeap*, 
+                                          ComDiagsArea** = 0);
+  Long pack(void *);
+
+  // ---------------------------------------------------------------------
+  // Redefinition of methods inherited from NAVersionedObject.
+  // ---------------------------------------------------------------------
+  virtual unsigned char getClassVersionID()
+  {
+    return 1;
+  }
+
+  virtual void populateImageVersionIDArray()
+  {
+    setImageVersionID(2,getClassVersionID());
+    ex_function_clause::populateImageVersionIDArray();
+  }
+
+  virtual short getClassSize() { return (short)sizeof(*this); }
+  // ---------------------------------------------------------------------
+};
+
 class  ex_function_current : public ex_function_clause {
 public:
   ex_function_current(OperatorTypeEnum oper_type,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/generator/GenExpGenerator.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenExpGenerator.cpp 
b/core/sql/generator/GenExpGenerator.cpp
index cde3481..1b038a5 100644
--- a/core/sql/generator/GenExpGenerator.cpp
+++ b/core/sql/generator/GenExpGenerator.cpp
@@ -3700,6 +3700,7 @@ short ExpGenerator::generateInputExpr(const ValueIdList 
&val_id_list,
       else
        if ((item_expr->isAUserSuppliedInput()) || //evaluate once functions
                (item_expr->getOperatorType() == ITM_CURRENT_TIMESTAMP) ||
+               (item_expr->getOperatorType() == ITM_UNIX_TIMESTAMP) ||
            (item_expr->getOperatorType() == ITM_CURRENT_USER) ||
            (item_expr->getOperatorType() == ITM_SESSION_USER) ||
             (item_expr->getOperatorType() == ITM_EXEC_COUNT) ||

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/generator/GenItemFunc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenItemFunc.cpp 
b/core/sql/generator/GenItemFunc.cpp
index 9821e4a..df3f674 100644
--- a/core/sql/generator/GenItemFunc.cpp
+++ b/core/sql/generator/GenItemFunc.cpp
@@ -152,6 +152,22 @@ short BuiltinFunction::codeGen(Generator * generator)
 
       break;
       
+    case ITM_SLEEP:
+      {
+       function_clause =
+         new(generator->getSpace()) 
ex_function_sleep(getOperatorType(),(1+getArity()), 
+                                                        attr, space);
+      }
+      
+      break;
+    case ITM_UNIX_TIMESTAMP:
+      {
+       function_clause =
+         new(generator->getSpace()) ex_function_unixtime(getOperatorType(), 
(1+getArity()),
+                                                        attr, space);
+      }
+      
+      break;
     case ITM_CURRENT_TIMESTAMP:
     case ITM_CURRENT_TIMESTAMP_RUNNING:
       {

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/optimizer/BindItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindItemExpr.cpp 
b/core/sql/optimizer/BindItemExpr.cpp
index 7a1193f..ee687e4 100644
--- a/core/sql/optimizer/BindItemExpr.cpp
+++ b/core/sql/optimizer/BindItemExpr.cpp
@@ -3187,6 +3187,7 @@ ItemExpr *BuiltinFunction::bindNode(BindWA *bindWA)
 
     case ITM_ISIPV4:
     case ITM_ISIPV6:
+    case ITM_SLEEP:
     case ITM_MD5:
     case ITM_CRC32:
     case ITM_SHA1:
@@ -8417,6 +8418,38 @@ ItemExpr *DefaultSpecification::bindNode(BindWA *bindWA)
 } // DefaultSpecification::bindNode()
 
 // -----------------------------------------------------------------------
+// member functions for class UnixTimestamp
+// -----------------------------------------------------------------------
+
+ItemExpr *UnixTimestamp::bindNode(BindWA *bindWA)
+{
+
+  if (bindWA->inDDL() && (bindWA->inCheckConstraintDefinition()))
+  {
+       StmtDDLAddConstraintCheck *pCkC = bindWA->getUsageParseNodePtr()
+                                    ->castToElemDDLNode()
+                                    ->castToStmtDDLAddConstraintCheck();
+    *CmpCommon::diags() << DgSqlCode(-4131);
+    bindWA->setErrStatus();
+    return this;
+  }
+
+  if (nodeIsBound())
+    return getValueId().getItemExpr();
+  const NAType *type = synthTypeWithCollateClause(bindWA);
+  if (!type) return this;
+
+  ItemExpr * ie = ItemExpr::bindUserInput(bindWA,type,getText());
+  if (bindWA->errStatus())
+    return this;
+
+  // add this value id to BindWA's input function list.
+  bindWA->inputFunction().insert(getValueId());
+
+  return ie;
+} // UnixTimestamp::bindNode()
+
+// -----------------------------------------------------------------------
 // member functions for class CurrentTimestamp
 // -----------------------------------------------------------------------
 
@@ -11980,7 +12013,17 @@ ItemExpr *ZZZBinderFunction::bindNode(BindWA *bindWA)
          }
       }
     break;
-
+/*
+    case ITM_SLEEP:
+      {
+        ItemExpr * tempBoundTree = 
child(0)->castToItemExpr()->bindNode(bindWA);
+        if (bindWA->errStatus())
+          return this;
+        buf[0] = 0;
+        parseTree = child(0);
+      }
+    break;
+*/
     case ITM_TO_NUMBER:
       {
        ItemExpr *tempBoundTree = child(0)->castToItemExpr()->bindNode(bindWA); 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/optimizer/GroupAttr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/GroupAttr.cpp b/core/sql/optimizer/GroupAttr.cpp
index 30a04fd..eb6a87b 100644
--- a/core/sql/optimizer/GroupAttr.cpp
+++ b/core/sql/optimizer/GroupAttr.cpp
@@ -1792,7 +1792,9 @@ void GroupAttributes::resolveCharacteristicInputs(const 
ValueIdSet& externalInpu
           {
             ItemExpr * vidExpr = vid.getItemExpr();
             if ((vidExpr->getOperatorType() == ITM_CURRENT_USER) ||
-                (vidExpr->getOperatorType() == ITM_CURRENT_TIMESTAMP))
+                (vidExpr->getOperatorType() == ITM_CURRENT_TIMESTAMP) ||
+                (vidExpr->getOperatorType() == ITM_UNIX_TIMESTAMP))
+
               currentConstants += vid;
           }
         }

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/optimizer/ItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp
index c791a92..006639e 100644
--- a/core/sql/optimizer/ItemExpr.cpp
+++ b/core/sql/optimizer/ItemExpr.cpp
@@ -7491,6 +7491,10 @@ const NAString BuiltinFunction::getText() const
       return "CONVERTTOBITS";
     case ITM_CONVERTTIMESTAMP:
       return "converttimestamp";
+    case ITM_SLEEP:
+      return "sleep";
+    case ITM_UNIX_TIMESTAMP:
+      return "unix_timestamp";
     case ITM_CURRENT_TIMESTAMP:
       return "current_timestamp";
     case ITM_CURRENT_TIMESTAMP_RUNNING:
@@ -8266,6 +8270,24 @@ ItemExpr * ConvertTimestamp::copyTopNode(ItemExpr 
*derivedNode,
 
 } // ConvertTimestamp::copyTopNode()
 
+UnixTimestamp::~UnixTimestamp() {}
+
+ItemExpr * UnixTimestamp::copyTopNode(ItemExpr *derivedNode,
+                                        CollHeap* outHeap)
+{
+  ItemExpr *result;
+
+  if (derivedNode == NULL)
+    result = new (outHeap) UnixTimestamp();
+  else
+    result = derivedNode;
+
+  return BuiltinFunction::copyTopNode(result,outHeap);
+
+} // UnixTimestamp::copyTopNode()
+
+NABoolean UnixTimestamp::isAUserSuppliedInput() const    { return TRUE; }
+
 // -----------------------------------------------------------------------
 // member functions for class CurrentTimestamp
 // -----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/optimizer/ItemFunc.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemFunc.h b/core/sql/optimizer/ItemFunc.h
index 0435521..09f4652 100644
--- a/core/sql/optimizer/ItemFunc.h
+++ b/core/sql/optimizer/ItemFunc.h
@@ -1751,6 +1751,38 @@ public:
   virtual NABoolean hasEquivalentProperties(ItemExpr * other) { return TRUE;}
 }; // class ConvertTimestamp
 
+class UnixTimestamp : public CacheableBuiltinFunction
+{
+public:
+  UnixTimestamp()
+   : CacheableBuiltinFunction(ITM_UNIX_TIMESTAMP)
+  {}
+
+  UnixTimestamp( ItemExpr *val1Ptr )
+   : CacheableBuiltinFunction(ITM_UNIX_TIMESTAMP, 1, val1Ptr)
+  {}
+  // virtual destructor
+  virtual ~UnixTimestamp();
+
+  // A method that returns for "user-given" input values.
+  // These are values that are either constants, host variables, parameters,
+  // or even values that are sensed from the environment such as
+  // current time, the user name, etcetera.
+  virtual NABoolean isAUserSuppliedInput() const;
+
+  // a virtual function for performing name binding within the query tree
+  virtual ItemExpr * bindNode(BindWA *bindWA);
+
+  // a virtual function for type propagating the node
+  virtual const NAType * synthesizeType();
+
+  virtual ItemExpr * copyTopNode(ItemExpr *derivedNode = NULL,
+                                CollHeap* outHeap = 0);
+
+  virtual NABoolean hasEquivalentProperties(ItemExpr * other) { return TRUE;}
+
+}; // class UnixTimestamp
+
 class CurrentTimestamp : public CacheableBuiltinFunction
 {
 public:

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/optimizer/OptItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/OptItemExpr.cpp 
b/core/sql/optimizer/OptItemExpr.cpp
index 9741c10..4b7d6ba 100644
--- a/core/sql/optimizer/OptItemExpr.cpp
+++ b/core/sql/optimizer/OptItemExpr.cpp
@@ -1811,6 +1811,7 @@ NABoolean 
BuiltinFunction::calculateMinMaxUecs(ColStatDescList & histograms,
     }
     break;
   case ITM_CONVERTTIMESTAMP:
+  case ITM_UNIX_TIMESTAMP:
   case ITM_CURRENT_TIMESTAMP:
   case ITM_CURRENT_TIMESTAMP_RUNNING:
   case ITM_JULIANTIMESTAMP:

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/optimizer/SynthType.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/SynthType.cpp b/core/sql/optimizer/SynthType.cpp
index a0f9042..fd7fd1f 100644
--- a/core/sql/optimizer/SynthType.cpp
+++ b/core/sql/optimizer/SynthType.cpp
@@ -1119,6 +1119,15 @@ const NAType *BuiltinFunction::synthesizeType()
          }
       }
     break;
+
+    case ITM_SLEEP:
+      {
+        ValueId vid1 = child(0)->getValueId();
+        SQLInt c1( HEAP, TRUE , TRUE);
+        vid1.coerceType(c1, NA_NUMERIC_TYPE);
+        retType = new HEAP SQLInt(HEAP, TRUE, TRUE);
+      }
+    break;
     case ITM_INET_ATON:
       {
         // type cast any params
@@ -3062,6 +3071,11 @@ const NAType *ConvertTimestamp::synthesizeType()
 
 }
 
+const NAType *UnixTimestamp::synthesizeType()
+{
+  return new HEAP SQLLargeInt(HEAP, FALSE,FALSE);
+}
+
 // -----------------------------------------------------------------------
 // member functions for class CurrentTimestamp
 // -----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/parser/ParKeyWords.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/ParKeyWords.cpp b/core/sql/parser/ParKeyWords.cpp
index f604c23..a213458 100644
--- a/core/sql/parser/ParKeyWords.cpp
+++ b/core/sql/parser/ParKeyWords.cpp
@@ -1007,6 +1007,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("SIZE",               TOK_SIZE,        ANS_|RESWORD_),
   ParKeyWord("SKIP",               TOK_SKIP,        
FIRST_|SECOND_|NONRESTOKEN_),
   ParKeyWord("SLACK",              TOK_SLACK,        NONRESTOKEN_),
+  ParKeyWord("SLEEP",              TOK_SLEEP,        NONRESTOKEN_),
   ParKeyWord("SMALLINT",           TOK_SMALLINT,    ANS_|RESWORD_|MPWORD_),
   ParKeyWord("SNAPSHOT",           TOK_SNAPSHOT,    NONRESTOKEN_),
   ParKeyWord("SOFTWARE",           TOK_SOFTWARE,    NONRESTOKEN_),
@@ -1144,6 +1145,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("UNIQUE",             TOK_UNIQUE,      ANS_|RESWORD_|MPWORD_),
   ParKeyWord("UNIQUE_ID",             TOK_UNIQUE_ID,      NONRESTOKEN_),
   ParKeyWord("UNIVERSAL",          TOK_UNIVERSAL,   NONRESTOKEN_),
+  ParKeyWord("UNIX_TIMESTAMP",     TOK_UNIX_TIMESTAMP,   NONRESTOKEN_),
   ParKeyWord("UNKNOWN",            TOK_UNKNOWN,     ANS_|RESWORD_),
   ParKeyWord("UNLOAD",             TOK_UNLOAD,      NONRESTOKEN_),
   ParKeyWord("UNLOCK",             TOK_UNLOCK,      NONRESTOKEN_),
@@ -1167,6 +1169,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("USERS",              TOK_USERS,       NONRESTOKEN_),
   ParKeyWord("USING",              TOK_USING,       ANS_|RESWORD_),
   ParKeyWord("UUID",                TOK_UUID,         NONRESTOKEN_),
+  ParKeyWord("UUID_SHORT",          TOK_UUID_SHORT,    NONRESTOKEN_),
   ParKeyWord("VALIDATE",          TOK_VALIDATE,    NONRESTOKEN_),
   ParKeyWord("VALUE",              TOK_VALUE,       NONRESTOKEN_),
   ParKeyWord("VALUES",             TOK_VALUES,      ANS_|RESWORD_|MPWORD_),

http://git-wip-us.apache.org/repos/asf/trafodion/blob/dbe4cac9/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 2e9dcee..5fa9107 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -1176,6 +1176,9 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %token <tokval> TOK_WHENEVER
 %token <tokval> TOK_WHERE
 %token <tokval> TOK_WITH
+%token <tokval> TOK_SLEEP
+%token <tokval> TOK_UUID_SHORT
+%token <tokval> TOK_UNIX_TIMESTAMP
 // QSTUFF
 %token <tokval> TOK_WITHOUT             /* standard holdable cursor */
 // QSTUFF
@@ -8696,6 +8699,33 @@ datetime_value_function : TOK_CURDATE '(' ')'
                                   $$ = 
CurrentTimestamp::construct(PARSERHEAP());
                                 }
 
+    | TOK_UNIX_TIMESTAMP '(' ')'
+                                {
+                                   NAType * type;
+                                   type = new (PARSERHEAP())
+                                      SQLLargeInt(PARSERHEAP() , FALSE , 
FALSE);
+                                   ItemExpr * ie = new (PARSERHEAP()) 
UnixTimestamp();
+                                   $$ = new (PARSERHEAP()) Cast(ie, type);
+                                }
+    | TOK_UNIX_TIMESTAMP '(' value_expression ')'
+                                {
+                                   NAType * type;
+                                   type = new (PARSERHEAP())
+                                      SQLLargeInt(PARSERHEAP() , FALSE , 
FALSE);
+                                   ItemExpr * ie = new (PARSERHEAP()) 
UnixTimestamp($3);
+                                   $$ = new (PARSERHEAP()) Cast(ie, type);
+                               }
+    | TOK_UUID '(' ')'
+    | TOK_UUID_SHORT '(' ')'
+              {
+                  ItemExpr * uniqueId =  new (PARSERHEAP()) 
BuiltinFunction(ITM_UNIQUE_ID, PARSERHEAP());
+                  ItemExpr *conv = new (PARSERHEAP()) 
ConvertHex(ITM_CONVERTTOHEX, uniqueId);
+                  NAType * type;
+                  type = new (PARSERHEAP())
+                       SQLVarChar(PARSERHEAP() , 128 , FALSE);
+                  $$ = new (PARSERHEAP()) Cast(conv,type);
+              }
+
 /* type item */
 datetime_misc_function : TOK_CONVERTTIMESTAMP '(' value_expression ')'
                                {
@@ -8849,6 +8879,11 @@ datetime_misc_function : TOK_CONVERTTIMESTAMP '(' 
value_expression ')'
                                 $$ = new (PARSERHEAP()) 
                                   ZZZBinderFunction(ITM_TO_TIMESTAMP, $3);
                               }
+    | TOK_SLEEP '(' value_expression ')'
+                               {
+                                $$ = new (PARSERHEAP()) 
+                                  BuiltinFunction(ITM_SLEEP,  
CmpCommon::statementHeap(), 1, $3);
+                               }
 
 CHAR_FUNC_optional_character_set : ',' CHAR_FUNC_character_set
          {
@@ -14811,24 +14846,6 @@ interactive_query_expression:
                                 {
                                   $$ = finalize($1);
                                 }
-              | TOK_SELECT TOK_UUID '(' ')'
-                               {
-                                 NAString * v = new (PARSERHEAP()) 
NAString("1");
-                                 ItemExpr * lit = literalOfNumericNoScale(v);
-                                 Tuple * tuple = new (PARSERHEAP()) Tuple(lit);
-                                 NAString cn ("x");
-                                 RenameTable * rt = 
-                                   new(PARSERHEAP()) RenameTable(tuple, cn);
-                                 RelRoot * rr1 = new (PARSERHEAP()) 
RelRoot(rt, REL_ROOT);
-                                 ItemExpr * uniqueId = 
-                                   new (PARSERHEAP()) 
BuiltinFunction(ITM_UNIQUE_ID, PARSERHEAP());
-                                 ItemExpr * convToHex =
-                                   new (PARSERHEAP()) 
ConvertHex(ITM_CONVERTTOHEX, uniqueId);
-
-                                 RelRoot * rr = new (PARSERHEAP())
-                                   RelRoot(rr1, REL_ROOT, convToHex);
-                                 $$ = finalize(rr);
-                               }
 
 dml_query : query_expression order_by_clause access_type
             optional_lock_mode for_update_spec optional_limit_spec

Reply via email to