lxy-9602 commented on code in PR #258:
URL: https://github.com/apache/paimon-cpp/pull/258#discussion_r3925071715
##########
test/inte/global_index_test.cpp:
##########
@@ -1504,6 +1507,97 @@ TEST_P(GlobalIndexTest, TestDataEvolutionBatchScan) {
}
}
+TEST_P(GlobalIndexTest, TestDataEvolutionGlobalIndexSnapshotSelection) {
+ CreateTable();
+ std::string table_path = PathUtil::JoinPath(dir_->Str(), "foo.db/bar");
+ auto schema = arrow::schema(fields_);
+ std::vector<std::string> write_cols = schema->field_names();
+ auto src_array =
arrow::ipc::internal::json::ArrayFromJSON(arrow::struct_(fields_), R"([
+["Alice", 10, 1, 11.1],
+["Bob", 20, 0, 12.1]
+ ])")
+ .ValueOrDie();
+
+ ASSERT_OK_AND_ASSIGN(auto commit_msgs, WriteArray(table_path, write_cols,
src_array));
+ ASSERT_OK(Commit(table_path, commit_msgs));
+ ASSERT_OK(WriteIndex(table_path, /*partition_filters=*/{}, "f0", "bitmap",
/*options=*/{},
+ Range(0, 1)));
+
+ auto predicate =
+ PredicateBuilder::Equal(/*field_index=*/0, /*field_name=*/"f0",
FieldType::STRING,
+ Literal(FieldType::STRING, "missing", 7));
+
+ ASSERT_OK_AND_ASSIGN(auto latest_plan, ScanGlobalIndexAndData(table_path,
predicate));
+ ASSERT_TRUE(latest_plan->Splits().empty());
+ ASSERT_EQ(latest_plan->SnapshotId(), std::optional<int64_t>(2));
+
+ const std::map<std::string, std::string> explicit_latest_options = {
+ {Options::SCAN_MODE, "latest"},
+ {Options::SCAN_SNAPSHOT_ID, "999"},
+ {Options::SCAN_TAG_NAME, "ignored"},
+ {Options::SCAN_TIMESTAMP_MILLIS, "0"}};
+ ASSERT_OK_AND_ASSIGN(auto explicit_latest_plan,
+ ScanGlobalIndexAndData(table_path, predicate,
explicit_latest_options));
+ ASSERT_TRUE(explicit_latest_plan->Splits().empty());
+ ASSERT_EQ(explicit_latest_plan->SnapshotId(), std::optional<int64_t>(2));
+
+ auto empty_index_result = BitmapGlobalIndexResult::FromRanges({});
+ ASSERT_OK_AND_ASSIGN(auto supplied_latest_plan,
+ ScanGlobalIndexAndData(table_path,
/*predicate=*/nullptr,
+ explicit_latest_options,
empty_index_result));
+ ASSERT_TRUE(supplied_latest_plan->Splits().empty());
+ ASSERT_FALSE(supplied_latest_plan->SnapshotId());
+
+ ASSERT_OK_AND_ASSIGN(auto supplied_explicit_plan,
+ ScanGlobalIndexAndData(table_path,
/*predicate=*/nullptr,
+ {{Options::SCAN_SNAPSHOT_ID,
"1"},
+ {Options::SCAN_TAG_NAME,
"ignored"},
+
{Options::SCAN_TIMESTAMP_MILLIS, "0"}},
+ empty_index_result));
+ ASSERT_TRUE(supplied_explicit_plan->Splits().empty());
+ ASSERT_FALSE(supplied_explicit_plan->SnapshotId());
+
+ ASSERT_NOK_WITH_MSG(
+ ScanGlobalIndexAndData(table_path, predicate, {{Options::SCAN_MODE,
"from-snapshot"}}),
+ "scan.snapshot-id or scan.tag-name must be set when startup mode is
FROM_SNAPSHOT");
+
+ std::vector<std::map<std::string, std::string>> time_travel_options = {
+ {{Options::SCAN_TAG_NAME, "tag"}},
+ {{Options::SCAN_TIMESTAMP_MILLIS,
std::to_string(std::numeric_limits<int64_t>::max())}}};
+ for (const auto& options : time_travel_options) {
+ Result<std::shared_ptr<Plan>> result =
+ ScanGlobalIndexAndData(table_path, predicate, options);
+ ASSERT_TRUE(result.status().IsNotImplemented()) <<
result.status().ToString();
+
+ ASSERT_OK_AND_ASSIGN(
+ std::shared_ptr<Plan> supplied_plan,
+ ScanGlobalIndexAndData(table_path, /*predicate=*/nullptr, options,
empty_index_result));
+ ASSERT_TRUE(supplied_plan->Splits().empty());
+ ASSERT_FALSE(supplied_plan->SnapshotId());
+ }
+
+ auto unindexed_predicate = PredicateBuilder::Equal(/*field_index=*/3,
/*field_name=*/"f3",
+ FieldType::DOUBLE,
Literal(99.9));
+ Result<std::shared_ptr<Plan>> unindexed_time_travel_result =
+ ScanGlobalIndexAndData(table_path, unindexed_predicate,
time_travel_options.back());
+ ASSERT_TRUE(unindexed_time_travel_result.status().IsNotImplemented())
+ << unindexed_time_travel_result.status().ToString();
+
+ ASSERT_OK_AND_ASSIGN(
+ std::shared_ptr<Plan> no_index_plan,
+ ScanGlobalIndexAndData(table_path, /*predicate=*/nullptr,
time_travel_options.back()));
+ ASSERT_EQ(no_index_plan->SnapshotId(), std::optional<int64_t>(2));
+
+ ASSERT_OK_AND_ASSIGN(
+ std::shared_ptr<Plan> supplied_nonexistent_snapshot_plan,
+ ScanGlobalIndexAndData(table_path, /*predicate=*/nullptr,
+ {{Options::SCAN_SNAPSHOT_ID, "999"}},
empty_index_result));
+ ASSERT_TRUE(supplied_nonexistent_snapshot_plan->Splits().empty());
+ ASSERT_FALSE(supplied_nonexistent_snapshot_plan->SnapshotId());
+
+ ASSERT_NOK(ScanGlobalIndexAndData(table_path, predicate,
{{Options::SCAN_SNAPSHOT_ID, "999"}}));
+}
Review Comment:
It seems there may be a missed update here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]