trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hzel...@apache.org
Subject [6/7] incubator-trafodion git commit: [TRAFODION-2382] rework from git review
Date Fri, 23 Dec 2016 19:18:29 GMT
[TRAFODION-2382] rework from git review

Fixed issues pointed out during the review and also searched the
code for related issues (which existed). Fixed another problem,
that interval data types don't use 1 byte integers, unlike
numerics.


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

Branch: refs/heads/master
Commit: acd08ef84597a132cfd68f7ca0ebdd5544bd4559
Parents: 5097291
Author: Hans Zeller <hzeller@apache.org>
Authored: Thu Dec 22 19:58:52 2016 +0000
Committer: Hans Zeller <hzeller@apache.org>
Committed: Thu Dec 22 19:58:52 2016 +0000

----------------------------------------------------------------------
 core/sql/generator/LmExpr.cpp                   |  3 +-
 core/sql/optimizer/RelRoutine.cpp               |  2 +-
 core/sql/sqludr/sqludr.cpp                      | 43 ++++++++++++++------
 .../java/org/trafodion/sql/udr/TupleInfo.java   | 35 ++++++++++------
 .../java/org/trafodion/sql/udr/TypeInfo.java    |  3 ++
 5 files changed, 59 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/acd08ef8/core/sql/generator/LmExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/LmExpr.cpp b/core/sql/generator/LmExpr.cpp
index 9267841..7280008 100644
--- a/core/sql/generator/LmExpr.cpp
+++ b/core/sql/generator/LmExpr.cpp
@@ -362,11 +362,12 @@ LmExprResult CreateLmOutputExpr(const NAType &formalType,
 // specified type t to be converted to/from C strings. The only 
 // SQL types that do not need to be converted to C strings are:
 // 
-//  INT, SMALLINT, LARGEINT, FLOAT, REAL, DOUBLE PRECISION, BOOLEAN
+//  INT, TINYINT, SMALLINT, LARGEINT, FLOAT, REAL, DOUBLE PRECISION, BOOLEAN
 //
 // because these types map to Java primitive types:
 //
 //  INT -> int
+//  TINYINT -> byte
 //  SMALLINT -> short
 //  LARGEINT -> long
 //  FLOAT -> float or double

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/acd08ef8/core/sql/optimizer/RelRoutine.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/RelRoutine.cpp b/core/sql/optimizer/RelRoutine.cpp
index df415cd..4146b5f 100644
--- a/core/sql/optimizer/RelRoutine.cpp
+++ b/core/sql/optimizer/RelRoutine.cpp
@@ -1044,7 +1044,7 @@ PredefinedTableMappingFunction::~PredefinedTableMappingFunction()
 
 // static method to find out whether a given name is a
 // built-in table-mapping function - returns operator type
-// of predefined function if so, REL_TABLE_MAPPING_UDF otherwise
+// of predefined function if so, REL_ANY_TABLE_MAPPING_UDF otherwise
 OperatorTypeEnum PredefinedTableMappingFunction::nameIsAPredefinedTMF(const CorrName &name)
 {
   // Predefined functions don't reside in a schema, they are referenced with an unqualified
name

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/acd08ef8/core/sql/sqludr/sqludr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqludr/sqludr.cpp b/core/sql/sqludr/sqludr.cpp
index 91dedc9..19bb262 100644
--- a/core/sql/sqludr/sqludr.cpp
+++ b/core/sql/sqludr/sqludr.cpp
@@ -840,8 +840,9 @@ TypeInfo::TypeInfo(SQLTypeCode sqlType,
                38900,
                "TypeInfo::TypeInfo(): Scale (fraction precision) should not be specified
for a type when end field is not SECOND");
 
-        // convert decimal to binary precision
-        d_.length_ = convertToBinaryPrecision(totalPrecision);
+        // convert decimal to binary precision, but intervals don't
+        // use single byte representation (yet?)
+        d_.length_ = MAXOF(2,convertToBinaryPrecision(totalPrecision));
       }
       break;
 
@@ -1235,7 +1236,7 @@ long TypeInfo::getLong(const char *row, bool &wasNull) const
           tempSQLType = TINYINT_UNSIGNED;
         else
           tempSQLType = TINYINT;
-      if (d_.length_ == 2)
+      else if (d_.length_ == 2)
         if (d_.sqlType_ == NUMERIC_UNSIGNED)
           tempSQLType = SMALLINT_UNSIGNED;
         else
@@ -1724,7 +1725,7 @@ void TypeInfo::setLong(long val, char *row) const
           tempSQLType = TINYINT_UNSIGNED;
         else
           tempSQLType = TINYINT;
-      if (d_.length_ == 2)
+      else if (d_.length_ == 2)
         if (d_.sqlType_ == NUMERIC_UNSIGNED)
           tempSQLType = SMALLINT_UNSIGNED;
         else
@@ -1742,14 +1743,29 @@ void TypeInfo::setLong(long val, char *row) const
   switch (tempSQLType)
     {
     case TINYINT:
+      if (val < SCHAR_MIN || val > SCHAR_MAX)
+        throw UDRException(
+             38900,
+             "Overflow/underflow when assigning %ld to TINYINT type",
+             val);
       *((char *) data) = val;
       break;
 
     case SMALLINT:
+      if (val < SHRT_MIN || val > SHRT_MAX)
+        throw UDRException(
+             38900,
+             "Overflow/underflow when assigning %ld to SMALLINT type",
+             val);
       *((short *) data) = val;
       break;
 
     case INT:
+      if (val < INT_MIN || val > INT_MAX)
+        throw UDRException(
+             38900,
+             "Overflow/underflow when assigning %ld to INTEGER type",
+             val);
       *((int *) data) = val;
       break;
 
@@ -1758,27 +1774,30 @@ void TypeInfo::setLong(long val, char *row) const
       break;
 
     case TINYINT_UNSIGNED:
-      if (val < 0)
+      if (val < 0 || val > UCHAR_MAX)
         throw UDRException(
              38900,
-             "Trying to assign a negative value to a TINYINT UNSIGNED type");
+             "Overflow/underflow when assigning %ld to TINYINT UNSIGNED type",
+             val);
       *((unsigned char *) data) = val;
       break;
 
     case SMALLINT_UNSIGNED:
-      if (val < 0)
+      if (val < 0 || val > USHRT_MAX)
         throw UDRException(
              38900,
-             "Trying to assign a negative value to a SMALLINT UNSIGNED type");
+             "Overflow/underflow when assigning %ld to SMALLINT UNSIGNED type",
+             val);
       *((unsigned short *) data) = val;
       break;
 
     case INT_UNSIGNED:
-      if (val < 0)
+      if (val < 0 || val > UINT_MAX)
         throw UDRException(
              38900,
-             "Trying to assign a negative value to an INT UNSIGNED type");
-      *((int *) data) = val;
+             "Overflow/underflow when assigning %ld to INTEGER UNSIGNED type",
+             val);
+      *((unsigned int *) data) = val;
       break;
 
     case DECIMAL_LSE:
