YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/master/yql_vtable_iterator.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#include "yb/master/yql_vtable_iterator.h"
15
#include <iterator>
16
17
#include "yb/common/ql_expr.h"
18
#include "yb/common/ql_rowblock.h"
19
#include "yb/common/ql_value.h"
20
#include "yb/common/schema.h"
21
22
#include "yb/gutil/casts.h"
23
24
#include "yb/util/result.h"
25
26
namespace yb {
27
namespace master {
28
29
YQLVTableIterator::YQLVTableIterator(
30
    std::shared_ptr<QLRowBlock> vtable,
31
    const google::protobuf::RepeatedPtrField<QLExpressionPB>& hashed_column_values)
32
262k
    : vtable_(std::move(vtable)), hashed_column_values_(hashed_column_values) {
33
262k
  Advance(false /* increment */);
34
262k
}
35
36
2.35M
Status YQLVTableIterator::DoNextRow(const Schema& projection, QLTableRow* table_row) {
37
2.35M
  if (vtable_index_ >= vtable_->row_count()) {
38
0
    return STATUS(NotFound, "No more rows left!");
39
0
  }
40
41
  // TODO: return columns in projection only.
42
2.35M
  QLRow& row = vtable_->row(vtable_index_);
43
23.7M
  for (size_t i = 0; i < row.schema().num_columns(); 
i++21.4M
) {
44
21.4M
    table_row->AllocColumn(row.schema().column_id(i), down_cast<const QLValue&>(row.column(i)));
45
21.4M
  }
46
2.35M
  Advance(true /* increment */);
47
2.35M
  return Status::OK();
48
2.35M
}
49
50
0
void YQLVTableIterator::SkipRow() {
51
0
  if (vtable_index_ < vtable_->row_count()) {
52
0
    Advance(true /* increment */);
53
0
  }
54
0
}
55
56
2.61M
Result<bool> YQLVTableIterator::HasNext() const {
57
2.61M
  return vtable_index_ < vtable_->row_count();
58
2.61M
}
59
60
0
std::string YQLVTableIterator::ToString() const {
61
0
  return "YQLVTableIterator";
62
0
}
63
64
0
const Schema& YQLVTableIterator::schema() const {
65
0
  return vtable_->schema();
66
0
}
67
68
// Advances iterator to next valid row, filtering columns using hashed_column_values_.
69
2.61M
void YQLVTableIterator::Advance(bool increment) {
70
2.61M
  if (increment) {
71
2.35M
    ++vtable_index_;
72
2.35M
  }
73
2.61M
  int num_hashed_columns = hashed_column_values_.size();
74
2.61M
  if (num_hashed_columns == 0) {
75
2.42M
    return;
76
2.42M
  }
77
712k
  
while (190k
vtable_index_ < vtable_->row_count()) {
78
616k
    auto& row = vtable_->row(vtable_index_);
79
616k
    bool bad = false;
80
710k
    for (int idx = 0; idx != num_hashed_columns; 
++idx93.8k
) {
81
616k
      if (hashed_column_values_[idx].value() != row.column(idx)) {
82
522k
        bad = true;
83
522k
        break;
84
522k
      }
85
616k
    }
86
616k
    if (!bad) {
87
94.1k
      break;
88
94.1k
    }
89
522k
    ++vtable_index_;
90
522k
  }
91
190k
}
92
93
261k
YQLVTableIterator::~YQLVTableIterator() {
94
261k
}
95
96
262k
HybridTime YQLVTableIterator::RestartReadHt() {
97
262k
  return HybridTime::kInvalid;
98
262k
}
99
100
}  // namespace master
101
}  // namespace yb