trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ansha...@apache.org
Subject [10/11] incubator-trafodion git commit: JIRA 2086 Add support for largeint unsigned
Date Fri, 01 Jul 2016 14:46:28 GMT
JIRA 2086  Add support for largeint unsigned

This commit delivers part 1 of the jira changes.
It includes changes in traf compiler, executor and expressions
to handle largeint unsigned datatype.


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

Branch: refs/heads/master
Commit: 911f1d64f83aabf280825361534673eba041f959
Parents: d5999d8
Author: Anoop Sharma <anoop.sharma@esgyn.com>
Authored: Sat Jun 25 17:27:53 2016 +0000
Committer: Anoop Sharma <anoop.sharma@esgyn.com>
Committed: Sat Jun 25 17:27:53 2016 +0000

----------------------------------------------------------------------
 .../trafodion/jdbc/t4/InterfaceResultSet.java   |   11 +-
 .../trafodion/jdbc/t4/InterfaceUtilities.java   |   11 +-
 .../odbc/src/odbc/nsksrvrcore/sqlinterface.cpp  |   31 +
 core/sql/bin/SqlciErrors.txt                    |    2 +-
 core/sql/cli/Descriptor.cpp                     |    4 +-
 core/sql/common/BigNumHelper.cpp                |   27 +-
 core/sql/common/BigNumHelper.h                  |    6 +-
 core/sql/common/ComSmallDefs.h                  |    2 +-
 core/sql/common/Int64.cpp                       |    2 +-
 core/sql/common/NumericType.cpp                 |  155 +--
 core/sql/common/NumericType.h                   |   24 +-
 core/sql/exp/ExpPCodeOptsConstProp.cpp          |    2 +-
 core/sql/exp/exp_bignum.cpp                     |   12 +-
 core/sql/exp/exp_clause_derived.h               |   42 +-
 core/sql/exp/exp_comp.cpp                       |   90 +-
 core/sql/exp/exp_conv.cpp                       |  633 +++--------
 core/sql/exp/exp_fixup.cpp                      |   34 +-
 core/sql/generator/GenPreCode.cpp               |  104 +-
 core/sql/optimizer/BindRelExpr.cpp              |   85 +-
 core/sql/optimizer/ItemExpr.cpp                 |   21 +-
 core/sql/optimizer/ValueDesc.cpp                |   25 +
 core/sql/parser/SqlParserAux.cpp                |   20 +-
 core/sql/parser/sqlparser.y                     |   17 -
 core/sql/regress/compGeneral/EXPECTED042        |   32 +-
 core/sql/regress/executor/EXPECTED063           |  166 +--
 core/sql/regress/executor/EXPECTED140           |   60 +-
 core/sql/regress/hive/EXPECTED009               |   16 +-
 core/sql/regress/hive/TEST009                   |    2 +-
 core/sql/regress/qat/eqatdml12                  |   98 +-
 core/sql/regress/qat/eqatdml13                  |   98 +-
 core/sql/regress/seabase/EXPECTED003            | 1013 +++++++++++++++++-
 core/sql/regress/seabase/EXPECTED020            |    8 +-
 core/sql/regress/seabase/TEST003                |  119 +-
 core/sql/sqlci/SqlciEnv.cpp                     |    7 +-
 core/sql/sqlci/SqlciEnv.h                       |    2 +-
 core/sql/sqlcomp/DefaultConstants.h             |    9 +
 core/sql/sqlcomp/nadefaults.cpp                 |    5 +
 core/sql/ustat/hs_cli.cpp                       |    9 +
 core/sql/ustat/hs_faststats.cpp                 |    9 +-
 core/sql/ustat/hs_globals.cpp                   |   34 +
 40 files changed, 2052 insertions(+), 995 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java
