quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jianq...@apache.org
Subject [09/10] incubator-quickstep git commit: Updates
Date Sat, 04 Feb 2017 03:28:03 GMT
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3bcb5c89/storage/PackedPayloadAggregationStateHashTable.hpp
----------------------------------------------------------------------
diff --git a/storage/PackedPayloadAggregationStateHashTable.hpp b/storage/PackedPayloadAggregationStateHashTable.hpp
index 8364bb4..85d4f8a 100644
--- a/storage/PackedPayloadAggregationStateHashTable.hpp
+++ b/storage/PackedPayloadAggregationStateHashTable.hpp
@@ -40,6 +40,7 @@
 #include "storage/StorageManager.hpp"
 #include "storage/TupleReference.hpp"
 #include "storage/ValueAccessor.hpp"
+#include "storage/ValueAccessorMultiplexer.hpp"
 #include "storage/ValueAccessorUtil.hpp"
 #include "threading/SpinMutex.hpp"
 #include "threading/SpinSharedMutex.hpp"
@@ -73,10 +74,9 @@ class PackedPayloadSeparateChainingAggregationStateHashTable
   void destroyPayload() override;
 
   bool upsertValueAccessor(
-      const std::vector<std::vector<attribute_id>> &argument_ids,
-      const std::vector<attribute_id> &key_attr_ids,
-      ValueAccessor *accessor,
-      ColumnVectorsValueAccessor *aux_accessor = nullptr) override;
+      const std::vector<std::vector<MultiSourceAttributeId>> &argument_ids,
+      const std::vector<MultiSourceAttributeId> &key_ids,
+      ValueAccessorMultiplexer *accessor_mux) override;
 
   inline block_id getBlobId() const {
     return blob_->getID();
@@ -142,12 +142,12 @@ class PackedPayloadSeparateChainingAggregationStateHashTable
       const std::vector<TypedValue> &key,
       const std::size_t variable_key_size);
 
-  template <bool has_aux_accessor>
+  template <bool use_two_accessors>
   inline bool upsertValueAccessorCompositeKeyInternal(
-      const std::vector<std::vector<attribute_id>> &argument_ids,
-      const std::vector<attribute_id> &key_attr_ids,
-      ValueAccessor *accessor,
-      ColumnVectorsValueAccessor *aux_accessor);
+      const std::vector<std::vector<MultiSourceAttributeId>> &argument_ids,
+      const std::vector<MultiSourceAttributeId> &key_ids,
+      ValueAccessor *base_accessor,
+      ColumnVectorsValueAccessor *derived_accessor);
 
   // Generate a hash for a composite key by hashing each component of 'key' and
   // mixing their bits with CombineHashes().
@@ -170,20 +170,24 @@ class PackedPayloadSeparateChainingAggregationStateHashTable
     return total_payload_size;
   }
 
