trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ansha...@apache.org
Subject [3/6] incubator-trafodion git commit: JIRA TRAFODION-2099 Add support for boolean datatype
Date Tue, 12 Jul 2016 22:55:43 GMT
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/exp/exp_attrs.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_attrs.cpp b/core/sql/exp/exp_attrs.cpp
index 9259481..6161377 100644
--- a/core/sql/exp/exp_attrs.cpp
+++ b/core/sql/exp/exp_attrs.cpp
@@ -278,6 +278,8 @@ switch (datatype)
   case REC_INT_FRACTION: return extFormat? (char *)"INTERVAL FRACTION":(char *)"REC_INT_FRACTION";
   case REC_BLOB: return extFormat? (char *)"BLOB":(char *)"REC_BLOB";
   case REC_CLOB: return extFormat? (char *)"CLOB":(char *)"REC_CLOB";
+  case REC_BOOLEAN: return extFormat ? (char *)"BOOLEAN" : (char *)"BOOLEAN";
+
   // When you add new datatype in /common/dfs2rec.h, don't
   // forget add new case here. Otherwise, showplan won't display it.
   default: return extFormat? (char *)"UNKNOWN":(char *)"add datatype in getDatatypeAsString()";

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/exp/exp_clause.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_clause.cpp b/core/sql/exp/exp_clause.cpp
index 2c8c1e4..164268c 100644
--- a/core/sql/exp/exp_clause.cpp
+++ b/core/sql/exp/exp_clause.cpp
@@ -1570,7 +1570,8 @@ ex_arith_clause::ex_arith_clause(OperatorTypeEnum oper_type,
 				 Space * space,
 				 short arithRoundingMode,
 				 NABoolean divToDownscale) 
-     : ex_clause (ex_clause::ARITH_TYPE, oper_type, 3, attr, space),
+     : ex_clause (ex_clause::ARITH_TYPE, oper_type, 
+                  (oper_type == ITM_NEGATE ? 2 : 3), attr, space),
        flags_(0)
 {
   arithRoundingMode_ = (char)arithRoundingMode;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/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 6a8ea39..8d09325 100644
--- a/core/sql/exp/exp_clause_derived.h
+++ b/core/sql/exp/exp_clause_derived.h
@@ -434,7 +434,9 @@ public:
     MUL_BIN32S_BIN16S_BIN64S      =67,
     MUL_BIN32S_BIN32S_BIN64S      =68,
 
-    DIV_BIN64S_BIN64S_BIN64S_ROUND=69
+    DIV_BIN64S_BIN64S_BIN64S_ROUND=69,
+
+    NEGATE_BOOLEAN                =70
     };
 
   // Construction
@@ -490,6 +492,11 @@ public:
   NA_EIDPROC Long pack(void *);
   NA_EIDPROC ex_expr::exp_return_type pCodeGenerate(Space *space,
 						    UInt32 flags);
+
+  // pcode for unary arith operators, like NEGATE.
+  ex_expr::exp_return_type unaryArithPCodeGenerate
+    (Space *space, UInt32 flags);
+
   NA_EIDPROC ex_expr::exp_return_type fixup(Space * space = 0,
 					    CollHeap * exHeap = 0,
 					    char * constants_area = 0,
@@ -1115,8 +1122,24 @@ public:
     GE_BIN64U_BIN64S    =175,
     GE_BIN64S_BIN64U    =176,
     
-    COMP_NOT_SUPPORTED  =177
-      
+    EQ_BOOL_BOOL        =177,
+    NE_BOOL_BOOL        =178,
+
+    // tinyint operations
+    EQ_BIN8S_BIN8S      =179,
+    EQ_BIN8U_BIN8U      =180,
+    NE_BIN8S_BIN8S      =181,
+    NE_BIN8U_BIN8U      =182,
+    LT_BIN8S_BIN8S      =183,
+    LT_BIN8U_BIN8U      =184,
+    LE_BIN8S_BIN8S      =185,
+    LE_BIN8U_BIN8U      =186,
+    GT_BIN8S_BIN8S      =187,
+    GT_BIN8U_BIN8U      =188,
+    GE_BIN8S_BIN8S      =189,
+    GE_BIN8U_BIN8U      =190,
+
+    COMP_NOT_SUPPORTED  =191
     };
 
   // Construction
@@ -1572,27 +1595,35 @@ enum conv_case_index {
   CONV_BIN8U_BIN16U                    =255,
   CONV_BIN16S_BIN8S                    =256,
   CONV_BIN16U_BIN8U                    =257,
-  CONV_BIN8S_ASCII                     =258,
-  CONV_BIN8U_ASCII                     =259,
-  CONV_BIN16U_BIN8S                    =260,
-  CONV_BIN16S_BIN8U                    =261,
-  CONV_BIN8U_BIN16S                    =262,
-  CONV_ASCII_BIN8S                     =263,
-  CONV_ASCII_BIN8U                     =264,
+  CONV_BIN16U_BIN8S                    =258,
+  CONV_BIN16S_BIN8U                    =259,
+  CONV_BIN8U_BIN16S                    =260,
+  CONV_BIN8S_BIN32S                    =261,
+  CONV_BIN8U_BIN32U                    =262,
+  CONV_BIN8S_BIN64S                    =263,
+  CONV_BIN8U_BIN64U                    =264,
+  CONV_BIN8S_ASCII                     =265,
+  CONV_BIN8U_ASCII                     =266,
+  CONV_ASCII_BIN8S                     =267,
+  CONV_ASCII_BIN8U                     =268,
+  
+  // boolean conversions
+  CONV_BOOL_BOOL                       =269,
+  CONV_BOOL_ASCII                      =270,
+  CONV_ASCII_BOOL                      =271,
 
   // unsigned largeint related conversions
-  CONV_BIN64S_BIN64U                   =269,
-  CONV_BIN64U_BIN64U                   =270,
-  CONV_FLOAT32_BIN64U                  =271, 
-  CONV_FLOAT64_BIN64U                  =272,
-  CONV_BIN64U_BIN64S                   =273,
-  CONV_BIN64U_BIGNUM                   =274,
-  CONV_BIGNUM_BIN64U                   =275,
-  CONV_BIN64U_FLOAT32                  =276,
-  CONV_BIN64U_FLOAT64                  =277,
-  CONV_BIN64U_ASCII                    =278,
-  CONV_ASCII_BIN64U                    =279
-
+  CONV_BIN64S_BIN64U                   =272,
+  CONV_BIN64U_BIN64U                   =273,
+  CONV_FLOAT32_BIN64U                  =274, 
+  CONV_FLOAT64_BIN64U                  =275,
+  CONV_BIN64U_BIN64S                   =276,
+  CONV_BIN64U_BIGNUM                   =277,
+  CONV_BIGNUM_BIN64U                   =278,
+  CONV_BIN64U_FLOAT32                  =279,
+  CONV_BIN64U_FLOAT64                  =280,
+  CONV_BIN64U_ASCII                    =281,
+  CONV_ASCII_BIN64U                    =282
 };
 
 class SQLEXP_LIB_FUNC  ex_conv_clause : public ex_clause {
@@ -1655,6 +1686,8 @@ public:
                                              short targetType, Lng32 targetLen,
                                              Lng32 scaleDifference);
 
+  NABoolean isConversionSupported(short sourceType, short targetType);
+
   NA_EIDPROC NABoolean treatAllSpacesAsZero()
     { return ((flags_ & TREAT_ALL_SPACES_AS_ZERO) != 0); };
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/exp/exp_comp.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_comp.cpp b/core/sql/exp/exp_comp.cpp
index b69ad07..2e4fb3e 100644
--- a/core/sql/exp/exp_comp.cpp
+++ b/core/sql/exp/exp_comp.cpp
@@ -190,6 +190,14 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
   switch (get_case_index())
     {
     // EQUAL opcode
+    case EQ_BIN8S_BIN8S:
+      *(Lng32 *)op_data[0] = (*(Int8 *)op_data[1] == *(Int8 *)op_data[2]);
+      break;
+  
+    case EQ_BIN8U_BIN8U:
+      *(Lng32 *)op_data[0] = (*(UInt8 *)op_data[1] == *(UInt8 *)op_data[2]);
+      break;
+  
     case EQ_BIN16S_BIN16S:
       *(Lng32 *)op_data[0] = (*(short *)op_data[1] == *(short *)op_data[2]);
       break;
@@ -317,6 +325,14 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
   
   
     // NOT EQUAL operator
+    case NE_BIN8S_BIN8S:
+      *(Lng32 *)op_data[0] = (*(Int8 *)op_data[1] != *(Int8 *)op_data[2]);
+      break;
+
+    case NE_BIN8U_BIN8U:
+      *(Lng32 *)op_data[0] = (*(UInt8 *)op_data[1] != *(UInt8 *)op_data[2]);
+      break;
+
     case NE_BIN16S_BIN16S:
     	// LCOV_EXCL_START
       *(Lng32 *)op_data[0] = (*(short *)op_data[1] != *(short *)op_data[2]);
@@ -451,6 +467,14 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
   
   
     // LESS THAN opcode
+    case LT_BIN8S_BIN8S:
+      *(Lng32 *)op_data[0] = (*(Int8 *)op_data[1] < *(Int8 *)op_data[2]);
+      break;
+
+    case LT_BIN8U_BIN8U:
+      *(Lng32 *)op_data[0] = (*(UInt8 *)op_data[1] < *(UInt8 *)op_data[2]);
+      break;
+
     case LT_BIN16S_BIN16S:
       *(Lng32 *)op_data[0] = (*(short *)op_data[1] < *(short *)op_data[2]);
       break;
@@ -626,6 +650,14 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
   
   
     // LESS THAN OR EQUAL TO opcode
+    case LE_BIN8S_BIN8S:
+      *(Lng32 *)op_data[0] = (*(Int8 *)op_data[1] <= *(Int8 *)op_data[2]);
+      break;
+
+    case LE_BIN8U_BIN8U:
+      *(Lng32 *)op_data[0] = (*(UInt8 *)op_data[1] <= *(UInt8 *)op_data[2]);
+      break;
+
     case LE_BIN16S_BIN16S:
       *(Lng32 *)op_data[0] = (*(short *)op_data[1] <= *(short *)op_data[2]);
       break;
@@ -807,6 +839,14 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
   
   
     // GREATER THAN opcode
+    case GT_BIN8S_BIN8S:
+      *(Lng32 *)op_data[0] = (*(Int8 *)op_data[1] > *(Int8 *)op_data[2]);
+      break;
+
+    case GT_BIN8U_BIN8U:
+      *(Lng32 *)op_data[0] = (*(UInt8 *)op_data[1] > *(UInt8 *)op_data[2]);
+      break;
+
     case GT_BIN16S_BIN16S:
       *(Lng32 *)op_data[0] = (*(short *)op_data[1] > *(short *)op_data[2]);
       break;
@@ -984,6 +1024,14 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
   
   
     // GREATER THAN OR EQUAL TO
+    case GE_BIN8S_BIN8S:
+      *(Lng32 *)op_data[0] = (*(Int8 *)op_data[1] >= *(Int8 *)op_data[2]);
+      break;
+
+    case GE_BIN8U_BIN8U:
+      *(Lng32 *)op_data[0] = (*(UInt8 *)op_data[1] >= *(UInt8 *)op_data[2]);
+      break;
+
     case GE_BIN16S_BIN16S:
       *(Lng32 *)op_data[0] = (*(short *)op_data[1] >= *(short *)op_data[2]);
       break;
@@ -1205,6 +1253,19 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
        break;
         }
 
+     // boolean comparison
+    case EQ_BOOL_BOOL:
+      {
+        *(Lng32*)op_data[0] = (*(Int8 *)op_data[1] == *(Int8 *)op_data[2]);
+      }
+      break;
+
+    case NE_BOOL_BOOL:
+      {
+        *(Lng32*)op_data[0] = (*(Int8 *)op_data[1] != *(Int8 *)op_data[2]);
+      }
+      break;
+
     case COMP_COMPLEX:
       *(Lng32 *)op_data[0] =
 	((ComplexType *)getOperand(1))->comp(getOperType(), getOperand(2), op_data);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/exp/exp_conv.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_conv.cpp b/core/sql/exp/exp_conv.cpp
index c10643d..1de00ea 100644
--- a/core/sql/exp/exp_conv.cpp
+++ b/core/sql/exp/exp_conv.cpp
@@ -5118,7 +5118,31 @@ convDoIt(char * source,
       *(Int16 *)target = *(UInt8 *)source;
     }
   break;