index 0fc346d..c5c5814 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceResultSet.java
@@ -55,6 +55,7 @@ class InterfaceResultSet {
 
 	static final int SQLTYPECODE_INTEGER_UNSIGNED = -401;
 	static final int SQLTYPECODE_LARGEINT = -402;
+	static final int SQLTYPECODE_LARGEINT_UNSIGNED = -405;
 
 	/* SMALLINT */
 	static final int SQLTYPECODE_SMALLINT = 5;
@@ -300,6 +301,7 @@ class InterfaceResultSet {
 			}
 			break;
 		case SQLTYPECODE_LARGEINT:
+                case SQLTYPECODE_LARGEINT_UNSIGNED:
 			tbuffer = new byte[byteLen];
 			System.arraycopy(ibuffer, byteIndex, tbuffer, 0, byteLen);
 			retObj = new BigInteger(tbuffer);
@@ -319,6 +321,7 @@ class InterfaceResultSet {
 				tmpStr = String.valueOf(Bytes.extractInt(ibuffer, byteIndex, this.ic_.getByteSwap()));
 				break;
 			case 134:
+                        case 138:
 				tmpStr = String.valueOf(Bytes.extractLong(ibuffer, byteIndex, this.ic_.getByteSwap()));
 				break;
 			default:
@@ -555,11 +558,17 @@ class InterfaceResultSet {
 				retObj = new BigDecimal(new BigInteger(retObj.toString()), desc.scale_);
 			}
 			break;
+		case SQLTYPECODE_LARGEINT_UNSIGNED:
+			tbuffer = new byte[desc.sqlOctetLength_];
+			System.arraycopy(values, noNullValue, tbuffer, 0, desc.sqlOctetLength_);
+			retObj = InterfaceUtilities.convertSQLBigNumToBigDecimal(tbuffer, desc.scale_, swap, true);
+			break;
+
 		case SQLTYPECODE_NUMERIC:
 		case SQLTYPECODE_NUMERIC_UNSIGNED:
 			tbuffer = new byte[desc.sqlOctetLength_];
 			System.arraycopy(values, noNullValue, tbuffer, 0, desc.sqlOctetLength_);
-			retObj = InterfaceUtilities.convertSQLBigNumToBigDecimal(tbuffer, desc.scale_, swap);
+			retObj = InterfaceUtilities.convertSQLBigNumToBigDecimal(tbuffer, desc.scale_, swap, false);
 			break;
 		case SQLTYPECODE_DECIMAL:
 		case SQLTYPECODE_DECIMAL_UNSIGNED:

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java
----------------------------------------------------------------------
diff --git a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java
index 95fa7f9..9080b0d 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/InterfaceUtilities.java
@@ -160,7 +160,7 @@ public class InterfaceUtilities {
 		return targetData;
 	}
 
-	public static BigDecimal convertSQLBigNumToBigDecimal(byte[] sourceData, int scale, boolean swap) {
+    public static BigDecimal convertSQLBigNumToBigDecimal(byte[] sourceData, int scale, boolean swap, boolean isUnsigned) {
 		String strVal = ""; // our final String
 
 		// we need the data in an array which can hold UNSIGNED 16 bit values
@@ -172,9 +172,12 @@ public class InterfaceUtilities {
 		// the
 		// data
 		
-		boolean negative = ((dataInShorts[dataInShorts.length - 1] & 0x8000) > 0);
-		dataInShorts[dataInShorts.length - 1] &= 0x7FFF; // force sign to 0, continue
-		// normally
+                boolean negative = false;
+                if (!isUnsigned) {
+                    negative = ((dataInShorts[dataInShorts.length - 1] & 0x8000) > 0);
+                    dataInShorts[dataInShorts.length - 1] &= 0x7FFF; // force sign to 0, continue
+                                                                     // normally
+                }
 
 		int curPos = dataInShorts.length - 1; // start at the end
 		while (curPos >= 0 && dataInShorts[curPos] == 0)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/conn/odbc/src/odbc/nsksrvrcore/sqlinterface.cpp
----------------------------------------------------------------------
diff --git a/core/conn/odbc/src/odbc/nsksrvrcore/sqlinterface.cpp b/core/conn/odbc/src/odbc/nsksrvrcore/sqlinterface.cpp
index ee64cc0..0629e7a 100644
--- a/core/conn/odbc/src/odbc/nsksrvrcore/sqlinterface.cpp
+++ b/core/conn/odbc/src/odbc/nsksrvrcore/sqlinterface.cpp
@@ -327,6 +327,24 @@ SQLRETURN SRVR::GetODBCValues(Int32 DataType, Int32 DateTimeCode, Int32 &Length,
 			totalMemLen = ((totalMemLen + 8 - 1) >> 3) << 3; 
 			totalMemLen += Length ;
 			break;		
+		case SQLTYPECODE_LARGEINT_UNSIGNED:
+			if (Precision == 0)
+			{
+				ODBCPrecision = 19;
+				if (srvrGlobal->EnvironmentType & MXO_BIGINT_NUMERIC)
+					ODBCDataType = SQL_NUMERIC;
+				else
+					ODBCDataType = SQL_BIGINT;
+			}
+			else
+			{
+				ODBCPrecision = Precision;
+				ODBCDataType = SQL_NUMERIC;
+			}
+			SignType = FALSE;
+			totalMemLen = ((totalMemLen + 8 - 1) >> 3) << 3; 
+			totalMemLen += Length ;
+			break;		
 		case SQLTYPECODE_IEEE_REAL:
 			ODBCDataType = SQL_REAL;
 			ODBCPrecision = 7;
@@ -716,6 +734,7 @@ SQLRETURN SRVR::SetDataPtr(SQLDESC_ID *pDesc, SQLItemDescList_def *SQLDesc, Int3
 			memOffSet += SQLItemDesc->maxLen ;
 			break;
 		case SQLTYPECODE_LARGEINT:
+		case SQLTYPECODE_LARGEINT_UNSIGNED:
 			memOffSet = ((memOffSet + 8 - 1) >> 3) << 3;
 			VarPtr = memPtr + memOffSet;
 			memOffSet += SQLItemDesc->maxLen ;
@@ -1054,6 +1073,7 @@ SQLRETURN SRVR::AllocAssignValueBuffer(
 				AllocLength = SQLItemDesc->maxLen;
 				break;
 			case SQLTYPECODE_LARGEINT:
+                        case SQLTYPECODE_LARGEINT_UNSIGNED:
 				memOffSet = ((memOffSet + 8 - 1) >> 3) << 3; 
 				VarPtr = memPtr + memOffSet;
 				memOffSet += SQLItemDesc->maxLen ;
@@ -1293,6 +1313,9 @@ SQLRETURN SRVR::BuildSQLDesc(SQLDESC_ID *pDesc,
 				case 137:
 					DataType = SQLTYPECODE_TINYINT_UNSIGNED;
 					break;
+				case 138:
+					DataType = SQLTYPECODE_LARGEINT_UNSIGNED;
+					break;	
 							
 				default:
 					break;
@@ -1538,6 +1561,9 @@ SQLRETURN SRVR::BuildSQLDesc2(SQLDESC_ID *pDesc,
 				case 137:
 					DataType = SQLTYPECODE_TINYINT_UNSIGNED;
 					break;
+				case 138:
+					DataType = SQLTYPECODE_LARGEINT_UNSIGNED;
+					break;
 				
 				default:
 					break;
@@ -2279,6 +2305,9 @@ SQLRETURN SRVR::BuildSQLDesc2withRowsets( SQLDESC_ID          *pDesc
 				case 137:
 					DataType = SQLTYPECODE_TINYINT_UNSIGNED;
 					break;
+				case 138:
+					DataType = SQLTYPECODE_LARGEINT_UNSIGNED;
+					break;					
 
 				default:
 					break;
@@ -2508,6 +2537,7 @@ SQLRETURN SRVR::BuildSQLDesc2withRowsets( SQLDESC_ID          *pDesc
 			memOffSet += SqlDescInfo[i].Length;
 			break;
 		case SQLTYPECODE_LARGEINT:
+		case SQLTYPECODE_LARGEINT_UNSIGNED:
 		case SQLTYPECODE_IEEE_REAL:
 		case SQLTYPECODE_IEEE_FLOAT:
 		case SQLTYPECODE_IEEE_DOUBLE:
@@ -7067,6 +7097,7 @@ SQLRETURN SRVR::SetIndandVarPtr(SQLDESC_ID *pDesc,
 			memOffSet += SqlDescInfo[i].Length;
 			break;
 		case SQLTYPECODE_LARGEINT:
+		case SQLTYPECODE_LARGEINT_UNSIGNED:
 		case SQLTYPECODE_IEEE_REAL:
 		case SQLTYPECODE_IEEE_FLOAT:
 		case SQLTYPECODE_IEEE_DOUBLE:

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/bin/SqlciErrors.txt
----------------------------------------------------------------------
diff --git a/core/sql/bin/SqlciErrors.txt b/core/sql/bin/SqlciErrors.txt
index 2be1bc5..77e2041 100644
--- a/core/sql/bin/SqlciErrors.txt
+++ b/core/sql/bin/SqlciErrors.txt
@@ -1532,7 +1532,7 @@ $1~String1 --------------------------------
 8411 22003 99999 BEGINNER MINOR LOGONLY A numeric overflow occurred during an arithmetic computation or data conversion.$0~string0
 8412 22024 99999 BEGINNER MINOR LOGONLY An input character host variable is missing its null terminator.
 8413 22007 99999 BEGINNER MINOR LOGONLY The string argument contains characters that cannot be converted.
-8414 0A000 99999 BEGINNER MINOR LOGONLY The attempted conversion is not supported on this platform.
+8414 0A000 99999 BEGINNER MINOR LOGONLY The attempted conversion is not supported on this platform.$0~string0
 8415 22007 99999 BEGINNER MINOR LOGONLY The provided DATE, TIME, or TIMESTAMP is not valid and cannot be converted.
 8416 22008 99999 BEGINNER MINOR LOGONLY A datetime expression evaluated to an invalid datetime value.
 8417 ZZZZZ 99999 BEGINNER MAJOR DBADMIN An error occurred during the evaluation of USER function. The provided userid $0~string0 is invalid, incorrect, obsolete or inexistent and could not be converted to username.

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/cli/Descriptor.cpp
----------------------------------------------------------------------
diff --git a/core/sql/cli/Descriptor.cpp b/core/sql/cli/Descriptor.cpp
index da76a0c..a24c6eb 100644
--- a/core/sql/cli/Descriptor.cpp
+++ b/core/sql/cli/Descriptor.cpp
@@ -2058,7 +2058,7 @@ RETCODE Descriptor::processNumericDatatypeWithPrecision(desc_struct &descItem,
 	      ((descItem.datatype == REC_BIN32_UNSIGNED) &&
 	       (descItem.precision > 9)) ||
 	      ((descItem.datatype == REC_BIN64_UNSIGNED) &&
-	       (descItem.precision > 18)) ||
+	       (descItem.precision > 19)) ||
 	      ((descItem.datatype == REC_NUM_BIG_UNSIGNED) &&
 	       (descItem.precision > 128)))
 	    {
@@ -2068,7 +2068,7 @@ RETCODE Descriptor::processNumericDatatypeWithPrecision(desc_struct &descItem,
 	      else if (descItem.datatype == REC_BIN32_UNSIGNED)
 		maxPrec = 9;
 	      else if (descItem.datatype == REC_BIN64_UNSIGNED)
-		maxPrec = 18;
+		maxPrec = 19;
 	      else
 		maxPrec = 128;
 	      diags << DgSqlCode(-3008) 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/common/BigNumHelper.cpp
----------------------------------------------------------------------
diff --git a/core/sql/common/BigNumHelper.cpp b/core/sql/common/BigNumHelper.cpp
index c7b3dbb..7e3d143 100644
--- a/core/sql/common/BigNumHelper.cpp
+++ b/core/sql/common/BigNumHelper.cpp
@@ -994,7 +994,8 @@ short BigNumHelper::ConvPowersOfTenToBigNumHelper(Lng32 exponent,
 
 short BigNumHelper::ConvInt64ToBigNumWithSignHelper(Int32 targetLength,
                                                     Int64 sourceData,
-                                                    char * targetData)
+                                                    char * targetData,
+                                                    NABoolean isUnsigned)
 
 {
   Int32 tgtLength16 = targetLength >> 1; 
@@ -1007,7 +1008,7 @@ short BigNumHelper::ConvInt64ToBigNumWithSignHelper(Int32 targetLength,
   for (Int32 k = 0; k < tgtLength16; k++)
     tgt[k] = 0;
 
-  if (sourceData < 0) {
+  if ((NOT isUnsigned) && (sourceData < 0)) {
     sourceData = -sourceData;
     isNeg = TRUE;
   }
@@ -1035,14 +1036,16 @@ short BigNumHelper::ConvInt64ToBigNumWithSignHelper(Int32 targetLength,
 
 short BigNumHelper::ConvBigNumWithSignToInt64Helper(Lng32 sourceLength,
                                                     char * sourceData,
-                                                    Int64 * targetData)
+                                                    void * targetDataPtr,
+                                                    NABoolean isUnsigned)
 
 {
+  UInt64 *uTargetData = (UInt64*)targetDataPtr;
+  Int64  *targetData  = (Int64*)targetDataPtr;
+
   // Recast from bytes to unsigned shorts.
   unsigned short * sourceDataInShorts = (unsigned short *) sourceData;
   Lng32 sourceLengthInShorts = sourceLength/2;
-  unsigned short * targetDataInShorts = (unsigned short *) targetData;
-
   char srcSign = BIGN_GET_SIGN(sourceData, sourceLength);
 
   // Clear source sign temporarily
@@ -1072,6 +1075,8 @@ short BigNumHelper::ConvBigNumWithSignToInt64Helper(Lng32 sourceLength,
     // Do nothing, target already in correct format.
 #else
     // Reverse the shorts in the target.
+    unsigned short * targetDataInShorts = (unsigned short *) targetData;
+
     unsigned short temp = targetDataInShorts[0];
     targetDataInShorts[0] = targetDataInShorts[3];
     targetDataInShorts[3] = temp;
@@ -1085,19 +1090,21 @@ short BigNumHelper::ConvBigNumWithSignToInt64Helper(Lng32 sourceLength,
   // We have to make sure that the source did not contain a Big Num outside this range.
 
   if (srcSign == 0) { // source is positive.
+    if (isUnsigned)
+      return 0; // all values are ok
 
-    if (*targetData >= 0) // target magnitude is between 0 and 2^63-1.
+    else if (*targetData >= 0) // target magnitude is between 0 and 2^63-1.
       return 0;            
     else  // target magnitude is beyond 2^63-1.
       return -1;
-
     }
   else {                    // source is negative.
-
-    if (*targetData >= 0) { // target magnitude is between 0 and 2^63-1.
+    if (isUnsigned)
+      return -1; // error
+    else if (*targetData >= 0) { // target magnitude is between 0 and 2^63-1.
       *targetData = -*targetData;
       return 0;
-      }
+    }
     else if (*targetData == LLONG_MIN) // target magnitude is 2^63. We do not even 
                                        // have to negate the target, because the bit
                                        // representations of 2^63 and -2^63 (the latter

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/common/BigNumHelper.h
----------------------------------------------------------------------
diff --git a/core/sql/common/BigNumHelper.h b/core/sql/common/BigNumHelper.h
index fab2a4e..c93abdc 100644
--- a/core/sql/common/BigNumHelper.h
+++ b/core/sql/common/BigNumHelper.h
@@ -195,13 +195,15 @@ static short ConvPowersOfTenToBigNumHelper(Lng32 exponent,
 NA_EIDPROC
 static short ConvInt64ToBigNumWithSignHelper(Lng32 targetLength,
                                              Int64 sourceData,
-                                             char * targetData);
+                                             char * targetData,
+                                             NABoolean isUnsigned);
 
 // The following converts a Big Num (with sign) into an Int64.
 NA_EIDPROC
 static short ConvBigNumWithSignToInt64Helper(Lng32 sourceLength,
                                              char * sourceData,
-                                             Int64 * targetData);
+                                             void * targetData,
+                                             NABoolean isUnsigned);
 
 // The following converts a BIGNUM (with sign) into Int64 and scale it, 
 // returning information about the conversion to the caller (e.g. 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/common/ComSmallDefs.h
----------------------------------------------------------------------
diff --git a/core/sql/common/ComSmallDefs.h b/core/sql/common/ComSmallDefs.h
index 3101b2b..5b0442e 100644
--- a/core/sql/common/ComSmallDefs.h
+++ b/core/sql/common/ComSmallDefs.h
@@ -78,7 +78,7 @@ typedef          Int32          ComSInt32;
 #define MAX_HARDWARE_SUPPORTED_SIGNED_NUMERIC_PRECISION 18
 
 //Unsigned NUMERICs upto this range are supported by hardware.
-#define MAX_HARDWARE_SUPPORTED_UNSIGNED_NUMERIC_PRECISION 9
+#define MAX_HARDWARE_SUPPORTED_UNSIGNED_NUMERIC_PRECISION 20
 
 typedef NAString                ComString;
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/common/Int64.cpp
----------------------------------------------------------------------
diff --git a/core/sql/common/Int64.cpp b/core/sql/common/Int64.cpp
index fe7adb9..565d849 100644
--- a/core/sql/common/Int64.cpp
+++ b/core/sql/common/Int64.cpp
@@ -142,7 +142,7 @@ void convertInt64ToAscii(const Int64 &src, char* tgt)
 
 void convertUInt64ToAscii(const UInt64 &src, char* tgt)
 {
-  UInt64 temp = src;  // (src >= 0) ? src : - src;
+  UInt64 temp = src;
   char buffer[21];
   char *s = &buffer[21];
   *--s = '\0';

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/common/NumericType.cpp
----------------------------------------------------------------------
diff --git a/core/sql/common/NumericType.cpp b/core/sql/common/NumericType.cpp
index d2a5081..b401522 100644
--- a/core/sql/common/NumericType.cpp
+++ b/core/sql/common/NumericType.cpp
@@ -110,7 +110,7 @@ static void insertScaleIndicator(NAString * str, Int32 scale)
 
 unsigned short getBinaryStorageSize(Lng32 precision)
 {
-  if (precision < 1 || precision > 18) {
+  if (precision < 1 || precision > 19) {
     return 0;
   }
   if (precision < 5)
@@ -584,11 +584,7 @@ const NAType* NumericType::synthesizeType(enum NATypeSynthRuleEnum synthRule,
       case SQL_INT_SIZE:
         return new(h) SQLInt(isSigned, isNullable);
       case SQL_LARGE_SIZE:
-        //
-        // The result must be a signed LARGEINT.  LARGEINT UNSIGNED is not
-        // supported.
-        //
-        return new(h) SQLLargeInt(TRUE, isNullable);
+        return new(h) SQLLargeInt(isSigned, isNullable);
       default:
         return NULL;
       }
@@ -838,6 +834,24 @@ NABoolean NumericType::isEncodingNeeded() const
 #endif
 }
 
+NABoolean NumericType::expConvSupported
+(const NAType &otherNAType) const
+{
+  if (getFSDatatype() != REC_BIN64_UNSIGNED)
+    return TRUE;
+
+  if ((otherNAType.getFSDatatype() == REC_BIN64_SIGNED) ||
+      (otherNAType.getFSDatatype() == REC_BIN64_UNSIGNED) ||
+      (otherNAType.getFSDatatype() == REC_FLOAT32) ||
+      (otherNAType.getFSDatatype() == REC_FLOAT64) ||
+      (otherNAType.getFSDatatype() == REC_NUM_BIG_SIGNED) ||
+      (otherNAType.getFSDatatype() == REC_NUM_BIG_UNSIGNED) ||
+      (DFS2REC::isAnyCharacter(otherNAType.getFSDatatype())))
+    return TRUE;
+
+  return FALSE;
+}
+
 // -----------------------------------------------------------------------
 //  Methods for SQLTiny
 // -----------------------------------------------------------------------
@@ -1383,63 +1397,76 @@ double SQLLargeInt::encode (void* bufPtr) const
   }
 }
 
-void SQLLargeInt::minRepresentableValue
-( void* bufPtr
-, Lng32* bufLen
-, NAString ** stringLiteral
-, CollHeap* h
-) const
+void SQLLargeInt::minRepresentableValue(void* bufPtr, Lng32* bufLen,
+                                        NAString ** stringLiteral,
+                                        CollHeap* h) const
 {
-  assert(*bufLen >= getNominalSize());
-  *bufLen = getNominalSize();
-  Int64 temp;
-  Lng32 *dblword = (Lng32 *) &temp;
-#ifdef NA_LITTLE_ENDIAN
-  dblword[0] = 0;
-  dblword[1] = INT_MIN;
-#else
-  dblword[0] = INT_MIN;
-  dblword[1] = 0;
-#endif
-  str_cpy_all((char *) bufPtr, (char *) &temp, getNominalSize());
-  if (stringLiteral != NULL) {
-    //
-    // Generate a printable string for the minimum value.
-    //
-    char nameBuf[NAME_BUF_LEN];   // a reasonably large buffer
-    convertInt64ToAscii(temp, nameBuf);
-    *stringLiteral = new (h) NAString(nameBuf, h);
+  assert(*bufLen >= sizeof(Int64));
+  *bufLen = sizeof(Int64);
+  char nameBuf[NAME_BUF_LEN];
+  if (NumericType::isUnsigned())
+    {
+      UInt64 temp = 0;
+      for (Lng32 i = 0; i < sizeof(UInt64); i++)
+	{
+	  ((char *)bufPtr)[i] = 0;
+	}
+      if (stringLiteral != NULL) //only when need to return a string
+	{
+	  convertUInt64ToAscii(temp, nameBuf);
+	}
+     }
+  else
+    {
+      Int64 temp = LLONG_MIN;
+      for (Lng32 i = 0; i < sizeof(Int64); i++)
+	{
+	  ((char *)bufPtr)[i] = ((char *)&temp)[i];
+	}
+      if (stringLiteral != NULL) //only when need to return a string
+	{
+           convertInt64ToAscii(temp, nameBuf);
+	}
   }
+
+  if (stringLiteral != NULL)
+    *stringLiteral = new (h) NAString(nameBuf, h);
+
 } // SQLLargeInt::minRepresentableValue()
 
-void SQLLargeInt::maxRepresentableValue
-( void* bufPtr
-, Lng32* bufLen
-, NAString ** stringLiteral
-, CollHeap* h
-) const
+void SQLLargeInt::maxRepresentableValue(void* bufPtr, Lng32* bufLen,
+                                        NAString ** stringLiteral,
+                                        CollHeap* h) const
 {
-  assert(*bufLen >= getNominalSize());
-  *bufLen = getNominalSize();
-  Int64 temp;
-  Lng32 *dblword = (Lng32 *) &temp;
-#ifdef NA_LITTLE_ENDIAN
-  dblword[0] = -1;
-  dblword[1] = INT_MAX;
-#else
-  dblword[0] = INT_MAX;
-  dblword[1] = -1;
-#endif
-
-  str_cpy_all((char *) bufPtr, (char *) &temp, getNominalSize());
-  if (stringLiteral != NULL) {
-    //
-    // Generate a printable string for the maximum value.
-    //
-    char nameBuf[NAME_BUF_LEN];   // a reasonably large buffer
-    convertInt64ToAscii(temp, nameBuf);
+  assert(*bufLen >= sizeof(Int64));
+  char nameBuf[NAME_BUF_LEN];
+  *bufLen = sizeof(Int64);
+  if (NumericType::isUnsigned())
+    {
+      UInt64 temp = ULLONG_MAX;
+      for (Lng32 i = 0; i < getNominalSize(); i++)
+	{
+	  ((char *)bufPtr)[i] = ((char *)&temp)[i];
+	}
+      if (stringLiteral != NULL) //only when need to return a string
+	{
+	  convertUInt64ToAscii(temp, nameBuf);
+	}
+    }
+  else
+    {
+      Int64 temp = LLONG_MAX;
+      for (short i = 0; i < getNominalSize(); i++)
+	{
+	  ((char *)bufPtr)[i] = ((char *)&temp)[i];
+	}
+      if (stringLiteral != NULL) //only when need to return a string
+	{
+          convertInt64ToAscii(temp, nameBuf);
+	}
+    }
+  if (stringLiteral != NULL)
     *stringLiteral = new (h) NAString(nameBuf, h);
-  }
 } // SQLLargeInt::maxRepresentableValue()
 
 NAString* SQLLargeInt::convertToString(double v, CollHeap* h) const
@@ -1457,20 +1484,6 @@ NAString* SQLLargeInt::convertToString(double v, CollHeap* h) const
    return new (h) NAString(nameBuf, h);
 }
 
-NABoolean SQLLargeInt::expConvSupported
-(const NAType &otherNAType) const
-{
-  if (NOT isUnsigned())
-    return TRUE;
-
-  if ((otherNAType.getFSDatatype() == REC_BIN64_SIGNED) ||
-      (otherNAType.getFSDatatype() == REC_BIN64_UNSIGNED) ||
-      (DFS2REC::isAnyCharacter(otherNAType.getFSDatatype())))
-    return TRUE;
-
-  return FALSE;
-}
-
 // -----------------------------------------------------------------------
 //  Methods for SQLBigInt
 // -----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/common/NumericType.h
----------------------------------------------------------------------
diff --git a/core/sql/common/NumericType.h b/core/sql/common/NumericType.h
index b561d9b..3ed2039 100644
--- a/core/sql/common/NumericType.h
+++ b/core/sql/common/NumericType.h
@@ -120,7 +120,7 @@ public:
   NABoolean isBigNum() const { return qualifier_ == SQLBigNum_TYPE;}
   NABoolean isInternalType() const { return (isBigNum()); }
  
-  NABoolean supportsSign () const  {return TRUE;}
+  NABoolean supportsSign () const  {return isExact(); }
 
   // ---------------------------------------------------------------------
   // Accessor functions for the precision, magnitude, scale and unsigned
@@ -247,6 +247,9 @@ public:
   virtual NAType *newCopy(CollHeap* h=0) const 
     { return new(h) NumericType(*this,h); }
 
+  virtual NABoolean expConvSupported
+  (const NAType &otherNAType) const;
+
 protected:
 
   // ---------------------------------------------------------------------
@@ -749,13 +752,19 @@ public:
         return REC_BIN64_SIGNED;
     }
 
-  virtual Lng32 getMagnitude() const { return 189; }
+  virtual Lng32 getMagnitude() const 
+  { return (isUnsigned() ? 195 : 189); }
 
-  virtual double getMaxValue() const { return 9.2233720368547e+18; } 
-  // 2**63-1=9223372036854775807, use the above number to avoid a
-  // larger number passes the comparison checking after rounding
+  virtual double getMaxValue() const 
+  { 
+    return
+      (isUnsigned() ? 18446744073709551615ULL : 9223372036854775807ULL); 
+  } 
 
-  virtual double getMinValue() const { return -9.2233720368547e+18; } 
+  virtual double getMinValue() const 
+  { 
+    return (isUnsigned() ? 0 : -9.2233720368547e+18);
+  }
 
   virtual NABoolean shouldCheckValueFitInType() const { return TRUE; }
 
@@ -813,9 +822,6 @@ public:
   virtual double getNormalizedValue(void* buf) const 
   { return (double) *(Int64 *)buf; }
 
-  virtual NABoolean expConvSupported
-  (const NAType &otherNAType) const;
-
 private:
 
   NAString clientDataType_; // added the protected string to distinguish 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/exp/ExpPCodeOptsConstProp.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpPCodeOptsConstProp.cpp b/core/sql/exp/ExpPCodeOptsConstProp.cpp
index ed9ed84..9f57619 100644
--- a/core/sql/exp/ExpPCodeOptsConstProp.cpp
+++ b/core/sql/exp/ExpPCodeOptsConstProp.cpp
@@ -2136,7 +2136,7 @@ PCodeInst* PCodeCfg::constantFold(PCodeInst* inst, NABoolean rDefsAvailable)
         Int64 value = getIntConstValue(op2);
         Int32 tgtLen = inst->getWOps()[0]->getLen();
         char* result = (char*) new(heap_) char[tgtLen];
-        BigNumHelper::ConvInt64ToBigNumWithSignHelper(tgtLen, value, result);
+        BigNumHelper::ConvInt64ToBigNumWithSignHelper(tgtLen, value, result, FALSE);
 
         off = addConstant((void*)result, tgtLen,inst->getWOps()[0]->getAlign());
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/exp/exp_bignum.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_bignum.cpp b/core/sql/exp/exp_bignum.cpp
index d77c6b7..64ffa6e 100644
--- a/core/sql/exp/exp_bignum.cpp
+++ b/core/sql/exp/exp_bignum.cpp
@@ -611,7 +611,17 @@ short BigNum::castFrom (Attributes * source,
       // Since this case is a little more complex, we call a helper method. 
       BigNumHelper::ConvInt64ToBigNumWithSignHelper(getLength(),
                                                     *((Int64 *) op_data[1]),
-                                                    op_data[0] );
+                                                    op_data[0],
+                                                    FALSE);
+      }
+      break;
+      
+    case REC_BIN64_UNSIGNED: {
+      // Since this case is a little more complex, we call a helper method. 
+      BigNumHelper::ConvInt64ToBigNumWithSignHelper(getLength(),
+                                                    *((Int64 *) op_data[1]),
+                                                    op_data[0],
+                                                    TRUE);
       }
       break;
       

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/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 2718606..6a8ea39 100644
--- a/core/sql/exp/exp_clause_derived.h
+++ b/core/sql/exp/exp_clause_derived.h
@@ -1095,8 +1095,27 @@ public:
     LE_BLOB        =156, 
     GT_BLOB        =157,
     GE_BLOB        =158,
+
+    EQ_BIN64U_BIN64U    =159,
+    EQ_BIN64U_BIN64S    =160,
+    EQ_BIN64S_BIN64U    =161,
+    NE_BIN64U_BIN64U    =162,
+    NE_BIN64U_BIN64S    =163,
+    NE_BIN64S_BIN64U    =164,
+    LT_BIN64U_BIN64U    =165,
+    LT_BIN64U_BIN64S    =166,
+    LT_BIN64S_BIN64U    =167,
+    LE_BIN64U_BIN64U    =168,
+    LE_BIN64U_BIN64S    =169,
+    LE_BIN64S_BIN64U    =170,
+    GT_BIN64U_BIN64U    =171,
+    GT_BIN64U_BIN64S    =172,
+    GT_BIN64S_BIN64U    =173,
+    GE_BIN64U_BIN64U    =174,
+    GE_BIN64U_BIN64S    =175,
+    GE_BIN64S_BIN64U    =176,
     
-    COMP_NOT_SUPPORTED  =153
+    COMP_NOT_SUPPORTED  =177
       
     };
 
@@ -1562,24 +1581,17 @@ enum conv_case_index {
   CONV_ASCII_BIN8U                     =264,
 
   // unsigned largeint related conversions
-  CONV_BIN16S_BIN64U                   =265,   
-  CONV_BIN16U_BIN64U                   =266,   
-  CONV_BIN32S_BIN64U                   =267,   
-  CONV_BIN32U_BIN64U                   =268,   
   CONV_BIN64S_BIN64U                   =269,
   CONV_BIN64U_BIN64U                   =270,
   CONV_FLOAT32_BIN64U                  =271, 
   CONV_FLOAT64_BIN64U                  =272,
-
-  CONV_BIN64U_BIN16S                   =273,
-  CONV_BIN64U_BIN16U                   =274,   
-  CONV_BIN64U_BIN32S                   =275,
-  CONV_BIN64U_BIN32U                   =276,
-  CONV_BIN64U_BIN64S                   =277,
-  CONV_BIN64U_FLOAT32                  =278,
-  CONV_BIN64U_FLOAT64                  =279,
-  CONV_BIN64U_ASCII                    =280,
-  CONV_ASCII_BIN64U                    =281
+  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
 
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/exp/exp_comp.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_comp.cpp b/core/sql/exp/exp_comp.cpp
index a238d59..b69ad07 100644
--- a/core/sql/exp/exp_comp.cpp
+++ b/core/sql/exp/exp_comp.cpp
@@ -272,6 +272,18 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
       *(Lng32 *)op_data[0] = (*(Int64 *)op_data[1] == *(Int64 *)op_data[2]);
       break;
   
+    case EQ_BIN64U_BIN64U:
+      *(Lng32 *)op_data[0] = (*(UInt64 *)op_data[1] == *(UInt64 *)op_data[2]);
+      break;
+  
+    case EQ_BIN64U_BIN64S:
+      *(Lng32 *)op_data[0] = (*(UInt64 *)op_data[1] == *(Int64 *)op_data[2]);
+      break;
+  
+    case EQ_BIN64S_BIN64U:
+      *(Lng32 *)op_data[0] = (*(Int64 *)op_data[1] == *(UInt64 *)op_data[2]);
+      break;
+  
   
     case EQ_DECU_DECU:
     case EQ_DECS_DECS:
@@ -384,14 +396,21 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
       *(Lng32 *)op_data[0] = (*(ULng32 *)op_data[1] != *(ULng32 *)op_data[2]);
       break;
   
-  
-  
     case NE_BIN64S_BIN64S:
-     // LCOV_EXCL_START
       *(Lng32 *)op_data[0] = (*(Int64 *)op_data[1] != *(Int64 *)op_data[2]);
       break;
-      // LCOV_EXCL_STOP
+
+    case NE_BIN64U_BIN64U:
+      *(Lng32 *)op_data[0] = (*(UInt64 *)op_data[1] != *(UInt64 *)op_data[2]);
+      break;
   
+    case NE_BIN64U_BIN64S:
+      *(Lng32 *)op_data[0] = (*(UInt64 *)op_data[1] != *(Int64 *)op_data[2]);
+      break;
+  
+    case NE_BIN64S_BIN64U:
+      *(Lng32 *)op_data[0] = (*(Int64 *)op_data[1] != *(UInt64 *)op_data[2]);
+      break;
   
     case NE_DECU_DECU:
     case NE_DECS_DECS:
@@ -512,6 +531,22 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
       *(Lng32 *)op_data[0] = (*(Int64 *)op_data[1] < *(Int64 *)op_data[2]);
       break;
   
+    case LT_BIN64U_BIN64U:
+      *(Lng32 *)op_data[0] = (*(UInt64 *)op_data[1] < *(UInt64 *)op_data[2]);
+      break;
+  
+    case LT_BIN64U_BIN64S:
+      *(Lng32 *)op_data[0] = 
+        ((*(Int64*)op_data[2] < 0) ? 0 :
+         (*(UInt64 *)op_data[1] < *(Int64 *)op_data[2]));
+      break;
+  
+    case LT_BIN64S_BIN64U:
+      *(Lng32 *)op_data[0] = 
+        ((*(Int64*)op_data[1] < 0) ? 1 :
+         (*(Int64 *)op_data[1] < *(UInt64 *)op_data[2]));
+      break;
+  
     case LT_DECS_DECS:
       {
   	if ((op_data[1][0] & 0200) == 0)
@@ -674,7 +709,22 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
       *(Lng32 *)op_data[0] = (*(Int64 *)op_data[1] <= *(Int64 *)op_data[2]);
       break;
   
+    case LE_BIN64U_BIN64U:
+      *(Lng32 *)op_data[0] = (*(UInt64 *)op_data[1] <= *(UInt64 *)op_data[2]);
+      break;
   
+    case LE_BIN64U_BIN64S:
+      *(Lng32 *)op_data[0] = 
+        ((*(Int64*)op_data[2] < 0) ? 0 :
+         (*(UInt64 *)op_data[1] <= *(Int64 *)op_data[2]));
+      break;
+  
+    case LE_BIN64S_BIN64U:
+      *(Lng32 *)op_data[0] = 
+        ((*(Int64*)op_data[1] < 0) ? 1 :
+         (*(Int64 *)op_data[1] <= *(UInt64 *)op_data[2]));
+      break;
+   
    case LE_DECS_DECS:
       {
   	if ((op_data[1][0] & 0200) == 0)
@@ -837,6 +887,22 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
       *(Lng32 *)op_data[0] = (*(Int64 *)op_data[1] > *(Int64 *)op_data[2]);
       break;
   
+    case GT_BIN64U_BIN64U:
+      *(Lng32 *)op_data[0] = (*(UInt64 *)op_data[1] > *(UInt64 *)op_data[2]);
+      break;
+  
+    case GT_BIN64U_BIN64S:
+      *(Lng32 *)op_data[0] = 
+        ((*(Int64*)op_data[2] < 0) ? 1 :
+         (*(UInt64 *)op_data[1] > *(Int64 *)op_data[2]));
+      break;
+  
+    case GT_BIN64S_BIN64U:
+      *(Lng32 *)op_data[0] = 
+        ((*(Int64*)op_data[1] < 0) ? 0 :
+         (*(Int64 *)op_data[1] > *(UInt64 *)op_data[2]));
+      break;
+  
     case GT_DECS_DECS:
       {
   	if ((op_data[1][0] & 0200) == 0)
@@ -998,6 +1064,22 @@ ex_expr::exp_return_type ex_comp_clause::eval(char *op_data[],
       *(Lng32 *)op_data[0] = (*(Int64 *)op_data[1] >= *(Int64 *)op_data[2]);
       break;
   
+    case GE_BIN64U_BIN64U:
+      *(Lng32 *)op_data[0] = (*(UInt64 *)op_data[1] >= *(UInt64 *)op_data[2]);
+      break;
+  
+    case GE_BIN64U_BIN64S:
+      *(Lng32 *)op_data[0] = 
+        ((*(Int64*)op_data[2] < 0) ? 1 :
+         (*(UInt64 *)op_data[1] >= *(Int64 *)op_data[2]));
+      break;
+  
+    case GE_BIN64S_BIN64U:
+      *(Lng32 *)op_data[0] = 
+        ((*(Int64*)op_data[1] < 0) ? 0 :
+         (*(Int64 *)op_data[1] >= *(UInt64 *)op_data[2]));
+      break;
+  
     case GE_DECS_DECS:
       {
   	if ((op_data[1][0] & 0200) == 0)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/exp/exp_conv.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_conv.cpp b/core/sql/exp/exp_conv.cpp
index 774351b..df24fcf 100644
--- a/core/sql/exp/exp_conv.cpp
+++ b/core/sql/exp/exp_conv.cpp
@@ -1007,7 +1007,8 @@ ex_expr::exp_return_type convInt64ToBigNum(char *target,
 
   short retCode = BigNumHelper::ConvInt64ToBigNumWithSignHelper(targetLen,
                                                                 source,
-                                                                target);
+                                                                target,
+                                                                FALSE);
   if (retCode == -1) {
     // target is not long enough - overflow
     ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,(char*)&source,
@@ -1020,6 +1021,32 @@ ex_expr::exp_return_type convInt64ToBigNum(char *target,
 };
 
 //////////////////////////////////////////////////////////////////
+// function to convert a UInt64 to a Big Num
+///////////////////////////////////////////////////////////////////
+NA_EIDPROC
+ex_expr::exp_return_type convUInt64ToBigNum(char *target,
+                                            Lng32 targetLen,
+                                            UInt64 source,
+                                            NAMemory *heap,
+                                            ComDiagsArea** diagsArea,
+                                            ULng32 flags) {
+
+  short retCode = BigNumHelper::ConvInt64ToBigNumWithSignHelper(targetLen,
+                                                                source,
+                                                                target,
+                                                                TRUE);
+  if (retCode == -1) {
+    // target is not long enough - overflow
+    ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,(char*)&source,
+                          sizeof(Int64), REC_BIN64_UNSIGNED, 0, REC_NUM_BIG_SIGNED,
+                          flags);
+    return ex_expr::EXPR_ERROR;
+  };
+
+  return ex_expr::EXPR_OK;
+};
+
+//////////////////////////////////////////////////////////////////
 // function to convert BIGNUM to LARGEDEC
 ///////////////////////////////////////////////////////////////////
 NA_EIDPROC 
@@ -2018,9 +2045,9 @@ ex_expr::exp_return_type convAsciiToUInt64base(UInt64 &target,
   }
 
 ///////////////////////////////////////////////////////////////////
-// function to convert an ASCII string to Int64
+// function to convert an ASCII string to UInt64
 // The function assumes that source is at least
-// sourceLen long. Trailing '\0' is not recongnized
+// sourceLen long. Trailing '\0' is not recognized
 ///////////////////////////////////////////////////////////////////
 ex_expr::exp_return_type convAsciiToUInt64(UInt64 &target,
                                            Lng32 targetScale,
@@ -2100,261 +2127,6 @@ ex_expr::exp_return_type convAsciiToInt64(Int64 &target,
   return ex_expr::EXPR_OK;
 }
 
-#ifdef __ignore
-///////////////////////////////////////////////////////////////////
-// function to convert an ASCII string to Int64
-// The function assumes that source is at least
-// sourceLen long. Trailing '\0' is not recongnized
-///////////////////////////////////////////////////////////////////
-NA_EIDPROC
-ex_expr::exp_return_type convAsciiToInt64(Int64 &target,
-					  Lng32 targetScale,
-					  char *source,
-					  Lng32 sourceLen,
-					  CollHeap *heap,
-					  ComDiagsArea** diagsArea,
-                                          ULng32 flags)
-  {
-  NABoolean SignFound = FALSE;   // did we find a sign (+/-)
-  NABoolean DigitsAllowed = TRUE;
-  NABoolean negative = FALSE;    // default is a positive value
-  NABoolean pointFound = FALSE;  // did we find a decimal point
-  Lng32 currPos = 0;              // current position in the string
-  short digitCnt = 0;            // digits found so far
-  Lng32 sourceScale = 0;          // default is a scale of 0
-
-  target = 0;
-  while (currPos < sourceLen)
-    {
-    if ((source[currPos] >= '0') && (source[currPos] <= '9'))
-      { // process digits
-      if (!DigitsAllowed)
-        {
-	// syntax error in the input
-        ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
-	return ex_expr::EXPR_ERROR;
-        }
-      digitCnt++;
-
-      // if we've read enough source characters to achieve the needed 
-      // targetScale, then stop appending digits to the target value.
-      //   They would only be thrown away later.
-      if ( !pointFound || sourceScale < targetScale )
-	{           // this digit needs to be processed.
-
-        // if we found a decimal point before, another digit increases
-        // the source scale
-        if (pointFound)
-	  sourceScale++;
-
-        Int32 thisDigit = source[currPos] - '0';
-        if (digitCnt > 18)
-          {
-          // check overflow/underflow
-          if (negative)
-            {
-            if (digitCnt == 19)
-              target = -target; // target is alway positive before
-
-            if (target < (LLONG_MIN / 10))
-              { // next power of 10 causes an underflow
-              ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                    source, sourceLen, REC_BYTE_F_ASCII,
-                                    SQLCHARSETCODE_ISO88591,
-                                    REC_BIN64_SIGNED, flags);
-              return ex_expr::EXPR_ERROR;
-              }
-            target *= 10;
-            Int64 tempMin = LLONG_MIN;
-            tempMin += thisDigit; // this was done because the following
-            // generates bade code using MSDEV _int64 (??? Larry Schumacher ???)
-            // if (target < (LLONG_MIN + thisDigit));
-            if (target < tempMin)
-              { // subtracting this digit causes an underflow
-              ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                    source, sourceLen, REC_BYTE_F_ASCII,
-                                    SQLCHARSETCODE_ISO88591,
-                                    REC_BIN64_SIGNED, flags);
-              return ex_expr::EXPR_ERROR;
-              }
-            target = target - (Int64)thisDigit;
-            // LCOV_EXCL_STOP
-            }
-          else
-            {
-            if (target > (LLONG_MAX / 10))
-              { // next power of 10 causes an overflow
-              ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                    source, sourceLen, REC_BYTE_F_ASCII,
-                                    SQLCHARSETCODE_ISO88591,
-                                    REC_BIN64_SIGNED, flags);
-              return ex_expr::EXPR_ERROR;
-              }
-            target *= 10;
-            Int64 tempMax = LLONG_MAX;
-            tempMax -= thisDigit; // this was done because the following
-            // generates bade code using MSDEV _int64 (??? Larry Schumacher ???)
-            // if (target > (LLONG_MAX - thisDigit));
-            if (target > tempMax)
-              { // adding this digit causes an overflow
-              ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                    source, sourceLen, REC_BYTE_F_ASCII,
-                                    SQLCHARSETCODE_ISO88591,
-                                    REC_BIN64_SIGNED, flags);
-              return ex_expr::EXPR_ERROR;
-              }
-            target = target + (Int64)thisDigit;
-            }
-          }   // if digitCnt > 18, check overflow or underflow
-        else
-          {
-          // at this point we never consider overflow
-          // and target is alway potitive or absolute value
-          target = target * 10 + thisDigit;
-          }
-        }   // fi ( sourceScale < targetScale )
-      }
-    else if (source[currPos] == ' ')
-      { // process blanks
-      if (digitCnt || pointFound)	
-	// we found already some digits or a decimal point. A blank now 
-        // means, that from now on we should not see any digits anymore.
-	DigitsAllowed = FALSE;
-      }
-    else if ((source[currPos] == '+') || (source[currPos] == '-'))
-      { // process sign
-      if (SignFound || digitCnt || pointFound) 
-        {
-	// we found already a sign or we found already digits
-        // or we found a point already.
-        // A sign is an error now!
-	ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
-	return ex_expr::EXPR_ERROR;
-        }
-      SignFound = TRUE;
-      negative = (source[currPos] == '-');
-      }
-    else if (source[currPos] == '.')
-      { // process decimal point
-      if (pointFound || !DigitsAllowed)    
-        {
-	// we found a second decimal point. This is an error
-        // we are already not allowing anymore digits because of illegal
-        // blank space(s)
-	ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
-	return ex_expr::EXPR_ERROR;
-        }
-      pointFound = TRUE;
-      }
-    else
-      { // process illegal characters
-      // if the illegal character is a 'E' or 'e', the input
-      // might be a float value. Try to convert the input
-      // to double and then to Int64
-      if ((source[currPos] == 'E') || (source[currPos] == 'e'))
-        {
-	  if (currPos == 0)
-	    {
-	      // 'E' alone is not a valid numeric.
-	      ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
-	      return ex_expr::EXPR_ERROR;
-	    }
-
-	  double intermediate;
-	  if (convAsciiToFloat64((char*)&intermediate,
-				 source,
-				 sourceLen,
-				 heap,
-				 diagsArea,
-                                 flags | CONV_INTERMEDIATE_CONVERSION) != ex_expr::EXPR_OK)
-	    return ex_expr::EXPR_ERROR;
-
-	  // scale the intermediate
-	  for (Lng32 i = 0; i < targetScale; i++)
-	    intermediate *= 10.0;
-
-	  if ((intermediate < LLONG_MIN) || (intermediate > LLONG_MAX))
-	    {
-	      ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                    source, sourceLen, REC_BYTE_F_ASCII,
-                                    SQLCHARSETCODE_ISO88591,
-                                    REC_BIN64_SIGNED, flags);
-	      return ex_expr::EXPR_ERROR;
-	    }
-	  
-	  target = (Int64) intermediate;
-
-	  return ex_expr::EXPR_OK;
-	}
-      else
-        {
-	  // illegal character in this input string
-	  ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
-	  return ex_expr::EXPR_ERROR;
-        }
-      }
-    currPos++;
-    }
-
-  // if we didn't find any digits, it is an error
-  if (!digitCnt)
-    {
-      if ((flags & CONV_TREAT_ALL_SPACES_AS_ZERO) &&
-	  (NOT (pointFound || SignFound)))
-	{
-	  target = 0;
-	  return ex_expr::EXPR_OK;
-	}
-      
-      ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_STRING_ERROR);
-      return ex_expr::EXPR_ERROR;
-    }
-
-  // if we didn't set the sign at overflow checking above, set it here
-  if (negative && digitCnt <= 18)
-    target = -target;
-
-  // up- or downscale
-  if (sourceScale < targetScale)
-    {
-    for (Int32 i = 0; i < (targetScale - sourceScale); i++)
-      {
-      if (negative)
-        {
-        if (target < (LLONG_MIN / 10))
-          { // next power of 10 causes an underflow
-          ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW, source,
-                                sourceLen, REC_BYTE_F_ASCII, 
-                                SQLCHARSETCODE_ISO88591,
-                                REC_BIN64_SIGNED,
-                                flags);
-          return ex_expr::EXPR_ERROR;
-          }
-        }
-      else
-        {
-        if (target > (LLONG_MAX / 10))
-          { // next power of 10 causes an overflow
-          ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW, source,
-                                sourceLen, REC_BYTE_F_ASCII,
-                                SQLCHARSETCODE_ISO88591,REC_BIN64_SIGNED,
-                                flags);
-          return ex_expr::EXPR_ERROR;
-          }
-        }
-      target *= 10;
-      }
-    }
-  else
-    {
-    for (Int32 i = 0; i < sourceScale - targetScale; i++)
-      target /= 10;
-    }
-  
-  return ex_expr::EXPR_OK;
-  }
-#endif
-
 //////////////////////////////////////////////////////////////////
 // function to convert an Int64  to Decimal
 ///////////////////////////////////////////////////////////////////
@@ -3335,9 +3107,11 @@ ex_expr::exp_return_type convBigNumToInt64(Int64 *target,
 					   ComDiagsArea** diagsArea,
                                            ULng32 flags)
 
-{ short retCode = BigNumHelper::ConvBigNumWithSignToInt64Helper(sourceLen,
+{ 
+  short retCode = BigNumHelper::ConvBigNumWithSignToInt64Helper(sourceLen,
                                                                 source,
-                                                                target);
+                                                                (void*)target,
+                                                                FALSE);
   if (retCode == -1) {
     // target is not long enough - overflow
     ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW, source,
@@ -3349,6 +3123,29 @@ ex_expr::exp_return_type convBigNumToInt64(Int64 *target,
   return ex_expr::EXPR_OK;
 }
 
+ex_expr::exp_return_type convBigNumToUInt64(UInt64 *target,
+                                            char *source,
+                                            Lng32 sourceLen,
+                                            NAMemory *heap,
+                                            ComDiagsArea** diagsArea,
+                                            ULng32 flags)
+
+{ 
+  short retCode = BigNumHelper::ConvBigNumWithSignToInt64Helper(sourceLen,
+                                                                source,
+                                                                (void*)target,
+                                                                TRUE);
+  if (retCode == -1) {
+    // target is not long enough - overflow
+    ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW, source,
+		          sourceLen, REC_NUM_BIG_SIGNED, 0, REC_BIN64_UNSIGNED,
+                          flags);
+    return ex_expr::EXPR_ERROR;
+  };
+
+  return ex_expr::EXPR_OK;
+}
+
 
 
 ///////////////////////////////////////////////////////////////////
@@ -5689,12 +5486,6 @@ convDoIt(char * source,
     }
   break;
  
-  case CONV_BIN16S_BIN64U: 
-    {
-      *(UInt64 *)target = *(short *)source;
-    }
-  break;
- 
   case CONV_BIN16S_DECU:
   case CONV_BIN16S_DECS:
     {
@@ -5891,11 +5682,6 @@ convDoIt(char * source,
   };
   break;
 
-  case CONV_BIN16U_BIN64U: {
-    *(UInt64 *)target = *(unsigned short *)source;
-  };
-  break;
-
   case CONV_BIN16U_DECS:
     // covers conversion to DECS and DECU (see exp_fixup.cpp)
     {
@@ -6201,12 +5987,6 @@ convDoIt(char * source,
     }
   break;
 
-  case CONV_BIN32S_BIN64U: 
-    {
-      *(UInt64 *)target = *(Lng32 *)source;
-    }
-  break;
-
   case CONV_BIN32S_DECU:
   case CONV_BIN32S_DECS:
     {
@@ -6481,12 +6261,6 @@ convDoIt(char * source,
     }
   break;
 
-  case CONV_BIN32U_BIN64U: 
-    {
-      *(UInt64 *)target = (UInt64)(*(ULng32 *)source);
-    }
-  break;
-
   case CONV_BIN32U_DECS:
   // covers conversion to DECS and DECU (see exp_fixup.cpp)
      {
@@ -6905,228 +6679,6 @@ convDoIt(char * source,
     }
   break;
 
-  case CONV_BIN64U_BIN16S:
-    {
-      if (*(UInt64 *)source < SHRT_MIN)
-        {
-          if (dataConversionErrorFlag != 0)  // Capture error in variable?
-            {
-              *(short *)target = SHRT_MIN;
-              *dataConversionErrorFlag = ex_conv_clause::CONV_RESULT_ROUNDED_UP_TO_MIN;
-            }
-          else
-            {
-              ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                    source, sourceLen, sourceType, sourceScale,
-                                    targetType, tempFlags);
-              return ex_expr::EXPR_ERROR;
-            }
-        }
-      else if (*(UInt64 *)source > SHRT_MAX)
-        {
-          if (dataConversionErrorFlag != 0)  // Capture error in variable?
-            {
-              *(short *)target = SHRT_MAX;
-              *dataConversionErrorFlag = ex_conv_clause::CONV_RESULT_ROUNDED_DOWN_TO_MAX;
-            }
-          else
-            {
-              ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                    source, sourceLen, sourceType, sourceScale,
-                                    targetType, tempFlags);
-              return ex_expr::EXPR_ERROR;
-            }
-        }
-      else
-        {
-          if (dataConversionErrorFlag != 0)
-            { // Set the target value.
-              *(short *)target = (short) *(UInt64 *)source;
-            }
-          else
-            { // Check target precision. Then set target value.
-              if (checkPrecision(*(Int64 *)source,                 
-				 sourceLen,
-                                 sourceType,
-		                 sourcePrecision,
-                                 sourceScale,
-		                 targetType,
-		                 targetPrecision,
-                                 targetScale,
-		                 heap,
-                                 diagsArea,
-                                 tempFlags) == ex_expr::EXPR_OK)
-                {
-                  *(short *)target = (short) *(UInt64 *)source;
-                }
-              else
-                {
-                  return ex_expr::EXPR_ERROR;
-                }
-            }
-        }
-    }
-  break;
-
-  case CONV_BIN64U_BIN16U:
-    {
-      if (*(UInt64 *)source > USHRT_MAX)
-        {
-          if (dataConversionErrorFlag != 0)  // Capture error in variable?
-            {
-              *(unsigned short *)target = USHRT_MAX;
-              *dataConversionErrorFlag = ex_conv_clause::CONV_RESULT_ROUNDED_DOWN_TO_MAX;
-            }
-          else
-            {
-              ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                    source, sourceLen, sourceType, sourceScale,
-                                    targetType, tempFlags);
-              return ex_expr::EXPR_ERROR;
-            }
-        }
-      else
-        {
-          if (dataConversionErrorFlag != 0)
-            { // Set the target value.
-              *(unsigned short *)target = (unsigned short) *(UInt64 *)source;
-            }
-          else
-            { // Check target precision. Then set target value.
-              if (checkPrecision(*(Int64 *)source,
-				 sourceLen,
-                                 sourceType,
-                                 sourcePrecision,
-                                 sourceScale,
-                                 targetType,
-                                 targetPrecision,
-                                 targetScale,
-                                 heap,
-                                 diagsArea,
-                                 tempFlags) == ex_expr::EXPR_OK)
-                {
-                  *(unsigned short *)target = (unsigned short) *(UInt64 *)source;
-                }
-              else
-                {
-                  return ex_expr::EXPR_ERROR;
-                }
-            }
-        }
-    }
-  break;
-
-  case CONV_BIN64U_BIN32S:
-    {
-      if (*(UInt64 *)source < INT_MIN)
-        {
-          if (dataConversionErrorFlag != 0)  // Capture error in variable?
-            {
-              *(Lng32 *)target = INT_MIN;
-              *dataConversionErrorFlag = ex_conv_clause::CONV_RESULT_ROUNDED_UP_TO_MIN;
-            }
-          else
-            {
-              ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                    source, sourceLen, sourceType, sourceScale,
-                                    targetType, tempFlags);
-              return ex_expr::EXPR_ERROR;
-            }
-        }
-      else if (*(UInt64 *)source > INT_MAX)
-        {
-          if (dataConversionErrorFlag != 0)  // Capture error in variable?
-            {
-              *(Lng32 *)target = INT_MAX;
-              *dataConversionErrorFlag = ex_conv_clause::CONV_RESULT_ROUNDED_DOWN_TO_MAX;
-            }
-          else
-            {
-              ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                    source, sourceLen, sourceType, sourceScale,
-                                    targetType, tempFlags);
-              return ex_expr::EXPR_ERROR;
-            }
-        }
-      else
-        {
-          if (dataConversionErrorFlag != 0)
-            { // Set the target value.
-              *(Lng32 *)target = (Lng32) *(UInt64 *)source;
-            }
-          else
-            { // Check target precision. Then set target value.
-              if (checkPrecision(*(Int64 *)source,
-				 sourceLen,
-		                 sourceType,
-		                 sourcePrecision,
-                                 sourceScale,
-		                 targetType,
-		                 targetPrecision,
-                                 targetScale,
-		                 heap,
-		                 diagsArea,
-                                 tempFlags) == ex_expr::EXPR_OK)
-                {
-                  *(Lng32 *)target = (Lng32) *(UInt64 *)source;
-                }
-              else
-                {
-                  return ex_expr::EXPR_ERROR;
-                }
-            }
-        }
-    }
-  break;
-
-  case CONV_BIN64U_BIN32U:
-    {
-      if (*(UInt64 *)source > UINT_MAX)
-        {
-          if (dataConversionErrorFlag != 0)  // Capture error in variable?
-            {
-              *(ULng32 *)target = UINT_MAX;
-              *dataConversionErrorFlag = ex_conv_clause::CONV_RESULT_ROUNDED_DOWN_TO_MAX;
-            }
-          else
-            {
-              ExRaiseDetailSqlError(heap, diagsArea, EXE_NUMERIC_OVERFLOW,
-                                    source, sourceLen, sourceType, sourceScale,
-                                    targetType, tempFlags);
-              return ex_expr::EXPR_ERROR; 
-            }
-        }
-      else
-        {
-          if (dataConversionErrorFlag != 0)
-            { // Set the target value.
-              *(ULng32 *)target = (ULng32) *(UInt64 *)source;
-            }
-          else
-            { // Check target precision. Then set target value.
-              if (checkPrecision(*(Int64 *)source,
-				 sourceLen,
-		                 sourceType,
-		                 sourcePrecision,
-                                 sourceScale,
-		                 targetType,
-		                 targetPrecision,
-                                 targetScale,
-		                 heap,
-		                 diagsArea,
-                                 tempFlags) == ex_expr::EXPR_OK)
-                {
-                  *(ULng32 *)target = (ULng32) *(UInt64 *)source;
-                }
-              else
-                {
-                  return ex_expr::EXPR_ERROR;
-                }
-            }
-        }
-    }
-  break;
-
   case CONV_BIN64U_BIN64U:
     {
       if (dataConversionErrorFlag != 0)
@@ -7242,6 +6794,16 @@ convDoIt(char * source,
   };
   break;
 
+  case CONV_BIN64U_BIGNUM: {
+    return convUInt64ToBigNum(target,
+			     targetLen,
+			     *(UInt64 *) source,
+			     heap,
+			     diagsArea,
+                             tempFlags);
+  };
+  break;
+
   case CONV_BIN64S_BIGNUMU: {
     if (*(Int64 *)source < 0) {
       ExRaiseSqlError(heap, diagsArea, EXE_UNSIGNED_OVERFLOW);
@@ -9060,6 +8622,48 @@ convDoIt(char * source,
   };
   break;
 
+  case CONV_BIGNUM_BIN64U: {
+    UInt64 intermediate;
+    if (dataConversionErrorFlag)
+      {
+        Int64 intermediateTemp;
+      // want conversion errors in a variable
+      *dataConversionErrorFlag
+           = convBigNumToInt64AndScale(&intermediateTemp,
+                                       source,
+                                       sourceLen,
+                                       targetScale-sourceScale,
+                                       heap);     
+      }
+    else
+      {
+      // want conversion errors in diagsArea
+      if (convBigNumToUInt64(&intermediate,
+                             source,
+                             sourceLen,
+                             heap,
+                             diagsArea,
+                             tempFlags) != ex_expr::EXPR_OK)
+        return ex_expr::EXPR_ERROR;
+
+      if (checkPrecision(intermediate,
+			 sourceLen,
+                         sourceType,
+                         sourcePrecision,
+                         sourceScale,
+                         targetType,
+	                 targetPrecision,
+                         targetScale,
+                         heap,
+                         diagsArea,
+                         tempFlags) != ex_expr::EXPR_OK)
+        return ex_expr::EXPR_ERROR;
+      }
+ 
+    *(UInt64 *)target = intermediate;
+  };
+  break;
+
   case CONV_BIGNUM_DECU: 
   case CONV_BIGNUM_DECS: {
     if (dataConversionErrorFlag) {
@@ -11615,17 +11219,24 @@ convDoIt(char * source,
     break;
 
   case CONV_NOT_SUPPORTED:
+  default:
     {
-      // this conversion is not supported.
-      ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_NOT_SUPPORTED);
+    ExRaiseDetailSqlError(heap, diagsArea, EXE_CONVERT_NOT_SUPPORTED,
+                          source,
+                          sourceLen,
+                          sourceType,
+                          sourceScale,
+                          targetType,
+                          0,
+                          targetLen,
+                          targetScale);
+    
+    // this conversion is not supported.
+    //      ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_NOT_SUPPORTED);
       return ex_expr::EXPR_ERROR;
     }
   break;
 
-  default: {
-      ExRaiseSqlError(heap, diagsArea, EXE_CONVERT_NOT_SUPPORTED);
-      return ex_expr::EXPR_ERROR;
-    };
   };
   return ex_expr::EXPR_OK;
 }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/exp/exp_fixup.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_fixup.cpp b/core/sql/exp/exp_fixup.cpp
index b90c7d8..417745f 100644
--- a/core/sql/exp/exp_fixup.cpp
+++ b/core/sql/exp/exp_fixup.cpp
@@ -650,7 +650,10 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_EQUAL, REC_BIN32_UNSIGNED, REC_BIN16_UNSIGNED, EQ_BIN32U_BIN16U},
       {ITM_EQUAL, REC_BIN32_UNSIGNED, REC_BIN32_UNSIGNED, EQ_BIN32U_BIN32U},    // Was BIN32S. Error? ANS
 
-      {ITM_EQUAL, REC_BIN64_SIGNED,   REC_BIN64_SIGNED,   EQ_BIN64S_BIN64S},
+      {ITM_EQUAL, REC_BIN64_SIGNED,   REC_BIN64_SIGNED,     EQ_BIN64S_BIN64S},
+      {ITM_EQUAL, REC_BIN64_UNSIGNED, REC_BIN64_UNSIGNED,   EQ_BIN64U_BIN64U},
+      {ITM_EQUAL, REC_BIN64_SIGNED,   REC_BIN64_UNSIGNED,   EQ_BIN64S_BIN64U},
+      {ITM_EQUAL, REC_BIN64_UNSIGNED, REC_BIN64_SIGNED,     EQ_BIN64U_BIN64S},
 
       {ITM_EQUAL, REC_DECIMAL_UNSIGNED, REC_DECIMAL_UNSIGNED, EQ_DECU_DECU},
       {ITM_EQUAL, REC_DECIMAL_LSE,      REC_DECIMAL_LSE,      EQ_DECS_DECS},
@@ -709,6 +712,9 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_NOT_EQUAL, REC_BIN32_UNSIGNED, REC_BIN32_UNSIGNED, NE_BIN32U_BIN32U},  //Was 32S. Error? ANS
 
       {ITM_NOT_EQUAL, REC_BIN64_SIGNED,   REC_BIN64_SIGNED,   NE_BIN64S_BIN64S},
+      {ITM_NOT_EQUAL, REC_BIN64_UNSIGNED, REC_BIN64_UNSIGNED, NE_BIN64U_BIN64U},
+      {ITM_NOT_EQUAL, REC_BIN64_SIGNED,   REC_BIN64_UNSIGNED, NE_BIN64S_BIN64U},
+      {ITM_NOT_EQUAL, REC_BIN64_UNSIGNED, REC_BIN64_SIGNED,   NE_BIN64U_BIN64S},
 
       {ITM_NOT_EQUAL, REC_DECIMAL_UNSIGNED, REC_DECIMAL_UNSIGNED, NE_DECU_DECU},
       {ITM_NOT_EQUAL, REC_DECIMAL_LSE,      REC_DECIMAL_LSE,      NE_DECS_DECS},
@@ -765,6 +771,9 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_LESS, REC_BIN32_UNSIGNED, REC_BIN32_UNSIGNED, LT_BIN32U_BIN32U},   // Was 32S. Error? ANS
 
       {ITM_LESS, REC_BIN64_SIGNED,   REC_BIN64_SIGNED,   LT_BIN64S_BIN64S},
+      {ITM_LESS, REC_BIN64_UNSIGNED, REC_BIN64_UNSIGNED, LT_BIN64U_BIN64U},
+      {ITM_LESS, REC_BIN64_SIGNED,   REC_BIN64_UNSIGNED,   LT_BIN64S_BIN64U},
+      {ITM_LESS, REC_BIN64_UNSIGNED, REC_BIN64_SIGNED,     LT_BIN64U_BIN64S},
 
       {ITM_LESS, REC_DECIMAL_UNSIGNED, REC_DECIMAL_UNSIGNED, LT_DECU_DECU},
       {ITM_LESS, REC_DECIMAL_LSE,      REC_DECIMAL_LSE,      LT_DECS_DECS},
@@ -821,6 +830,9 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_LESS_EQ, REC_BIN32_UNSIGNED, REC_BIN32_UNSIGNED, LE_BIN32U_BIN32U},    // Was 32S. Error? ANS
 
       {ITM_LESS_EQ, REC_BIN64_SIGNED,   REC_BIN64_SIGNED,   LE_BIN64S_BIN64S},
+      {ITM_LESS_EQ, REC_BIN64_UNSIGNED, REC_BIN64_UNSIGNED, LE_BIN64U_BIN64U},
+      {ITM_LESS_EQ, REC_BIN64_SIGNED,   REC_BIN64_UNSIGNED,   LE_BIN64S_BIN64U},
+      {ITM_LESS_EQ, REC_BIN64_UNSIGNED, REC_BIN64_SIGNED,     LE_BIN64U_BIN64S},
 
       {ITM_LESS_EQ, REC_DECIMAL_UNSIGNED, REC_DECIMAL_UNSIGNED, LE_DECU_DECU},
       {ITM_LESS_EQ, REC_DECIMAL_LSE,      REC_DECIMAL_LSE,      LE_DECS_DECS},
@@ -877,6 +889,9 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_GREATER, REC_BIN32_UNSIGNED, REC_BIN32_UNSIGNED, GT_BIN32U_BIN32U},    // Was 32S. Error? ANS
 
       {ITM_GREATER, REC_BIN64_SIGNED,   REC_BIN64_SIGNED,   GT_BIN64S_BIN64S},
+      {ITM_GREATER, REC_BIN64_UNSIGNED, REC_BIN64_UNSIGNED, GT_BIN64U_BIN64U},
+      {ITM_GREATER, REC_BIN64_SIGNED,   REC_BIN64_UNSIGNED,   GT_BIN64S_BIN64U},
+      {ITM_GREATER, REC_BIN64_UNSIGNED, REC_BIN64_SIGNED,     GT_BIN64U_BIN64S},
 
       {ITM_GREATER, REC_DECIMAL_UNSIGNED, REC_DECIMAL_UNSIGNED, GT_DECU_DECU},
       {ITM_GREATER, REC_DECIMAL_LSE,      REC_DECIMAL_LSE,      GT_DECS_DECS},
@@ -933,6 +948,9 @@ const ex_comp_struct * ex_comp_clause::getMatchingRow(OperatorTypeEnum op,
       {ITM_GREATER_EQ, REC_BIN32_UNSIGNED, REC_BIN32_UNSIGNED, GE_BIN32U_BIN32U},   // Was 32S. Error? ANS
 
       {ITM_GREATER_EQ, REC_BIN64_SIGNED,   REC_BIN64_SIGNED,   GE_BIN64S_BIN64S},
+      {ITM_GREATER_EQ, REC_BIN64_UNSIGNED, REC_BIN64_UNSIGNED, GE_BIN64U_BIN64U},
+      {ITM_GREATER_EQ, REC_BIN64_SIGNED,   REC_BIN64_UNSIGNED,   GE_BIN64S_BIN64U},
+      {ITM_GREATER_EQ, REC_BIN64_UNSIGNED, REC_BIN64_SIGNED,     GE_BIN64U_BIN64S},
 
       {ITM_GREATER_EQ, REC_DECIMAL_UNSIGNED, REC_DECIMAL_UNSIGNED, GE_DECU_DECU},
       {ITM_GREATER_EQ, REC_DECIMAL_LSE,      REC_DECIMAL_LSE,      GE_DECS_DECS},
@@ -1148,7 +1166,6 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     {REC_BIN16_SIGNED,  REC_BIN32_SIGNED,           CONV_BIN16S_BIN32S},
     {REC_BIN16_SIGNED,  REC_BIN32_UNSIGNED,         CONV_BIN16S_BIN32U},
     {REC_BIN16_SIGNED,  REC_BIN64_SIGNED,           CONV_BIN16S_BIN64S},
-    {REC_BIN16_SIGNED,  REC_BIN64_UNSIGNED,         CONV_BIN16S_BIN64U},
     {REC_BIN16_SIGNED,  REC_DECIMAL_LSE,            CONV_BIN16S_DECS},
     {REC_BIN16_SIGNED,  REC_DECIMAL_UNSIGNED,       CONV_BIN16S_DECU},
     {REC_BIN16_SIGNED,  REC_FLOAT32,                CONV_BIN16S_FLOAT32},
@@ -1170,7 +1187,6 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     {REC_BIN16_UNSIGNED,  REC_BIN32_SIGNED,           CONV_BIN16U_BIN32S},
     {REC_BIN16_UNSIGNED,  REC_BIN32_UNSIGNED,         CONV_BIN16U_BIN32U},
     {REC_BIN16_UNSIGNED,  REC_BIN64_SIGNED,           CONV_BIN16U_BIN64S},
-    {REC_BIN16_UNSIGNED,  REC_BIN64_UNSIGNED,         CONV_BIN16U_BIN64U},
     {REC_BIN16_UNSIGNED,  REC_DECIMAL_LSE,            CONV_BIN16U_DECS},
     {REC_BIN16_UNSIGNED,  REC_DECIMAL_UNSIGNED,       CONV_BIN16U_DECS},
     {REC_BIN16_UNSIGNED,  REC_FLOAT32,                CONV_BIN16U_FLOAT32},
@@ -1192,7 +1208,6 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     {REC_BIN32_SIGNED,   REC_BIN32_SIGNED,           CONV_BIN32S_BIN32S},
     {REC_BIN32_SIGNED,   REC_BIN32_UNSIGNED,         CONV_BIN32S_BIN32U},
     {REC_BIN32_SIGNED,   REC_BIN64_SIGNED,           CONV_BIN32S_BIN64S},
-    {REC_BIN32_SIGNED,   REC_BIN64_UNSIGNED,         CONV_BIN32S_BIN64U},
     {REC_BIN32_SIGNED,   REC_DECIMAL_LSE,            CONV_BIN32S_DECS},
     {REC_BIN32_SIGNED,   REC_DECIMAL_UNSIGNED,       CONV_BIN32S_DECU},
     {REC_BIN32_SIGNED,   REC_FLOAT32,                CONV_BIN32S_FLOAT32},
@@ -1211,7 +1226,6 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     {REC_BIN32_UNSIGNED,  REC_BIN32_SIGNED,           CONV_BIN32U_BIN32S},
     {REC_BIN32_UNSIGNED,  REC_BIN32_UNSIGNED,         CONV_BIN32U_BIN32U},
     {REC_BIN32_UNSIGNED,  REC_BIN64_SIGNED,           CONV_BIN32U_BIN64S},
-    {REC_BIN32_UNSIGNED,  REC_BIN64_UNSIGNED,         CONV_BIN32U_BIN64U},
     {REC_BIN32_UNSIGNED,  REC_DECIMAL_LSE,            CONV_BIN32U_DECS},
     {REC_BIN32_UNSIGNED,  REC_DECIMAL_UNSIGNED,       CONV_BIN32U_DECS},
     {REC_BIN32_UNSIGNED,  REC_FLOAT32,                CONV_BIN32U_FLOAT32},
@@ -1244,17 +1258,15 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     {REC_BIN64_SIGNED,   REC_NCHAR_V_UNICODE,        CONV_BIN64S_UNICODE},
     {REC_BIN64_SIGNED,   REC_DATETIME,               CONV_BIN64S_DATETIME},
 
-    {REC_BIN64_UNSIGNED,   REC_BIN16_SIGNED,           CONV_BIN64U_BIN16S},
-    {REC_BIN64_UNSIGNED,   REC_BIN16_UNSIGNED,         CONV_BIN64U_BIN16U},
-    {REC_BIN64_UNSIGNED,   REC_BIN32_SIGNED,           CONV_BIN64U_BIN32S},
-    {REC_BIN64_UNSIGNED,   REC_BIN32_UNSIGNED,         CONV_BIN64U_BIN32U},
     {REC_BIN64_UNSIGNED,   REC_BIN64_SIGNED,           CONV_BIN64U_BIN64S},
     {REC_BIN64_UNSIGNED,   REC_BIN64_UNSIGNED,         CONV_BIN64U_BIN64U},
+    {REC_BIN64_UNSIGNED,   REC_NUM_BIG_SIGNED,         CONV_BIN64U_BIGNUM},
+    {REC_BIN64_UNSIGNED,   REC_NUM_BIG_UNSIGNED,       CONV_BIN64U_BIGNUM},
     {REC_BIN64_UNSIGNED,   REC_FLOAT32,                CONV_BIN64U_FLOAT32},
     {REC_BIN64_UNSIGNED,   REC_FLOAT64,                CONV_BIN64U_FLOAT64},
     {REC_BIN64_UNSIGNED,   REC_BYTE_F_ASCII,           CONV_BIN64U_ASCII},
     {REC_BIN64_UNSIGNED,   REC_BYTE_V_ASCII,           CONV_BIN64U_ASCII},
-      
+
     {REC_DECIMAL_UNSIGNED,   REC_BPINT_UNSIGNED,         CONV_DECS_BIN32U},
     {REC_DECIMAL_UNSIGNED,   REC_BIN16_UNSIGNED,         CONV_DECS_BIN32U},
     {REC_DECIMAL_UNSIGNED,   REC_BIN16_SIGNED,           CONV_DECS_BIN32S},
@@ -1332,6 +1344,7 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     {REC_NUM_BIG_UNSIGNED, REC_BIN32_SIGNED,           CONV_BIGNUM_BIN32S},
     {REC_NUM_BIG_UNSIGNED, REC_BIN32_UNSIGNED,         CONV_BIGNUM_BIN32U},
     {REC_NUM_BIG_UNSIGNED, REC_BIN64_SIGNED,           CONV_BIGNUM_BIN64S},
+    {REC_NUM_BIG_UNSIGNED, REC_BIN64_UNSIGNED,         CONV_BIGNUM_BIN64U},
     {REC_NUM_BIG_UNSIGNED, REC_DECIMAL_LSE,            CONV_BIGNUM_DECS},
     {REC_NUM_BIG_UNSIGNED, REC_DECIMAL_UNSIGNED,       CONV_BIGNUM_DECU},
     {REC_NUM_BIG_UNSIGNED, REC_FLOAT32,                CONV_BIGNUM_FLOAT32},
@@ -1350,6 +1363,7 @@ conv_case_index ex_conv_clause::find_case_index(short sourceType, Lng32 sourceLe
     {REC_NUM_BIG_SIGNED, REC_BIN32_SIGNED,           CONV_BIGNUM_BIN32S},
     {REC_NUM_BIG_SIGNED, REC_BIN32_UNSIGNED,         CONV_BIGNUM_BIN32U},
     {REC_NUM_BIG_SIGNED, REC_BIN64_SIGNED,           CONV_BIGNUM_BIN64S},
+    {REC_NUM_BIG_SIGNED, REC_BIN64_UNSIGNED,         CONV_BIGNUM_BIN64U},
     {REC_NUM_BIG_SIGNED, REC_DECIMAL_LSE,            CONV_BIGNUM_DECS},
     {REC_NUM_BIG_SIGNED, REC_DECIMAL_UNSIGNED,       CONV_BIGNUM_DECU},
     {REC_NUM_BIG_SIGNED, REC_FLOAT32,                CONV_BIGNUM_FLOAT32},

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/generator/GenPreCode.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenPreCode.cpp b/core/sql/generator/GenPreCode.cpp
index 0c22802..c6e3c20 100644
--- a/core/sql/generator/GenPreCode.cpp
+++ b/core/sql/generator/GenPreCode.cpp
@@ -5610,18 +5610,6 @@ RelExpr * HbaseInsert::preCodeGen(Generator * generator,
 		} // lobinsert
 
 	      GenAssert(li, "must have a LobInsert node");
-#ifdef __ignore 
-	      LOBload * ll = new(generator->wHeap()) 
-		LOBload(li->child(0), li->getObj());
-	      ll->insertedTableObjectUID() = li->insertedTableObjectUID();
-	      ll->insertedTableSchemaName() = li->insertedTableSchemaName();
-
-	      ll->lobNum() = col->lobNum();
-	      ll->lobStorageType() = col->lobStorageType();
-	      ll->lobStorageLocation() = col->lobStorageLocation();
-	      ll->bindNode(generator->getBindWA());
-	      lobLoadExpr_.insert(ll->getValueId());
-#endif
 	    } // lob
 	}
     }
@@ -8305,13 +8293,15 @@ ItemExpr * BiRelat::preCodeGen(Generator * generator)
 
 
   // following is for simple types.
+  const NAType &type1B =
+    child(0)->castToItemExpr()->getValueId().getType();
+  const NAType &type2B =
+    child(1)->castToItemExpr()->getValueId().getType();
 
   SimpleType * attr_op1 = (SimpleType *)
-    (ExpGenerator::convertNATypeToAttributes(
-	 child(0)->getValueId().getType(), generator->wHeap()));
+    (ExpGenerator::convertNATypeToAttributes(type1B, generator->wHeap()));
   SimpleType * attr_op2 = (SimpleType *)
-    (ExpGenerator::convertNATypeToAttributes(
-	 child(1)->getValueId().getType(), generator->wHeap()));
+    (ExpGenerator::convertNATypeToAttributes(type2B, generator->wHeap()));
 
   ex_comp_clause temp_clause;
 
@@ -8319,6 +8309,68 @@ ItemExpr * BiRelat::preCodeGen(Generator * generator)
 			     attr_op1,
 			     attr_op2
 			     );
+
+  if ((temp_clause.get_case_index() == ex_comp_clause::COMP_NOT_SUPPORTED) &&
+      (type1B.getTypeQualifier() == NA_NUMERIC_TYPE) &&
+      (type2B.getTypeQualifier() == NA_NUMERIC_TYPE))
+    {
+      const NumericType &numOp1 = (NumericType&)type1B;
+      const NumericType &numOp2 = (NumericType&)type2B;
+
+      if ((numOp1.isExact() && numOp2.isExact()) &&
+          ((numOp1.getFSDatatype() == REC_BIN64_UNSIGNED) ||
+           (numOp2.getFSDatatype() == REC_BIN64_UNSIGNED)))
+        {
+          if (numOp1.getFSDatatype() == REC_BIN64_UNSIGNED)
+            {
+              // add a Cast node to convert op2 to sqllargeint.
+              ItemExpr * newOp2 =
+                new (generator->wHeap())
+                Cast(child(1),
+                     new (generator->wHeap())
+                     SQLLargeInt(numOp2.isSigned(),
+                                 numOp2.supportsSQLnull()));
+              
+              newOp2 = newOp2->bindNode(generator->getBindWA());
+              newOp2 = newOp2->preCodeGen(generator);
+              if (! newOp2)
+                return NULL;
+              
+              setChild(1, newOp2);
+
+              attr_op2 = (SimpleType *)
+                (ExpGenerator::convertNATypeToAttributes(
+                     newOp2->getValueId().getType(), generator->wHeap()));
+            }
+          else 
+           {
+              // add a Cast node to convert op1 to sqllargeint.
+              ItemExpr * newOp1 =
+                new (generator->wHeap())
+                Cast(child(0),
+                     new (generator->wHeap())
+                     SQLLargeInt(numOp1.isSigned(),
+                                 numOp1.supportsSQLnull()));
+              
+              newOp1 = newOp1->bindNode(generator->getBindWA());
+              newOp1 = newOp1->preCodeGen(generator);
+              if (! newOp1)
+                return NULL;
+              
+              setChild(0, newOp1);
+
+              attr_op1 = (SimpleType *)
+                (ExpGenerator::convertNATypeToAttributes(
+                     newOp1->getValueId().getType(), generator->wHeap()));
+           }
+
+          temp_clause.set_case_index(getOperatorType(),
+                                     attr_op1,
+                                     attr_op2
+                                     );
+        } // convert
+    }
+  
   if (temp_clause.get_case_index() != ex_comp_clause::COMP_NOT_SUPPORTED)
     {
       NABoolean doConstFolding = FALSE;
@@ -8361,7 +8413,7 @@ ItemExpr * BiRelat::preCodeGen(Generator * generator)
                                                        *type_op1,
                                                        *type_op2,
 						       generator->wHeap(),
-                                          &flags);
+                                                       &flags);
   CMPASSERT(result_type);
   if (result_type->getTypeQualifier() == NA_NUMERIC_TYPE)
     {
@@ -8634,23 +8686,19 @@ ItemExpr * Cast::preCodeGen(Generator * generator)
       srcFsType = child(0)->getValueId().getType().getFSDatatype();
     }
 
-  if ((srcNAType.getTypeName() == LiteralLargeInt) ||
-      (tgtNAType.getTypeName() == LiteralLargeInt))
-    {
-      Lng32 ij = 1;
-    }
- 
-  if (((srcNAType.getTypeName() == LiteralLargeInt) &&
-       (NOT srcNAType.expConvSupported(tgtNAType))) ||
-      ((tgtNAType.getTypeName() == LiteralLargeInt) &&
+  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(TRUE,
+             SQLLargeInt(numSrc.getScale(), 1,
+                         TRUE,
                          srcNAType.supportsSQLnull()));
       ((Cast*)newChild)->setFlags(getFlags());
       setSrcIsVarcharPtr(FALSE);
@@ -8934,8 +8982,6 @@ ItemExpr * Cast::preCodeGen(Generator * generator)
 	    // -----------  ------------   --------------------------
 	    // IEEE 32 bit            38        7
 	    // IEEE 64 bit           308       17
-	    // Tandem 32 bit          78        7
-	    // Tandem 64 bit          78       18
 
 	    if (sourceNumType->getFSDatatype() == REC_IEEE_FLOAT32)
 	      {

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/911f1d64/core/sql/optimizer/BindRelExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/BindRelExpr.cpp b/core/sql/optimizer/BindRelExpr.cpp
index 0be1d61..c82fb37 100644
--- a/core/sql/optimizer/BindRelExpr.cpp
+++ b/core/sql/optimizer/BindRelExpr.cpp
@@ -1010,21 +1010,21 @@ void castComputedColumnsToAnsiTypes(BindWA *bindWA,
     if (col->getValueId().getType().getTypeQualifier() == NA_ROWSET_TYPE) {
       return;
     }
-    const NAType &naType = col->getValueId().getType();
+    NAType *naType = &(NAType&)col->getValueId().getType();
     //
     // Note: the unsupported and DATETIME cases are mutually exclusive with the LARGEDEC case below.
     //
-    if (!naType.isSupportedType()) {
+    if (!naType->isSupportedType()) {
       // Unsupported types are displayed as strings of '#' to their display length
       ItemExpr *theRepeat =
         new (bindWA->wHeap()) Repeat(new (bindWA->wHeap()) SystemLiteral("#"),
                                        new (bindWA->wHeap()) SystemLiteral(
-                                         naType.getDisplayLength(
-                                           naType.getFSDatatype(),
-                                           0,
-                                           naType.getPrecision(),
-                                           naType.getScale(),
-                                           0)));
+                                            naType->getDisplayLength(
+                                                 naType->getFSDatatype(),
+                                                 0,
+                                                 naType->getPrecision(),
+                                                 naType->getScale(),
+                                                 0)));
       theRepeat = theRepeat->bindNode(bindWA);
       col->setValueId(theRepeat->getValueId());
       compExpr[i] = theRepeat->getValueId();
@@ -1033,8 +1033,8 @@ void castComputedColumnsToAnsiTypes(BindWA *bindWA,
              (NOT bindWA->inViewDefinition()) &&
              (NOT bindWA->inMVDefinition()) &&
              (NOT bindWA->inCTAS()) &&
-             (naType.getTypeQualifier()== NA_DATETIME_TYPE &&
-              ((const DatetimeType &)naType).getSubtype() == 
+             (naType->getTypeQualifier()== NA_DATETIME_TYPE &&
+              ((const DatetimeType *)naType)->getSubtype() == 
               DatetimeType::SUBTYPE_SQLDate) &&
              (! CmpCommon::context()->getSqlmxRegress()) &&
              (strcmp(ActiveSchemaDB()->getDefaults().getValue(OUTPUT_DATE_FORMAT),
@@ -1048,26 +1048,50 @@ void castComputedColumnsToAnsiTypes(BindWA *bindWA,
         compExpr[i] = newChild->getValueId();
       }
 
-    // if ON, return tinyint as smallint.
+    if ((naType->getFSDatatype() == REC_BIN64_UNSIGNED) &&
+        (CmpCommon::getDefault(TRAF_LARGEINT_UNSIGNED_IO) == DF_OFF) &&
+        (NOT bindWA->inCTAS()))
+      {
+        NumericType *nTyp = (NumericType *)naType;
+        
+        ItemExpr * cast = new (bindWA->wHeap())
+          Cast(col->getValueId().getItemExpr(),
+               new (bindWA->wHeap())
+               SQLBigNum(MAX_HARDWARE_SUPPORTED_UNSIGNED_NUMERIC_PRECISION,
+                         nTyp->getScale(),
+                         FALSE,
+                         FALSE,
+                         naType->supportsSQLnull(),
+                         NULL));
+        
+        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
     // handle IO of tinyint datatypes.
-    if ((naType.getTypeName() == LiteralTinyInt) &&
+    if ((naType->getTypeName() == LiteralTinyInt) &&
         ((CmpCommon::getDefault(TRAF_TINYINT_SUPPORT) == DF_OFF) ||
          (CmpCommon::getDefault(TRAF_TINYINT_RETURN_VALUES) == DF_OFF)))
       {
         ItemExpr * cast = new (bindWA->wHeap())
           Cast(col->getValueId().getItemExpr(),
-               new (bindWA->wHeap()) SQLSmall(TRUE, naType.supportsSQLnull()));
+               new (bindWA->wHeap()) SQLSmall(TRUE, naType->supportsSQLnull()));
         cast = cast->bindNode(bindWA);
         if (bindWA->errStatus()) 
           return;
         col->setValueId(cast->getValueId());
         compExpr[i] = cast->getValueId();
       }
-    
-    else if (naType.getTypeQualifier() == NA_NUMERIC_TYPE && 
+    else if (naType->getTypeQualifier() == NA_NUMERIC_TYPE && 
              !((NumericType &)col->getValueId().getType()).binaryPrecision()) {
-      NumericType &nTyp = (NumericType &)col->getValueId().getType();
+      NumericType *nTyp = (NumericType *)naType;
       
       ItemExpr * ie = col->getValueId().getItemExpr();
       NAType *newTyp = NULL;
@@ -1082,8 +1106,8 @@ void castComputedColumnsToAnsiTypes(BindWA *bindWA,
         bignumIO = FALSE; // explicitely set to OFF
       else if (CmpCommon::getDefault(BIGNUM_IO) == DF_SYSTEM)
         {
-          if ((((NumericType &)col->getValueId().getType()).isBigNum()) &&
-              (((SQLBigNum &)col->getValueId().getType()).isARealBigNum()))
+          if ((nTyp->isBigNum()) &&
+              (((SQLBigNum*)nTyp)->isARealBigNum()))
             bignumIO = TRUE;
         }
 
@@ -1092,14 +1116,14 @@ void castComputedColumnsToAnsiTypes(BindWA *bindWA,
         bignumIO = FALSE;
 
       if (bignumIO)
-        bignumOflow = nTyp.getPrecision() - 
+        bignumOflow = nTyp->getPrecision() - 
           (Lng32)CmpCommon::getDefaultNumeric(MAX_NUMERIC_PRECISION_ALLOWED);
       else
         {
-          if (nTyp.isSigned())
-            oflow = nTyp.getPrecision() - MAX_HARDWARE_SUPPORTED_SIGNED_NUMERIC_PRECISION;
+          if (nTyp->isSigned())
+            oflow = nTyp->getPrecision() - MAX_HARDWARE_SUPPORTED_SIGNED_NUMERIC_PRECISION;
           else
-            oflow = nTyp.getPrecision() - MAX_HARDWARE_SUPPORTED_UNSIGNED_NUMERIC_PRECISION;
+            oflow = nTyp->getPrecision() - MAX_HARDWARE_SUPPORTED_UNSIGNED_NUMERIC_PRECISION;
         }
 
       if ((bignumOflow > 0) || (oflow > 0))
@@ -1107,7 +1131,7 @@ void castComputedColumnsToAnsiTypes(BindWA *bindWA,
           if (bignumOflow > 0) {
             newPrec = 
               (Lng32)CmpCommon::getDefaultNumeric(MAX_NUMERIC_PRECISION_ALLOWED);
-            Lng32 orgMagnitude = nTyp.getPrecision() - nTyp.getScale();
+            Lng32 orgMagnitude = nTyp->getPrecision() - nTyp->getScale();
         
             // set the newScale
             // IF there is overflow in magnitude set the scale to 0.
@@ -1127,17 +1151,16 @@ void castComputedColumnsToAnsiTypes(BindWA *bindWA,
               SQLBigNum(newPrec,
                         newScale,
                         ((SQLBigNum &)col->getValueId().getType()).isARealBigNum(),
-                        nTyp.isSigned(),
-                        nTyp.supportsSQLnull(),
+                        nTyp->isSigned(),
+                        nTyp->supportsSQLnull(),
                         NULL);
           }
           else if (oflow > 0) {
             // If it's not a computed expr, but a column w/ a legal type, re-loop
             if (col->getValueId().getNAColumn(TRUE/*don't assert*/)) {
-              //CMPASSERT(!nTyp.isInternalType());
+              //CMPASSERT(!nTyp->isInternalType());
               //continue;
             }
-            CMPASSERT(nTyp.isInternalType());
             
             OperatorTypeEnum op = ie->origOpType();
             CMPASSERT(op != NO_OPERATOR_TYPE &&      // Init'd correctly?
@@ -1154,7 +1177,7 @@ void castComputedColumnsToAnsiTypes(BindWA *bindWA,
 
             // ANSI 6.5 SR 7 - 9:  aggregates must be exact if column is exact.
             newPrec  = MAX_NUMERIC_PRECISION;
-            Lng32 orgMagnitude = (nTyp.getMagnitude() + 9) / 10;
+            Lng32 orgMagnitude = (nTyp->getMagnitude() + 9) / 10;
             // set the newScale
             // IF there is overflow in magnitude set the scale to 0.
             // ELSE set the accomodate the magnitude part and truncate the scale
@@ -1198,14 +1221,14 @@ void castComputedColumnsToAnsiTypes(BindWA *bindWA,
             if (newScale == 0)
               newTyp = new (bindWA->wHeap())
                          SQLLargeInt(TRUE, // hardware only supports signed
-                                     nTyp.supportsSQLnull());
+                                     nTyp->supportsSQLnull());
             else
               newTyp = new (bindWA->wHeap())
                          SQLNumeric(sizeof(Int64),
                                     newPrec,
                                     newScale,
-                                    nTyp.isSigned(),
-                                    nTyp.supportsSQLnull());
+                                    nTyp->isSigned(),
+                                    nTyp->supportsSQLnull());
             
           } // overflow
           



Mime
View raw message