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 2016/11/25 13:34:18 UTC

[2/5] incubator-trafodion git commit: [TRAFODION-2353] initial execution part

[TRAFODION-2353] initial execution part


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

Branch: refs/heads/master
Commit: 4355adf59b8380c774e7ea471ee31b225eec936d
Parents: 05e19f2
Author: Liu Ming <ov...@sina.com>
Authored: Thu Nov 17 00:59:28 2016 -0500
Committer: Liu Ming <ov...@sina.com>
Committed: Thu Nov 17 00:59:28 2016 -0500

----------------------------------------------------------------------
 core/sql/exp/ExpPackDefs.cpp        |   5 +
 core/sql/exp/exp_clause.cpp         |  24 ++++-
 core/sql/exp/exp_clause.h           |   3 +-
 core/sql/exp/exp_clause_derived.h   | 169 +++++++++++++++++++++++++++++++
 core/sql/exp/exp_like.cpp           |  56 ++++++++++
 core/sql/generator/GenItemFunc.cpp  |   6 +-
 core/sql/optimizer/BindItemExpr.cpp |   1 +
 core/sql/optimizer/ItemExpr.cpp     |   2 +
 core/sql/parser/sqlparser.y         |   4 +-
 9 files changed, 266 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4355adf5/core/sql/exp/ExpPackDefs.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpPackDefs.cpp b/core/sql/exp/ExpPackDefs.cpp
index d87497a..2778493 100644
--- a/core/sql/exp/ExpPackDefs.cpp
+++ b/core/sql/exp/ExpPackDefs.cpp
@@ -163,6 +163,11 @@ NA_EIDPROC Long ex_unlogic_clause::pack(void * space_)
   return packClause(space_, sizeof(ex_unlogic_clause));
 }
 