- 
+
+  case CONV_BIN8S_BIN32S:
+    {
+      *(Int32 *)target = *(Int8 *)source;
+    }
+  break;
+
+  case CONV_BIN8S_BIN64S:
+    {
+      *(Int64 *)target = *(Int8 *)source;
+    }
+  break;
+
+  case CONV_BIN8U_BIN32U:
+    {
+      *(UInt32 *)target = *(UInt8 *)source;
+    }
+  break;
+  
+  case CONV_BIN8U_BIN64U:
+    {
+      *(UInt64 *)target = *(UInt8 *)source;
+    }
+  break;
+  
   case CONV_BIN16U_BIN8S:
     {
       if (*(UInt16 *)source > CHAR_MAX)
@@ -11231,6 +11255,89 @@ convDoIt(char * source,
     }
     break;
 
+  case CONV_BOOL_BOOL:
+    {
+      if ((*(Int8*)source == 1) ||
+          (*(Int8*)source == 0))
+        *(Int8*)target = *(Int8*)source;
+      else
+        {
+          char tempBuf[10];
+          str_itoa(*(Int8*)source, tempBuf);
+          ExRaiseSqlError(heap, diagsArea, EXE_INVALID_BOOLEAN_VALUE,
+                          NULL, NULL, NULL, NULL,
+                          tempBuf);
+          return ex_expr::EXPR_ERROR;
+        }
+    }
+    break;
+
+  case CONV_BOOL_ASCII:
+    {
+      char boolbuf[10];
+      if (*(Int8*)source == 1)
+        strcpy(boolbuf, "TRUE");
+      else if (*(Int8*)source == 0)
+        strcpy(boolbuf, "FALSE");
+      else
+        {
+          char tempBuf[10];
+          str_itoa(*(Int8*)source, tempBuf);
+          ExRaiseSqlError(heap, diagsArea, EXE_INVALID_BOOLEAN_VALUE,
+                          NULL, NULL, NULL, NULL,
+                          tempBuf);
+          return ex_expr::EXPR_ERROR;
+        }
+
+      // this case isn't translated into PCODE at this time
+      Lng32 convertedDataLen;
+      
+      if (convCharToChar(boolbuf, strlen(boolbuf), REC_BYTE_F_ASCII, 
+                         0, SQLCHARSETCODE_ISO88591,
+                         target,
+                         targetLen,
+                         targetType,
+                         targetPrecision,
+                         targetScale,
+                         heap,
+                         diagsArea,
+                         NULL,
+                         &convertedDataLen,
+                         ((varCharLenSize > 0) ? FALSE : TRUE),
+                         TRUE,
+                         FALSE)
+          != ex_expr::EXPR_OK)
+        return ex_expr::EXPR_ERROR;
+      if (varCharLenSize > 0)
+        setVCLength(varCharLen, varCharLenSize, convertedDataLen);
+    }
+    break;
+
+  case CONV_ASCII_BOOL:
+    {
+      char srcTempBuf[sourceLen+1];
+      str_cpy_convert(srcTempBuf, source, sourceLen, 1);
+      srcTempBuf[sourceLen] = 0;
+      Lng32 tempLen;
+      char * srcTempPtr = srcTempBuf;
+      srcTempPtr = str_strip_blanks(srcTempBuf, tempLen, TRUE, TRUE);
+
+      if ((strcmp(srcTempPtr, "TRUE") == 0) ||
+          (strcmp(srcTempPtr, "1") == 0))
+        *(Int8*)target = 1;
+      else if ((strcmp(srcTempPtr, "FALSE") == 0) ||
+               (strcmp(srcTempPtr, "0") == 0))
+        *(Int8*)target = 0;
+      else
+        {
+          ExRaiseSqlError(heap, diagsArea, EXE_INVALID_BOOLEAN_VALUE,
+                          NULL, NULL, NULL, NULL,
+                          srcTempPtr);
+          return ex_expr::EXPR_ERROR;
+        }
+    }
+    break;
+
   case CONV_NOT_SUPPORTED:
   default:
     {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/exp/exp_eval.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_eval.cpp b/core/sql/exp/exp_eval.cpp
index d841463..d438125 100644
--- a/core/sql/exp/exp_eval.cpp
+++ b/core/sql/exp/exp_eval.cpp
@@ -3614,9 +3614,27 @@ ex_expr::exp_return_type ex_expr::evalPCode(PCodeBinary* pCode32,
      break;
     }
 
+    case PCIT::MOVE_MBIN16S_MBIN8S:
+      MOVE_INSTR( Int16, Int8 );
+
+    case PCIT::MOVE_MBIN16U_MBIN8U:
+      MOVE_INSTR( UInt16, UInt8 );
+
     case PCIT::MOVE_MBIN16U_MBIN8:
       MOVE_INSTR( UInt16, UInt8 );
 
+    case PCIT::MOVE_MBIN32S_MBIN8S:
+      MOVE_INSTR( Int32, Int8 );
+
+    case PCIT::MOVE_MBIN32U_MBIN8U:
+      MOVE_INSTR( UInt32, UInt8 );
+
+    case PCIT::MOVE_MBIN64S_MBIN8S:
+      MOVE_INSTR( Int64, Int8 );
+
+    case PCIT::MOVE_MBIN64U_MBIN8U:
+      MOVE_INSTR( UInt64, UInt8 );
+
     case PCIT::MOVE_MBIN32U_MBIN16U:
       MOVE_INSTR( UInt32, UInt16 );
 
@@ -3653,6 +3671,15 @@ ex_expr::exp_return_type ex_expr::evalPCode(PCodeBinary* pCode32,
     case PCIT::MOVE_MBIN64S_MBIN64S:
       MOVE_INSTR( Int64 , Int64 );
 
+    case PCIT::MOVE_MBIN64S_MBIN64U:
+      MOVE_INSTR( Int64 , UInt64 );
+
+    case PCIT::MOVE_MBIN64U_MBIN64S:
+      MOVE_INSTR( UInt64 , Int64 );
+
+    case PCIT::MOVE_MBIN64U_MBIN64U:
+      MOVE_INSTR( UInt64 , UInt64 );
+
     case PCIT::MOVE_MBIN64S_MDECS_IBIN32S:
       {
 	PTR_DEF_ASSIGN(char, src, 2);
@@ -5350,6 +5377,153 @@ ex_expr::exp_return_type ex_expr::evalPCode(PCodeBinary* pCode32,
     }
 
   
+    case PCIT::EQ_MBIN32S_MBIN8S_MBIN8S:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(Int8, x, 2 );
+      PTR_DEF_ASSIGN(Int8, y, 4 );
+
+      *result = (*x == *y);
+
+      pCode += 6;
+      break;
+    }
+
+    case PCIT::NE_MBIN32S_MBIN8S_MBIN8S:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(Int8, x, 2 );
+      PTR_DEF_ASSIGN(Int8, y, 4 );
+
+      *result = (*x != *y);
+
+      pCode += 6;
+      break;
+    }
+
+    case PCIT::LT_MBIN32S_MBIN8S_MBIN8S:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(Int8, x, 2 );
+      PTR_DEF_ASSIGN(Int8, y, 4 );
+
+      *result = (*x < *y);
+
+      pCode += 6;
+      break;
+    }
+
+    case PCIT::GT_MBIN32S_MBIN8S_MBIN8S:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(Int8, x, 2 );
+      PTR_DEF_ASSIGN(Int8, y, 4 );
+
+      *result = (*x > *y);
+
+      pCode += 6;
+      break;
+    }
+
+    case PCIT::LE_MBIN32S_MBIN8S_MBIN8S:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(Int8, x, 2 );
+      PTR_DEF_ASSIGN(Int8, y, 4 );
+
+      *result = (*x <= *y);
+
+      pCode += 6;
+      break;
+    }
+
+    case PCIT::GE_MBIN32S_MBIN8S_MBIN8S:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(Int8, x, 2 );
+      PTR_DEF_ASSIGN(Int8, y, 4 );
+
+      *result = (*x >= *y);
+
+      pCode += 6;
+      break;
+    }
+
+
+    case PCIT::EQ_MBIN32S_MBIN8U_MBIN8U:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(UInt8, x, 2 );
+      PTR_DEF_ASSIGN(UInt8, y, 4 );
+
+      *result = (*x == *y);
+
+      pCode += 6;
+      break;
+    }
+
+    case PCIT::NE_MBIN32S_MBIN8U_MBIN8U:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(UInt8, x, 2 );
+      PTR_DEF_ASSIGN(UInt8, y, 4 );
+
+      *result = (*x != *y);
+
+      pCode += 6;
+      break;
+    }
+
+    case PCIT::LT_MBIN32S_MBIN8U_MBIN8U:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(UInt8, x, 2 );
+      PTR_DEF_ASSIGN(UInt8, y, 4 );
+
+      *result = (*x < *y);
+
+      pCode += 6;
+      break;
+    }
+
+    case PCIT::GT_MBIN32S_MBIN8U_MBIN8U:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(UInt8, x, 2 );
+      PTR_DEF_ASSIGN(UInt8, y, 4 );
+
+      *result = (*x > *y);
+
+      pCode += 6;
+      break;
+    }
+
+    case PCIT::LE_MBIN32S_MBIN8U_MBIN8U:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(UInt8, x, 2 );
+      PTR_DEF_ASSIGN(UInt8, y, 4 );
+
+      *result = (*x <= *y);
+
+      pCode += 6;
+      break;
+    }
+
+    case PCIT::GE_MBIN32S_MBIN8U_MBIN8U:
+    {
+      PTR_DEF_ASSIGN(Int32, result, 0 );
+      PTR_DEF_ASSIGN(UInt8, x, 2 );
+      PTR_DEF_ASSIGN(UInt8, y, 4 );
+
+      *result = (*x >= *y);
+
+      pCode += 6;
+      break;
+    }
+
+
+
     case PCIT::EQ_MBIN32S_MBIN16U_MBIN16S:
     {
       PTR_DEF_ASSIGN(Int32, result, 0 );
@@ -6077,6 +6251,40 @@ ex_expr::exp_return_type ex_expr::evalPCode(PCodeBinary* pCode32,
       break;
     }
 
+    case PCIT::ENCODE_MASCII_MBIN8S_IBIN32S:
+      {
+	PTR_DEF_ASSIGN(Int8, outputPtr, 0 );
+	PTR_DEF_ASSIGN(Int8, resultPtr, 2 );
+	DEF_ASSIGN(Int32, bitwiseNOT,   4 );
+	Int8 result = *resultPtr;
+
+	result ^= 0x80;
+
+	if ( bitwiseNOT ) 
+          result = ~result;
+
+	* outputPtr = result ;
+
+	pCode += 5;
+      }
+      break;
+
+    case PCIT::ENCODE_MASCII_MBIN8U_IBIN32S:
+      {
+	PTR_DEF_ASSIGN(Int8, outputPtr, 0 );
+	PTR_DEF_ASSIGN(Int8, resultPtr, 2 );
+	DEF_ASSIGN(Int32, bitwiseNOT , 4 );
+	UInt8 result = *resultPtr;
+
+	if ( bitwiseNOT ) 
+          result = ~result;
+
+	* outputPtr = result ;
+
+	pCode += 5;
+      }
+      break;
+
     case PCIT::ENCODE_MASCII_MBIN16S_IBIN32S:
       {
 	PTR_DEF_ASSIGN(Int16, outputPtr, 0 );
@@ -6760,6 +6968,18 @@ ex_expr::exp_return_type ex_expr::evalPCode(PCodeBinary* pCode32,
       break;
     }
     
+    case PCIT::NEGATE_MASCII_MASCII:
+    {
+      PTR_DEF_ASSIGN(char, result, 0 );
+      PTR_DEF_ASSIGN(char, op1, 2 );
+      if (*(Int8*)op1 == 1)
+        *(Int8*)result = 0;
+      else 
+        *(Int8*)result = 1;
+      pCode += 4;
+      break;
+    }
+
     case PCIT::RANGE_MFLT64:
     {
       double flt64_1;
@@ -8058,7 +8278,7 @@ ex_expr::exp_return_type ex_expr::evalPCode(PCodeBinary* pCode32,
     };
   };
   
-					    Error1_:
+ Error1_:
   return reportOverflowError(atp1, pCodeOpcPtr, pCode, stack);
 					    
 					    Error2_:

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/exp/exp_expr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_expr.cpp b/core/sql/exp/exp_expr.cpp
index b0e3d17..9424eb9 100644
--- a/core/sql/exp/exp_expr.cpp
+++ b/core/sql/exp/exp_expr.cpp
@@ -333,8 +333,6 @@ void ex_expr::displayContents(Space * space, short mode, const char * displayStr
 	  //creating text for the showplan
 	  UInt32 f = 0;
 	  ex_expr_base::setForShowplan(f, TRUE);
-          ex_expr_base::setDownrevCompileR2FCS(f, ((flag & 0x00000010) != 0));
-          ex_expr_base::setDownrevCompileRR(f, ((flag & 0x00000020) != 0));
 	  pCodeGenerate(&tempSpace, &tempSpace, f);
 	  
 	  if(getPCodeObject())

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/exp/exp_expr.h
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_expr.h b/core/sql/exp/exp_expr.h
index cb14d62..022f999 100644
--- a/core/sql/exp/exp_expr.h
+++ b/core/sql/exp/exp_expr.h
@@ -698,17 +698,6 @@ public:
   static void setForShowplan(UInt32 &f, NABoolean v)
   { ( v ? f |= FOR_SHOWPLAN : f &= ~FOR_SHOWPLAN );}
 
-  static NABoolean downrevCompile(UInt32 f) {return ((f & DOWNREV_COMPILE) != 0);}
-  static NABoolean downrevCompileR2FCS(UInt32 f) {return ((f & DOWNREV_COMPILE) != 0);}
-  static void setDownrevCompile(UInt32 &f, NABoolean v)
-  { ( v ? f |= DOWNREV_COMPILE : f &= ~DOWNREV_COMPILE );}
-
-  static void setDownrevCompileR2FCS(UInt32 &f, NABoolean v)
-  { ( v ? f |= DOWNREV_COMPILE : f &= ~DOWNREV_COMPILE );}
-
-  static NABoolean downrevCompileRR(UInt32 f) {return ((f & DOWNREV_COMPILE_RR) != 0);}
-  static void setDownrevCompileRR(UInt32 &f, NABoolean v)
-  { ( v ? f |= DOWNREV_COMPILE_RR : f &= ~DOWNREV_COMPILE_RR );}
   static NABoolean notValidateFloat64(UInt32 f)
   { return ((f & NOT_VALIDATE_FLOAT64) != 0); }
   static void setNotValidateFloat64(UInt32 &f, NABoolean v)
@@ -800,16 +789,9 @@ protected:
     // expression being generated for SHOWPLAN request
     FOR_SHOWPLAN = 0x0001,
 
-    // expressions compatible with pre-R2.1(052005) and post R1.8
-    // release(R2 FCS) need to be generated
-    DOWNREV_COMPILE = 0x0002,
-
-    // expressions compatible with R2.1(roadrunner) need to be generated
-    DOWNREV_COMPILE_RR = 0x0004,
-
     // tell clause pcodegenerate() to generate PCode instruction
     // to validate value range for float64 to float64 assigments
-    NOT_VALIDATE_FLOAT64 = 0x0008
+    NOT_VALIDATE_FLOAT64 = 0x0002
   };
 
   exp_eye_catcher         eyeCatcher_;                           // 00-03
@@ -1200,7 +1182,8 @@ public:
 	(((source >= REC_MIN_INTERVAL) && (source <= REC_MAX_INTERVAL)) &&
 	 ((target >= REC_MIN_INTERVAL) && (target <= REC_MAX_INTERVAL))) ||
 	((source == REC_BLOB) && (target == REC_BLOB)) ||
-	((source == REC_CLOB) && (target == REC_CLOB)))
+	((source == REC_CLOB) && (target == REC_CLOB)) ||
+        ((source == REC_BOOLEAN) && (target == REC_BOOLEAN)))
       return TRUE;
     else
       return FALSE;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/exp/exp_fixup.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_fixup.cpp b/core/sql/exp/exp_fixup.cpp
