Skip to content

YQ-3697 Add partition count to fqrun #9837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ NThreading::TFuture<IPqGateway::TListStreams> TDummyPqGateway::ListStreams(const
TDummyPqGateway& TDummyPqGateway::AddDummyTopic(const TDummyTopic& topic) {
with_lock (Mutex) {
Y_ENSURE(topic.Cluster);
Y_ENSURE(topic.Path);
const auto key = std::make_pair(topic.Cluster, topic.Path);
Y_ENSURE(topic.TopicName);
const auto key = std::make_pair(topic.Cluster, topic.TopicName);
Y_ENSURE(Topics.emplace(key, topic).second, "Already inserted dummy topic {" << topic.Cluster << ", " << topic.Path << "}");
return *this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
namespace NYql {

struct TDummyTopic {
TDummyTopic(const TString& cluster, const TString& path, const TMaybe<TString>& filePath = {})
TDummyTopic(const TString& cluster, const TString& topicName, const TMaybe<TString>& path = {}, size_t partitionCount = 1)
: Cluster(cluster)
, TopicName(topicName)
, Path(path)
, FilePath(filePath)
, PartitionsCount(partitionCount)
{
}

Expand All @@ -22,9 +23,9 @@ struct TDummyTopic {
}

TString Cluster;
TString Path;
TMaybe<TString> FilePath;
size_t PartitionsCount = 1;
TString TopicName;
TMaybe<TString> Path;
size_t PartitionsCount;
};

// Dummy Pq gateway for tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <library/cpp/threading/future/async.h>

#include <util/folder/path.h>
#include <util/system/file.h>
#include "yql_pq_blocking_queue.h"

Expand Down Expand Up @@ -337,17 +338,24 @@ struct TDummyPartitionSession: public NYdb::NTopic::TPartitionSession {

std::shared_ptr<NYdb::NTopic::IReadSession> TFileTopicClient::CreateReadSession(const NYdb::NTopic::TReadSessionSettings& settings) {
Y_ENSURE(!settings.Topics_.empty());
auto topicPath = settings.Topics_.front().Path_;

const auto& topic = settings.Topics_.front();
auto topicPath = topic.Path_;
Y_ENSURE(topic.PartitionIds_.size() >= 1);
ui64 partitionId = topic.PartitionIds_.front();
auto topicsIt = Topics_.find(make_pair("pq", topicPath));
Y_ENSURE(topicsIt != Topics_.end());
auto filePath = topicsIt->second.FilePath;
auto filePath = topicsIt->second.Path;
Y_ENSURE(filePath);

TFsPath fsPath(*filePath);
if (fsPath.IsDirectory()) {
filePath = TStringBuilder() << *filePath << "/" << ToString(partitionId);
} else if (!fsPath.Exists()) {
filePath = TStringBuilder() << *filePath << "_" << partitionId;
}

// TODO
ui64 sessionId = 0;
ui64 partitionId = 0;

return std::make_shared<TFileTopicReadSession>(
TFile(*filePath, EOpenMode::TEnum::RdOnly),
MakeIntrusive<TDummyPartitionSession>(sessionId, TString{topicPath}, partitionId)
Expand Down Expand Up @@ -411,7 +419,7 @@ std::shared_ptr<NYdb::NTopic::IWriteSession> TFileTopicClient::CreateWriteSessio
auto topicPath = TString{settings.Path_};
auto topicsIt = Topics_.find(make_pair("pq", topicPath));
Y_ENSURE(topicsIt != Topics_.end());
auto filePath = topicsIt->second.FilePath;
auto filePath = topicsIt->second.Path;
Y_ENSURE(filePath);

return std::make_shared<TFileTopicWriteSession>(TFile(*filePath, EOpenMode::TEnum::RdWr));
Expand Down
20 changes: 11 additions & 9 deletions ydb/tests/tools/fqrun/fqrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ class TMain : public TMainBase {
options.AddLongOption("emulate-pq", "Emulate YDS with local file, accepts list of tables to emulate with following format: topic@file (can be used in query from cluster `pq`)")
.RequiredArgument("topic@file")
.Handler1([this](const NLastGetopt::TOptsParser* option) {
TStringBuf topicName;
TStringBuf filePath;
TStringBuf(option->CurVal()).Split('@', topicName, filePath);
if (topicName.empty() || filePath.empty()) {
ythrow yexception() << "Incorrect PQ file mapping, expected form topic@file";
TStringBuf topicName, others;
TStringBuf(option->CurVal()).Split('@', topicName, others);
TStringBuf path, partitionCountStr;
TStringBuf(others).Split(':', path, partitionCountStr);
size_t partitionCount = !partitionCountStr.empty() ? FromString<size_t>(partitionCountStr) : 1;
if (topicName.empty() || path.empty()) {
ythrow yexception() << "Incorrect PQ file mapping, expected form topic@path[:partitions_count]" << Endl;
}
if (!PqFilesMapping.emplace(topicName, filePath).second) {
if (!PqFilesMapping.emplace(topicName, NYql::TDummyTopic("pq", TString(topicName), TString(path), partitionCount)).second) {
ythrow yexception() << "Got duplicated topic name: " << topicName;
}
});
Expand Down Expand Up @@ -222,8 +224,8 @@ class TMain : public TMainBase {

if (!PqFilesMapping.empty()) {
auto fileGateway = MakeIntrusive<NYql::TDummyPqGateway>();
for (const auto& [topic, file] : PqFilesMapping) {
fileGateway->AddDummyTopic(NYql::TDummyTopic("pq", TString(topic), TString(file)));
for (const auto& [_, topic] : PqFilesMapping) {
fileGateway->AddDummyTopic(topic);
}
RunnerOptions.FqSettings.PqGateway = std::move(fileGateway);
}
Expand All @@ -246,7 +248,7 @@ class TMain : public TMainBase {
private:
TExecutionOptions ExecutionOptions;
TRunnerOptions RunnerOptions;
std::unordered_map<TString, TString> PqFilesMapping;
std::unordered_map<TString, NYql::TDummyTopic> PqFilesMapping;
};

} // anonymous namespace
Expand Down