Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
igormunkin committed Sep 11, 2024
1 parent 7f7ec8e commit 8970a44
Showing 1 changed file with 247 additions and 0 deletions.
247 changes: 247 additions & 0 deletions ydb/library/yql/minikql/comp_nodes/ut/mkql_block_map_join_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,5 +918,252 @@ Y_UNIT_TEST_SUITE(TMiniKQLBlockMapJoinMoreTest) {

} // Y_UNIT_TEST_SUITE

Y_UNIT_TEST_SUITE(TMiniKQLBlockMapJoinDropKeyColumns) {

constexpr size_t testSize = 1 << 14;
constexpr size_t valueSize = 3;
static const TVector<TString> threeLetterValues = GenerateValues(valueSize);
static const TSet<ui64> fibonacci = GenerateFibonacci(21);

Y_UNIT_TEST(TestInnerOnUint64) {
TSetup<false> setup;
// 1. Make input for the "left" flow.
TVector<ui64> keyInit(testSize);
std::iota(keyInit.begin(), keyInit.end(), 1);
TVector<ui64> subkeyInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(subkeyInit),
[](const auto key) { return key * 1001; });
TVector<TString> valueInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(valueInit),
[](const auto key) { return threeLetterValues[key]; });
// 2. Make input for the "right" dict.
TMap<ui64, TString> rightMap;
for (const auto& key : fibonacci) {
rightMap[key] = std::to_string(key);
}
// 3. Make "expected" data.
TVector<ui64> subkeyExpected;
TVector<TString> valueExpected;
TVector<TString> rightExpected;
for (size_t i = 0; i < keyInit.size(); i++) {
const auto found = rightMap.find(keyInit[i]);
if (found != rightMap.cend()) {
subkeyExpected.push_back(subkeyInit[i]);
valueExpected.push_back(valueInit[i]);
rightExpected.push_back(found->second);
}
}
// 4. Convert input and expected TVectors to List<UV>.
const auto [leftType, leftList] = ConvertVectorsToTuples(setup,
keyInit, subkeyInit, valueInit);
const auto [expectedType, expected] = ConvertVectorsToTuples(setup,
subkeyExpected, valueExpected, rightExpected);
// 5. Build "right" computation node.
const auto rightMapNode = MakeDict(*setup.PgmBuilder, rightMap);
// 6. Run tests.
RunTestBlockJoin(setup, EJoinKind::Inner, expectedType, expected,
rightMapNode, leftType, leftList, {0}, {0});
}

Y_UNIT_TEST(TestInnerMultiOnUint64) {
TSetup<false> setup;
// 1. Make input for the "left" flow.
TVector<ui64> keyInit(testSize);
std::iota(keyInit.begin(), keyInit.end(), 1);
TVector<ui64> subkeyInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(subkeyInit),
[](const auto key) { return key * 1001; });
TVector<TString> valueInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(valueInit),
[](const auto key) { return threeLetterValues[key]; });
// 2. Make input for the "right" dict.
TMap<ui64, TVector<TString>> rightMultiMap;
for (const auto& key : fibonacci) {
rightMultiMap[key] = {std::to_string(key), std::to_string(key * 1001)};
}
// 3. Make "expected" data.
TVector<ui64> subkeyExpected;
TVector<TString> valueExpected;
TVector<TString> rightExpected;
for (size_t i = 0; i < keyInit.size(); i++) {
const auto found = rightMultiMap.find(keyInit[i]);
if (found != rightMultiMap.cend()) {
for (const auto& right : found->second) {
subkeyExpected.push_back(subkeyInit[i]);
valueExpected.push_back(valueInit[i]);
rightExpected.push_back(right);
}
}
}
// 4. Convert input and expected TVectors to List<UV>.
const auto [leftType, leftList] = ConvertVectorsToTuples(setup,
keyInit, subkeyInit, valueInit);
const auto [expectedType, expected] = ConvertVectorsToTuples(setup,
subkeyExpected, valueExpected, rightExpected);
// 5. Build "right" computation node.
const auto rightMultiMapNode = MakeMultiDict(*setup.PgmBuilder, rightMultiMap);
// 6. Run tests.
RunTestBlockJoin(setup, EJoinKind::Inner, expectedType, expected,
rightMultiMapNode, leftType, leftList, {0}, {0});
}

Y_UNIT_TEST(TestLeftOnUint64) {
TSetup<false> setup;
// 1. Make input for the "left" flow.
TVector<ui64> keyInit(testSize);
std::iota(keyInit.begin(), keyInit.end(), 1);
TVector<ui64> subkeyInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(subkeyInit),
[](const auto key) { return key * 1001; });
TVector<TString> valueInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(valueInit),
[](const auto key) { return threeLetterValues[key]; });
// 2. Make input for the "right" dict.
TMap<ui64, TString> rightMap;
for (const auto& key : fibonacci) {
rightMap[key] = std::to_string(key);
}
// 3. Make "expected" data.
TVector<ui64> subkeyExpected;
TVector<TString> valueExpected;
TVector<std::optional<TString>> rightExpected;
for (size_t i = 0; i < keyInit.size(); i++) {
subkeyExpected.push_back(subkeyInit[i]);
valueExpected.push_back(valueInit[i]);
const auto found = rightMap.find(keyInit[i]);
if (found != rightMap.cend()) {
rightExpected.push_back(found->second);
} else {
rightExpected.push_back(std::nullopt);
}
}
// 4. Convert input and expected TVectors to List<UV>.
const auto [leftType, leftList] = ConvertVectorsToTuples(setup,
keyInit, subkeyInit, valueInit);
const auto [expectedType, expected] = ConvertVectorsToTuples(setup,
subkeyExpected, valueExpected, rightExpected);
// 5. Build "right" computation node.
const auto rightMapNode = MakeDict(*setup.PgmBuilder, rightMap);
// 6. Run tests.
RunTestBlockJoin(setup, EJoinKind::Left, expectedType, expected,
rightMapNode, leftType, leftList, {0}, {0});
}

