Skip to content

Commit 1167609

Browse files
authored
YQ-4232 added validation for ShuffleLeftSideBy / ShuffleRightSideBy (#16986)
1 parent c9350b3 commit 1167609

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

ydb/core/kqp/ut/join/kqp_join_ut.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,48 @@ Y_UNIT_TEST_SUITE(KqpJoin) {
18781878
)", FormatResultSetYson(result.GetResultSet(0)));
18791879
}
18801880
}
1881+
1882+
Y_UNIT_TEST(HashJoinWithAsTable) {
1883+
TKikimrRunner kikimr;
1884+
1885+
auto client = kikimr.GetQueryClient();
1886+
1887+
{
1888+
const TString query = R"(
1889+
CREATE TABLE test_table (
1890+
test_column Int32,
1891+
PRIMARY key (test_column)
1892+
))";
1893+
1894+
const auto result = client.ExecuteQuery(query, NYdb::NQuery::TTxControl::NoTx()).ExtractValueSync();
1895+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::SUCCESS, result.GetIssues().ToString());
1896+
}
1897+
1898+
const TString joinQuery = R"(
1899+
PRAGMA ydb.HashJoinMode = "grace";
1900+
PRAGMA ydb.OptShuffleElimination = "true";
1901+
1902+
$as_table = SELECT * FROM AS_TABLE([<|test_column: 42|>]);
1903+
1904+
SELECT
1905+
as_table.test_column
1906+
FROM $as_table AS as_table
1907+
LEFT JOIN test_table
1908+
ON test_table.test_column = as_table.test_column
1909+
)";
1910+
1911+
const auto result = client.ExecuteQuery(joinQuery, NYdb::NQuery::TTxControl::NoTx()).ExtractValueSync();
1912+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::SUCCESS, result.GetIssues().ToString());
1913+
UNIT_ASSERT_VALUES_EQUAL(result.GetResultSets().size(), 1);
1914+
1915+
const auto& resultSet = result.GetResultSet(0);
1916+
UNIT_ASSERT_VALUES_EQUAL(resultSet.ColumnsCount(), 1);
1917+
UNIT_ASSERT_VALUES_EQUAL(resultSet.RowsCount(), 1);
1918+
1919+
TResultSetParser parser(resultSet);
1920+
UNIT_ASSERT(parser.TryNextRow());
1921+
UNIT_ASSERT_VALUES_EQUAL(parser.ColumnParser(0).GetInt32(), 42);
1922+
}
18811923
}
18821924

18831925
} // namespace NKqp

ydb/library/yql/dq/opt/dq_opt_join.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ TExprBase DqBuildHashJoin(const TDqJoin& join, EHashJoinMode mode, TExprContext&
14761476
YQL_CLOG(TRACE, CoreDq) << "ShuffleLeftSide isn't defined";
14771477
}
14781478
if (shuffleLeftSide) {
1479-
if (shuffleElimination) {
1479+
if (shuffleElimination && join.ShuffleLeftSideBy()) {
14801480
leftConnection = buildShuffle(
14811481
leftIn,
14821482
buildShuffleKeys(join.ShuffleLeftSideBy().Cast(), leftJoinKeys)
@@ -1497,7 +1497,7 @@ TExprBase DqBuildHashJoin(const TDqJoin& join, EHashJoinMode mode, TExprContext&
14971497
YQL_CLOG(TRACE, CoreDq) << "ShuffleRightSide isn't defined";
14981498
}
14991499
if (shuffleRightSide) {
1500-
if (shuffleElimination) {
1500+
if (shuffleElimination && join.ShuffleRightSideBy()) {
15011501
rightConnection = buildShuffle(
15021502
rightIn,
15031503
buildShuffleKeys(join.ShuffleRightSideBy().Cast(), rightJoinKeys)

0 commit comments

Comments
 (0)