-  // Assign '*key_vector' with the attribute values specified by 'key_attr_ids'
-  // at the current position of 'accessor'. If 'check_for_null_keys' is true,
-  // stops and returns true if any of the values is null, otherwise returns
-  // false.
-  template <typename ValueAccessorT>
+  // Assign '*key_vector' with the attribute values specified by 'key_ids' at
+  // the current position of 'accessor'. If 'check_for_null_keys' is true, stops
+  // and returns true if any of the values is null, otherwise returns false.
+  template <bool use_two_accessors,
+            bool check_for_null_keys,
+            typename ValueAccessorT>
   inline static bool GetCompositeKeyFromValueAccessor(
-      const ValueAccessorT &accessor,
-      const std::vector<attribute_id> &key_attr_ids,
-      const bool check_for_null_keys,
+      const std::vector<MultiSourceAttributeId> &key_ids,
+      const ValueAccessorT *accessor,
+      const ColumnVectorsValueAccessor *derived_accessor,
       std::vector<TypedValue> *key_vector) {
-    for (std::vector<attribute_id>::size_type key_idx = 0;
-         key_idx < key_attr_ids.size();
-         ++key_idx) {
-      (*key_vector)[key_idx] = accessor.getTypedValue(key_attr_ids[key_idx]);
+    for (std::size_t key_idx = 0; key_idx < key_ids.size(); ++key_idx) {
+      const MultiSourceAttributeId &key_id = key_ids[key_idx];
+      if (use_two_accessors && key_id.source == ValueAccessorSource::kDerived) {
+        (*key_vector)[key_idx] = derived_accessor->getTypedValue(key_id.attr_id);
+      } else {
+        (*key_vector)[key_idx] = accessor->getTypedValue(key_id.attr_id);
+      }
       if (check_for_null_keys && (*key_vector)[key_idx].isNull()) {
         return true;
       }
@@ -623,22 +627,19 @@ inline std::uint8_t* PackedPayloadSeparateChainingAggregationStateHashTable
   return value;
 }
 
-template <bool has_aux_accessor>
+template <bool use_two_accessors>
 inline bool PackedPayloadSeparateChainingAggregationStateHashTable
     ::upsertValueAccessorCompositeKeyInternal(
-        const std::vector<std::vector<attribute_id>> &argument_ids,
-        const std::vector<attribute_id> &key_attr_ids,
-        ValueAccessor *accessor,
-        ColumnVectorsValueAccessor *aux_accessor) {
+        const std::vector<std::vector<MultiSourceAttributeId>> &argument_ids,
+        const std::vector<MultiSourceAttributeId> &key_ids,
+        ValueAccessor *base_accessor,
+        ColumnVectorsValueAccessor *derived_accessor) {
   std::size_t variable_size;
   std::vector<TypedValue> key_vector;
-  key_vector.resize(key_attr_ids.size());
-
-  // TODO(jianqiao): determine this bool value
-  const bool check_for_null_keys = true;
+  key_vector.resize(key_ids.size());
 
   return InvokeOnAnyValueAccessor(
-      accessor,
+      base_accessor,
       [&](auto *accessor) -> bool {  // NOLINT(build/c++11)
     bool continuing = true;
     while (continuing) {
@@ -646,14 +647,14 @@ inline bool PackedPayloadSeparateChainingAggregationStateHashTable
         continuing = false;
         SpinSharedMutexSharedLock<true> lock(resize_shared_mutex_);
         while (accessor->next()) {
-          if (has_aux_accessor) {
-            aux_accessor->next();
+          if (use_two_accessors) {
+            derived_accessor->next();
           }
-          // TODO(jianqiao): templatize to involve aux_accessor
-          if (this->GetCompositeKeyFromValueAccessor(*accessor,
-                                                     key_attr_ids,
-                                                     check_for_null_keys,
-                                                     &key_vector)) {
+          if (this->GetCompositeKeyFromValueAccessor<use_two_accessors, true>(
+                  key_ids,
+                  accessor,
+                  derived_accessor,
+                  &key_vector)) {
             continue;
           }
           variable_size = this->calculateVariableLengthCompositeKeyCopySize(key_vector);
@@ -667,16 +668,15 @@ inline bool PackedPayloadSeparateChainingAggregationStateHashTable
             for (unsigned int k = 0; k < num_handles_; ++k) {
               const auto &ids = argument_ids[k];
               if (ids.empty()) {
-                handles_[k]->updateStateNullary(
-                    value + payload_offsets_[k]);
+                handles_[k]->updateStateNullary(value + payload_offsets_[k]);
               } else {
-                const attribute_id argument_id = ids.front();
-                if (has_aux_accessor && argument_id < 0) {
-                  DCHECK_NE(argument_id, kInvalidAttributeID);
-                  handles_[k]->updateStateUnary(aux_accessor->getTypedValue(-(argument_id+2)),
+                const MultiSourceAttributeId &arg_id = ids.front();
+                if (use_two_accessors && arg_id.source == ValueAccessorSource::kDerived)
{
+                  DCHECK_NE(arg_id.attr_id, kInvalidAttributeID);
+                  handles_[k]->updateStateUnary(derived_accessor->getTypedValue(arg_id.attr_id),
                                                 value + payload_offsets_[k]);
                 } else {
-                  handles_[k]->updateStateUnary(accessor->getTypedValue(argument_id),
+                  handles_[k]->updateStateUnary(accessor->getTypedValue(arg_id.attr_id),
                                                 value + payload_offsets_[k]);
                 }
               }
@@ -687,8 +687,8 @@ inline bool PackedPayloadSeparateChainingAggregationStateHashTable
       if (continuing) {
         this->resize(0, variable_size);
         accessor->previous();
-        if (has_aux_accessor) {
-          aux_accessor->previous();
+        if (use_two_accessors) {
+          derived_accessor->previous();
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3bcb5c89/storage/ValueAccessorMultiplexer.hpp
----------------------------------------------------------------------
diff --git a/storage/ValueAccessorMultiplexer.hpp b/storage/ValueAccessorMultiplexer.hpp
new file mode 100644
index 0000000..0ed6175
--- /dev/null
+++ b/storage/ValueAccessorMultiplexer.hpp
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ **/
+
+#ifndef QUICKSTEP_STORAGE_VALUE_ACCESSOR_MULTIPLEXER_HPP_
+#define QUICKSTEP_STORAGE_VALUE_ACCESSOR_MULTIPLEXER_HPP_
+
+#include <cstddef>
+
+#include "catalog/CatalogTypedefs.hpp"
+#include "utility/Macros.hpp"
+
+namespace quickstep {
+
+class ValueAccessor;
+
+/** \addtogroup Utility
+ *  @{
+ */
+
+enum class ValueAccessorSource {
+  kBase = 0,
+  kDerived,
+  kInvalid
+};
+
+struct MultiSourceAttributeId {
+  MultiSourceAttributeId(const ValueAccessorSource in_source,
+                         const attribute_id in_attr_id)
+      : source(in_source),
+        attr_id(in_attr_id) {}
+
+  MultiSourceAttributeId(const MultiSourceAttributeId &other)
+      : source(other.source),
+        attr_id(other.attr_id) {}
+
+  const ValueAccessorSource source;
+  const attribute_id attr_id;
+};
+
+class ValueAccessorMultiplexer {
+ public:
+  ValueAccessorMultiplexer(ValueAccessor *base_accessor,
+                           ValueAccessor *derived_accessor)
+      : base_accessor_(base_accessor),
+        derived_accessor_(derived_accessor) {}
+
+  inline ValueAccessor* getBaseAccessor() const {
+    return base_accessor_;
+  }
+
+  inline ValueAccessor* getDerivedAccessor() const {
+    return derived_accessor_;
+  }
+
+  inline ValueAccessor* getValueAccessorBySource(
+      const ValueAccessorSource &source) const {
+    switch (source) {
+      case ValueAccessorSource::kBase:
+        return base_accessor_;
+      case ValueAccessorSource::kDerived:
+        return derived_accessor_;
+      default:
+        return nullptr;
+    }
+  }
+
+ private:
+  ValueAccessor *base_accessor_;
+  ValueAccessor *derived_accessor_;
+
+  DISALLOW_COPY_AND_ASSIGN(ValueAccessorMultiplexer);
+};
+
+/** @} */
+
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_STORAGE_VALUE_ACCESSOR_MULTIPLEXER_HPP_


Mime
View raw message