fix up wrong assumption that the sample_block_with_keys has same ordering as key_names_right

This commit is contained in:
Martijn Bakker 2019-03-31 22:56:37 +01:00
parent 02320de49c
commit 27776ca929
3 changed files with 29 additions and 3 deletions

View File

@ -330,6 +330,7 @@ void Join::setSampleBlock(const Block & block)
sample_block_with_columns_to_add = materializeBlock(block);
LOG_DEBUG(log, "setSampleBlock sample_block_with_columns_to_add " << sample_block_with_columns_to_add.dumpStructure());
/// Move from `sample_block_with_columns_to_add` key columns to `sample_block_with_keys`, keeping the order.
size_t pos = 0;
@ -361,6 +362,9 @@ void Join::setSampleBlock(const Block & block)
if (use_nulls && isLeftOrFull(kind))
for (size_t i = 0; i < num_columns_to_add; ++i)
convertColumnToNullable(sample_block_with_columns_to_add.getByPosition(i));
LOG_DEBUG(log, "setSampleBlock sample_block_with_keys " << sample_block_with_keys.dumpStructure());
LOG_DEBUG(log, "setSampleBlock sample_block_with_columns_to_add " << sample_block_with_columns_to_add.dumpStructure());
}
namespace
@ -618,6 +622,7 @@ public:
void fillRightIndices(const Block& rhs_block)
{
std::cout << "rhs_block=" << rhs_block.dumpStructure() << std::endl;
for(auto& tn : type_name) {
right_indexes.push_back(rhs_block.getPositionByName(tn.second));
}
@ -861,8 +866,9 @@ void Join::joinBlockImpl(
AddedColumns added(sample_block_with_columns_to_add, block_with_columns_to_add, block);
// the last column in the key names is the asof column
if constexpr (STRICTNESS == ASTTableJoin::Strictness::Asof)
added.addColumn(sample_block_with_keys.safeGetByPosition(sample_block_with_keys.columns()-1));
added.addColumn(sample_block_with_keys.getByName(key_names_right.back()));
if(!blocks.empty()) {
added.fillRightIndices(*blocks.begin());

View File

@ -3,3 +3,13 @@
1 103 3 2 102 1
1 104 4 4 104 1
1 105 5 4 104 1
1 101 1 0 0 0
1 102 2 2 102 1
1 103 3 2 102 1
1 104 4 4 104 1
1 105 5 4 104 1
1 101 1 0 0 0
1 102 2 2 102 1
1 103 3 2 102 1
1 104 4 4 104 1
1 105 5 4 104 1

View File

@ -8,8 +8,18 @@ INSERT INTO A(k,t,a) VALUES (1,101,1),(1,102,2),(1,103,3),(1,104,4),(1,105,5);
CREATE TABLE B(k UInt32, t UInt32, b UInt64) ENGINE = MergeTree() ORDER BY (k, t);
INSERT INTO B(k,t,b) VALUES (1,102,2), (1,104,4);
SELECT A.k, A.t, A.a, B.b, B.t, B.k FROM A ASOF LEFT JOIN B USING(k,t) ORDER BY (A.k, A.t);
DROP TABLE B;
CREATE TABLE B(t UInt32, k UInt32, b UInt64) ENGINE = MergeTree() ORDER BY (k, t);
INSERT INTO B(k,t,b) VALUES (1,102,2), (1,104,4);
SELECT A.k, A.t, A.a, B.b, B.t, B.k FROM A ASOF LEFT JOIN B USING(k,t) ORDER BY (A.k, A.t);
DROP TABLE B;
CREATE TABLE B(k UInt32, b UInt64, t UInt32) ENGINE = MergeTree() ORDER BY (k, t);
INSERT INTO B(k,t,b) VALUES (1,102,2), (1,104,4);
SELECT A.k, A.t, A.a, B.b, B.t, B.k FROM A ASOF LEFT JOIN B USING(k,t) ORDER BY (A.k, A.t);
DROP TABLE B;
DROP TABLE A;
DROP TABLE B;