index 417745f..c407a9f 100644
--- a/core/sql/exp/exp_fixup.cpp
+++ b/core/sql/exp/exp_fixup.cpp
@@ -324,13 +324,14 @@ ex_expr::exp_return_type ex_clause::fixup(Space * space,
 					  NABoolean spaceCompOnly)
 {
   for (Lng32 i=0; i<numOperands_;i++)
+    if (op_[i])
       op_[i]->fixup(space, 
 		    constantsArea,
 		    tempsArea,
 		    persistentArea,
 		    fixupFlag,
 		    spaceCompOnly);
-
+  
   return ex_expr::EXPR_OK;
 };
 
@@ -468,7 +469,10 @@ const ex_arith_struct * ex_arith_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_DIVIDE, REC_BIN16_UNSIGNED, REC_BIN32_UNSIGNED, REC_BIN32_UNSIGNED, DIV_BIN16U_BIN32U_BIN32U},
       {ITM_DIVIDE, REC_BIN32_UNSIGNED, REC_BIN16_UNSIGNED, REC_BIN32_UNSIGNED, DIV_BIN32U_BIN16U_BIN32U},
       {ITM_DIVIDE, REC_BIN32_UNSIGNED, REC_BIN32_UNSIGNED, REC_BIN32_UNSIGNED, DIV_BIN32U_BIN32U_BIN32U},
-      {ITM_DIVIDE, REC_FLOAT64, REC_FLOAT64, REC_FLOAT64, DIV_FLOAT64_FLOAT64_FLOAT64}
+      {ITM_DIVIDE, REC_FLOAT64, REC_FLOAT64, REC_FLOAT64, DIV_FLOAT64_FLOAT64_FLOAT64},
+
+      {ITM_NEGATE, REC_BOOLEAN, REC_BOOLEAN, REC_BOOLEAN, NEGATE_BOOLEAN},
+
     };
 
   Int32 max_array_size = sizeof(as) / sizeof(ex_arith_struct);
@@ -503,10 +507,16 @@ const ex_arith_clause::arith_case_index ex_arith_clause::computeCaseIndex(Operat
   getCaseDatatypes(attr1->getDatatype(), attr1->getLength(), type_op1,
                    result->getDatatype(), result->getLength(), type_result,
                    0 /* don't need to take scale difference into account here */);
+
+// attr2 eill be null for unary operands.
+// Some methods below expect 2 operands. Change oper2 to be the same as oper1
+// to avoid null pointer exception.
+  if (!attr2)
+    attr2 = attr1;
   getCaseDatatypes(attr2->getDatatype(), attr2->getLength(), type_op2,
                    result->getDatatype(), result->getLength(), type_result,
                    0 /* don't need to take scale difference into account here */);
-
+  
   const ex_arith_struct * as = getMatchingRow(op, 
 					      type_op1,
 					      type_op2,
@@ -573,7 +583,9 @@ void ex_arith_clause::set_case_index()
   else
     {
       // Simple types are handled here.
-      case_index = computeCaseIndex(getOperType(), getOperand(1), getOperand(2),
+      case_index = computeCaseIndex(getOperType(), 
+                                    getOperand(1), 
+                                    (getNumOperands() == 3 ? getOperand(2) : NULL),
 				    getOperand(0));
     }
 }
@@ -620,6 +632,10 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
   const static ex_comp_struct cs[] =
     {
       // op       op1 datatype        op2 datatype        case statement index
+
+      {ITM_EQUAL, REC_BIN8_SIGNED,    REC_BIN8_SIGNED,    EQ_BIN8S_BIN8S},
+      {ITM_EQUAL, REC_BIN8_UNSIGNED,  REC_BIN8_UNSIGNED,  EQ_BIN8U_BIN8U},
+
       {ITM_EQUAL, REC_BIN16_SIGNED,   REC_BIN16_SIGNED,   EQ_BIN16S_BIN16S},
       {ITM_EQUAL, REC_BIN16_SIGNED,   REC_BIN32_SIGNED,   EQ_BIN16S_BIN32S},
       {ITM_EQUAL, REC_BIN16_SIGNED,   REC_BPINT_UNSIGNED, EQ_BIN16S_BIN16U},
@@ -674,13 +690,18 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_EQUAL, REC_BYTE_V_ASCII_LONG,  REC_BYTE_V_ASCII,       EQ_ASCII_COMP},
       {ITM_EQUAL, REC_BYTE_V_ASCII_LONG,  REC_BYTE_V_ASCII_LONG,  EQ_ASCII_COMP},
 
-       {ITM_EQUAL,REC_NCHAR_F_UNICODE,REC_NCHAR_F_UNICODE,EQ_UNICODE_F_F},
-       {ITM_EQUAL, REC_NCHAR_F_UNICODE,REC_NCHAR_V_UNICODE,UNICODE_COMP},
-       {ITM_EQUAL, REC_NCHAR_V_UNICODE,REC_NCHAR_F_UNICODE,UNICODE_COMP},
-       {ITM_EQUAL, REC_NCHAR_V_UNICODE,REC_NCHAR_V_UNICODE,UNICODE_COMP},
+      {ITM_EQUAL,REC_NCHAR_F_UNICODE,REC_NCHAR_F_UNICODE,EQ_UNICODE_F_F},
+      {ITM_EQUAL, REC_NCHAR_F_UNICODE,REC_NCHAR_V_UNICODE,UNICODE_COMP},
+      {ITM_EQUAL, REC_NCHAR_V_UNICODE,REC_NCHAR_F_UNICODE,UNICODE_COMP},
+      {ITM_EQUAL, REC_NCHAR_V_UNICODE,REC_NCHAR_V_UNICODE,UNICODE_COMP},
+      
+      {ITM_EQUAL, REC_BLOB,REC_BLOB,EQ_BLOB},
+
+      {ITM_EQUAL, REC_BOOLEAN, REC_BOOLEAN, EQ_BOOL_BOOL},
 
-       {ITM_EQUAL, REC_BLOB,REC_BLOB,EQ_BLOB},
-	
+      {ITM_NOT_EQUAL, REC_BIN8_SIGNED,    REC_BIN8_SIGNED,    NE_BIN8S_BIN8S},
+      {ITM_NOT_EQUAL, REC_BIN8_UNSIGNED,  REC_BIN8_UNSIGNED,  NE_BIN8U_BIN8U},
+      
       {ITM_NOT_EQUAL, REC_BIN16_SIGNED,   REC_BIN16_SIGNED,   NE_BIN16S_BIN16S},
       {ITM_NOT_EQUAL, REC_BIN16_SIGNED,   REC_BIN32_SIGNED,   NE_BIN16S_BIN32S},
       {ITM_NOT_EQUAL, REC_BIN16_SIGNED,   REC_BPINT_UNSIGNED, NE_BIN16S_BIN16U},
@@ -740,6 +761,11 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_NOT_EQUAL, REC_NCHAR_V_UNICODE,      REC_NCHAR_F_UNICODE,      UNICODE_COMP},
       {ITM_NOT_EQUAL, REC_NCHAR_V_UNICODE,      REC_NCHAR_V_UNICODE,      UNICODE_COMP},
 
+      {ITM_NOT_EQUAL, REC_BOOLEAN, REC_BOOLEAN, NE_BOOL_BOOL},
+
+      {ITM_LESS, REC_BIN8_SIGNED,    REC_BIN8_SIGNED,    LT_BIN8S_BIN8S},
+      {ITM_LESS, REC_BIN8_UNSIGNED,  REC_BIN8_UNSIGNED,  LT_BIN8U_BIN8U},
+
       {ITM_LESS, REC_BIN16_SIGNED,   REC_BIN16_SIGNED,   LT_BIN16S_BIN16S},
       {ITM_LESS, REC_BIN16_SIGNED,   REC_BIN32_SIGNED,   LT_BIN16S_BIN32S},
       {ITM_LESS, REC_BIN16_SIGNED,   REC_BPINT_UNSIGNED, LT_BIN16S_BIN16U},
@@ -799,6 +825,9 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_LESS, REC_NCHAR_V_UNICODE,     REC_NCHAR_V_UNICODE,     UNICODE_COMP},
 
 
+      {ITM_LESS_EQ, REC_BIN8_SIGNED,    REC_BIN8_SIGNED,    LE_BIN8S_BIN8S},
+      {ITM_LESS_EQ, REC_BIN8_UNSIGNED,  REC_BIN8_UNSIGNED,  LE_BIN8U_BIN8U},
+
       {ITM_LESS_EQ, REC_BIN16_SIGNED,   REC_BIN16_SIGNED,   LE_BIN16S_BIN16S},
       {ITM_LESS_EQ, REC_BIN16_SIGNED,   REC_BIN32_SIGNED,   LE_BIN16S_BIN32S},
       {ITM_LESS_EQ, REC_BIN16_SIGNED,   REC_BPINT_UNSIGNED, LE_BIN16S_BIN16U},
@@ -858,6 +887,10 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_LESS_EQ, REC_NCHAR_V_UNICODE,     REC_NCHAR_F_UNICODE,     UNICODE_COMP},
       {ITM_LESS_EQ, REC_NCHAR_V_UNICODE,     REC_NCHAR_V_UNICODE,     UNICODE_COMP},
 
+
+      {ITM_GREATER, REC_BIN8_SIGNED,    REC_BIN8_SIGNED,    GT_BIN8S_BIN8S},
+      {ITM_GREATER, REC_BIN8_UNSIGNED,  REC_BIN8_UNSIGNED,  GT_BIN8U_BIN8U},
+
       {ITM_GREATER, REC_BIN16_SIGNED,   REC_BIN16_SIGNED,   GT_BIN16S_BIN16S},
       {ITM_GREATER, REC_BIN16_SIGNED,   REC_BIN32_SIGNED,   GT_BIN16S_BIN32S},
       {ITM_GREATER, REC_BIN16_SIGNED,   REC_BPINT_UNSIGNED, GT_BIN16S_BIN16U},
