Github user zuyu commented on a diff in the pull request:

    https://github.com/apache/incubator-quickstep/pull/237#discussion_r112827934
  
    --- Diff: expressions/scalar/ScalarSharedExpression.cpp ---
    @@ -0,0 +1,141 @@
    +/**
    + * 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.
    + **/
    +
    +#include "expressions/scalar/ScalarSharedExpression.hpp"
    +
    +#include <string>
    +#include <utility>
    +#include <vector>
    +
    +#include "catalog/CatalogTypedefs.hpp"
    +#include "expressions/Expressions.pb.h"
    +#include "storage/ValueAccessor.hpp"
    +#include "types/TypedValue.hpp"
    +#include "types/containers/ColumnVector.hpp"
    +#include "utility/ColumnVectorCache.hpp"
    +
    +namespace quickstep {
    +
    +struct SubBlocksReference;
    +
    +ScalarSharedExpression::ScalarSharedExpression(const int share_id,
    +                                               Scalar *operand)
    +    : Scalar(operand->getType()),
    +      share_id_(share_id),
    +      operand_(operand) {
    +}
    +
    +serialization::Scalar ScalarSharedExpression::getProto() const {
    +  serialization::Scalar proto;
    +  proto.set_data_source(serialization::Scalar::SHARED_EXPRESSION);
    +  proto.SetExtension(serialization::ScalarSharedExpression::share_id, 
share_id_);
    +  proto.MutableExtension(serialization::ScalarSharedExpression::operand)
    +      ->CopyFrom(operand_->getProto());
    +
    +  return proto;
    +}
    +
    +Scalar* ScalarSharedExpression::clone() const {
    +  return new ScalarSharedExpression(share_id_, operand_->clone());
    +}
    +
    +TypedValue ScalarSharedExpression::getValueForSingleTuple(const 
ValueAccessor &accessor,
    +                                                          const tuple_id 
tuple) const {
    +  return operand_->getValueForSingleTuple(accessor, tuple);
    +}
    +
    +TypedValue ScalarSharedExpression::getValueForJoinedTuples(
    +    const ValueAccessor &left_accessor,
    +    const relation_id left_relation_id,
    +    const tuple_id left_tuple_id,
    +    const ValueAccessor &right_accessor,
    +    const relation_id right_relation_id,
    +    const tuple_id right_tuple_id) const {
    +  return operand_->getValueForJoinedTuples(left_accessor,
    +                                           left_relation_id,
    +                                           left_tuple_id,
    +                                           right_accessor,
    +                                           right_relation_id,
    +                                           right_tuple_id);
    +}
    +
    +ColumnVectorPtr ScalarSharedExpression::getAllValues(
    +    ValueAccessor *accessor,
    +    const SubBlocksReference *sub_blocks_ref,
    +    ColumnVectorCache *cv_cache) const {
    +  if (cv_cache == nullptr) {
    +    return operand_->getAllValues(accessor, sub_blocks_ref, cv_cache);
    +  } else {
    +    ColumnVectorPtr result;
    +    if (cv_cache->contains(share_id_)) {
    +      result = cv_cache->get(share_id_);
    +    } else {
    +      result = operand_->getAllValues(accessor, sub_blocks_ref, cv_cache);
    +      cv_cache->set(share_id_, result);
    +    }
    +    return result;
    +  }
    --- End diff --
    
    Suggest to change to
    
    ```
      if (cv_cache == nullptr) {
        return operand_->getAllValues(accessor, sub_blocks_ref, cv_cache);
      }
    
      ColumnVectorPtr result;
      if (cv_cache->contains(share_id_)) {
        result = cv_cache->get(share_id_);
      } else {
        result = operand_->getAllValues(accessor, sub_blocks_ref, cv_cache);
        cv_cache->set(share_id_, result);
      }
      return result;
    ```
    
    Ditto for `getAllValuesForJoin` below.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to