Skip to content

Commit

Permalink
#312 Fix handling of min value as token upper bound
Browse files Browse the repository at this point in the history
Summary:
In Cassandra using min token value (INT64_MIN) as an upper bound is specially interpreted to
include all token hashes (rather than none).
This behavior is used, for instance, by Presto when splitting the entire token range into
partitions.

Test Plan: jenkins, ql-query-test.cc

Reviewers: pritam.damania, robert

Reviewed By: robert

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D4911
  • Loading branch information
m-iancu committed May 31, 2018
1 parent ffb0f50 commit b6248d5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/yb/yql/cql/ql/exec/eval_where.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,24 @@ CHECKED_STATUS Executor::WhereClauseToPB(QLReadRequestPB *req,
req->set_hash_code(hash_code);
break;
case QL_OP_LESS_THAN:
if (hash_code > YBPartition::kMinHashCode) {
req->set_max_hash_code(hash_code - 1);
} else {
// Token hash smaller than min implies no results.
*no_results = true;
return Status::OK();
// Cassandra treats INT64_MIN upper bound as special case that includes everything (i.e. it
// adds no real restriction). So we skip (do nothing) in that case.
if (result.int64_value() != INT64_MIN) {
if (hash_code > YBPartition::kMinHashCode) {
req->set_max_hash_code(hash_code - 1);
} else {
// Token hash smaller than min implies no results.
*no_results = true;
return Status::OK();
}
}
break;
case QL_OP_LESS_THAN_EQUAL:
req->set_max_hash_code(hash_code);
// Cassandra treats INT64_MIN upper bound as special case that includes everything (i.e. it
// adds no real restriction). So we skip (do nothing) in that case.
if (result.int64_value() != INT64_MIN) {
req->set_max_hash_code(hash_code);
}
break;
case QL_OP_EQUAL:
req->set_hash_code(hash_code);
Expand Down
23 changes: 23 additions & 0 deletions src/yb/yql/cql/ql/test/ql-query-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,29 @@ TEST_F(TestQLQuery, TestScanWithBounds) {
Substitute(select_stmt_template, "<=", std::get<0>(rows[9]), ">", INT64_MAX), processor, rows,
0, 0);

//------------------------------------------------------------------------------------------------
// Testing Select with token range limits
//------------------------------------------------------------------------------------------------
// Entire range: [min, max].
TestSelectWithoutOrderBy(
Substitute(select_stmt_template, ">=", INT64_MIN, "<=", INT64_MAX), processor, rows, 0, 10);

// Entire range: [min, min] (upper bound min is treated as a special case in Cassandra).
TestSelectWithoutOrderBy(
Substitute(select_stmt_template, ">=", INT64_MIN, "<=", INT64_MIN), processor, rows, 0, 10);

// Entire range: [min, min). (upper bound min is treated as a special case in Cassandra).
TestSelectWithoutOrderBy(
Substitute(select_stmt_template, ">=", INT64_MIN, "<", INT64_MIN), processor, rows, 0, 10);

// Empty range: (max, max].
TestSelectWithoutOrderBy(
Substitute(select_stmt_template, ">", INT64_MAX, "<=", INT64_MAX), processor, rows, 0, 0);

// Empty range: (max, min] (max as strict lower bound already excludes all hashes).
TestSelectWithoutOrderBy(
Substitute(select_stmt_template, ">", INT64_MAX, "<=", INT64_MIN), processor, rows, 0, 0);

//------------------------------------------------------------------------------------------------
// Testing Select with exact partition key (equal condition with token)
//------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit b6248d5

Please sign in to comment.