@@ -917,6 +950,10 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_GREATER, REC_NCHAR_V_UNICODE,     REC_NCHAR_F_UNICODE,     UNICODE_COMP},
       {ITM_GREATER, REC_NCHAR_V_UNICODE,     REC_NCHAR_V_UNICODE,     UNICODE_COMP},
 
+
+      {ITM_GREATER_EQ, REC_BIN8_SIGNED,    REC_BIN8_SIGNED,    GE_BIN8S_BIN8S},
+      {ITM_GREATER_EQ, REC_BIN8_UNSIGNED,  REC_BIN8_UNSIGNED,  GE_BIN8U_BIN8U},
+
       {ITM_GREATER_EQ, REC_BIN16_SIGNED,   REC_BIN16_SIGNED,   GE_BIN16S_BIN16S},
       {ITM_GREATER_EQ, REC_BIN16_SIGNED,   REC_BIN32_SIGNED,   GE_BIN16S_BIN32S},
       {ITM_GREATER_EQ, REC_BIN16_SIGNED,   REC_BPINT_UNSIGNED, GE_BIN16S_BIN16U},
@@ -1150,11 +1187,15 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     {REC_BPINT_UNSIGNED, REC_NCHAR_V_UNICODE,        CONV_BIN16U_UNICODE},
 
     {REC_BIN8_SIGNED,    REC_BIN16_SIGNED,           CONV_BIN8S_BIN16S},
+    {REC_BIN8_SIGNED,    REC_BIN32_SIGNED,           CONV_BIN8S_BIN32S},
+    {REC_BIN8_SIGNED,    REC_BIN64_SIGNED,           CONV_BIN8S_BIN64S},
     {REC_BIN8_SIGNED,    REC_BIN8_SIGNED,            CONV_BIN8S_BIN8S},
     {REC_BIN8_SIGNED,    REC_BYTE_F_ASCII,           CONV_BIN8S_ASCII},
     {REC_BIN8_SIGNED,    REC_BYTE_V_ASCII,           CONV_BIN8S_ASCII},
 
     {REC_BIN8_UNSIGNED,  REC_BIN16_UNSIGNED,         CONV_BIN8U_BIN16U},
+    {REC_BIN8_UNSIGNED,  REC_BIN32_UNSIGNED,         CONV_BIN8U_BIN32U},
+    {REC_BIN8_UNSIGNED,  REC_BIN64_UNSIGNED,         CONV_BIN8U_BIN64U},
     {REC_BIN8_UNSIGNED,  REC_BIN16_SIGNED,           CONV_BIN8U_BIN16S},
     {REC_BIN8_UNSIGNED,  REC_BIN8_UNSIGNED,          CONV_BIN8U_BIN8U},
     {REC_BIN8_UNSIGNED,  REC_BYTE_F_ASCII,           CONV_BIN8U_ASCII},
@@ -1451,6 +1492,8 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     {REC_BYTE_F_ASCII,       REC_NCHAR_V_UNICODE,        CONV_ASCII_UNICODE_V},
     {REC_BYTE_F_ASCII,       REC_NCHAR_V_ANSI_UNICODE,   CONV_ASCII_TO_ANSI_V_UNICODE},
 
+    {REC_BYTE_F_ASCII,      REC_BOOLEAN,                 CONV_ASCII_BOOL},
+
 // 12/8/97: added for Unicode. Note the importance of
 // grouping tuples with similar source types together.
     {REC_NCHAR_F_UNICODE,    REC_NCHAR_F_UNICODE,        CONV_UNICODE_F_F},
@@ -1534,6 +1577,7 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     {REC_BYTE_V_ASCII,       REC_NCHAR_V_UNICODE,        CONV_ASCII_UNICODE_V},
     {REC_BYTE_V_ASCII,       REC_NCHAR_V_ANSI_UNICODE,   CONV_ASCII_TO_ANSI_V_UNICODE},
 
+    {REC_BYTE_V_ASCII,      REC_BOOLEAN,                 CONV_ASCII_BOOL},
 
     {REC_BYTE_V_ASCII_LONG,   REC_BPINT_UNSIGNED,         CONV_ASCII_BIN16U},  
     {REC_BYTE_V_ASCII_LONG,   REC_BIN16_SIGNED,           CONV_ASCII_BIN16S},
@@ -1568,8 +1612,12 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     {REC_NCHAR_V_ANSI_UNICODE, REC_NCHAR_V_UNICODE, CONV_ANSI_V_UNICODE_TO_UNICODE_V},
     {REC_BLOB,          REC_BLOB,         CONV_BLOB_BLOB},
     {REC_BLOB,          REC_BYTE_F_ASCII,      CONV_BLOB_ASCII_F},
-    {REC_CLOB,          REC_CLOB,         CONV_BLOB_BLOB},
-    {REC_CLOB,          REC_BYTE_F_ASCII,      CONV_BLOB_ASCII_F}
+    {REC_CLOB,          REC_CLOB,              CONV_BLOB_BLOB},
+    {REC_CLOB,          REC_BYTE_F_ASCII,      CONV_BLOB_ASCII_F},
+
+    {REC_BOOLEAN,       REC_BOOLEAN,           CONV_BOOL_BOOL},
+    {REC_BOOLEAN,       REC_BYTE_F_ASCII,      CONV_BOOL_ASCII},
+    {REC_BOOLEAN,       REC_BYTE_V_ASCII,      CONV_BOOL_ASCII},
   };
   
   getConvCaseDatatypes(sourceType, sourceLen, sourceType, targetType, targetLen, targetType, scaleDifference);
@@ -1593,14 +1641,6 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     i++;
   };
 
-  if (case_index == CONV_NOT_SUPPORTED) {
-#if (!defined (__TANDEM) && !defined(__EID))
-    //    cout << sourceType << " to " 
-    //	 << targetType << " conversion not yet supported. \n";
-#endif
-  };
-
-
   if (case_index == CONV_INTERVALS_INTERVALS_DIV)
     {
     // have to look at scale difference to distinguish whether
@@ -1615,6 +1655,17 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
 
 };
 