Y_UNIT_TEST(TestLeftMultiOnUint64) {
TSetup<false> setup;
// 1. Make input for the "left" flow.
TVector<ui64> keyInit(testSize);
std::iota(keyInit.begin(), keyInit.end(), 1);
TVector<ui64> subkeyInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(subkeyInit),
[](const auto key) { return key * 1001; });
TVector<TString> valueInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(valueInit),
[](const auto key) { return threeLetterValues[key]; });
// 2. Make input for the "right" dict.
TMap<ui64, TVector<TString>> rightMultiMap;
for (const auto& key : fibonacci) {
rightMultiMap[key] = {std::to_string(key), std::to_string(key * 1001)};
}
// 3. Make "expected" data.
TVector<ui64> subkeyExpected;
TVector<TString> valueExpected;
TVector<std::optional<TString>> rightExpected;
for (size_t i = 0; i < keyInit.size(); i++) {
const auto found = rightMultiMap.find(keyInit[i]);
if (found != rightMultiMap.cend()) {
for (const auto& right : found->second) {
subkeyExpected.push_back(subkeyInit[i]);
valueExpected.push_back(valueInit[i]);
rightExpected.push_back(right);
}
} else {
subkeyExpected.push_back(subkeyInit[i]);
valueExpected.push_back(valueInit[i]);
rightExpected.push_back(std::nullopt);
}
}
// 4. Convert input and expected TVectors to List<UV>.
const auto [leftType, leftList] = ConvertVectorsToTuples(setup,
keyInit, subkeyInit, valueInit);
const auto [expectedType, expected] = ConvertVectorsToTuples(setup,
subkeyExpected, valueExpected, rightExpected);
// 5. Build "right" computation node.
const auto rightMultiMapNode = MakeMultiDict(*setup.PgmBuilder, rightMultiMap);
// 6. Run tests.
RunTestBlockJoin(setup, EJoinKind::Left, expectedType, expected,
rightMultiMapNode, leftType, leftList, {0}, {0});
}

Y_UNIT_TEST(TestLeftSemiOnUint64) {
TSetup<false> setup;
// 1. Make input for the "left" flow.
TVector<ui64> keyInit(testSize);
std::iota(keyInit.begin(), keyInit.end(), 1);
TVector<ui64> subkeyInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(subkeyInit),
[](const auto key) { return key * 1001; });
TVector<TString> valueInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(valueInit),
[](const auto key) { return threeLetterValues[key]; });
// 2. Make input for the "right" dict.
const TSet<ui64> rightSet(fibonacci);
// 3. Make "expected" data.
TVector<ui64> subkeyExpected;
TVector<TString> valueExpected;
for (size_t i = 0; i < keyInit.size(); i++) {
if (rightSet.contains(keyInit[i])) {
subkeyExpected.push_back(subkeyInit[i]);
valueExpected.push_back(valueInit[i]);
}
}
// 4. Convert input and expected TVectors to List<UV>.
const auto [leftType, leftList] = ConvertVectorsToTuples(setup,
keyInit, subkeyInit, valueInit);
const auto [expectedType, expected] = ConvertVectorsToTuples(setup,
subkeyExpected, valueExpected);
// 5. Build "right" computation node.
const auto rightSetNode = MakeSet(*setup.PgmBuilder, rightSet);
// 6. Run tests.
RunTestBlockJoin(setup, EJoinKind::LeftSemi, expectedType, expected,
rightSetNode, leftType, leftList, {0}, {0});
}

Y_UNIT_TEST(TestLeftOnlyOnUint64) {
TSetup<false> setup;
// 1. Make input for the "left" flow.
TVector<ui64> keyInit(testSize);
std::iota(keyInit.begin(), keyInit.end(), 1);
TVector<ui64> subkeyInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(subkeyInit),
[](const auto key) { return key * 1001; });
TVector<TString> valueInit;
std::transform(keyInit.cbegin(), keyInit.cend(), std::back_inserter(valueInit),
[](const auto key) { return threeLetterValues[key]; });
// 2. Make input for the "right" dict.
const TSet<ui64> rightSet(fibonacci);
// 3. Make "expected" data.
TVector<ui64> subkeyExpected;
TVector<TString> valueExpected;
for (size_t i = 0; i < keyInit.size(); i++) {
if (!rightSet.contains(keyInit[i])) {
subkeyExpected.push_back(subkeyInit[i]);
valueExpected.push_back(valueInit[i]);
}
}
// 4. Convert input and expected TVectors to List<UV>.
const auto [leftType, leftList] = ConvertVectorsToTuples(setup,
keyInit, subkeyInit, valueInit);
const auto [expectedType, expected] = ConvertVectorsToTuples(setup,
subkeyExpected, valueExpected);
// 5. Build "right" computation node.
const auto rightSetNode = MakeSet(*setup.PgmBuilder, rightSet);
// 6. Run tests.
RunTestBlockJoin(setup, EJoinKind::LeftOnly, expectedType, expected,
rightSetNode, leftType, leftList, {0}, {0});
}

} // Y_UNIT_TEST_SUITE

} // namespace NMiniKQL
} // namespace NKikimr

0 comments on commit 8970a44

Please sign in to comment.