YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
259k
    : vtable_(std::move(vtable)), hashed_column_values_(hashed_column_values) {
33
259k
  Advance(false /* increment */);
34
259k
}
35
36
2.33M
Status YQLVTableIterator::DoNextRow(const Schema& projection, QLTableRow* table_row) {
37
2.33M
  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.33M
  QLRow& row = vtable_->row(vtable_index_);
43
23.7M
  for (size_t i = 0; i < row.schema().num_columns(); i++) {
44
21.4M
    table_row->AllocColumn(row.schema().column_id(i), down_cast<const QLValue&>(row.column(i)));
45
21.4M
  }
46
2.33M
  Advance(true /* increment */);
47
2.33M
  return Status::OK();
48
2.33M
}
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.59M
Result<bool> YQLVTableIterator::HasNext() const {
57
2.59M
  return vtable_index_ < vtable_->row_count();
58
2.59M
}
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.59M
void YQLVTableIterator::Advance(bool increment) {
70
2.59M
  if (increment) {
71
2.33M
    ++vtable_index_;
72
2.33M
  }
73
2.59M
  int num_hashed_columns = hashed_column_values_.size();
74
2.59M
  if (num_hashed_columns == 0) {
75
2.40M
    return;
76
2.40M
  }
77
695k
  while (vtable_index_ < vtable_->row_count()) {
78
599k
    auto& row = vtable_->row(vtable_index_);
79
599k
    bool bad = false;
80
692k
    for (int idx = 0; idx != num_hashed_columns; ++idx) {
81
599k
      if (hashed_column_values_[idx].value() != row.column(idx)) {
82
506k
        bad = true;
83
506k
        break;
84
506k
      }
85
599k
    }
86
599k
    if (!bad) {
87
92.9k
      break;
88
92.9k
    }
89
506k
    ++vtable_index_;
90
506k
  }
91
188k
}
92
93
259k
YQLVTableIterator::~YQLVTableIterator() {
94
259k
}
95
96
259k
HybridTime YQLVTableIterator::RestartReadHt() {
97
259k
  return HybridTime::kInvalid;
98
259k
}
99
100
}  // namespace master
101
}  // namespace yb