Skip to content

Fix plan tests & improve plan signatures for sources/sinks #1041

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 2 commits into from
Jan 16, 2024
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
26 changes: 16 additions & 10 deletions ydb/core/kqp/opt/kqp_query_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class TxPlanSerializer {
}
return res;
}
};
};
};

struct TOperator {
Expand Down Expand Up @@ -345,7 +345,7 @@ class TxPlanSerializer {
else {
TArgContext c = std::get<TArgContext>(input);
writer.BeginObject();

auto input = LambdaInputs.find(c);
if (input != LambdaInputs.end()){
if (std::holds_alternative<ui32>(input->second)) {
Expand Down Expand Up @@ -814,10 +814,13 @@ class TxPlanSerializer {
}

// Common settings that can be overwritten by provider
op.Properties["Name"] = "Read from external data source";
op.Properties["SourceType"] = dataSourceCategory;
if (auto cluster = TryGetCluster(dataSource)) {
op.Properties["ExternalDataSource"] = RemovePathPrefix(std::move(*cluster));
TString dataSource = RemovePathPrefix(std::move(*cluster));
op.Properties["ExternalDataSource"] = dataSource;
op.Properties["Name"] = TStringBuilder() << "Read " << dataSource;
} else {
op.Properties["Name"] = "Read from external data source";
}

if (dqIntegration) {
Expand All @@ -842,10 +845,13 @@ class TxPlanSerializer {
}

// Common settings that can be overwritten by provider
op.Properties["Name"] = "Write to external data source";
op.Properties["SinkType"] = dataSinkCategory;
if (auto cluster = TryGetCluster(dataSink)) {
op.Properties["ExternalDataSource"] = RemovePathPrefix(std::move(*cluster));
TString dataSource = RemovePathPrefix(std::move(*cluster));
op.Properties["ExternalDataSource"] = dataSource;
op.Properties["Name"] = TStringBuilder() << "Write " << dataSource;
} else {
op.Properties["Name"] = "Write to external data source";
}

if (dqIntegration) {
Expand Down Expand Up @@ -1036,7 +1042,7 @@ class TxPlanSerializer {
inputIds.insert(inputIds.end(), flatMapLambdaInputs.begin(), flatMapLambdaInputs.end());

}
else {
else {
for (const auto& child : node->Children()) {
if(!child->IsLambda()) {
auto ids = Visit(child, planNode);
Expand Down Expand Up @@ -1278,7 +1284,7 @@ class TxPlanSerializer {
auto operatorId = AddOperator(planNode, name, std::move(op));

Visit(flatMap, planNode);

return operatorId;
}

Expand Down Expand Up @@ -1333,7 +1339,7 @@ class TxPlanSerializer {
AddOptimizerEstimates(op, join);

Visit(flatMap, planNode);

return operatorId;
}

Expand Down Expand Up @@ -2101,7 +2107,7 @@ TString AddExecStatsToTxPlan(const TString& txPlanJson, const NYql::NDqProto::TD
}

stats["Tasks"] = (*stat)->GetTotalTasksCount();

stats["StageDurationUs"] = (*stat)->GetStageDurationUs();

if ((*stat)->HasDurationUs()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ Y_UNIT_TEST_SUITE(KqpGenericPlanTest) {
NJson::TJsonValue plan;
UNIT_ASSERT(NJson::ReadJsonTree(*queryResult.GetStats()->GetPlan(), &plan));

const auto& stagePlan = plan["Plan"]["Plans"][0]["Plans"][0]["Plans"][0]["Plans"][0];
UNIT_ASSERT_VALUES_EQUAL(stagePlan["Node Type"].GetStringSafe(), "Filter-Source");
const auto& sourceOp = stagePlan["Operators"].GetArraySafe()[1];
const auto& stagePlan = plan["Plan"]["Plans"][0]["Plans"][0]["Plans"][0]["Plans"][0]["Plans"][0];
UNIT_ASSERT_VALUES_EQUAL(stagePlan["Node Type"].GetStringSafe(), "Source");
const auto& sourceOp = stagePlan["Operators"].GetArraySafe()[0];
UNIT_ASSERT_VALUES_EQUAL(sourceOp["ExternalDataSource"].GetStringSafe(), "pg_data_source");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Database"].GetStringSafe(), GetPgDatabase());
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Protocol"].GetStringSafe(), "Native");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Table"].GetStringSafe(), "pg_table_plan_test");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Name"].GetStringSafe(), "Read from external data source");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Name"].GetStringSafe(), "Read pg_data_source");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["SourceType"].GetStringSafe(), "PostgreSql");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["ReadColumns"].GetArraySafe()[0].GetStringSafe(), "key");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["ReadColumns"].GetArraySafe()[1].GetStringSafe(), "name");
Expand Down Expand Up @@ -163,14 +163,14 @@ Y_UNIT_TEST_SUITE(KqpGenericPlanTest) {
NJson::TJsonValue plan;
UNIT_ASSERT(NJson::ReadJsonTree(*queryResult.GetStats()->GetPlan(), &plan));

const auto& stagePlan = plan["Plan"]["Plans"][0]["Plans"][0]["Plans"][0]["Plans"][0];
UNIT_ASSERT_VALUES_EQUAL(stagePlan["Node Type"].GetStringSafe(), "Filter-Source");
const auto& sourceOp = stagePlan["Operators"].GetArraySafe()[1];
const auto& stagePlan = plan["Plan"]["Plans"][0]["Plans"][0]["Plans"][0]["Plans"][0]["Plans"][0];
UNIT_ASSERT_VALUES_EQUAL(stagePlan["Node Type"].GetStringSafe(), "Source");
const auto& sourceOp = stagePlan["Operators"].GetArraySafe()[0];
UNIT_ASSERT_VALUES_EQUAL(sourceOp["ExternalDataSource"].GetStringSafe(), "ch_data_source");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Database"].GetStringSafe(), GetChDatabase());
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Protocol"].GetStringSafe(), "Native");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Table"].GetStringSafe(), "ch_table_plan_test");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Name"].GetStringSafe(), "Read from external data source");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Name"].GetStringSafe(), "Read ch_data_source");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["SourceType"].GetStringSafe(), "ClickHouse");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["ReadColumns"].GetArraySafe()[0].GetStringSafe(), "key");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["ReadColumns"].GetArraySafe()[1].GetStringSafe(), "name");
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/kqp/ut/federated_query/s3/kqp_s3_plan_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Y_UNIT_TEST_SUITE(KqpS3PlanTest) {
const auto& sourceOp = stagePlan["Plans"][0]["Operators"].GetArraySafe()[0];
UNIT_ASSERT_VALUES_EQUAL(sourceOp["ExternalDataSource"].GetStringSafe(), "external_data_source");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Format"].GetStringSafe(), "json_each_row");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Name"].GetStringSafe(), "Parse from external data source");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["Name"].GetStringSafe(), "Parse external_data_source");
UNIT_ASSERT_VALUES_EQUAL(sourceOp["SourceType"].GetStringSafe(), "s3");
UNIT_ASSERT(!IsIn(sourceOp.GetMap(), "RowsLimitHint"));
UNIT_ASSERT_VALUES_EQUAL(sourceOp["ReadColumns"].GetArraySafe()[0].GetStringSafe(), "key");
Expand Down
15 changes: 13 additions & 2 deletions ydb/library/yql/providers/s3/provider/yql_s3_dq_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,18 +437,29 @@ class TS3DqIntegration: public TDqIntegrationBase {
return false;
}

