quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zu...@apache.org
Subject incubator-quickstep git commit: Fix the bug with min/max aggregation.
Date Fri, 04 Aug 2017 21:23:12 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/master b1aab0096 -> 679257094


Fix the bug with min/max aggregation.


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

Branch: refs/heads/master
Commit: 67925709450be3ceef8a789c8054a446dc693a0a
Parents: b1aab00
Author: Jianqiao Zhu <jianqiao@cs.wisc.edu>
Authored: Wed Aug 2 15:47:30 2017 -0500
Committer: Jianqiao Zhu <jianqiao@cs.wisc.edu>
Committed: Fri Aug 4 16:12:15 2017 -0500

----------------------------------------------------------------------
 .../comparisons/LiteralComparators-inl.hpp      | 76 +++++++++++++++-----
 1 file changed, 60 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/67925709/types/operations/comparisons/LiteralComparators-inl.hpp
----------------------------------------------------------------------
diff --git a/types/operations/comparisons/LiteralComparators-inl.hpp b/types/operations/comparisons/LiteralComparators-inl.hpp
index fd59e2e..ad54d4e 100644
--- a/types/operations/comparisons/LiteralComparators-inl.hpp
+++ b/types/operations/comparisons/LiteralComparators-inl.hpp
@@ -543,7 +543,11 @@ TypedValue LiteralUncheckedComparator<ComparisonFunctor,
         const TypedValue &current,
         ValueAccessor *accessor,
         const attribute_id value_accessor_id) const {
-  const void *current_literal = current.isNull() ? nullptr : current.getDataPtr();
+  bool is_null = current.isNull();
+  LeftCppType current_literal;
+  if (!is_null) {
+    current_literal = current.getLiteral<LeftCppType>();
+  }
 
   InvokeOnValueAccessorMaybeTupleIdSequenceAdapter(
       accessor,
@@ -555,32 +559,72 @@ TypedValue LiteralUncheckedComparator<ComparisonFunctor,
       std::unique_ptr<const ColumnAccessor<left_nullable>>
           column_accessor(accessor->template getColumnAccessor<left_nullable>(value_accessor_id));
       DCHECK(column_accessor != nullptr);
-      while (accessor->next()) {
-        const void *va_value = column_accessor->getUntypedValue();
-        if (left_nullable && !va_value) {
-          continue;
+
+      // Locate the first non-null value.
+      if (is_null) {
+        const void *va_value = nullptr;
+        while (accessor->next()) {
+          va_value = column_accessor->getUntypedValue();
+          if (!left_nullable || va_value) {
+            break;
+          }
+        }
+        if (va_value != nullptr) {
+          is_null = false;
+          current_literal = *static_cast<const LeftCppType*>(va_value);
         }
-        if (!current_literal || this->compareDataPtrsHelper<true>(va_value, current_literal))
{
-          current_literal = va_value;
+      }
+
+      // Aggregate on the remaining values.
+      if (!accessor->iterationFinished()) {
+        DCHECK(!is_null);
+        while (accessor->next()) {
+          const void *va_value = column_accessor->getUntypedValue();
+          if (left_nullable && !va_value) {
+            continue;
+          }
+          if (this->compareDataPtrsHelper<true>(va_value, &current_literal))
{
+            current_literal = *static_cast<const LeftCppType*>(va_value);
+          }
         }
       }
     } else {
-      while (accessor->next()) {
-        const void *va_value = accessor->template getUntypedValue<left_nullable>(value_accessor_id);
-        if (left_nullable && !va_value) {
-          continue;
+      // Locate the first non-null value.
+      if (is_null) {
+        const void *va_value = nullptr;
+        while (accessor->next()) {
+          va_value = accessor->template getUntypedValue<left_nullable>(value_accessor_id);
+          if (!left_nullable || va_value) {
+            break;
+          }
+        }
+        if (va_value != nullptr) {
+          is_null = false;
+          current_literal = *static_cast<const LeftCppType*>(va_value);
         }
-        if (!current_literal || this->compareDataPtrsHelper<true>(va_value, current_literal))
{
-          current_literal = va_value;
+      }
+
+      // Aggregate on the remaining values.
+      if (!accessor->iterationFinished()) {
+        DCHECK(!is_null);
+        while (accessor->next()) {
+          const void *va_value =
+              accessor->template getUntypedValue<left_nullable>(value_accessor_id);
+          if (left_nullable && !va_value) {
+            continue;
+          }
+          if (this->compareDataPtrsHelper<true>(va_value, &current_literal))
{
+            current_literal = *static_cast<const LeftCppType*>(va_value);
+          }
         }
       }
     }
   });
 
-  if (current_literal) {
-    return TypedValue(*static_cast<const LeftCppType*>(current_literal));
-  } else {
+  if (is_null) {
     return TypedValue(current.getTypeID());
+  } else {
+    return TypedValue(current_literal);
   }
 }
 


Mime
View raw message