You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by li...@apache.org on 2018/02/23 09:45:20 UTC

[1/9] trafodion git commit: [TRAFODION-2157] add MySQL function unix_timestamp, uuid, sleep

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 <ov...@sina.com>
Authored: Wed Feb 14 08:57:58 2018 +0000
Committer: Liu Ming <ov...@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


[2/9] trafodion git commit: Merge branch 'master' of git://git.apache.org/trafodion into TRAFODION-2157

Posted by li...@apache.org.
Merge branch 'master' of git://git.apache.org/trafodion into TRAFODION-2157


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

Branch: refs/heads/master
Commit: 3555983cdeb03059277913babd646400f5f319ff
Parents: dbe4cac bd886c1
Author: Liu Ming <ov...@sina.com>
Authored: Wed Feb 14 08:58:30 2018 +0000
Committer: Liu Ming <ov...@sina.com>
Committed: Wed Feb 14 08:58:30 2018 +0000

----------------------------------------------------------------------
 core/conn/odb/Makefile                          |   2 +-
 core/conn/odb/src/odb.c                         |  59 +++--
 .../odbc/src/odbc/nsksrvrcore/srvrothers.cpp    |  85 ++++++
 core/sqf/commonLogger/CommonLogger.cpp          |   8 +-
 core/sqf/commonLogger/CommonLogger.h            |   8 +-
 core/sqf/sql/scripts/analyzeULOG.py             |  62 ++++-
 core/sql/cli/Cli.cpp                            |  47 +++-
 core/sql/comexe/ComTdbExeUtil.h                 |  15 +-
 core/sql/executor/ExExeUtil.h                   |   2 +
 core/sql/executor/ExExeUtilLoad.cpp             |  85 +++++-
 core/sql/exp/ExpLOBaccess.cpp                   |  70 +++++
 core/sql/exp/ExpLOBaccess.h                     |   2 +
 core/sql/exp/ExpLOBenums.h                      |   4 +-
 core/sql/exp/ExpLOBexternal.h                   |   5 +-
 core/sql/exp/ExpLOBinterface.cpp                | 115 ++++++++
 core/sql/exp/ExpLOBinterface.h                  |  21 ++
 core/sql/exp/exp_function.cpp                   |   9 +-
 core/sql/generator/GenRelExeUtil.cpp            |  12 +-
 core/sql/optimizer/RelExeUtil.h                 |   3 +-
 core/sql/parser/sqlparser.y                     |  53 ++++
 core/sql/qmscommon/QRLogger.cpp                 |  98 ++++++-
 core/sql/qmscommon/QRLogger.h                   |  18 +-
 core/sql/regress/compGeneral/EXPECTED023        |  54 ++--
 core/sql/regress/compGeneral/TEST023            |   4 +
 core/sql/regress/executor/EXPECTED130           |  96 ++++---
 core/sql/regress/executor/TEST130               |  17 ++
 core/sql/sqlcomp/DefaultConstants.h             |   1 +
 core/sql/sqlcomp/nadefaults.cpp                 |   6 +-
 core/sql/ustat/hs_globals.cpp                   |  30 +--
 core/sql/ustat/hs_lex.ll                        |   4 +
 core/sql/ustat/hs_log.cpp                       | 265 ++++++++++---------
 core/sql/ustat/hs_log.h                         |  25 +-
 core/sql/ustat/hs_update.cpp                    |  11 +-
 core/sql/ustat/hs_yacc.y                        |  17 +-
 34 files changed, 1019 insertions(+), 294 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/3555983c/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/3555983c/core/sql/parser/sqlparser.y
----------------------------------------------------------------------


[5/9] trafodion git commit: fix an issue, add regress tests

Posted by li...@apache.org.
fix an issue, add regress tests


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

Branch: refs/heads/master
Commit: f59119c8195e8c04646124c2312c2ac180662c28
Parents: dc9f5b5
Author: Liu Ming <ov...@sina.com>
Authored: Fri Feb 16 19:28:21 2018 +0000
Committer: Liu Ming <ov...@sina.com>
Committed: Fri Feb 16 19:28:21 2018 +0000

