YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/tablet/tablet-pushdown-test.cc
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
//
18
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
33
#include <algorithm>
34
#include <limits>
35
#include <string>
36
#include <unordered_set>
37
#include <vector>
38
39
#include <glog/logging.h>
40
#include <gtest/gtest.h>
41
42
#include "yb/common/common_fwd.h"
43
#include "yb/common/ql_protocol_util.h"
44
#include "yb/common/ql_rowblock.h"
45
#include "yb/common/schema.h"
46
47
#include "yb/gutil/strings/numbers.h"
48
49
#include "yb/tablet/local_tablet_writer.h"
50
#include "yb/tablet/read_result.h"
51
#include "yb/tablet/tablet-test-util.h"
52
#include "yb/tablet/tablet.h"
53
54
#include "yb/util/status_log.h"
55
#include "yb/util/test_macros.h"
56
#include "yb/util/test_util.h"
57
58
namespace yb {
59
namespace tablet {
60
61
class TabletPushdownTest : public YBTabletTest {
62
 public:
63
  TabletPushdownTest()
64
    : YBTabletTest(Schema({ ColumnSchema("key", INT32, false, true),
65
                            ColumnSchema("int_val", INT32),
66
2
                            ColumnSchema("string_val", STRING) }, 1)) {
67
2
  }
68
69
2
  void SetUp() override {
70
2
    YBTabletTest::SetUp();
71
72
2
    FillTestTablet();
73
2
  }
74
75
2
  void FillTestTablet() {
76
2
    nrows_ = 2100;
77
2
    if (AllowSlowTests()) {
78
0
      nrows_ = 100000;
79
0
    }
80
81
2
    LocalTabletWriter writer(tablet().get());
82
2
    QLWriteRequestPB req;
83
4.20k
    for (int i = 0; i < nrows_; i++) {
84
4.20k
      QLAddInt32HashValue(&req, i);
85
4.20k
      QLAddInt32ColumnValue(&req, kFirstColumnId + 1, i * 10);
86
4.20k
      QLAddStringColumnValue(&req, kFirstColumnId + 2, StringPrintf("%08d", i));
87
4.20k
      ASSERT_OK_FAST(writer.Write(&req));
88
4.20k
    }
89
2
  }
90
91
  // The predicates tested in the various test cases all yield
92
  // the same set of rows. Run the scan and verify that the
93
  // expected rows are returned.
94
2
  void TestScanYieldsExpectedResults(int column_id, int lower, int upper) {
95
2
    ReadHybridTime read_time = ReadHybridTime::SingleTime(CHECK_RESULT(tablet()->SafeTime()));
96
2
    QLReadRequestPB req;
97
2
    auto* condition = req.mutable_where_expr()->mutable_condition();
98
2
    condition->set_op(QLOperator::QL_OP_AND);
99
2
    QLAddInt32Condition(condition, column_id, QL_OP_GREATER_THAN_EQUAL, lower);
100
2
    QLAddInt32Condition(condition, column_id, QL_OP_LESS_THAN_EQUAL, upper);
101
2
    QLReadRequestResult result;
102
2
    TransactionMetadataPB transaction;
103
2
    QLAddColumns(schema_, {}, &req);
104
2
    EXPECT_OK(tablet()->HandleQLReadRequest(
105
2
        CoarseTimePoint::max() /* deadline */, read_time, req, transaction, &result));
106
107
4
    ASSERT_EQ(QLResponsePB::YQL_STATUS_OK, result.response.status())
108
4
        << "Error: " << result.response.error_message();
109
110
2
    auto row_block = CreateRowBlock(QLClient::YQL_CLIENT_CQL, schema_, result.rows_data);
111
2
    std::vector<std::string> results;
112
22
    for (const auto& row : row_block->rows()) {
113
22
      results.push_back(row.ToString());
114
22
    }
115
2
    std::sort(results.begin(), results.end());
116
22
    for (const string &str : results) {
117
22
      LOG(INFO) << str;
118
22
    }
119
2
    ASSERT_EQ(11, results.size());
120
2
    ASSERT_EQ("{ int32:200, int32:2000, string:\"00000200\" }", results[0]);
121
2
    ASSERT_EQ("{ int32:210, int32:2100, string:\"00000210\" }", results[10]);
122
2
  }
123
124
 private:
125
  int nrows_;
126
};
127
128
1
TEST_F(TabletPushdownTest, TestPushdownIntKeyRange) {
129
1
  TestScanYieldsExpectedResults(kFirstColumnId, 200, 210);
130
1
}
131
132
// TODO: Value range scan is not working yet, it returns 2100 rows.
133
1
TEST_F(TabletPushdownTest, TestPushdownIntValueRange) {
134
  // Push down a double-ended range on the integer value column.
135
1
  TestScanYieldsExpectedResults(kFirstColumnId + 1, 2000, 2100);
136
1
}
137
138
} // namespace tablet
139
} // namespace yb