+NA_EIDPROC Long ExRegexpClauseChar::pack(void * space_)
+{
+  return packClause(space_, sizeof(ExRegexpClauseChar));
+}
+
 NA_EIDPROC Long ex_like_clause_char::pack(void * space_)
 {
   return packClause(space_, sizeof(ex_like_clause_char));

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4355adf5/core/sql/exp/exp_clause.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_clause.cpp b/core/sql/exp/exp_clause.cpp
index c527c77..49caed7 100644
--- a/core/sql/exp/exp_clause.cpp
+++ b/core/sql/exp/exp_clause.cpp
@@ -194,6 +194,9 @@ ex_clause::ex_clause(clause_type type,
 	case ITM_LIKE_DOUBLEBYTE: 
 	  setClassID(LIKE_CLAUSE_DOUBLEBYTE_ID);
 	  break;
+        case ITM_REGEXP:
+          setClassID(REGEXP_CLAUSE_CHAR_ID);
+          break;
 	case ITM_ASCII: 
 	case ITM_CODE_VALUE: 
 	case ITM_UNICODE_CODE_VALUE: 
@@ -683,6 +686,9 @@ NA_EIDPROC char *ex_clause::findVTblPtr(short classID)
     case ex_clause::LIKE_CLAUSE_DOUBLEBYTE_ID:
       GetVTblPtr(vtblPtr, ex_like_clause_doublebyte);
       break;
+    case ex_clause::REGEXP_CLAUSE_CHAR_ID:
+            GetVTblPtr(vtblPtr, ExRegexpClauseChar);
+      break;
     case ex_clause::FUNC_ASCII_ID:
       GetVTblPtr(vtblPtr, ExFunctionAscii);
       break;
@@ -1191,6 +1197,7 @@ NA_EIDPROC const char * getOperTypeEnumAsString(Int16 /*OperatorTypeEnum*/ ote)
     case ITM_BETWEEN: return "ITM_BETWEEN";
     // LCOV_EXCL_STOP
     case ITM_LIKE: return "ITM_LIKE";
+    case ITM_REGEXP: return "ITM_REGEXP";
     // LCOV_EXCL_START
     case ITM_CURRENT_TIMESTAMP: return "ITM_CURRENT_TIMESTAMP";
     case ITM_CURRENT_USER: return "ITM_CURRENT_USER";
@@ -1648,7 +1655,16 @@ ex_arith_clause::ex_arith_clause(OperatorTypeEnum oper_type,
   if (attr)
     setInstruction();
 }
- 
+
+
+ExRegexpClauseChar::ExRegexpClauseChar(OperatorTypeEnum oper_type, 
+			    short num_operands,
+			    Attributes ** attr,
+			    Space * space)
+: ExRegexpClauseBase(oper_type, num_operands,attr,space)
+{
+}
+
 ex_arith_clause::ex_arith_clause(clause_type type,
                                  OperatorTypeEnum oper_type,
                                  Attributes ** attr,
@@ -2052,6 +2068,12 @@ void ex_like_clause_char::displayContents(Space * space, const char * /*displayS
 {
   ex_clause::displayContents(space, "ex_like_clause_char", clauseNum, constsArea);
 }
+
+void ExRegexpClauseChar::displayContents(Space * space, const char * /*displayStr*/, Int32 clauseNum, char * constsArea)
+{
+  ex_clause::displayContents(space, "ExRegexpClauseChar", clauseNum, constsArea);
+}
+
 // LCOV_EXCL_START
 void ex_like_clause_doublebyte::displayContents(Space * space, const char * /*displayStr*/, Int32 clauseNum, char * constsArea)
 {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4355adf5/core/sql/exp/exp_clause.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_clause.h b/core/sql/exp/exp_clause.h
index 275914b..5028bb1 100644
--- a/core/sql/exp/exp_clause.h
+++ b/core/sql/exp/exp_clause.h
@@ -207,7 +207,8 @@ public:
     FUNC_CRC32_ID            = 122,
     FUNC_MD5_ID              = 123,
     FUNC_SHA1_ID             = 124,
-    FUNC_SHA2_ID             = 125
+    FUNC_SHA2_ID             = 125,
+    REGEXP_CLAUSE_CHAR_ID    = 126
   };
 
   // max number of operands (including result) in a clause.

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4355adf5/core/sql/exp/exp_clause_derived.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_clause_derived.h b/core/sql/exp/exp_clause_derived.h
index 5669b66..e2c7646 100644
--- a/core/sql/exp/exp_clause_derived.h
+++ b/core/sql/exp/exp_clause_derived.h
@@ -2424,7 +2424,176 @@ private:
 };
 
 
+class SQLEXP_LIB_FUNC  ExRegexpClauseBase : public ex_clause {
 
+public:
+  // Construction
+  //
+  NA_EIDPROC ExRegexpClauseBase() 
+  {
+    setCollation(CharInfo::DefaultCollation);
+  }
+  NA_EIDPROC ExRegexpClauseBase(OperatorTypeEnum oper_type,
+			    short num_operands,
+			    Attributes ** attr,
+			    Space * space) :
+		ex_clause(ex_clause::LIKE_TYPE, oper_type,
+                          num_operands, attr, space
+                         ) 
+  {
+    setCollation(CharInfo::DefaultCollation);
+  }
+
+
+  // Null Semantics
+  //
+  NA_EIDPROC Int32 isNullInNullOut() const { return 0; };
+  NA_EIDPROC Int32 isNullRelevant() const { return 1; };
+  NA_EIDPROC ex_expr::exp_return_type processNulls(char *op_data[],
+  						   CollHeap * = 0,
+						   ComDiagsArea ** = 0);
+
+  // Execution
+  //
+  NA_EIDPROC Int32 isEvalRelevant() const { return 1; };
+  NA_EIDPROC ex_expr::exp_return_type eval(char *op_data[],
+					   CollHeap * = 0,
+					   ComDiagsArea ** = 0) = 0;
+
+  // Fixup
+  //
+  NA_EIDPROC Long pack (void *) = 0;
+  
+  // Display
+  //
+  NA_EIDPROC void displayContents(Space * space, const char * displayStr, 
+					  Int32 clauseNum, char * constsArea)
+    {};
+
+
+  // ---------------------------------------------------------------------
+  // Redefinition of methods inherited from NAVersionedObject.
+  // ---------------------------------------------------------------------
+  NA_EIDPROC virtual unsigned char getClassVersionID()
+  {
+    return 1;
+  }
+
+  NA_EIDPROC virtual void populateImageVersionIDArray()
+  {
+    setImageVersionID(1,getClassVersionID());
+    ex_clause::populateImageVersionIDArray();
+  }
+
+  NA_EIDPROC virtual short getClassSize() { return (short)sizeof(*this); }
+
+  NA_EIDPROC inline char* getPatternStr()
+  {
+    return patternStr_;
+  }
+
+  NA_EIDPROC inline void setPatternStr(char* pat)
+  {
+    patternStr_ = pat;
+  }
+
+  // Flags used in pcode implementation of like clauses
+  enum
+  {
+    LIKE_HEAD = 0x01,  // Check for pattern at beginning of string only
+    LIKE_TAIL = 0x02,  // Check for pattern at end of string only
+    END       = 0xFF   // Last possible flag for use in pcode implementation
+  };
+
+  // ---------------------------------------------------------------------
+protected:
+  
+  NA_EIDPROC inline CharInfo::Collation getCollation()
+  {
+    return (CharInfo::Collation) collation_;
+  }
+
+  NA_EIDPROC inline void setCollation(CharInfo::Collation v)
+  {
+    collation_ = (Int16) v;
+  }
+
+private:
+union {
+  LikePattern     *pattern_;          // 00-07
+  char            *patternStr_;
+};
+#ifndef NA_64BIT
+  char             fillerPattern_[4]; // 04-07
+#endif
+
+  Int16 collation_; //08-09
+
+  // ---------------------------------------------------------------------
+  // Fillers for potential future extensions without changing class size.
+  // When a new member is added, size of this filler should be reduced so
+  // that the size of the object remains the same (and is modulo 8).
+  // ---------------------------------------------------------------------
+  char                       fillers_[14];           // 10-23
+
+};
+
+
+// Added for unicode like function
+class SQLEXP_LIB_FUNC  ExRegexpClauseChar : public ExRegexpClauseBase {
+
+public:
+  // Construction
+  //
+  NA_EIDPROC ExRegexpClauseChar() {};
+  NA_EIDPROC ExRegexpClauseChar(OperatorTypeEnum oper_type, 
+			    short num_operands,
+			    Attributes ** attr,
+			    Space * space);
+
+
+  // Execution
+  //
+  NA_EIDPROC ex_expr::exp_return_type eval(char *op_data[],
+					   CollHeap * = 0,
+					   ComDiagsArea ** = 0);
+
+  // Fixup
+  //
+  NA_EIDPROC Long pack (void *);
+
+  // Display
+  //
+  NA_EIDPROC void displayContents(Space * space, const char * displayStr, 
+					  Int32 clauseNum, char * constsArea);
+
+  // ---------------------------------------------------------------------
+  // Redefinition of methods inherited from NAVersionedObject.
+  // ---------------------------------------------------------------------
+  NA_EIDPROC virtual unsigned char getClassVersionID()
+  {
+    return 1;
+  }
+
+  NA_EIDPROC virtual void populateImageVersionIDArray()
+  {
+    setImageVersionID(2,getClassVersionID());
+    ExRegexpClauseBase::populateImageVersionIDArray();
+  }
+
+  NA_EIDPROC virtual short getClassSize() { return (short)sizeof(*this); }
+  // ---------------------------------------------------------------------
+
+private:
+
+  // ---------------------------------------------------------------------
+  // Fillers for potential future extensions without changing class size.
+  // When a new member is added, size of this filler should be reduced so
+  // that the size of the object remains the same (and is modulo 8).
+  // ---------------------------------------------------------------------
+  char                       fillers_[8];           // 00-07
+
+};
 //////////////////////////////////
 // Class like_clause            //
 //////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4355adf5/core/sql/exp/exp_like.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_like.cpp b/core/sql/exp/exp_like.cpp
index ec30c61..4409fc1 100644
--- a/core/sql/exp/exp_like.cpp
+++ b/core/sql/exp/exp_like.cpp
@@ -42,6 +42,8 @@
 
 
 #include <stddef.h>
+#include <sys/types.h>
+#include <regex.h>
 #include "exp_clause_derived.h"
 #include "exp_like.h"
 #include "exp_function.h"
@@ -49,6 +51,7 @@
 #include "nchar_mp.h"
 
 
+
 ///////////////////////////////////////////////////
 // class LikePattern
 ///////////////////////////////////////////////////
@@ -457,6 +460,27 @@ NABoolean LikePattern::matches
 }
 
 ///////////////////////////////////////////////////
+// class ExRegexpClauseBase
+///////////////////////////////////////////////////
+ex_expr::exp_return_type 
+ExRegexpClauseBase::processNulls(char *op_data[], CollHeap *heap,
+	     ComDiagsArea **diagsArea
+	    )
+{
+  //
+  // If an operand is missing(its a null value), set the result to UNKNOWN.
+  //
+  for (short i = 1; i < getNumOperands(); i++) {
+    if (getOperand(i)->getNullFlag() && (NOT op_data[i])) {
+      *(Lng32*)op_data[2 * MAX_OPERANDS] = -1;
+      return ex_expr::EXPR_NULL;
+    }
+  }
+
+  return ex_expr::EXPR_OK;
+}
+
+///////////////////////////////////////////////////
 // class ex_like_clause_base
 ///////////////////////////////////////////////////
 ex_expr::exp_return_type 
@@ -477,6 +501,38 @@ ex_like_clause_base::processNulls(char *op_data[], CollHeap *heap,
   return ex_expr::EXPR_OK;
 }
 
+
+ex_expr::exp_return_type ExRegexpClauseChar::eval(char *op_data[],
+					      CollHeap* exHeap,
+					      ComDiagsArea** diagsArea)
+{
+//comehere
+  Lng32 len1 = getOperand(1)->getLength(op_data[-MAX_OPERANDS+1]);
+  Lng32 len2 = getOperand(2)->getLength(op_data[-MAX_OPERANDS+2]);
+  regex_t reg;
+  regmatch_t pm[10];
+  const size_t nmatch = 10;
+  int cflags, z;
+  cflags = REG_EXTENDED|REG_NEWLINE;
+  char * pattern;
+  pattern = new (exHeap) char[len2];
+  char *srcStr= new (exHeap) char[len1];
+  memcpy(pattern, op_data[2], len2);
+  memcpy(srcStr, op_data[1], len1);
+  z = regcomp(&reg, pattern, cflags);
+  if (z != 0){
+    //ERROR
+    return ex_expr::EXPR_ERROR;
+  }
+
+  NABoolean matchFlag = true;
+  z = regexec(&reg,srcStr , nmatch, pm, 0);
+  if (z == REG_NOMATCH) 
+    matchFlag = false;
+   
+  *(Lng32 *)op_data[0] = (Lng32)matchFlag;
+  return ex_expr::EXPR_OK;
+}
 ex_expr::exp_return_type ex_like_clause_char::eval(char *op_data[],
 					      CollHeap* exHeap,
 					      ComDiagsArea** diagsArea)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4355adf5/core/sql/generator/GenItemFunc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenItemFunc.cpp b/core/sql/generator/GenItemFunc.cpp
index 3992389..29ab72d 100644
--- a/core/sql/generator/GenItemFunc.cpp
+++ b/core/sql/generator/GenItemFunc.cpp
@@ -90,7 +90,11 @@ short BuiltinFunction::codeGen(Generator * generator)
       }
     break;
     case ITM_REGEXP:
-//TODO
+      {
+        function_clause = 
+          new(generator->getSpace()) ExRegexpClauseChar(getOperatorType(), (1+getArity()),
+                                                       attr, space);
+      }
     break; 
     case ITM_LIKE:
       {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4355adf5/core/sql/optimizer/BindItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindItemExpr.cpp b/core/sql/optimizer/BindItemExpr.cpp
index 2241600..2726903 100644
--- a/core/sql/optimizer/BindItemExpr.cpp
+++ b/core/sql/optimizer/BindItemExpr.cpp
@@ -1252,6 +1252,7 @@ Int32 ItemExpr::shouldPushTranslateDown(CharInfo::CharSet chrset) const
      case ITM_LEFT:                  // b) counts characters
      case ITM_RIGHT:                 // b) counts characters
      case ITM_LIKE:                  // b) counts characters
+     case ITM_REGEXP:                  // b) counts characters
      case ITM_SUBSTR:                // b) counts characters
      case ITM_REPLACE:               // b) counts characters
      case ITM_INSERT_STR:            // b) counts characters

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4355adf5/core/sql/optimizer/ItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp
index 53d0f5f..904fe65 100644
--- a/core/sql/optimizer/ItemExpr.cpp
+++ b/core/sql/optimizer/ItemExpr.cpp
@@ -7532,6 +7532,8 @@ const NAString BuiltinFunction::getText() const
     case ITM_LIKE:
     case ITM_LIKE_DOUBLEBYTE:
       return "like";
+    case ITM_REGEXP:
+      return "regexp";
     case ITM_LOWER:
     case ITM_LOWER_UNICODE:
       return "lower";

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4355adf5/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index f8c9456..bde168f 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -19064,7 +19064,9 @@ like_predicate : value_expression not_like value_expression
               | value_expression TOK_REGEXP value_expression
                                 {
                                   //TODO
-                                  YYERROR;
+                                  $$ = new (PARSERHEAP()) Regexp($1,$3);
+				  if ($2 == TOK_NOT)
+				    $$ = new (PARSERHEAP()) UnLogic(ITM_NOT,$$);
                                 } 
 
 /* type item */