----------------------------------------------------------------------
 core/sql/exp/exp_function.cpp            |    2 +-
 core/sql/regress/executor/EXPECTED002.SB | 1050 +++++++++++++++++++++++++
 core/sql/regress/executor/FILTER002      |    2 +
 core/sql/regress/executor/TEST002        |   27 +
 4 files changed, 1080 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/f59119c8/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index 8f03bab..e80401f 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -2589,7 +2589,7 @@ ex_expr::exp_return_type ex_function_unixtime::eval(char *op_data[],
 {
   char *opData = op_data[1];
   //if there is input value
-  if(opData[0] != 0 &&  getNumOperands() == 2)
+  if( getNumOperands() == 2)
   {
     struct tm* ptr;
     char* r = strptime(opData, "%Y-%m-%d %H:%M:%S", ptr);

http://git-wip-us.apache.org/repos/asf/trafodion/blob/f59119c8/core/sql/regress/executor/EXPECTED002.SB
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/EXPECTED002.SB b/core/sql/regress/executor/EXPECTED002.SB
index d4742cb..6260f06 100644
--- a/core/sql/regress/executor/EXPECTED002.SB
+++ b/core/sql/regress/executor/EXPECTED002.SB
@@ -6852,6 +6852,1056 @@ C1
 >>drop table regexp_test;
 
 --- SQL operation complete.
+>>
+>>--create table have 1K rows
+>>create table T002T1K (uniq int not null,
++> c1K int, c100 int,
++> c10 int, c1 int, c0 int  )
++> STORE BY (uniq)
++>  ATTRIBUTES ALIGNED FORMAT
++>  SALT USING 8 PARTITIONS
++>  ;
+
+--- SQL operation complete.
+>>
+>>upsert using load into T002T1K select
++>0 + (1000 * x10) + (100 * x1) + (10 * x1) + (1 * x01),
++>0 + (100 * x10) + (10 * x1) + (1 * x01),
++>0 + (10 * x1) + (1 * x01),
++>0 + (1 * x01),
++>0,
++>X01
++>from (values(0)) t
++>transpose 0,1,2,3,4,5,6,7,8,9 as x10
++>transpose 0,1,2,3,4,5,6,7,8,9 as x1
++>transpose 0,1,2,3,4,5,6,7,8,9 as X01;
+
+--- 1000 row(s) inserted.
+>>
+>>select sleep(5) from dual;
+
+(EXPR)
+-----------
+
+          1
+
+--- 1 row(s) selected.
+>>select 'unixtimestamp',unix_timestamp() from dual;
+
+(EXPR) (EXPR)
+----------
+
+unixtimestamp 1518772709
+
+--- 1 row(s) selected.
+>>select 'uuidrow', uuid(), unix_timestamp() from T002T1K;
+
+(EXPR) (EXPR) (EXPR)
+----------
+
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+uuid
+
+--- 1000 row(s) selected.
+>>
 >>------------------------------------------------------------------------
 >>-- added for JIRA TRAFODION-2843
 >>

http://git-wip-us.apache.org/repos/asf/trafodion/blob/f59119c8/core/sql/regress/executor/FILTER002
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/FILTER002 b/core/sql/regress/executor/FILTER002
index a7075c6..d872937 100755
--- a/core/sql/regress/executor/FILTER002
+++ b/core/sql/regress/executor/FILTER002
@@ -31,4 +31,6 @@ if [ "$fil" = "" ]; then
 fi
 sed "
 s/\.[ ]*\*\*\*/\. \*\*\*/g
+s/^uuidrow.*$/uuid/
+s/^unixtimestamp.*$/unixtimestamp/
 " $fil

http://git-wip-us.apache.org/repos/asf/trafodion/blob/f59119c8/core/sql/regress/executor/TEST002
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/TEST002 b/core/sql/regress/executor/TEST002
index 22cec00..f16c381 100755
--- a/core/sql/regress/executor/TEST002
+++ b/core/sql/regress/executor/TEST002
@@ -1188,6 +1188,32 @@ select * from regexp_test where c1 regexp '^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2
 select * from regexp_test where c1 regexp '(中文测试)';
 select * from regexp_test where c1 regexp '[^\';
 drop table regexp_test;
+
+--create table have 1K rows
+create table T002T1K (uniq int not null,
+ c1K int, c100 int,
+ c10 int, c1 int, c0 int  )
+ STORE BY (uniq)
+  ATTRIBUTES ALIGNED FORMAT
+  SALT USING 8 PARTITIONS
+  ;
+
+upsert using load into T002T1K select
+0 + (1000 * x10) + (100 * x1) + (10 * x1) + (1 * x01),
+0 + (100 * x10) + (10 * x1) + (1 * x01),
+0 + (10 * x1) + (1 * x01),
+0 + (1 * x01),
+0,
+X01
+from (values(0)) t
+transpose 0,1,2,3,4,5,6,7,8,9 as x10
+transpose 0,1,2,3,4,5,6,7,8,9 as x1
+transpose 0,1,2,3,4,5,6,7,8,9 as X01;
+
+select sleep(5) from dual;
+select 'unixtimestamp',unix_timestamp() from dual;
+select 'uuidrow', uuid(), unix_timestamp() from T002T1K;
+
 ------------------------------------------------------------------------
 -- added for JIRA TRAFODION-2843
 
@@ -1274,6 +1300,7 @@ drop table t002t8;
 drop table t002t9;
 drop table t002t10;
 drop table t002tab2;
+drop table t002t1k;
 -- * drop table t002ZZ;
 -- * drop table t002ZZI;
 -- * drop table t002FU;


[3/9] trafodion git commit: [TRAFODION-2157] fix various issues

Posted by li...@apache.org.
[TRAFODION-2157] fix various issues


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

Branch: refs/heads/master
Commit: 3c6bce6e10e8f319bcdeffa272ffc4ac31a74f48
Parents: 3555983
Author: Liu Ming <ov...@sina.com>
Authored: Wed Feb 14 21:51:10 2018 +0000
Committer: Liu Ming <ov...@sina.com>
Committed: Wed Feb 14 21:51:10 2018 +0000

----------------------------------------------------------------------
 core/sql/common/OperTypeEnum.h     |  1 +
 core/sql/exp/exp_clause.cpp        |  2 ++
 core/sql/exp/exp_function.cpp      | 36 ++++++++++++++++++++++++---------
 core/sql/generator/GenItemFunc.cpp |  1 +
 core/sql/optimizer/ItemExpr.cpp    |  2 ++
 core/sql/optimizer/SynthType.cpp   | 29 ++++++++++++++++++++++----
 core/sql/parser/sqlparser.y        | 16 +++++++++++----
 7 files changed, 70 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/common/OperTypeEnum.h
----------------------------------------------------------------------
diff --git a/core/sql/common/OperTypeEnum.h b/core/sql/common/OperTypeEnum.h
index af1d2ba..293a372 100644
--- a/core/sql/common/OperTypeEnum.h
+++ b/core/sql/common/OperTypeEnum.h
@@ -474,6 +474,7 @@ enum OperatorTypeEnum {
 			ITM_UNIX_TIMESTAMP = 2179,
 			ITM_UUID_SHORT = 2180,
 			ITM_SLEEP = 2181,
+			ITM_UNIQUE_SHORT_ID = 2182,
 
                         // numeric functions
                         ITM_ABS = 2200,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/exp/exp_clause.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_clause.cpp b/core/sql/exp/exp_clause.cpp
index 0ad09d5..2a9278e 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_SHORT_ID:
 	  setClassID(FUNC_UNIQUE_ID);
 	  break;
 	case ITM_ROWNUM:
@@ -1507,6 +1508,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_SHORT_ID: return "ITM_UNIQUE_SHORT_ID";
     case ITM_ROWNUM: return "ITM_ROWNUM";
     case ITM_HBASE_COLUMN_LOOKUP: return "ITM_HBASE_COLUMN_LOOKUP";
     case ITM_HBASE_COLUMNS_DISPLAY: return "ITM_HBASE_COLUMNS_DISPLAY";

http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index 821e392..9e5e49e 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -50,6 +50,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <stdio.h>
+#include <uuid/uuid.h>
 
 #include "NLSConversion.h"
 #include "nawstring.h"
@@ -6799,21 +6800,38 @@ ex_expr::exp_return_type ExFunctionUniqueId::eval(char *op_data[],
   Lng32 retcode = 0;
 
   char * result = op_data[0];
+  if(getOperType() == ITM_UNIQUE_ID)
+  {
+    //it is hard to find a common header file for these length
+    //so hardcode 36 here
+    //if change, please check the SynthType.cpp for ITM_UNIQUE_ID part as well
+    //libuuid is global unique, even across computer node
+    //NOTE: libuuid is avialble on normal CentOS, other system like Ubuntu may need to check 
+    //Trafodion only support RHEL and CentOS as for now
+    char str[36 + 1];
+    uuid_t uu;
+    uuid_generate( uu ); 
+    uuid_unparse(uu, str);
+    str_cpy_all(result, str, 36);
+  }
+  else //at present , it must be ITM_UUID_SHORT_ID
+  { 
+    Int64 uniqueUID;
 
-  Int64 uniqueUID;
-
-  ComUID comUID;
-  comUID.make_UID();
+    ComUID comUID;
+    comUID.make_UID();
 
 #if defined( NA_LITTLE_ENDIAN )
-  uniqueUID = reversebytes(comUID.get_value());
+    uniqueUID = reversebytes(comUID.get_value());
 #else
-  uniqueUID = comUID.get_value();
+    uniqueUID = comUID.get_value();
 #endif
 
-  str_cpy_all(result, (char*)&uniqueUID, sizeof(Int64));
-  str_pad(&result[sizeof(Int64)], sizeof(Int64), '\0');
-  
+    //it is safe, since the result is allocated 21 bytes in this case from synthtype,
+    //max in64 is 19 digits and one for sign, 21 is enough
+    sprintf(result,"%lu",uniqueUID); 
+  }
+ 
   return ex_expr::EXPR_OK;
 }
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/generator/GenItemFunc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenItemFunc.cpp b/core/sql/generator/GenItemFunc.cpp
index df3f674..86c1758 100644
--- a/core/sql/generator/GenItemFunc.cpp
+++ b/core/sql/generator/GenItemFunc.cpp
@@ -663,6 +663,7 @@ short BuiltinFunction::codeGen(Generator * generator)
     break;
 
     case ITM_UNIQUE_ID:
+    case ITM_UNIQUE_SHORT_ID:
       {
 	function_clause =
 	  new(generator->getSpace()) ExFunctionUniqueId(getOperatorType(),

http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/optimizer/ItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp
index 006639e..b58aa5e 100644
--- a/core/sql/optimizer/ItemExpr.cpp
+++ b/core/sql/optimizer/ItemExpr.cpp
@@ -7619,6 +7619,8 @@ const NAString BuiltinFunction::getText() const
       return "pack";
     case ITM_SAMPLE_VALUE:
       return "sample_size";
+    case ITM_UNIQUE_SHORT_ID:
+      return "unique_short_id";
     case ITM_UNIQUE_ID:
       return "unique_id";
     case ITM_HBASE_COLUMN_LOOKUP:

http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/optimizer/SynthType.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/SynthType.cpp b/core/sql/optimizer/SynthType.cpp
index fd7fd1f..c3dfc18 100644
--- a/core/sql/optimizer/SynthType.cpp
+++ b/core/sql/optimizer/SynthType.cpp
@@ -1122,9 +1122,23 @@ const NAType *BuiltinFunction::synthesizeType()
 
     case ITM_SLEEP:
       {
-        ValueId vid1 = child(0)->getValueId();
-        SQLInt c1( HEAP, TRUE , TRUE);
-        vid1.coerceType(c1, NA_NUMERIC_TYPE);
+        const NAType &typ1 = child(0)->getValueId().getType();
+       	if (typ1.getTypeQualifier() != NA_NUMERIC_TYPE)
+        {
+	    *CmpCommon::diags() << DgSqlCode(-4045) << DgString0("SLEEP");
+	    return NULL;
+        }
+        const NumericType &ntyp1 = (NumericType &) typ1;
+        if (NOT ntyp1.isExact() )
+        {
+             *CmpCommon::diags() << DgSqlCode(-4046) << DgString0(getTextUpper());
+             return NULL;
+        }
+        if (ntyp1.getScale() != 0 )
+        {
+          *CmpCommon::diags() << DgSqlCode(-4047) << DgString0(getTextUpper());
+          return NULL;
+        } 
         retType = new HEAP SQLInt(HEAP, TRUE, TRUE);
       }
     break;
@@ -1352,7 +1366,14 @@ const NAType *BuiltinFunction::synthesizeType()
 
     case ITM_UNIQUE_ID:
       {
-	retType = new HEAP SQLChar(HEAP, 16, FALSE);
+        //please check the ExFunctionUniqueId::eval if the size is changed
+	retType = new HEAP SQLChar(HEAP, 36, FALSE);
+      }
+      break;
+    case ITM_UNIQUE_SHORT_ID:
+      {
+        //please check the ExFunctionUniqueId::eval if the size is changed
+	retType = new HEAP SQLChar(HEAP, 21, FALSE);
       }
       break;
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c6bce6e/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 00672e8..336dfd6 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -8716,14 +8716,22 @@ datetime_value_function : TOK_CURDATE '(' ')'
                                    $$ = 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);
+                  //ItemExpr *conv = new (PARSERHEAP()) ConvertHex(ITM_CONVERTTOHEX, uniqueId);
+                  NAType * type;
+                  type = new (PARSERHEAP())
+                       SQLVarChar(PARSERHEAP() , 36, FALSE);
+                  $$ = new (PARSERHEAP()) Cast(uniqueId,type);
+              }
+    | 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() , 128 , FALSE);
-                  $$ = new (PARSERHEAP()) Cast(conv,type);
+                       SQLVarChar(PARSERHEAP() , 36, FALSE);
+                  $$ = new (PARSERHEAP()) Cast(uniqueId,type);
               }
 
 /* type item */


[8/9] trafodion git commit: fix temp debug code, typos

Posted by li...@apache.org.
fix temp debug code, typos


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

Branch: refs/heads/master
Commit: 9001298a7729e39cef8f364ae7b2ac3a1090c61e
Parents: 1bfb2a8
Author: Liu Ming <ov...@sina.com>
Authored: Thu Feb 22 01:42:41 2018 +0000
Committer: Liu Ming <ov...@sina.com>
Committed: Thu Feb 22 01:42:41 2018 +0000

----------------------------------------------------------------------
 core/sql/parser/sqlparser.y | 5 -----
 1 file changed, 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/9001298a/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index d1e7d56..69df367 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -8889,13 +8889,8 @@ datetime_misc_function : TOK_CONVERTTIMESTAMP '(' value_expression ')'
 			       }
     | TOK_SLEEP '(' numeric_literal_exact ')'
 				{
-                  NAType * type;
-                  type = new (PARSERHEAP())
-                       SQLInt(PARSERHEAP() , FALSE, FALSE);
-				 //ItemExpr* ie = new (PARSERHEAP()) 
 				 $$ = new (PARSERHEAP()) 
 				   SleepFunction( $3);
-                  //$$ = new (PARSERHEAP()) Cast(ie,type);
 				}
 
 CHAR_FUNC_optional_character_set : ',' CHAR_FUNC_character_set


[4/9] trafodion git commit: modify for the review comments to strictly check the input to unix_timestamp

Posted by li...@apache.org.
modify for the review comments to strictly check the input to unix_timestamp


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

Branch: refs/heads/master
Commit: dc9f5b5ae64cfb1df3a27ca67e46e1568c42dafd
Parents: 3c6bce6
Author: Liu Ming <ov...@sina.com>
Authored: Thu Feb 15 19:28:20 2018 +0000
Committer: Liu Ming <ov...@sina.com>
Committed: Thu Feb 15 19:28:20 2018 +0000

----------------------------------------------------------------------
 core/sql/exp/exp_function.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/dc9f5b5a/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index 9e5e49e..8f03bab 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -2593,7 +2593,7 @@ ex_expr::exp_return_type ex_function_unixtime::eval(char *op_data[],
   {
     struct tm* ptr;
     char* r = strptime(opData, "%Y-%m-%d %H:%M:%S", ptr);
-    if( r == NULL)
+    if( (r == NULL) ||  (*r != '\0') )
     {
         ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
         *(*diagsArea) << DgString0("UNIX_TIMESTAMP");


[7/9] trafodion git commit: [TRAFODION-2954] add MySQL function unix_timestamp, uuid, sleep

Posted by li...@apache.org.
[TRAFODION-2954] 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/1bfb2a87
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/1bfb2a87
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/1bfb2a87

Branch: refs/heads/master
Commit: 1bfb2a876a011472db705863d51e8277970afd80
Parents: 9312bd2
Author: Liu Ming <ov...@sina.com>
Authored: Thu Feb 22 01:33:37 2018 +0000
Committer: Liu Ming <ov...@sina.com>
Committed: Thu Feb 22 01:33:37 2018 +0000

----------------------------------------------------------------------
 core/sql/exp/exp_function.cpp            |    2 +-
 core/sql/generator/GenExpGenerator.cpp   |    3 +-
 core/sql/optimizer/BindItemExpr.cpp      |   50 +-
 core/sql/optimizer/GroupAttr.cpp         |    5 +-
 core/sql/optimizer/ItemExpr.cpp          |   29 +-
 core/sql/optimizer/ItemFunc.h            |   35 +-
 core/sql/optimizer/OptItemExpr.cpp       |    1 +
 core/sql/optimizer/SynthType.cpp         |   33 +-
 core/sql/parser/sqlparser.y              |    9 +-
 core/sql/regress/executor/EXPECTED002.SB | 1040 +------------------------
 core/sql/regress/executor/FILTER002      |    1 +
 core/sql/regress/executor/TEST002        |   14 +-
 12 files changed, 138 insertions(+), 1084 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/1bfb2a87/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index e80401f..a65c120 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -2522,7 +2522,7 @@ ex_expr::exp_return_type ex_function_sleep::eval(char *op_data[],
 						   CollHeap* heap,
 						   ComDiagsArea** diagsArea)
 {
-   Int32 sec = 0;
+  Int32 sec = 0;
   switch (getOperand(1)->getDatatype())
   {
     case REC_BIN8_SIGNED:

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1bfb2a87/core/sql/generator/GenExpGenerator.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenExpGenerator.cpp b/core/sql/generator/GenExpGenerator.cpp
index f2651c4..2fcc85d 100644
--- a/core/sql/generator/GenExpGenerator.cpp
+++ b/core/sql/generator/GenExpGenerator.cpp
@@ -3701,8 +3701,7 @@ short ExpGenerator::generateInputExpr(const ValueIdList &val_id_list,
 	if ((item_expr->isAUserSuppliedInput()) || //evaluate once functions
 		(item_expr->getOperatorType() == ITM_CURRENT_TIMESTAMP) ||
 		(item_expr->getOperatorType() == ITM_UNIX_TIMESTAMP) ||
-		(item_expr->getOperatorType() == ITM_UNIQUE_ID) ||
-		(item_expr->getOperatorType() == ITM_UNIQUE_SHORT_ID) ||
+		(item_expr->getOperatorType() == ITM_SLEEP) ||
 	    (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/1bfb2a87/core/sql/optimizer/BindItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindItemExpr.cpp b/core/sql/optimizer/BindItemExpr.cpp
index c617d17..3c81218 100644
--- a/core/sql/optimizer/BindItemExpr.cpp
+++ b/core/sql/optimizer/BindItemExpr.cpp
@@ -3187,7 +3187,6 @@ ItemExpr *BuiltinFunction::bindNode(BindWA *bindWA)
 
     case ITM_ISIPV4:
     case ITM_ISIPV6:
-    case ITM_SLEEP:
     case ITM_MD5:
     case ITM_CRC32:
     case ITM_SHA1:
@@ -3199,23 +3198,6 @@ ItemExpr *BuiltinFunction::bindNode(BindWA *bindWA)
       {
          break;
       }
-    case ITM_UNIQUE_ID:
-    case ITM_UNIQUE_SHORT_ID:
-      {
-        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;
-      }
-    break;
     case ITM_NULLIFZERO:
       {
 	// binder has already verified that child is numeric
@@ -8436,6 +8418,38 @@ ItemExpr *DefaultSpecification::bindNode(BindWA *bindWA)
 } // DefaultSpecification::bindNode()
 
 // -----------------------------------------------------------------------
+// member functions for class SleepFunction 
+// -----------------------------------------------------------------------
+
+ItemExpr *SleepFunction::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;
+} // SleepFunction::bindNode()
+
+// -----------------------------------------------------------------------
 // member functions for class UnixTimestamp
 // -----------------------------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1bfb2a87/core/sql/optimizer/GroupAttr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/GroupAttr.cpp b/core/sql/optimizer/GroupAttr.cpp
index 3ebe690..bf31b8b 100644
--- a/core/sql/optimizer/GroupAttr.cpp
+++ b/core/sql/optimizer/GroupAttr.cpp
@@ -1787,14 +1787,13 @@ void GroupAttributes::resolveCharacteristicInputs(const ValueIdSet& externalInpu
 	 {
 	   VEGReference *vegRef = ((VEGReference *)(x.getItemExpr()));
 	   ValueIdSet allValues = vegRef->getVEG()->getAllValues();
-	   // in all these values check for current_user amd current_timestamp
+	   // in all these values check for current_user and current_timestamp
 	   for (ValueId vid = allValues.init(); allValues.next(vid); allValues.advance(vid))
 	   {
 	     ItemExpr * vidExpr = vid.getItemExpr();
 	     if ((vidExpr->getOperatorType() == ITM_CURRENT_USER) ||
 		 (vidExpr->getOperatorType() == ITM_CURRENT_TIMESTAMP) ||
-		 (vidExpr->getOperatorType() == ITM_UNIQUE_SHORT_ID) ||
-		 (vidExpr->getOperatorType() == ITM_UNIQUE_ID) ||
+		 (vidExpr->getOperatorType() == ITM_SLEEP) ||
 		 (vidExpr->getOperatorType() == ITM_UNIX_TIMESTAMP))
 
 	       currentConstants += vid;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1bfb2a87/core/sql/optimizer/ItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp
index a2e56eb..744a0a5 100644
--- a/core/sql/optimizer/ItemExpr.cpp
+++ b/core/sql/optimizer/ItemExpr.cpp
@@ -872,8 +872,6 @@ NABoolean ItemExpr::doesExprEvaluateToConstant(NABoolean strict,
 
 		case ITM_DYN_PARAM:
 		case ITM_CACHE_PARAM:
-		case ITM_UNIQUE_ID:
-		case ITM_UNIQUE_SHORT_ID:
 		case ITM_CURRENT_USER:
 		case ITM_SESSION_USER:
 		case ITM_CURRENT_TIMESTAMP:
@@ -971,8 +969,6 @@ NABoolean ItemExpr::referencesAHostVar() const
       case ITM_CURRENT_TIMESTAMP:
       case ITM_GET_TRIGGERS_STATUS:
       case ITM_UNIQUE_EXECUTE_ID:
-      case ITM_UNIQUE_SHORT_ID:
-      case ITM_UNIQUE_ID:
       case ITM_CURR_TRANSID:
 	return TRUE;
 
@@ -7372,15 +7368,6 @@ Int32 BuiltinFunction::getArity() const
   return getNumChildren();
 }
 
-NABoolean BuiltinFunction::isAUserSuppliedInput() const 
-{
-  if(getOperatorType() == ITM_UNIQUE_ID ||
-     getOperatorType() == ITM_UNIQUE_SHORT_ID ) 
-    return TRUE;
-  else
-    return FALSE;
-}
-
 // -----------------------------------------------------------------------
 // BuiltinFunction::isCovered()
 // -----------------------------------------------------------------------
@@ -8285,6 +8272,22 @@ ItemExpr * ConvertTimestamp::copyTopNode(ItemExpr *derivedNode,
 
 } // ConvertTimestamp::copyTopNode()
 
+SleepFunction::~SleepFunction() {}
+ItemExpr * SleepFunction::copyTopNode(ItemExpr *derivedNode,
+					 CollHeap* outHeap)
+{
+  ItemExpr *result;
+
+  if (derivedNode == NULL)
+    result = new (outHeap) SleepFunction(child(0));
+  else
+    result = derivedNode;
+
+  return BuiltinFunction::copyTopNode(result,outHeap);
+
+} // SleepFunction::copyTopNode()
+NABoolean SleepFunction::isAUserSuppliedInput() const    { return TRUE; }
+
 UnixTimestamp::~UnixTimestamp() {}
 
 ItemExpr * UnixTimestamp::copyTopNode(ItemExpr *derivedNode,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1bfb2a87/core/sql/optimizer/ItemFunc.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemFunc.h b/core/sql/optimizer/ItemFunc.h
index 7c67931..6c0c779 100644
--- a/core/sql/optimizer/ItemFunc.h
+++ b/core/sql/optimizer/ItemFunc.h
@@ -680,12 +680,6 @@ public:
   // a virtual function for performing name binding within the query tree
   virtual ItemExpr * bindNode(BindWA *bindWA);
 
-  // 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;
-
   // Each operator supports a (virtual) method for transforming its
   // scalar expressions to a canonical form
   virtual void transformNode(NormWA & normWARef,
@@ -1757,6 +1751,35 @@ public:
   virtual NABoolean hasEquivalentProperties(ItemExpr * other) { return TRUE;}
 }; // class ConvertTimestamp
 
+class SleepFunction : public CacheableBuiltinFunction
+{
+public:
+
+  SleepFunction( ItemExpr *val1Ptr )
+   : CacheableBuiltinFunction(ITM_SLEEP, 1, val1Ptr)
+  {}
+  // virtual destructor
+  virtual ~SleepFunction();
+
+  // 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 SleepFunction 
+
 class UnixTimestamp : public CacheableBuiltinFunction
 {
 public:

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

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1bfb2a87/core/sql/optimizer/SynthType.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/SynthType.cpp b/core/sql/optimizer/SynthType.cpp
index c3dfc18..5dcb94e 100644
--- a/core/sql/optimizer/SynthType.cpp
+++ b/core/sql/optimizer/SynthType.cpp
@@ -1120,28 +1120,6 @@ const NAType *BuiltinFunction::synthesizeType()
       }
     break;
 
-    case ITM_SLEEP:
-      {
-        const NAType &typ1 = child(0)->getValueId().getType();
-       	if (typ1.getTypeQualifier() != NA_NUMERIC_TYPE)
-        {
-	    *CmpCommon::diags() << DgSqlCode(-4045) << DgString0("SLEEP");
-	    return NULL;
-        }
-        const NumericType &ntyp1 = (NumericType &) typ1;
-        if (NOT ntyp1.isExact() )
-        {
-             *CmpCommon::diags() << DgSqlCode(-4046) << DgString0(getTextUpper());
-             return NULL;
-        }
-        if (ntyp1.getScale() != 0 )
-        {
-          *CmpCommon::diags() << DgSqlCode(-4047) << DgString0(getTextUpper());
-          return NULL;
-        } 
-        retType = new HEAP SQLInt(HEAP, TRUE, TRUE);
-      }
-    break;
     case ITM_INET_ATON:
       {
         // type cast any params
@@ -3092,6 +3070,17 @@ const NAType *ConvertTimestamp::synthesizeType()
 
 }
 
+// -----------------------------------------------------------------------
+// member functions for class SleepFunction 
+// -----------------------------------------------------------------------
+const NAType *SleepFunction::synthesizeType()
+{
+    return  new HEAP SQLInt(HEAP, TRUE, TRUE);
+}
+
+// -----------------------------------------------------------------------
+// member functions for class UnixTimestamp
+// -----------------------------------------------------------------------
 const NAType *UnixTimestamp::synthesizeType()
 {
   return new HEAP SQLLargeInt(HEAP, FALSE,FALSE);

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1bfb2a87/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 336dfd6..d1e7d56 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -8887,10 +8887,15 @@ datetime_misc_function : TOK_CONVERTTIMESTAMP '(' value_expression ')'
 				 $$ = new (PARSERHEAP()) 
 				   ZZZBinderFunction(ITM_TO_TIMESTAMP, $3);
 			       }
-    | TOK_SLEEP '(' value_expression ')'
+    | TOK_SLEEP '(' numeric_literal_exact ')'
 				{
+                  NAType * type;
+                  type = new (PARSERHEAP())
+                       SQLInt(PARSERHEAP() , FALSE, FALSE);
+				 //ItemExpr* ie = new (PARSERHEAP()) 
 				 $$ = new (PARSERHEAP()) 
-				   BuiltinFunction(ITM_SLEEP,  CmpCommon::statementHeap(), 1, $3);
+				   SleepFunction( $3);
+                  //$$ = new (PARSERHEAP()) Cast(ie,type);
 				}
 
 CHAR_FUNC_optional_character_set : ',' CHAR_FUNC_character_set

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1bfb2a87/core/sql/regress/executor/EXPECTED002.SB
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/EXPECTED002.SB b/core/sql/regress/executor/EXPECTED002.SB
index 6260f06..cb581bd 100644
--- a/core/sql/regress/executor/EXPECTED002.SB
+++ b/core/sql/regress/executor/EXPECTED002.SB
@@ -6878,1030 +6878,44 @@ C1
 
 --- 1000 row(s) inserted.
 >>
->>select sleep(5) from dual;
+>>create table t002timert (c0 int, c1 int, c2 largeint);
 
-(EXPR)
------------
+--- SQL operation complete.
+>>create table t002tmp1 (c1 int);
 
-          1
+--- SQL operation complete.
+>>insert into t002tmp1 values(1),(2),(3);
 
---- 1 row(s) selected.
->>select 'unixtimestamp',unix_timestamp() from dual;
+--- 3 row(s) inserted.
+>>
+>>insert into t002timert select 1, sleep(5) , unix_timestamp() from t002tmp1;
+
+--- 3 row(s) inserted.
+>>insert into t002timert select 2, sleep(5) , unix_timestamp() from t002tmp1;
+
+--- 3 row(s) inserted.
+>>select 'sleeptimetest002', di from (select ( max(c2) - min(c2)) as di from t002timert ) where di between 5 and 9;
 
-(EXPR) (EXPR)
+(EXPR) DI
 ----------
 
-unixtimestamp 1518772709
+good
 
 --- 1 row(s) selected.
->>select 'uuidrow', uuid(), unix_timestamp() from T002T1K;
+>>select distinct(count(uuid())) from T002T1K;
 
-(EXPR) (EXPR) (EXPR)
+(EXPR)
 ----------
 
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-uuid
-
---- 1000 row(s) selected.
->>
+  1000 
+
+--- 1 row(s) selected.
+>>drop table t002timert;
+
+--- SQL operation complete.
+>>drop table t002tmp1;
+
+--- SQL operation complete.
 >>------------------------------------------------------------------------
 >>-- added for JIRA TRAFODION-2843
 >>

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1bfb2a87/core/sql/regress/executor/FILTER002
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/FILTER002 b/core/sql/regress/executor/FILTER002
index d872937..1b5f042 100755
--- a/core/sql/regress/executor/FILTER002
+++ b/core/sql/regress/executor/FILTER002
@@ -32,5 +32,6 @@ fi
 sed "
 s/\.[ ]*\*\*\*/\. \*\*\*/g
 s/^uuidrow.*$/uuid/
+s/^sleeptimetest002.*$/good/
 s/^unixtimestamp.*$/unixtimestamp/
 " $fil

http://git-wip-us.apache.org/repos/asf/trafodion/blob/1bfb2a87/core/sql/regress/executor/TEST002
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/TEST002 b/core/sql/regress/executor/TEST002
index f16c381..d66b483 100755
--- a/core/sql/regress/executor/TEST002
+++ b/core/sql/regress/executor/TEST002
@@ -1210,10 +1210,16 @@ transpose 0,1,2,3,4,5,6,7,8,9 as x10
 transpose 0,1,2,3,4,5,6,7,8,9 as x1
 transpose 0,1,2,3,4,5,6,7,8,9 as X01;
 
-select sleep(5) from dual;
-select 'unixtimestamp',unix_timestamp() from dual;
-select 'uuidrow', uuid(), unix_timestamp() from T002T1K;
-
+create table t002timert (c0 int, c1 int, c2 largeint);
+create table t002tmp1 (c1 int);
+insert into t002tmp1 values(1),(2),(3);
+
+insert into t002timert select 1, sleep(5) , unix_timestamp() from t002tmp1;
+insert into t002timert select 2, sleep(5) , unix_timestamp() from t002tmp1;
+select 'sleeptimetest002', di from (select ( max(c2) - min(c2)) as di from t002timert ) where di between 5 and 9;
+select distinct(count(uuid())) from T002T1K;
+drop table t002timert;
+drop table t002tmp1;
 ------------------------------------------------------------------------
 -- added for JIRA TRAFODION-2843
 


[6/9] trafodion git commit: make the uuid evaluate once per statement

Posted by li...@apache.org.
make the uuid evaluate once per statement


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

Branch: refs/heads/master
Commit: 9312bd20c952bc8f0a74141400a3a9e30c053dc5
Parents: f59119c
Author: Liu Ming <ov...@sina.com>
Authored: Fri Feb 16 22:51:10 2018 +0000
Committer: Liu Ming <ov...@sina.com>
Committed: Fri Feb 16 22:51:10 2018 +0000

----------------------------------------------------------------------
 core/sql/common/OperTypeEnum.h         |  5 ++---
 core/sql/generator/GenExpGenerator.cpp |  2 ++
 core/sql/optimizer/BindItemExpr.cpp    | 30 ++++++++++++++++++-----------
 core/sql/optimizer/GroupAttr.cpp       |  2 ++
 core/sql/optimizer/ItemExpr.cpp        | 13 +++++++++++++
 core/sql/optimizer/ItemFunc.h          |  6 ++++++
 6 files changed, 44 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/9312bd20/core/sql/common/OperTypeEnum.h
----------------------------------------------------------------------
diff --git a/core/sql/common/OperTypeEnum.h b/core/sql/common/OperTypeEnum.h
index 293a372..c70310f 100644
--- a/core/sql/common/OperTypeEnum.h
+++ b/core/sql/common/OperTypeEnum.h
@@ -472,9 +472,8 @@ enum OperatorTypeEnum {
                         // Regular Expression
                         ITM_REGEXP = 2178,
 			ITM_UNIX_TIMESTAMP = 2179,
-			ITM_UUID_SHORT = 2180,
-			ITM_SLEEP = 2181,
-			ITM_UNIQUE_SHORT_ID = 2182,
+			ITM_SLEEP = 2180,
+			ITM_UNIQUE_SHORT_ID = 2181,
 
                         // numeric functions
                         ITM_ABS = 2200,

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9312bd20/core/sql/generator/GenExpGenerator.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenExpGenerator.cpp b/core/sql/generator/GenExpGenerator.cpp
index 1b038a5..f2651c4 100644
--- a/core/sql/generator/GenExpGenerator.cpp
+++ b/core/sql/generator/GenExpGenerator.cpp
@@ -3701,6 +3701,8 @@ short ExpGenerator::generateInputExpr(const ValueIdList &val_id_list,
 	if ((item_expr->isAUserSuppliedInput()) || //evaluate once functions
 		(item_expr->getOperatorType() == ITM_CURRENT_TIMESTAMP) ||
 		(item_expr->getOperatorType() == ITM_UNIX_TIMESTAMP) ||
+		(item_expr->getOperatorType() == ITM_UNIQUE_ID) ||
+		(item_expr->getOperatorType() == ITM_UNIQUE_SHORT_ID) ||
 	    (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/9312bd20/core/sql/optimizer/BindItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindItemExpr.cpp b/core/sql/optimizer/BindItemExpr.cpp
index ee687e4..c617d17 100644
--- a/core/sql/optimizer/BindItemExpr.cpp
+++ b/core/sql/optimizer/BindItemExpr.cpp
@@ -3199,6 +3199,23 @@ ItemExpr *BuiltinFunction::bindNode(BindWA *bindWA)
       {
          break;
       }
+    case ITM_UNIQUE_ID:
+    case ITM_UNIQUE_SHORT_ID:
+      {
+        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;
+      }
+    break;
     case ITM_NULLIFZERO:
       {
 	// binder has already verified that child is numeric
@@ -3473,6 +3490,7 @@ ItemExpr *BuiltinFunction::bindNode(BindWA *bindWA)
   // expression getting translated correctly. 
 
   setReplacementExpr(ie);
+
   return ie;
 }
 
@@ -12013,17 +12031,7 @@ 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/9312bd20/core/sql/optimizer/GroupAttr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/GroupAttr.cpp b/core/sql/optimizer/GroupAttr.cpp
index eb6a87b..3ebe690 100644
--- a/core/sql/optimizer/GroupAttr.cpp
+++ b/core/sql/optimizer/GroupAttr.cpp
@@ -1793,6 +1793,8 @@ void GroupAttributes::resolveCharacteristicInputs(const ValueIdSet& externalInpu
 	     ItemExpr * vidExpr = vid.getItemExpr();
 	     if ((vidExpr->getOperatorType() == ITM_CURRENT_USER) ||
 		 (vidExpr->getOperatorType() == ITM_CURRENT_TIMESTAMP) ||
+		 (vidExpr->getOperatorType() == ITM_UNIQUE_SHORT_ID) ||
+		 (vidExpr->getOperatorType() == ITM_UNIQUE_ID) ||
 		 (vidExpr->getOperatorType() == ITM_UNIX_TIMESTAMP))
 
 	       currentConstants += vid;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9312bd20/core/sql/optimizer/ItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp
index b58aa5e..a2e56eb 100644
--- a/core/sql/optimizer/ItemExpr.cpp
+++ b/core/sql/optimizer/ItemExpr.cpp
@@ -872,6 +872,8 @@ NABoolean ItemExpr::doesExprEvaluateToConstant(NABoolean strict,
 
 		case ITM_DYN_PARAM:
 		case ITM_CACHE_PARAM:
+		case ITM_UNIQUE_ID:
+		case ITM_UNIQUE_SHORT_ID:
 		case ITM_CURRENT_USER:
 		case ITM_SESSION_USER:
 		case ITM_CURRENT_TIMESTAMP:
@@ -969,6 +971,8 @@ NABoolean ItemExpr::referencesAHostVar() const
       case ITM_CURRENT_TIMESTAMP:
       case ITM_GET_TRIGGERS_STATUS:
       case ITM_UNIQUE_EXECUTE_ID:
+      case ITM_UNIQUE_SHORT_ID:
+      case ITM_UNIQUE_ID:
       case ITM_CURR_TRANSID:
 	return TRUE;
 
@@ -7368,6 +7372,15 @@ Int32 BuiltinFunction::getArity() const
   return getNumChildren();
 }
 
+NABoolean BuiltinFunction::isAUserSuppliedInput() const 
+{
+  if(getOperatorType() == ITM_UNIQUE_ID ||
+     getOperatorType() == ITM_UNIQUE_SHORT_ID ) 
+    return TRUE;
+  else
+    return FALSE;
+}
+
 // -----------------------------------------------------------------------
 // BuiltinFunction::isCovered()
 // -----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/trafodion/blob/9312bd20/core/sql/optimizer/ItemFunc.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemFunc.h b/core/sql/optimizer/ItemFunc.h
index 09f4652..7c67931 100644
--- a/core/sql/optimizer/ItemFunc.h
+++ b/core/sql/optimizer/ItemFunc.h
@@ -680,6 +680,12 @@ public:
   // a virtual function for performing name binding within the query tree
   virtual ItemExpr * bindNode(BindWA *bindWA);
 
+  // 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;
+
   // Each operator supports a (virtual) method for transforming its
   // scalar expressions to a canonical form
   virtual void transformNode(NormWA & normWARef,


[9/9] trafodion git commit: [TRAFODION-2954] add MySQL function unix_timestamp, uuid, sleep

Posted by li...@apache.org.
[TRAFODION-2954] 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/75c7b395
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/75c7b395
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/75c7b395

Branch: refs/heads/master
Commit: 75c7b39545745a81945c4010ce34f6321090c104
Parents: 344cc3f 9001298
Author: Liu Ming <ov...@sina.com>
Authored: Fri Feb 23 04:31:26 2018 +0000
Committer: Liu Ming <ov...@sina.com>
Committed: Fri Feb 23 04:31:26 2018 +0000

----------------------------------------------------------------------
 core/sql/common/OperTypeEnum.h           |   3 +
 core/sql/exp/ExpPackDefs.cpp             |  10 ++
 core/sql/exp/exp_clause.cpp              |  16 +++
 core/sql/exp/exp_clause.h                |   4 +-
 core/sql/exp/exp_function.cpp            | 146 ++++++++++++++++++++++++--
 core/sql/exp/exp_function.h              |  60 +++++++++++
 core/sql/generator/GenExpGenerator.cpp   |   2 +
 core/sql/generator/GenItemFunc.cpp       |  17 +++
 core/sql/optimizer/BindItemExpr.cpp      |  65 ++++++++++++
 core/sql/optimizer/GroupAttr.cpp         |   7 +-
 core/sql/optimizer/ItemExpr.cpp          |  40 +++++++
 core/sql/optimizer/ItemFunc.h            |  61 +++++++++++
 core/sql/optimizer/OptItemExpr.cpp       |   2 +
 core/sql/optimizer/SynthType.cpp         |  26 ++++-
 core/sql/parser/ParKeyWords.cpp          |   3 +
 core/sql/parser/sqlparser.y              |  61 +++++++----
 core/sql/regress/executor/EXPECTED002.SB |  64 +++++++++++
 core/sql/regress/executor/FILTER002      |   3 +
 core/sql/regress/executor/TEST002        |  33 ++++++
 19 files changed, 592 insertions(+), 31 deletions(-)
----------------------------------------------------------------------