SteNicholas commented on code in PR #461: URL: https://github.com/apache/paimon-cpp/pull/461#discussion_r4417270038
########## src/paimon/core/table/source/data_evolution_full_text_scan.cpp: ########## @@ -0,0 +1,328 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "paimon/core/table/source/data_evolution_full_text_scan.h" + +#include <algorithm> +#include <cassert> +#include <functional> +#include <iterator> +#include <limits> +#include <map> +#include <optional> +#include <set> +#include <string> +#include <tuple> +#include <unordered_map> +#include <utility> + +#include "fmt/format.h" +#include "fmt/ranges.h" +#include "paimon/core/index/index_file_handler.h" +#include "paimon/core/manifest/index_manifest_entry.h" +#include "paimon/core/manifest/index_manifest_file.h" +#include "paimon/core/snapshot.h" +#include "paimon/core/table/source/index_full_text_search_split_impl.h" +#include "paimon/core/tag/tag.h" +#include "paimon/core/utils/branch_manager.h" +#include "paimon/core/utils/index_file_path_factories.h" +#include "paimon/core/utils/snapshot_manager.h" +#include "paimon/core/utils/tag_manager.h" +#include "paimon/defs.h" +#include "paimon/global_index/full_text/full_text_defs.h" +#include "paimon/global_index/global_indexer.h" +#include "paimon/global_index/global_indexer_factory.h" +#include "paimon/global_index/lucene/lucene_defs.h" + +namespace paimon { +namespace { +/// The files of one index shard that may rank rows of the searched field. +struct IndexRangeCandidate { + Range file_range; + std::string identity; + /// Whether the searched field is the indexed field of the index, not an extra field. + bool primary; + std::vector<std::shared_ptr<IndexFileMeta>> files; + /// The rows assigned to this shard, merged as they are assigned in ascending order. + std::vector<Range> assigned; +}; + +/// Resolves the snapshot to search as Java `TimeTravelUtil#tryTravelOrLatest` does: the one that +/// the time-travel option selects, whatever `scan.mode` is, or else the latest one. +Result<std::optional<Snapshot>> ResolveSnapshot(const CoreOptions& options, + const SnapshotManager& snapshot_manager, + const TagManager& tag_manager) { + // Java `TimeTravelUtil#SCAN_KEYS`, without `scan.watermark`, which Paimon C++ does not define. + const char* const time_travel_keys[] = {Options::SCAN_SNAPSHOT_ID, Options::SCAN_TAG_NAME, + Options::SCAN_TIMESTAMP, + Options::SCAN_TIMESTAMP_MILLIS}; + const std::map<std::string, std::string>& raw_options = options.ToMap(); + std::vector<std::string> keys; + for (const char* key : time_travel_keys) { + if (raw_options.count(key) > 0) { + keys.emplace_back(key); + } + } + if (keys.empty()) { + return snapshot_manager.LatestSnapshot(); + } + if (keys.size() > 1) { + return Status::Invalid( + fmt::format("Only one of the following parameters may be set: [{}], but got [{}]", + fmt::join(std::begin(time_travel_keys), std::end(time_travel_keys), ", "), + fmt::join(keys, ", "))); + } + const std::string& key = keys[0]; + if (key == Options::SCAN_SNAPSHOT_ID) { Review Comment: Aligned with Java in 83a29ba6. `SchemaValidation::ValidateStartupMode`, which was a `NotImplemented` stub, now ports Java `SchemaValidation#validateStartupMode` for the time-travel options that Paimon C++ defines, and the scan calls it before it resolves the snapshot, as Java validates these options when it loads the table with them. `latest-full` (or `latest`) with `scan.snapshot-id` now fails with `scan.snapshot-id must be null when you use latest-full for scan.mode`, while `from-snapshot`, `from-snapshot-full` and `from-timestamp` need exactly one of their own options and reject the others. The integration test now expects that error, and searches the earlier snapshot with `scan.mode` = `from-snapshot` instead. `SchemaValidationTest.TestStartupMode` covers every mode with missing, conflicting and valid options. -- 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]