@@ -1859,7 +1878,7 @@ void TypeInfo::setLong(long val, char *row) const
         if (val > maxvals[d_.precision_-1])
           throw UDRException(
                38900,
-               "Overflow occurred while converting value %ld to a DECIMAL(%d, %d)",
+               "Overflow/underflow occurred while converting value %ld to a DECIMAL(%d, %d)",
                val, d_.precision_, d_.scale_);
 
         if (d_.scale_ == 0)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/acd08ef8/core/sql/src/main/java/org/trafodion/sql/udr/TupleInfo.java
----------------------------------------------------------------------
diff --git a/core/sql/src/main/java/org/trafodion/sql/udr/TupleInfo.java b/core/sql/src/main/java/org/trafodion/sql/udr/TupleInfo.java
index 2b1ffad..f2d9b78 100644
--- a/core/sql/src/main/java/org/trafodion/sql/udr/TupleInfo.java
+++ b/core/sql/src/main/java/org/trafodion/sql/udr/TupleInfo.java
@@ -681,7 +681,7 @@ public class TupleInfo extends TMUDRSerializableObject {
      *
      *  @param colNum Column number.
      *  @return Boolean value.
-     *          If the value was a NULL value, an empty string
+     *          If the value was a NULL value, false
      *          is returned. The wasNull() method can be used to
      *          determine whether a NULL value was returned.
      *  @throws UDRException
@@ -1198,14 +1198,14 @@ public class TupleInfo extends TMUDRSerializableObject {
                 throw new UDRException(
                                        38900,
                                        "Overflow/Underflow when assigning %d to BOOLEAN type",
-                                       (int) val);
+                                       val);
             // fall through to next case
         case TINYINT:
             if (val > Byte.MAX_VALUE || val < Byte.MIN_VALUE)
                 throw new UDRException(
                                        38900,
                                        "Overflow/Underflow when assigning %d to TINYINT type",
-                                       (int) val);
+                                       val);
             row_.put(t.getDataOffset(), (byte) val);
             break;
             