+NABoolean ex_conv_clause::isConversionSupported
+(short sourceType, short targetType)
+{
+  conv_case_index ci = 
+    find_case_index(sourceType, 0, targetType, 0, 0);
+  if (ci == CONV_NOT_SUPPORTED)
+    return FALSE;
+  else
+    return TRUE;
+}
+
 void ex_conv_clause::set_case_index() {
   // Test added to allow conditional union to be rowset-aware
   if((getOperand(0)->getRowsetSize() > 0) && (getOperand(1)->getRowsetSize() > 0)) 
@@ -1623,9 +1674,7 @@ void ex_conv_clause::set_case_index() {
       SimpleType *op0 = (SimpleType *) getOperand(0);
       SimpleType *op1 = (SimpleType *) getOperand(1);
       if (!(op0->getUseTotalRowsetSize())) {
-#pragma nowarn(1506)   // warning elimination 
 	op0->setLength(sizeof(Lng32) + (op0->getLength() * op0->getRowsetSize()));
-#pragma warn(1506)  // warning elimination 
 	op0->setUseTotalRowsetSize();
 	op1->setUseTotalRowsetSize();
       }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index 8442a8e..c96b450 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -3208,6 +3208,7 @@ void ex_function_encode::encodeKeyValue(Attributes * attr,
     break;
 
   case REC_BIN8_UNSIGNED:
+  case REC_BOOLEAN:
     *(UInt8*)target = *(UInt8*)source;
     break;
 
@@ -4833,6 +4834,9 @@ ex_expr::exp_return_type ex_function_mod::eval(char *op_data[],
 
   switch (len1)
     {
+    case 1:
+      op1 = *((Int8 *) op_data[1]);
+      break;
     case 2:
       op1 = *((short *) op_data[1]);
       break;
@@ -4852,6 +4856,9 @@ ex_expr::exp_return_type ex_function_mod::eval(char *op_data[],
 
   switch (len2)
     {
+    case 1:
+      op2 = *((Int8 *) op_data[2]);
+      break;
     case 2:
       op2 = *((short *) op_data[2]);
       break;
@@ -4878,6 +4885,9 @@ ex_expr::exp_return_type ex_function_mod::eval(char *op_data[],
 
   switch (lenr)
     {
+    case 1:
+      *((Int8 *) op_data[0]) = (short) result;
+      break;
     case 2:
       *((short *) op_data[0]) = (short) result;
       break;
@@ -4911,6 +4921,16 @@ ex_expr::exp_return_type ex_function_mask::eval(char *op_data[],
 
   switch (getOperand(0)->getStorageLength())
     {
+    case 1:
+      op1 = *((UInt8 *) op_data[1]);
+      op2 = *((UInt8 *) op_data[2]);
+      if(getOperType() == ITM_MASK_SET) {
+        result = op1 | op2;
+      } else {
+        result = op1 & ~op2;
+      }
+      *((unsigned short *) op_data[0]) = (unsigned short) result;
+      break;
     case 2:
       op1 = *((unsigned short *) op_data[1]);
       op2 = *((unsigned short *) op_data[2]);
@@ -4969,6 +4989,15 @@ ex_expr::exp_return_type ExFunctionShift::eval(char *op_data[],
   ULng32 value, result;
 
   switch (getOperand(0)->getStorageLength()) {
+  case 1:
+    value = *((UInt8 *) op_data[1]);
+    if(getOperType() == ITM_SHIFT_RIGHT) {
+      result = value >> shift;
+    } else {
+      result = value << shift;
+    }
+    *((UInt8 *) op_data[0]) = (UInt8) result;
+    break;
   case 2:
     value = *((unsigned short *) op_data[1]);
     if(getOperType() == ITM_SHIFT_RIGHT) {
@@ -7152,6 +7181,7 @@ short ex_function_encode::decodeKeyValue(Attributes * attr,
     break;
 
   case REC_BIN8_UNSIGNED:
+  case REC_BOOLEAN:
     *(UInt8*)target = *(UInt8*)source;
     break;
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/exp/exp_math_func.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_math_func.cpp b/core/sql/exp/exp_math_func.cpp
index b6e6cd2..e249df0 100644
--- a/core/sql/exp/exp_math_func.cpp
+++ b/core/sql/exp/exp_math_func.cpp
@@ -82,6 +82,11 @@ ex_expr::exp_return_type ex_function_abs::eval(char *op_data[],
 
   switch (getOperand(1)->getDatatype())
     {
+    case REC_BIN8_SIGNED:
+      *(Int8 *)op_data[0] = (*(Int8 *)op_data[1] < 0 ? -*(Int8 *)op_data[1]
+			      : *(Int8 *)op_data[1]);
+      break;
+      
     case REC_BIN16_SIGNED:
 #pragma nowarn(1506)   // warning elimination 
       *(short *)op_data[0] = (*(short *)op_data[1] < 0 ? -*(short *)op_data[1]
@@ -500,7 +505,7 @@ ex_expr::exp_return_type ExFunctionBitOper::eval(char *op_data[],
 	UInt32 endByte   = (startBit + numBits - 1) / 8 ;
 
 	if ((numBits == 0) ||
-	    (endByte >= opLen))
+	    (endByte > opLen))
 	  {
 	    ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
 	    **diagsArea << DgString0("BITEXTRACT");
@@ -509,9 +514,18 @@ ex_expr::exp_return_type ExFunctionBitOper::eval(char *op_data[],
 	
 	UInt64 result = 0;
 
-	//Int64 temp = 0;
 	switch (getOperand(1)->getDatatype())
 	  {
+	  case REC_BIN8_SIGNED:
+	  case REC_BIN8_UNSIGNED:
+	    {
+	      UInt8 temp;
+	      temp = *(UInt8*)op_data[1] << startBit;
+	      temp = temp >> (8 - numBits);
+	      result = temp;
+	    }
+	  break;
+
 	  case REC_BIN16_SIGNED:
 	  case REC_BIN16_UNSIGNED:
 	    {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/generator/GenExpGenerator.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenExpGenerator.cpp b/core/sql/generator/GenExpGenerator.cpp
index ed20c83..bfdc65a 100644
--- a/core/sql/generator/GenExpGenerator.cpp
+++ b/core/sql/generator/GenExpGenerator.cpp
@@ -823,6 +823,84 @@ short ExpGenerator::genColNameList(const NAColumnArray &naColArr,
   return 0;
 }
 
+short ExpGenerator::handleUnsupportedCast(Cast * castNode)
+{
+  const NAType &srcNAType = castNode->child(0)->getValueId().getType();
+  const NAType &tgtNAType = castNode->getValueId().getType();
+  short srcFsType = srcNAType.getFSDatatype();
+  short tgtFsType = tgtNAType.getFSDatatype();
+
+  // check if conversion involves tinyint or largeint unsigned
+  if ((srcFsType != REC_BIN8_SIGNED) &&
+      (srcFsType != REC_BIN8_UNSIGNED) &&
+      (srcFsType != REC_BIN64_UNSIGNED) &&
+      (tgtFsType != REC_BIN8_SIGNED) &&
+      (tgtFsType != REC_BIN8_UNSIGNED) &&
+      (tgtFsType != REC_BIN64_UNSIGNED))
+    return 0;
+
+  ex_conv_clause tempClause;
+  if (tempClause.isConversionSupported(srcFsType, tgtFsType))
+    return 0;
+
+  // if this cast involved a tinyint and is unsupported, convert to
+  // smallint.
+  if ((srcFsType == REC_BIN8_SIGNED) ||
+      (srcFsType == REC_BIN8_UNSIGNED) ||
+      (tgtFsType == REC_BIN8_SIGNED) ||
+      (tgtFsType == REC_BIN8_UNSIGNED))
+    {
+      // add a Cast node to convert from/to tinyint to/from small int.
+      const NumericType &srcNum = (NumericType&)srcNAType; 
+      NumericType * newType;
+      if (srcNum.getScale() == 0)
+        newType = new (generator->wHeap())
+          SQLSmall(NOT srcNum.isUnsigned(),
+                   srcNAType.supportsSQLnull());
+      else
+        newType = new (generator->wHeap())
+          SQLNumeric(sizeof(short), srcNum.getPrecision(), srcNum.getScale(),
+                     NOT srcNum.isUnsigned(), srcNAType.supportsSQLnull());
+      ItemExpr * newChild =
+        new (generator->wHeap())
+        Cast(castNode->child(0), newType);
+      ((Cast*)newChild)->setFlags(castNode->getFlags());
+      castNode->setSrcIsVarcharPtr(FALSE);
+      newChild = newChild->bindNode(generator->getBindWA());
+      newChild = newChild->preCodeGen(generator);
+      if (! newChild)
+        return -1;
+      
+      castNode->setChild(0, newChild);
+      srcFsType = castNode->child(0)->getValueId().getType().getFSDatatype();
+    }
+
+  if ((srcFsType == REC_BIN64_UNSIGNED) ||
+      (tgtFsType == REC_BIN64_UNSIGNED))
+    {
+      const NumericType &numSrc = (NumericType&)srcNAType;
+      // add a Cast node to convert to sqllargeint signed.
+      ItemExpr * newChild =
+        new (generator->wHeap())
+        Cast(castNode->child(0),
+             new (generator->wHeap())
+             SQLLargeInt(numSrc.getScale(), 1,
+                         TRUE,
+                         srcNAType.supportsSQLnull()));
+      ((Cast*)newChild)->setFlags(castNode->getFlags());
+      castNode->setSrcIsVarcharPtr(FALSE);
+      newChild = newChild->bindNode(generator->getBindWA());
+      newChild = newChild->preCodeGen(generator);
+      if (! newChild)
+        return -1;
+      
+      castNode->setChild(0, newChild);
+      srcFsType = castNode->child(0)->getValueId().getType().getFSDatatype();
+    }
+
+  return 0;
+}
+
 /////////////////////////////////////////////////////////////////
 // this function returns an expr tree that multiplies the source
 // by 10 ** exponent.  If exponent is negative, the returned expr
@@ -911,6 +989,9 @@ ItemExpr * ExpGenerator::matchScales(const ValueId & source,
       retTree = new(wHeap()) Cast(retTree, &targetType);
       retTree->bindNode(generator->getBindWA());
 
+      if (handleUnsupportedCast((Cast*)retTree))
+        return NULL;
+
       // Mark this as preCodeGenned so we don't generate more
       // scaling code to handle possible scale differences in the
       // new Cast (note that matchScalesNoCast() in this case has
@@ -986,6 +1067,10 @@ ItemExpr * ExpGenerator::matchScalesNoCast(const ValueId & source,
 	(targetScale != sourceScale)) {
     retTree = new(wHeap()) Cast(retTree,&targetType);
     retTree->bindNode(generator->getBindWA());
+
+    if (handleUnsupportedCast((Cast*)retTree))
+      return NULL;
+
     retTree->markAsPreCodeGenned();
     retTree = scaleBy10x(retTree->getValueId(), targetScale - sourceScale);
     }
@@ -4666,18 +4751,6 @@ short ExpGenerator::endExprGen(ex_expr ** expr, short gen_last_clause)
   // generate pcode at compile time
   UInt32 f = 0;
   ex_expr_base::setForShowplan(f, FALSE);
-  if (generator->downrevCompileNeeded())
-    {
-      if (generator->getDownrevCompileMXV() == COM_VERS_R2_FCS)
-	{
-	  ex_expr_base::setDownrevCompileR2FCS(f, TRUE);
-	  ex_expr_base::setDownrevCompileRR(f, TRUE);
-	}
-      else if (generator->getDownrevCompileMXV() == COM_VERS_R2_1)
-	ex_expr_base::setDownrevCompileRR(f, TRUE);
-    }
-  else if ((CmpCommon::getDefaultLong(QUERY_OPTIMIZATION_OPTIONS) & QO_EXPR_OPT) == 0)
-    ex_expr_base::setDownrevCompileR2FCS(f, TRUE);
   if (generator->genNoFloatValidatePCode())
     ex_expr_base::setNotValidateFloat64(f, TRUE);
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/generator/GenExpGenerator.h
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenExpGenerator.h b/core/sql/generator/GenExpGenerator.h
index 87b31f9..500d747 100644
--- a/core/sql/generator/GenExpGenerator.h
+++ b/core/sql/generator/GenExpGenerator.h
@@ -892,6 +892,9 @@ public:
   ItemExpr * matchScalesNoCast(const ValueId & source, 
 			       const NAType & targetType);
 
+  // if Cast from/to is not supported, convert to supported datatype.
+  short handleUnsupportedCast(Cast * castNode);
+
   // if the source is an interval, this function returns an expr
   // tree to convert the source type to numeric.
   ItemExpr * convertIntervalToNumeric(const ValueId & source);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/generator/GenItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenItemExpr.cpp b/core/sql/generator/GenItemExpr.cpp
index 0df647e..517272b 100644
--- a/core/sql/generator/GenItemExpr.cpp
+++ b/core/sql/generator/GenItemExpr.cpp
@@ -398,6 +398,25 @@ short BiArithCount::codeGen(Generator * generator)
   return 0;
 }
 
+short UnArith::codeGen(Generator * generator)
+{
+  Attributes ** attr;
+  ExpGenerator * eg = generator->getExpGenerator();
+  
+  if (eg->genItemExpr(this, &attr, (1+getArity()), -1) == 1)
+    return 0;
+
+
+  ex_arith_clause * arith_clause = 
+    new(generator->getSpace()) 
+    ex_arith_clause(getOperatorType(), attr, generator->getSpace(),
+                    0, FALSE);
+  
+  generator->getExpGenerator()->linkClause(this, arith_clause);
+
+  return 0;
+}
+
 void
 markGeneratedEntries(Generator *generator, ItemExpr *item, ValueIdSet &marks)
 {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/generator/GenPreCode.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenPreCode.cpp b/core/sql/generator/GenPreCode.cpp
index 50c83cb..a122a44 100644
--- a/core/sql/generator/GenPreCode.cpp
+++ b/core/sql/generator/GenPreCode.cpp
@@ -1752,8 +1752,7 @@ RelExpr * RelRoot::preCodeGen(Generator * generator,
             }
 
 
-	  if ((CmpCommon::getDefault(EID_SPACE_USAGE_OPT) == DF_ON) &&
-	      (NOT generator->downrevCompileNeeded()))
+	  if (CmpCommon::getDefault(EID_SPACE_USAGE_OPT) == DF_ON)
 	    {
 	      generator->setDoEidSpaceUsageOpt(TRUE);
 	    }
@@ -1794,9 +1793,6 @@ RelExpr * RelRoot::preCodeGen(Generator * generator,
 		}
 	    }
 
-	  if (generator->downrevCompileNeeded())
-	    generator->oltOptInfo()->setOltEidLeanOpt(FALSE);
-
 	  if (CmpCommon::getDefault(OLT_QUERY_OPT_LEAN) == DF_OFF)
 	    generator->oltOptInfo()->setOltEidLeanOpt(FALSE);
 	} // oltAnyOpt
@@ -3577,18 +3573,6 @@ RelExpr * HashJoin::preCodeGen(Generator * generator,
 
   if (hjp.isEmpty())
   {
-    if (generator->downrevCompileNeeded())
-      {
-	// This is a cartesian product.
-	// create a join predicate " 1 = 1 " which will always be true.
-	//
-	ItemExpr *left = new(generator->wHeap()) ConstValue(1);
-	ItemExpr *right = new(generator->wHeap()) ConstValue(1);
-
-	BiRelat *pred = new(generator->wHeap()) BiRelat(ITM_EQUAL,left,right);
-	pred->bindNode(generator->getBindWA());
-	newJoinPreds.insert(pred->getValueId());
-      }
   }
   else
   {
@@ -7929,6 +7913,17 @@ ItemExpr * BiArith::preCodeGen(Generator * generator)
   return this;
 } // BiArith::preCodeGen()
 
+ItemExpr * UnArith::preCodeGen(Generator * generator)
+{
+  if (nodeIsPreCodeGenned())
+    return this;
+
+  if (! ItemExpr::preCodeGen(generator))
+    return NULL;
+
+  return this;
+}
+
 ItemExpr * BiLogic::preCodeGen(Generator * generator)
 {
   if (nodeIsPreCodeGenned())
@@ -8659,61 +8654,14 @@ ItemExpr * Cast::preCodeGen(Generator * generator)
         }
     }
 
+  if (generator->getExpGenerator()->handleUnsupportedCast(this))
+    return NULL;
+
   const NAType &srcNAType = child(0)->getValueId().getType();
   const NAType &tgtNAType = getValueId().getType();
   short srcFsType = srcNAType.getFSDatatype();
   short tgtFsType = tgtNAType.getFSDatatype();
 
-  // Currently, Tinyint conversions are only supported to/from smallint.
-  // if source is TINYINT, then convert it to SMALLINT first.
-  if (((srcNAType.getTypeName() == LiteralTinyInt) &&
-       (tgtNAType.getTypeName() != LiteralSmallInt)) ||
-      ((srcNAType.getTypeName() != LiteralSmallInt) &&
-       (tgtNAType.getTypeName() == LiteralTinyInt)))
-    {
-      // add a Cast node to convert from/to tinyint to/from small int.
-      ItemExpr * newChild =
-        new (generator->wHeap())
-        Cast(child(0),
-             new (generator->wHeap())
-             SQLSmall(TRUE,
-                      srcNAType.supportsSQLnull()));
-      ((Cast*)newChild)->setFlags(getFlags());
-      setSrcIsVarcharPtr(FALSE);
-      newChild = newChild->bindNode(generator->getBindWA());
-      newChild = newChild->preCodeGen(generator);
-      if (! newChild)
-        return NULL;
-      
-      setChild(0, newChild);
-      srcFsType = child(0)->getValueId().getType().getFSDatatype();
-    }
-
-  if (((srcNAType.getTypeQualifier() == NA_NUMERIC_TYPE) &&
-       (tgtNAType.getTypeQualifier() == NA_NUMERIC_TYPE)) &&
-      ((NOT srcNAType.expConvSupported(tgtNAType)) ||
-       (NOT tgtNAType.expConvSupported(srcNAType))))
-    {
-      const NumericType &numSrc = (NumericType&)srcNAType;
-      // add a Cast node to convert to sqllargeint signed.
-      ItemExpr * newChild =
-        new (generator->wHeap())
-        Cast(child(0),
-             new (generator->wHeap())
-             SQLLargeInt(numSrc.getScale(), 1,
-                         TRUE,
-                         srcNAType.supportsSQLnull()));
-      ((Cast*)newChild)->setFlags(getFlags());
-      setSrcIsVarcharPtr(FALSE);
-      newChild = newChild->bindNode(generator->getBindWA());
-      newChild = newChild->preCodeGen(generator);
-      if (! newChild)
-        return NULL;
-      
-      setChild(0, newChild);
-      srcFsType = child(0)->getValueId().getType().getFSDatatype();
-    }
-
   if ((sourceTypeQual == NA_NUMERIC_TYPE) &&
       (targetTypeQual == NA_DATETIME_TYPE))
     {
@@ -9012,6 +8960,9 @@ ItemExpr * Cast::preCodeGen(Generator * generator)
 
 	    child(0)->bindNode(generator->getBindWA());
 
+            if (generator->getExpGenerator()->handleUnsupportedCast((Cast*)child(0)->castToItemExpr()))
+              return NULL;
+
 	    // To suppress insertion of multiplying/dividing, mark Cast as
 	    // already pre-code-genned.
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/generator/GenRelJoin.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenRelJoin.cpp b/core/sql/generator/GenRelJoin.cpp
index e182935..6635756 100644
--- a/core/sql/generator/GenRelJoin.cpp
+++ b/core/sql/generator/GenRelJoin.cpp
@@ -2548,11 +2548,8 @@ short MergeJoin::codeGen(Generator * generator)
   generator->setGenNoFloatValidatePCode(TRUE);
 
   NABoolean doEncodedKeyCompOpt = FALSE;
-  if (NOT generator->downrevCompileNeeded())
-    {
-      doEncodedKeyCompOpt = TRUE;
-      encoded_key_atp_index = 2;
-    }
+  doEncodedKeyCompOpt = TRUE;
+  encoded_key_atp_index = 2;
 
   // generate expressions to find out if left or right rows are duplicate
   // of the previous rows.

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/generator/GenRelMisc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenRelMisc.cpp b/core/sql/generator/GenRelMisc.cpp
index bec9e24..7f61807 100644
--- a/core/sql/generator/GenRelMisc.cpp
+++ b/core/sql/generator/GenRelMisc.cpp
@@ -2881,9 +2881,6 @@ short RelRoot::codeGen(Generator * generator)
   // move ESP nodemask into frag dir
   exFragDir->setNodeMask((ULng32) getDefault(PARALLEL_ESP_NODEMASK));
 
-  if (generator->downrevCompileNeeded())
-    exFragDir->setPlanVersion(generator->getDownrevCompileMXV());
-
   // generate the partition input data descriptor from the compile-time
   // partitioning attributes
   ExPartInputDataDesc **partInputDataDescs =

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/generator/Generator.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/Generator.cpp b/core/sql/generator/Generator.cpp
index c244c5a..466e124 100644
--- a/core/sql/generator/Generator.cpp
+++ b/core/sql/generator/Generator.cpp
@@ -148,8 +148,6 @@ Generator::Generator(CmpContext* currentCmpContext) :
 
   tempSpace_ = NULL;
 
-  downrevCompileMXV_ = COM_VERS_CURR_PLAN;
-
   numBMOs_ = 0;
   totalNumBMOsPerCPU_ = 0;
 
@@ -346,15 +344,7 @@ void Generator::initTdbFields(ComTdb *tdb)
 
   tdb->setTdbId(getAndIncTdbId());
 
-  // set plan version to R2, if downrev compile needed.
-  // After R2.1 or whenever full versioning support is added,
-  // the next 3 lines should be removed.
-  if (downrevCompileNeeded())
-    {
-      tdb->setPlanVersion(getDownrevCompileMXV());
-    }
-  else   
-    tdb->setPlanVersion(ComVersion_GetCurrentPlanVersion());
+  tdb->setPlanVersion(ComVersion_GetCurrentPlanVersion());
     
   if (computeStats())
     {
@@ -492,11 +482,6 @@ RelExpr * Generator::preGenCode(RelExpr * expr_node)
 
   setUpdatableSelect(((RelRoot *)expr_node)->updatableSelect());
 
-  if (((RelRoot *)expr_node)->downrevCompileNeeded())
-    {
-      setDownrevCompileMXV(((RelRoot *)expr_node)->getDownrevCompileMXV());
-    }
-
   // see if aqr could be done
   NABoolean aqr = FALSE;
   // Only dynamic queries from odbc/jdbc, NCI or mxci will enable AQR.

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/generator/Generator.h
----------------------------------------------------------------------
diff --git a/core/sql/generator/Generator.h b/core/sql/generator/Generator.h
index 7cd02d6..58b9571 100644
--- a/core/sql/generator/Generator.h
+++ b/core/sql/generator/Generator.h
@@ -129,8 +129,6 @@ class Generator : public NABasicObject
 
 	DO_EID_SPACE_USAGE_OPT = 0x0800,
 
-	//DOWNREV_COMPILE_NEEDED = 0x1000,
-
 	//this flag is used to indicate to the Root TDB that this is a Non-atomic statement
 	// where nonfatal errors are to be tolerated.
 	TOLERATE_NONFATAL_ERROR = 0x2000,
@@ -210,9 +208,6 @@ class Generator : public NABasicObject
 
         // If the statement can be reclaimed
         CANT_RECLAIM_QUERY = 0x1000
-        // almost all 32 bits are used in this enum, except
-	// DOWNREV_COMPILE_NEEDED = 0x1000, 
-        // is unused, so we recycle it.
   };
 
   /* All enum values for the flags_ have been used. Use this enum with 
@@ -413,13 +408,6 @@ class Generator : public NABasicObject
 
   ComSpace * tempSpace_;
 
-  // downrevCompileMXV_ contains the version of code which needs to be
-  // generated. It is the min MXV of all partitions.
-  // For coyote, we need to generate either roadrunner or R2 fcs code,
-  // depending on the min MXV. Valid only if downrevCompileNeeded_ is TRUE.
-  // This will be removed when real versioning support is in.
-  COM_VERSION downrevCompileMXV_;
-
   // indicates to the split-top that this is a LRU query. This flag 
   // is set during RelRoot::codeGen(); that is where we know if this 
   // is a LRU query or not.
@@ -1105,11 +1093,6 @@ public:
   Int32 getSMTag() const { return genSMTag_; }
   Int32 getNextSMTag() { return ++genSMTag_; }
 
-  NABoolean downrevCompileNeeded() 
-  { 
-    return ((downrevCompileMXV_ == COM_VERS_CURR_PLAN) ? FALSE : TRUE);
-  }
-
   NABoolean doEidSpaceUsageOpt() { return (flags_ & DO_EID_SPACE_USAGE_OPT) != 0; };
   void setDoEidSpaceUsageOpt(NABoolean v)
   {
@@ -1384,10 +1367,6 @@ public:
   ComTdbRoot *getTopRoot();
   const Space *getTopSpace() const;
 
-  void setDownrevCompileMXV(COM_VERSION mxv) 
-  { downrevCompileMXV_ = mxv;}
-  COM_VERSION getDownrevCompileMXV() { return downrevCompileMXV_;}
-
   static Lng32 getRecordLength(ComTdbVirtTableIndexInfo * indexInfo,
                                ComTdbVirtTableColumnInfo * columnInfoArray);
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/BindItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindItemExpr.cpp b/core/sql/optimizer/BindItemExpr.cpp
index 2e4d8e0..0561f8d 100644
--- a/core/sql/optimizer/BindItemExpr.cpp
+++ b/core/sql/optimizer/BindItemExpr.cpp
@@ -5943,6 +5943,31 @@ ItemExpr *BiArith::bindNode(BindWA *bindWA)
 } // BiArith::bindNode()
 
 // -----------------------------------------------------------------------
+// member functions for class UnArith
+// -----------------------------------------------------------------------
+
+ItemExpr *UnArith::bindNode(BindWA *bindWA)
+{
+  ItemExpr * result = NULL;
+
+  if (nodeIsBound())
+    return getValueId().getItemExpr();
+
+  CMPASSERT(getOperatorType() == ITM_NEGATE);
+
+  child(0) = child(0)->bindNode(bindWA);
+  if (bindWA->errStatus()) 
+    return this;
+
+  result = ItemExpr::bindNode(bindWA);
+  if (bindWA->errStatus()) 
+    return this;
+
+  return result;
+
+} // UnArith::bindNode()
+
+// -----------------------------------------------------------------------
 // member functions for class Assign
 // -----------------------------------------------------------------------
 // Helper function

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/BindRelExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindRelExpr.cpp b/core/sql/optimizer/BindRelExpr.cpp
index c82fb37..966cd8f 100644
--- a/core/sql/optimizer/BindRelExpr.cpp
+++ b/core/sql/optimizer/BindRelExpr.cpp
@@ -1072,6 +1072,26 @@ void castComputedColumnsToAnsiTypes(BindWA *bindWA,
 
         naType = (NAType*)&cast->getValueId().getType();
       }
+
+    if ((naType->getFSDatatype() == REC_BOOLEAN) &&
+        (CmpCommon::getDefault(TRAF_BOOLEAN_IO) == DF_OFF) &&
+        (NOT bindWA->inCTAS()))
+      {
+        NumericType *nTyp = (NumericType *)naType;
+        
+        ItemExpr * cast = new (bindWA->wHeap())
+          Cast(col->getValueId().getItemExpr(),
+               new (bindWA->wHeap())
+               SQLChar(SQL_BOOLEAN_DISPLAY_SIZE, naType->supportsSQLnull()));
+        
+        cast = cast->bindNode(bindWA);
+        if (bindWA->errStatus()) 
+          return;
+        col->setValueId(cast->getValueId());
+        compExpr[i] = cast->getValueId();
+        
+        naType = (NAType*)&cast->getValueId().getType();
+      }
     
     // if OFF, return tinyint as smallint.
     // This is needed until all callers/drivers have full support to

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/ControlDB.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ControlDB.cpp b/core/sql/optimizer/ControlDB.cpp
index 96da26d..a8e4299 100644
--- a/core/sql/optimizer/ControlDB.cpp
+++ b/core/sql/optimizer/ControlDB.cpp
@@ -1734,7 +1734,7 @@ ExprNode *DecodeShapeSyntax(const NAString &fname,
 	      return NULL;
 	    }
 	  short arg =
-	    *((short *) itm->castToConstValue(dummyNegate)->getConstValue());
+	    itm->castToConstValue(dummyNegate)->getExactNumericValue();
 
 	  if (arg == _SYSTEM_)
 	    {
@@ -2051,13 +2051,13 @@ ExprNode *DecodeShapeSyntax(const NAString &fname,
 		}
 	      else if (nat->getTypeQualifier() == NA_NUMERIC_TYPE)
 		{
-		  if (cv->getStorageSize() != 2)
+		  if (cv->getStorageSize() > 2)
 		    {
 		      *diags << DgSqlCode(-3113) <<
 			DgString0("Number of ESPs (short int) expected.");
 		      return NULL;
 		    }
-		  numOfEsps = *((short *) cv->getConstValue());
+		  numOfEsps = cv->getExactNumericValue();
 		}
 	      else
 		{
@@ -2143,13 +2143,13 @@ ExprNode *DecodeShapeSyntax(const NAString &fname,
 		}
 	      else if (nat->getTypeQualifier() == NA_NUMERIC_TYPE)
 		{
-		  if (cv->getStorageSize() != 2)
+		  if (cv->getStorageSize() > 2)
 		    {
 		      *diags << DgSqlCode(-3113) <<
 			DgString0("Number of ESPs (short int) expected.");
 		      return NULL;
 		    }
-		  numOfEsps = *((short *) cv->getConstValue());
+		  numOfEsps = cv->getExactNumericValue();
 		}
 	      else
 		{

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/EncodedValue.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/EncodedValue.cpp b/core/sql/optimizer/EncodedValue.cpp
index d05e061..935fd66 100644
--- a/core/sql/optimizer/EncodedValue.cpp
+++ b/core/sql/optimizer/EncodedValue.cpp
@@ -501,6 +501,7 @@ EncodedValue::outputToBufferToComputeRTHash(
       flags = ExHDPHash::NO_FLAGS;
       switch (naType->getFSDatatype()) {
         case REC_BIN8_UNSIGNED:
+        case REC_BOOLEAN:
            len = 1;
            { UInt8 y = (UInt8)x; memcpy(data, &y, len); }
            break;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/ItemArith.h
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemArith.h b/core/sql/optimizer/ItemArith.h
index 224e85a..e0f0591 100644
--- a/core/sql/optimizer/ItemArith.h
+++ b/core/sql/optimizer/ItemArith.h
@@ -250,4 +250,36 @@ public:
 private:
 };
 
+class UnArith : public ItemExpr
+{
+  // ITM_NEGATE. Used with negation of boolean native datatype
+public:
+  UnArith(ItemExpr *child0 = NULL)
+       : ItemExpr(ITM_NEGATE,child0,NULL)
+  {
+  }
+
+  // get the degree of this node (it is a binary op).
+  virtual Int32 getArity() const { return 1;}
+
+  // get a printable string that identifies the operator
+  const NAString getText() const { return '!'; }
+
+  virtual ItemExpr * copyTopNode(ItemExpr *derivedNode = NULL,
+				 CollHeap* outHeap = NULL);
+
+  // 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();
+
+  // method to do code generation
+  ItemExpr * preCodeGen(Generator*);
+  short codeGen(Generator*);
+
+private:
+};
+
+
 #endif /* ITEMARITH_H */

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/ItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp
index 4b65904..cc6d372 100644
--- a/core/sql/optimizer/ItemExpr.cpp
+++ b/core/sql/optimizer/ItemExpr.cpp
@@ -3551,6 +3551,18 @@ NABoolean BiArith::hasEquivalentProperties(ItemExpr * other)
     (this->divToDownscale_ == otherBiArith->divToDownscale_);
 }
 
+ItemExpr * UnArith::copyTopNode(ItemExpr *derivedNode, CollHeap* outHeap)
+{
+  UnArith *result;
+
+  if (derivedNode == NULL)
+    result = new (outHeap) UnArith();
+  else
+    result = (UnArith*)derivedNode;
+
+  return result;
+}
+
 // -----------------------------------------------------------------------
 // member functions for class ColReference
 // -----------------------------------------------------------------------
@@ -10453,6 +10465,13 @@ Int64 ConstValue::getExactNumericValue(Lng32 &scale) const
   CMPASSERT(t.getNominalSize() == storageSize_);
   switch (storageSize_)
     {
+    case 1:
+      if (t.isUnsigned())
+	result = *((UInt8 *) value_);
+      else
+	result = *((Int8 *) value_);
+      break;
+
     case 2:
       if (t.isUnsigned())
 	result = *((unsigned short *) value_);
@@ -12031,6 +12050,14 @@ Cast::Cast(ItemExpr *val1Ptr, const NAType *type, OperatorTypeEnum otype,
   flags_(0)
 {
   ValueId vid = val1Ptr ? val1Ptr->getValueId() : NULL_VALUE_ID;
+
+  if ((type->getFSDatatype() == 132) &&
+      (vid != NULL_VALUE_ID) &&
+      (vid.getType().getFSDatatype() == 136))
+    {
+      Lng32 ij = 1;
+    }
+
   checkForTruncation_ = FALSE;
   if (checkForTrunc)
     if (vid == NULL_VALUE_ID)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/NAColumn.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NAColumn.cpp b/core/sql/optimizer/NAColumn.cpp
index 485e56c..9a726a8 100644
--- a/core/sql/optimizer/NAColumn.cpp
+++ b/core/sql/optimizer/NAColumn.cpp
@@ -562,6 +562,10 @@ NABoolean NAColumn::createNAType(columns_desc_struct *column_desc	/*IN*/,
 		column_desc->null_flag);
       break;
 
+    case REC_BOOLEAN :
+      type = new (heap) SQLBooleanNative(column_desc->null_flag);
+      break;
+
     default:
       {
 	// 4031 Column %s is an unknown data type, %d.

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/NATable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NATable.cpp b/core/sql/optimizer/NATable.cpp
index 737fd51..afdfaa0 100644
--- a/core/sql/optimizer/NATable.cpp
+++ b/core/sql/optimizer/NATable.cpp
@@ -3304,6 +3304,12 @@ NABoolean createNAType(columns_desc_struct *column_desc	/*IN*/,
 		column_desc->null_flag);
       break;
 
+    case REC_BOOLEAN :
+      {
+        type = new (heap) SQLBooleanNative(column_desc->null_flag);
+      }
+      break;
+
     default:
       {
 	// 4031 Column %s is an unknown data type, %d.
@@ -3580,6 +3586,9 @@ NAType* getSQColTypeForHive(const char* hiveType, NAMemory* heap)
   if ( !strcmp(hiveType, "bigint"))
     return new (heap) SQLLargeInt(TRUE /* neg */, TRUE /* allow NULL*/, heap);
 
+  if ( !strcmp(hiveType, "boolean"))
+    return new (heap) SQLBooleanNative(TRUE, heap);
+ 
   if ( !strcmp(hiveType, "string"))
     {
       Int32 len = CmpCommon::getDefaultLong(HIVE_MAX_STRING_LENGTH);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/NormItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/NormItemExpr.cpp b/core/sql/optimizer/NormItemExpr.cpp
index 5f908a7..df95266 100644
--- a/core/sql/optimizer/NormItemExpr.cpp
+++ b/core/sql/optimizer/NormItemExpr.cpp
@@ -67,7 +67,7 @@ static NABoolean canBeSQLUnknown(const ItemExpr *ie,
 {
   const NAType &typ = ie->getValueId().getType();
   if (typ.getTypeQualifier() == NA_BOOLEAN_TYPE)
-    return ((SQLBoolean &)typ).canBeSQLUnknown();
+    return ((SQLBooleanRelat &)typ).canBeSQLUnknown();
   CMPASSERT(!typeMustBeSQLBoolean);
   return FALSE;
 }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/OptRange.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/OptRange.cpp b/core/sql/optimizer/OptRange.cpp
index 8e6464c..2d773c2 100644
--- a/core/sql/optimizer/OptRange.cpp
+++ b/core/sql/optimizer/OptRange.cpp
@@ -533,11 +533,13 @@ void OptRangeSpec::addSubrange(ConstValue* start, ConstValue* end,
       case NA_NUMERIC_TYPE:
       case NA_DATETIME_TYPE:
       case NA_INTERVAL_TYPE:
+      case NA_BOOLEAN_TYPE:
         //if (((const NumericType*)type)->isExact())
         if (typeQual == NA_DATETIME_TYPE ||
             typeQual == NA_INTERVAL_TYPE ||
             (typeQual == NA_NUMERIC_TYPE && 
-               static_cast<const NumericType*>(type)->isExact()))
+             static_cast<const NumericType*>(type)->isExact()) ||
+            (typeQual == NA_BOOLEAN_TYPE))
           {
             // Fixed-point numeric subranges are normalized to be inclusive, to
             // simplify equivalence and subsumption checks.
@@ -2277,10 +2279,28 @@ Int64 getInt64Value(ConstValue* val, const NAType* rangeColType,
   else
     switch (storageSize)
       {
-        case 2:
+        case 1:
           {
             assertLogAndThrow1(CAT_SQL_COMP_RANGE, level,
                             isExactNumeric, QRDescriptorException,
+                            "Constant value of size 1 not exact numeric, type is: %d",
+                            constValNumType->getTypeQualifier());
+            Int8 i8val;
+            memcpy(&i8val, valuePtr, storageSize);
+            if (constValNumType->isSigned())
+              {
+                valWasNegative = (i8val < 0);
+                i64val = (Int64)(i8val * scaleFactor);
+              }
+            else
+              i64val = (Int64)((UInt8)i8val * scaleFactor);
+          }
+          break;
+
+       case 2:
+         {
+            assertLogAndThrow1(CAT_SQL_COMP_RANGE, level,
+                            isExactNumeric, QRDescriptorException,
                             "Constant value of size 2 not exact numeric, type is: %d",
                             constValNumType->getTypeQualifier());
             Int16 i16val;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/RelExeUtil.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/RelExeUtil.cpp b/core/sql/optimizer/RelExeUtil.cpp
index 7c9e1b4..25fbdd4 100644
--- a/core/sql/optimizer/RelExeUtil.cpp
+++ b/core/sql/optimizer/RelExeUtil.cpp
@@ -4704,6 +4704,12 @@ RelExpr * ExeUtilCreateTableAs::bindNode(BindWA *bindWA)
 	    ctQuery_ = "CREATE VOLATILE TABLE ";
 	  else
 	    ctQuery_ = "CREATE TABLE ";
+
+          if (createTableNode->createIfNotExists())
+            {
+              ctQuery_ += "IF NOT EXISTS ";
+            }
+
 	  ctQuery_ += 
 	    getTableName().getQualifiedNameObj().getQualifiedNameAsAnsiString();
 	  ctQuery_ += " ";

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/SynthType.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/SynthType.cpp b/core/sql/optimizer/SynthType.cpp
index 6d91505..cc39c36 100644
--- a/core/sql/optimizer/SynthType.cpp
+++ b/core/sql/optimizer/SynthType.cpp
@@ -1438,13 +1438,13 @@ const NAType *Aggregate::synthesizeType()
   case ITM_ANY_TRUE_MAX:
   case ITM_ANY_TRUE:
   {
-    const SQLBoolean& operand = (const SQLBoolean &)
+    const SQLBooleanRelat& operand = (const SQLBooleanRelat &)
                    child(0)->castToItemExpr()->getValueId().getType();
 
     // The argument of a ONE/ANY TRUE must be of type SQLBoolean
     CMPASSERT(operand.getTypeQualifier() == NA_BOOLEAN_TYPE);
 
-    result = new HEAP SQLBoolean(operand.canBeSQLUnknown());
+    result = new HEAP SQLBooleanRelat(operand.canBeSQLUnknown());
     break;
   }
   default:
@@ -1796,7 +1796,7 @@ const NAType *Between::synthesizeType()
   //
   // Return the result.
   //
-  return new HEAP SQLBoolean(allowsUnknown);
+  return new HEAP SQLBooleanRelat(allowsUnknown);
 }
 
 // -----------------------------------------------------------------------
@@ -1945,18 +1945,50 @@ const NAType *BiArith::synthesizeType()
 }
 
 // -----------------------------------------------------------------------
+// member functions for class UnArith
+// -----------------------------------------------------------------------
+
+const NAType *UnArith::synthesizeType()
+{
+  //
+  // Type cast any params.
+  //
+  ValueId vid1 = child(0)->getValueId();
+
+  if (vid1.getType().getTypeQualifier() == NA_UNKNOWN_TYPE)
+    {
+      vid1.coerceType(NA_BOOLEAN_TYPE);
+    }
+  
+  const NAType& operand1 = vid1.getType();
+  if (operand1.getFSDatatype() != REC_BOOLEAN)
+    {
+      *CmpCommon::diags() << DgSqlCode(-4034)
+                          << DgString0("!")
+                          << DgString1("")
+                          << DgString2(child(0)->getTextUpper());
+      
+      return NULL;
+    }
+
+  NAType * retType = new HEAP SQLBooleanNative(operand1.supportsSQLnull());
+
+  return retType;
+}
+
+// -----------------------------------------------------------------------
 // member functions for class BiLogic
 // -----------------------------------------------------------------------
 
 const NAType *BiLogic::synthesizeType()
 {
-  const SQLBoolean& operand0 = (SQLBoolean&) child(0).getValueId().getType();
-  const SQLBoolean& operand1 = (SQLBoolean&) child(1).getValueId().getType();
+  const SQLBooleanRelat& operand0 = (SQLBooleanRelat&) child(0).getValueId().getType();
+  const SQLBooleanRelat& operand1 = (SQLBooleanRelat&) child(1).getValueId().getType();
 
   NABoolean allowsUnknown = operand0.canBeSQLUnknown() OR
                             operand1.canBeSQLUnknown();
 
-  return new HEAP SQLBoolean(allowsUnknown);
+  return new HEAP SQLBooleanRelat(allowsUnknown);
 }
 
 // -----------------------------------------------------------------------
@@ -1995,7 +2027,7 @@ const NAType *BiRelat::synthesizeType()
   if (!synthItemExprLists(exprList1, exprList2, allowIncompatibleComparison,
 			  allowsUnknown, this))
     return NULL;
-  return new HEAP SQLBoolean(allowsUnknown);
+  return new HEAP SQLBooleanRelat(allowsUnknown);
 }
 
 // -----------------------------------------------------------------------
@@ -2004,7 +2036,7 @@ const NAType *BiRelat::synthesizeType()
 
 const NAType *BoolResult::synthesizeType()
 {
-  return new HEAP SQLBoolean(getOperatorType() == ITM_RETURN_NULL);
+  return new HEAP SQLBooleanRelat(getOperatorType() == ITM_RETURN_NULL);
 }
 
 // -----------------------------------------------------------------------
@@ -2013,7 +2045,7 @@ const NAType *BoolResult::synthesizeType()
 
 const NAType *BoolVal::synthesizeType()
 {
-  return new HEAP SQLBoolean(getOperatorType() == ITM_RETURN_NULL);
+  return new HEAP SQLBooleanRelat(getOperatorType() == ITM_RETURN_NULL);
 }
 
 //------------------------------------------------------------------
@@ -2031,7 +2063,7 @@ const NAType *RaiseError::synthesizeType()
 		return NULL;
 	}
   }
-  return new HEAP SQLBoolean(FALSE);	// can be overridden in IfThenElse
+  return new HEAP SQLBooleanRelat(FALSE);	// can be overridden in IfThenElse
 }
 
 // -----------------------------------------------------------------------
@@ -4159,7 +4191,7 @@ const NAType *TriRelational::synthesizeType()
   //
   // Return the result.
   //
-  return new HEAP SQLBoolean(allowsUnknown);
+  return new HEAP SQLBooleanRelat(allowsUnknown);
 }
 
 // -----------------------------------------------------------------------
@@ -4294,7 +4326,7 @@ const NAType *Like::synthesizeType()
 			   (typ3 AND
 			    typ3->supportsSQLnull());
 
-  return new HEAP SQLBoolean(allowsUnknown);
+  return new HEAP SQLBooleanRelat(allowsUnknown);
 }
 
 // -----------------------------------------------------------------------
@@ -4924,7 +4956,7 @@ const NAType *UnLogic::synthesizeType()
     case ITM_NOT:
     {
       CMPASSERT(child(0).getValueId().getType().getTypeQualifier() == NA_BOOLEAN_TYPE);
-      const SQLBoolean& operand0 = (SQLBoolean &) child(0).getValueId().getType();
+      const SQLBooleanRelat& operand0 = (SQLBooleanRelat &) child(0).getValueId().getType();
       allowsUnknown = operand0.canBeSQLUnknown();
       break;
     }
@@ -4945,7 +4977,7 @@ const NAType *UnLogic::synthesizeType()
       break;
   }
 
-  return new HEAP SQLBoolean(allowsUnknown);
+  return new HEAP SQLBooleanRelat(allowsUnknown);
 }
 
 // -----------------------------------------------------------------------
@@ -5312,7 +5344,7 @@ ValueIdProxy::pushDownType(NAType& desiredType,
 
 const NAType *VEGPredicate::synthesizeType()
 {
-  return new HEAP SQLBoolean();
+  return new HEAP SQLBooleanRelat();
 }
 
 // -----------------------------------------------------------------------
@@ -5586,7 +5618,7 @@ const NAType * ZZZBinderFunction::synthesizeType()
 
 const NAType *Subquery::synthesizeType()
 {
-  return new HEAP SQLBoolean();
+  return new HEAP SQLBooleanRelat();
 }
 
 const NAType *RowSubquery::synthesizeType()
@@ -5625,7 +5657,7 @@ RowSubquery::pushDownType(NAType& desiredType,
 const NAType *Exists::synthesizeType()
 {
   // EXISTS predicate can never evaluate to Unknown
-  return new HEAP SQLBoolean(FALSE);
+  return new HEAP SQLBooleanRelat(FALSE);
 }
 
 const NAType *QuantifiedComp::synthesizeType()
@@ -5640,7 +5672,7 @@ const NAType *QuantifiedComp::synthesizeType()
   if (!synthItemExprLists(exprList1, exprList2, allowIncompatibleComparison,
 			  allowsUnknown, this))
     return NULL;
-  return new HEAP SQLBoolean(allowsUnknown);
+  return new HEAP SQLBooleanRelat(allowsUnknown);
 }
 
 // MV,
@@ -5726,7 +5758,7 @@ const NAType *IsBitwiseAndTrue::synthesizeType()
     return NULL;
   }
 
-  return new HEAP SQLBoolean(FALSE);
+  return new HEAP SQLBooleanRelat(FALSE);
 }
 
 //--MV

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/UdfDllInteraction.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/UdfDllInteraction.cpp b/core/sql/optimizer/UdfDllInteraction.cpp
index 939c3ce..14a2e10 100644
--- a/core/sql/optimizer/UdfDllInteraction.cpp
+++ b/core/sql/optimizer/UdfDllInteraction.cpp
@@ -1214,6 +1214,29 @@ NABoolean TMUDFInternalSetup::setTypeInfoFromNAType(
           switch (length)
             {
               // SMALLINT, INT, LARGEINT, NUMERIC, signed and unsigned
+            case 1:
+              if (CmpCommon::getDefault(TRAF_TINYINT_SPJ_SUPPORT) == DF_ON)
+                {
+                  *diags << DgSqlCode(-11151)
+                         << DgString0("type")
+                         << DgString1(src->getTypeSQLname())
+                         << DgString2("Tinyint datatype not yet supported");
+                  result = FALSE;
+                  break;
+                }
+
+              if (isUnsigned)
+                {
+                  if (!isDecimalPrecision)
+                    sqlType = tmudr::TypeInfo::SMALLINT_UNSIGNED;
+                }
+              else
+                {
+                  if (!isDecimalPrecision)
+                    sqlType = tmudr::TypeInfo::SMALLINT;
+                }
+              break;
+
             case 2:
               if (isUnsigned)
                 {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/optimizer/ValueDesc.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ValueDesc.cpp b/core/sql/optimizer/ValueDesc.cpp
index eba2e2a..d6730bf 100644
--- a/core/sql/optimizer/ValueDesc.cpp
+++ b/core/sql/optimizer/ValueDesc.cpp
@@ -246,7 +246,7 @@ void ValueId::coerceType(enum NABuiltInTypeEnum desiredQualifier,
   NAType *desiredType = NULL;
   switch (desiredQualifier) {
   case NA_BOOLEAN_TYPE:
-    desiredType = new STMTHEAP SQLBoolean();
+    desiredType = new STMTHEAP SQLBooleanNative(originalType.supportsSQLnull());
     break;
   case NA_CHARACTER_TYPE:
     {
@@ -405,6 +405,13 @@ void ValueId::coerceType(const NAType& desiredType,
                              NULL);
                }
            }
+	 else if ((desiredType.getFSDatatype() == REC_BOOLEAN) &&
+                  (CmpCommon::getDefault(TRAF_BOOLEAN_IO) == DF_OFF))
+           {
+             newType = new (STMTHEAP)
+               SQLVarChar(SQL_BOOLEAN_DISPLAY_SIZE, 
+                          desiredType.supportsSQLnull());
+           }
 	 else if (DFS2REC::isBigNum(desiredType.getFSDatatype()))
 	   {
 	     // If bignum IO is not enabled or

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/parser/ParKeyWords.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/ParKeyWords.cpp b/core/sql/parser/ParKeyWords.cpp
index fee890f..39d3dd0 100644
--- a/core/sql/parser/ParKeyWords.cpp
+++ b/core/sql/parser/ParKeyWords.cpp
@@ -138,7 +138,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("BLOB",               TOK_BLOB,        COMPAQ_|RESWORD_),
   ParKeyWord("BLOCKS",             TOK_BLOCKS,      NONRESTOKEN_),
   ParKeyWord("BLOCKSIZE",          TOK_BLOCKSIZE,   NONRESTOKEN_),
-  ParKeyWord("BOOLEAN",            IDENTIFIER,      POTANS_|RESWORD_),
+  ParKeyWord("BOOLEAN",            TOK_BOOLEAN,     RESWORD_),
   ParKeyWord("BOTH",               TOK_BOTH,        ANS_|RESWORD_|MPWORD_),
   ParKeyWord("BREADTH",            IDENTIFIER,      POTANS_|RESWORD_),
   ParKeyWord("BRIEF",              TOK_BRIEF,       NONRESTOKEN_),

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/parser/SqlParserAux.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/SqlParserAux.cpp b/core/sql/parser/SqlParserAux.cpp
index 61ca86e..1f4667b 100644
--- a/core/sql/parser/SqlParserAux.cpp
+++ b/core/sql/parser/SqlParserAux.cpp
@@ -865,11 +865,17 @@ ItemExpr *literalOfNumericPassingScale(NAString *strptr, char sign,
 		       << DgInt1((Lng32)CmpCommon::getDefaultNumeric(MAX_NUMERIC_PRECISION_ALLOWED)); 
       return NULL;
     }
+
+  NABoolean createTinyLiteral = 
+    ((CmpCommon::getDefault(TRAF_CREATE_TINYINT_LITERAL)) == DF_ON);
   
   char numericVal[8];
   short datatype = -1;
   Lng32 length = -1;
-  if (strSize < 5) {
+  if ((createTinyLiteral) && (strSize < 3)) {
+    datatype = (createSignedDatatype ? REC_BIN8_SIGNED : REC_BIN8_UNSIGNED);
+    length = sizeof(Int8);
+  } else if (strSize < 5) {
     datatype = (createSignedDatatype ? REC_BIN16_SIGNED : REC_BIN16_UNSIGNED);
     length = sizeof(short);
   } else if (strSize < 10) {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 3cd3663..77d7d65 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -501,6 +501,7 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %token <tokval> TOK_BOTH
 %token <tokval> TOK_BROWSE       	/* Tandem extension */
 %token <tokval> TOK_BROWSE_ACCESS      	/* Tandem extension */
+%token <tokval> TOK_BOOLEAN
 %token <tokval> TOK_BY
 %token <tokval> TOK_BYTEINT             /* TD extension that HP wants to ignore */
 %token <tokval> TOK_C                   /* HP Neo extension non-reserved word */
@@ -1890,6 +1891,7 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %type <item>                   numeric_literal
 %type <item>                   numeric_literal_exact
 %type <item>                   character_literal_sbyte
+%type <item>                   boolean_literal
 %type <stringval> 		literal_as_string
 %type <stringval> 		character_string_literal
 %type <stringval>		sbyte_string_literal
@@ -2023,6 +2025,7 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %type <na_type>   		pic_type
 %type <na_type>   		string_type
 %type <na_type>                 blob_type
+%type <na_type>                 boolean_type
 %type <na_type>   		float_type
 %type <na_type>   		proc_arg_float_type
 %type <longint>                 pic_tail
@@ -3278,6 +3281,19 @@ literal :       numeric_literal
                   SqlParser_CurrentParser->collectItem4HQC($$);
                   restoreInferCharsetState();
                 }
+             | boolean_literal
+
+boolean_literal : truth_value
+                  {
+                    if ($1 == TOK_UNKNOWN)
+                      YYERROR;
+
+                    char v = ($1 == TOK_TRUE ? 1 : 0);
+                    NAString literalBuf($1 == TOK_TRUE ? "TRUE" : "FALSE");
+                    $$ = new (PARSERHEAP()) ConstValue 
+                      (new (PARSERHEAP()) SQLBooleanNative(FALSE),
+                       (void *) &v, 1, &literalBuf);
+                  }
 
 character_literal_notcasespecific_option : '(' TOK_NOT_CASESPECIFIC ')'
                                             {$$=TRUE;}
@@ -7839,6 +7855,11 @@ factor : sign primary
 				    //SqlParser_CurrentParser->FixupForUnaryNegate((BiArith*) $$);
 				    }
 				}
+              | '!' primary
+              {
+                $$ = new (PARSERHEAP())
+                  UnArith($2);
+              }
               | primary
 	      | primary TOK_LPAREN_BEFORE_FORMAT TOK_FORMAT character_string_literal ')'
                                {
@@ -10537,6 +10558,7 @@ predefined_type : date_time_type
 		| pic_type
 		| string_type
                 | blob_type
+                | boolean_type
 
 
 /* type na_type */
@@ -11448,6 +11470,12 @@ optional_blob_unit :   TOK_K {$$ = 1024;}
                      | TOK_G {$$ = 1024*1024*1024;}
                      | empty {$$ = 1;}
 
+/* type na_type */
+boolean_type : TOK_BOOLEAN
+            {
+              $$ = new (PARSERHEAP()) SQLBooleanNative (TRUE);
+            }
+
 /* type pCharLenSpec */
 toggled_optional_left_charlen_right: new_left_charlen_right
 	| empty
@@ -21467,13 +21495,16 @@ query_shape_control : shape_identifier
 					}
 				      if (nat->getTypeQualifier() == NA_NUMERIC_TYPE)
 					{
-					  if (cv->getStorageSize() != 2)
+					  if (cv->getStorageSize() > 2)
 					    {
 					      *SqlParser_Diags << DgSqlCode(-3113) <<
 						DgString0("Number of columns (short int) expected.");
 					      return NULL;
 					    }
-					  numColumns = *((short *) cv->getConstValue());
+					  numColumns = 
+                                            (cv->getStorageSize() == 1 
+                                             ? *((Int8*) cv->getConstValue()) 
+                                             : *((short *) cv->getConstValue()));
 					}
 				      else
 					{
@@ -21497,7 +21528,9 @@ query_shape_control : shape_identifier
 					}
 				      if (nat->getTypeQualifier() == NA_NUMERIC_TYPE)
 					{
-                                          if (cv->getStorageSize() <= 2)
+                                          if (cv->getStorageSize() <= 1)
+                                            blocksPerAccess = *((Int8 *) cv->getConstValue());
+                                          else if (cv->getStorageSize() <= 2)
                                             blocksPerAccess = *((short *) cv->getConstValue());
                                           else if (cv->getStorageSize() <= 4)
                                             blocksPerAccess = *((Lng32 *) cv->getConstValue());
@@ -26808,8 +26841,6 @@ range_n_arg : value_expression TOK_BETWEEN value_expression { $$ = NULL; }
 
             | TOK_NO TOK_RANGE TOK_OR  TOK_UNKNOWN          { $$ = NULL; }
             | TOK_NO TOK_RANGE                              { $$ = NULL; }
-            | TOK_UNKNOWN                                   { $$ = NULL; }
-
 
 /* type pElemDDL */
 partition_by_column_list : '(' column_reference_list ')'

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/d48a0c94/core/sql/parser/ulexer.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/ulexer.cpp b/core/sql/parser/ulexer.cpp
index d4bd74f..b4a9cbf 100644
--- a/core/sql/parser/ulexer.cpp
+++ b/core/sql/parser/ulexer.cpp
@@ -2143,8 +2143,7 @@ Int32 yyULexer::yylex(YYSTYPE *lvalp)
           else
             {
               doBeforeAction();
-              return setTokval(NON_SQLTEXT_CHARACTER, 
-                               DBGMSG("Non-SQLTEXT character <%s>\n"), lvalp);
+              return setTokval(yytext_[0], DBGMSG("Not %s\n"), lvalp);
             }
           break;
         case L'<':


Mime
View raw message