const NJson::TJsonValue* clusterNameProp = properties.FindPtr("ExternalDataSource");
const TString clusterName = clusterNameProp && clusterNameProp->IsString() ? clusterNameProp->GetString() : TString();

auto source = node.Cast<TDqSource>();
if (auto maybeSettings = source.Settings().Maybe<TS3SourceSettings>()) {
const TS3SourceSettings settings = maybeSettings.Cast();
properties["Name"] = "Raw read from external data source";
if (clusterName) {
properties["Name"] = TStringBuilder() << "Raw read " << clusterName;
} else {
properties["Name"] = "Raw read from external data source";
}
properties["Format"] = "raw";
if (TString limit = settings.RowsLimitHint().StringValue()) {
properties["RowsLimitHint"] = limit;
}
return true;
} else if (auto maybeSettings = source.Settings().Maybe<TS3ParseSettings>()) {
const TS3ParseSettings settings = maybeSettings.Cast();
properties["Name"] = "Parse from external data source";
if (clusterName) {
properties["Name"] = TStringBuilder() << "Parse " << clusterName;
} else {
properties["Name"] = "Parse from external data source";
}
properties["Format"] = settings.Format().StringValue();
if (TString limit = settings.RowsLimitHint().StringValue()) {
properties["RowsLimitHint"] = limit;
Expand Down