@@ -1214,7 +1214,7 @@ public class TupleInfo extends TMUDRSerializableObject {
                 throw new UDRException(
                                        38900,
                                        "Overflow/Underflow when assigning %d to SMALLINT
type",
-                                       (int) val);
+                                       val);
             row_.putShort(t.getDataOffset(), (short) val);
             break;
             
@@ -1222,7 +1222,8 @@ public class TupleInfo extends TMUDRSerializableObject {
             if (val > Integer.MAX_VALUE || val < Integer.MIN_VALUE)
                 throw new UDRException(
                                        38900,
-                                       "Overflow/Underflow when assigining to INT type");
+                                       "Overflow/Underflow when assigining %d to INT type",
+                                       val);
             row_.putInt(t.getDataOffset(), (int) val);
             break;
 
@@ -1232,14 +1233,18 @@ public class TupleInfo extends TMUDRSerializableObject {
 
         case TINYINT_UNSIGNED:
             if (val < 0 || val > Byte.MAX_VALUE)
-                if (val > (2 * Byte.MAX_VALUE + 1))
+                if (val < 0 || val > (2 * Byte.MAX_VALUE + 1))
                     throw new UDRException(
                         38900,
-                        "Overflow/underflow when assigning to TINYINT UNSIGNED type");
+                        "Overflow/underflow when assigning %d to TINYINT UNSIGNED type",
+                        val);
                 else
-                    // use the signed value that has the same bit
+                    // Use the signed value that has the same bit
                     // pattern as the desired unsigned value, since
-                    // Java doesn't support "unsigned" basic types
+                    // Java doesn't support "unsigned" basic types.
+                    // Example: 255
+                    //   val = 255 + (-128) + (-128) = -1
+                    // that makes the bit pattern 0xFF
                     val = val + Byte.MIN_VALUE + Byte.MIN_VALUE;
 
             row_.put(t.getDataOffset(), (byte) val);
@@ -1247,14 +1252,16 @@ public class TupleInfo extends TMUDRSerializableObject {
 
         case SMALLINT_UNSIGNED:
             if (val < 0 || val > Short.MAX_VALUE)
-                if (val > (2 * Short.MAX_VALUE + 1))
+                if (val < 0 || val > (2 * Short.MAX_VALUE + 1))
                     throw new UDRException(
                         38900,
-                        "Overflow/underflow when assigning to SMALLINT UNSIGNED type");
+                        "Overflow/underflow when assigning %d to SMALLINT UNSIGNED type",
+                        val);
                 else
                     // use the signed value that has the same bit
                     // pattern as the desired unsigned value, since
                     // Java doesn't support "unsigned" basic types
+                    // see tinyint_unsigned above for an example
                     val = val  + Short.MIN_VALUE + Short.MIN_VALUE;
 
             row_.putShort(t.getDataOffset(), (short) val);
@@ -1262,14 +1269,16 @@ public class TupleInfo extends TMUDRSerializableObject {
 
         case INT_UNSIGNED:
             if (val < 0 || val > Integer.MAX_VALUE)
-                if (val > (2 * Integer.MAX_VALUE + 1))
+                if (val < 0 || val > (2 * Integer.MAX_VALUE + 1))
                     throw new UDRException(
                         38900,
-                        "Overflow/underflow when assigning to an INT UNSIGNED type");
+                        "Overflow/underflow when assigning %d to an INT UNSIGNED type",
+                        val);
                 else
                     // use the signed value that has the same bit
                     // pattern as the desired unsigned value, since
                     // Java doesn't support "unsigned" basic types
+                    // see tinyint_unsigned above for an example
                     val = val + Integer.MIN_VALUE + Integer.MIN_VALUE;
  
             row_.putInt(t.getDataOffset(), (int) val);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/acd08ef8/core/sql/src/main/java/org/trafodion/sql/udr/TypeInfo.java
----------------------------------------------------------------------
diff --git a/core/sql/src/main/java/org/trafodion/sql/udr/TypeInfo.java b/core/sql/src/main/java/org/trafodion/sql/udr/TypeInfo.java
index 1facfc7..f993075 100644
--- a/core/sql/src/main/java/org/trafodion/sql/udr/TypeInfo.java
+++ b/core/sql/src/main/java/org/trafodion/sql/udr/TypeInfo.java
@@ -488,6 +488,9 @@ public class TypeInfo extends TMUDRSerializableObject {
         
         // convert decimal to binary precision
         length_ = convertToBinaryPrecision(totalPrecision);
+        if (length_ == 1)
+            // intervals don't use single byte representation (yet?)
+            length_ = 2;
         }
         break;
 


Mime
View raw message