You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2016/03/29 00:22:54 UTC

incubator-kudu git commit: KUDU-379: fix LESS_EQUAL predicates on bool, float and double columns

Repository: incubator-kudu
Updated Branches:
  refs/heads/master c693d878f -> 1b768723f


KUDU-379: fix LESS_EQUAL predicates on bool, float and double columns

This commit adds missing implementation of IncrementCell for bool, float and
double columns, which fixes a TS crash when scanning with an inclusive
upper-bound predicate on these column types. A follow up commit will add tests
for predicates on all column types.

Change-Id: I46cc354b70effba51037f640358f4df5d1fc6657
Reviewed-on: http://gerrit.cloudera.org:8080/2647
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <to...@apache.org>


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

Branch: refs/heads/master
Commit: 1b768723f0c5342e3a1b981b8021e92dbf62a5c8
Parents: c693d87
Author: Dan Burkert <da...@cloudera.com>
Authored: Mon Mar 28 12:36:04 2016 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Mon Mar 28 22:22:44 2016 +0000

----------------------------------------------------------------------
 src/kudu/common/key_util.cc | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/1b768723/src/kudu/common/key_util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/key_util.cc b/src/kudu/common/key_util.cc
index 609aaf8..df45516 100644
--- a/src/kudu/common/key_util.cc
+++ b/src/kudu/common/key_util.cc
@@ -18,7 +18,9 @@
 #include "kudu/common/key_util.h"
 
 #include <boost/iterator/counting_iterator.hpp>
+#include <cmath>
 #include <iterator>
+#include <limits>
 #include <string>
 #include <tuple>
 #include <type_traits>
@@ -29,6 +31,8 @@
 #include "kudu/common/schema.h"
 #include "kudu/gutil/map-util.h"
 
+using std::nextafter;
+using std::numeric_limits;
 using std::string;
 using std::tuple;
 using std::unordered_map;
@@ -39,6 +43,18 @@ namespace key_util {
 
 namespace {
 
+bool IncrementBoolCell(void* cell_ptr) {
+  bool orig;
+  memcpy(&orig, cell_ptr, sizeof(bool));
+  if (!orig) {
+    bool inc = true;
+    memcpy(cell_ptr, &inc, sizeof(bool));
+    return true;
+  } else {
+    return false;
+  }
+}
+
 template<DataType type>
 bool IncrementIntCell(void* cell_ptr) {
   typedef DataTypeTraits<type> traits;
@@ -63,6 +79,18 @@ bool IncrementIntCell(void* cell_ptr) {
   return inc > orig;
 }
 
+template<DataType type>
+bool IncrementFloatingPointCell(void* cell_ptr) {
+  typedef DataTypeTraits<type> traits;
+  typedef typename traits::cpp_type cpp_type;
+
+  cpp_type orig;
+  memcpy(&orig, cell_ptr, sizeof(cpp_type));
+  cpp_type inc = nextafter(orig, numeric_limits<cpp_type>::infinity());
+  memcpy(cell_ptr, &inc, sizeof(cpp_type));
+  return inc != orig;
+}
+
 bool IncrementStringCell(void* cell_ptr, Arena* arena) {
   Slice orig;
   memcpy(&orig, cell_ptr, sizeof(orig));
@@ -212,6 +240,8 @@ bool IncrementPrimaryKey(ContiguousRow* row, Arena* arena) {
 bool IncrementCell(const ColumnSchema& col, void* cell_ptr, Arena* arena) {
   DataType type = col.type_info()->physical_type();
   switch (type) {
+    case BOOL:
+      return IncrementBoolCell(cell_ptr);
 #define HANDLE_TYPE(t) case t: return IncrementIntCell<t>(cell_ptr);
     HANDLE_TYPE(UINT8);
     HANDLE_TYPE(UINT16);
@@ -222,15 +252,15 @@ bool IncrementCell(const ColumnSchema& col, void* cell_ptr, Arena* arena) {
     HANDLE_TYPE(INT32);
     HANDLE_TYPE(TIMESTAMP);
     HANDLE_TYPE(INT64);
-    case UNKNOWN_DATA:
-    case BOOL:
     case FLOAT:
+      return IncrementFloatingPointCell<FLOAT>(cell_ptr);
     case DOUBLE:
-      LOG(FATAL) << "Unable to handle type " << type << " in row keys";
+      return IncrementFloatingPointCell<DOUBLE>(cell_ptr);
     case STRING:
     case BINARY:
       return IncrementStringCell(cell_ptr, arena);
-    default: CHECK(false) << "Unknown data type: " << type;
+    case UNKNOWN_DATA:
+    default: LOG(FATAL) << "Unknown data type: " << type;
   }
   return false; // unreachable
 #undef HANDLE_TYPE