diff --git a/dbms/src/Dictionaries/ComplexKeyHashedDictionary.cpp b/dbms/src/Dictionaries/ComplexKeyHashedDictionary.cpp index 715942a6734..ab44e3e92e6 100644 --- a/dbms/src/Dictionaries/ComplexKeyHashedDictionary.cpp +++ b/dbms/src/Dictionaries/ComplexKeyHashedDictionary.cpp @@ -247,7 +247,7 @@ void ComplexKeyHashedDictionary::updateData() saved_block = std::make_shared(block.cloneEmpty()); for (const auto attribute_idx : ext::range(0, keys_size + attributes_size)) { - const IColumn &update_column = *block.getByPosition(attribute_idx).column.get(); + const IColumn & update_column = *block.getByPosition(attribute_idx).column.get(); MutableColumnPtr saved_column = saved_block->getByPosition(attribute_idx).column->mutate(); saved_column->insertRangeFrom(update_column, 0, update_column.size()); } @@ -272,7 +272,6 @@ void ComplexKeyHashedDictionary::updateData() return block.safeGetByPosition(key_idx).column; }); - const auto &saved_columns = saved_block->mutateColumns(); std::vector update_indices, saved_indices; for (size_t i = 0; i < saved_block->rows(); ++i) @@ -292,6 +291,9 @@ void ComplexKeyHashedDictionary::updateData() u_temp_key_pool.rollback(u_key.size); } } + + auto saved_columns = saved_block->mutateColumns(); + BlockPtr temp_block = std::make_shared(saved_block->cloneEmpty()); for (const auto attribute_idx : ext::range(0, keys_size + attributes_size)) { @@ -334,6 +336,8 @@ void ComplexKeyHashedDictionary::updateData() saved_block = std::make_shared(*temp_block); temp_block.reset(); } + else + saved_block->setColumns(std::move(saved_columns)); } stream->readSuffix(); } diff --git a/dbms/src/Dictionaries/ExternalQueryBuilder.cpp b/dbms/src/Dictionaries/ExternalQueryBuilder.cpp index 38eb3c41066..2524419cefe 100644 --- a/dbms/src/Dictionaries/ExternalQueryBuilder.cpp +++ b/dbms/src/Dictionaries/ExternalQueryBuilder.cpp @@ -141,7 +141,7 @@ std::string ExternalQueryBuilder::composeLoadAllQuery() const std::string ExternalQueryBuilder::composeUpdateQuery(const std::string &update_field, std::string &time_point) const { std::string out = composeLoadAllQuery(); - std::string update_query = " WHERE " + update_field + " > '" + time_point + "'"; + std::string update_query = " WHERE " + update_field + " >= '" + time_point + "'"; out.insert(out.size()-1, update_query); return out; diff --git a/dbms/src/Dictionaries/HashedDictionary.cpp b/dbms/src/Dictionaries/HashedDictionary.cpp index 5a2a9c81002..e504c923377 100644 --- a/dbms/src/Dictionaries/HashedDictionary.cpp +++ b/dbms/src/Dictionaries/HashedDictionary.cpp @@ -296,6 +296,8 @@ void HashedDictionary::updateData() saved_column->insertRangeFrom(update_column, 0, update_column.size()); } } + stream->readSuffix(); + } else { @@ -342,16 +344,15 @@ void HashedDictionary::updateData() } else temp_columns[attribute_idx]->insertFrom(*saved_block->safeGetByPosition(attribute_idx).column, i); - - for (size_t i = 0; i < update_id_column.size(); ++i) + } + for (size_t i = 0; i < update_id_column.size(); ++i) + { + bool exists = std::any_of(update_indices.begin(), update_indices.end(), [&](size_t x) { - bool exists = std::any_of(update_indices.begin(), update_indices.end(), [&](size_t x) - { - return x == i; - }); - if (!exists) - temp_columns[attribute_idx]->insertFrom(*block.safeGetByPosition(attribute_idx).column, i); - } + return x == i; + }); + if (!exists) + temp_columns[attribute_idx]->insertFrom(*block.safeGetByPosition(attribute_idx).column, i); } } } @@ -362,6 +363,7 @@ void HashedDictionary::updateData() temp_block.reset(); } } + stream->readSuffix(); } if (saved_block) diff --git a/dbms/src/Dictionaries/MySQLDictionarySource.cpp b/dbms/src/Dictionaries/MySQLDictionarySource.cpp index 10d9c4fe361..8ee8f930981 100644 --- a/dbms/src/Dictionaries/MySQLDictionarySource.cpp +++ b/dbms/src/Dictionaries/MySQLDictionarySource.cpp @@ -72,7 +72,7 @@ void MySQLDictionarySource::setDate() char buffer [80]; struct tm * timeinfo; timeinfo = localtime (&hr_time); - strftime(buffer, 80, "%Y-%m-%d%%20%H:%M:%S", timeinfo); + strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", timeinfo); std::string str_time(buffer); date = str_time; } @@ -88,9 +88,7 @@ void MySQLDictionarySource::setDate() strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", timeinfo); std::string str_time(buffer); date = str_time; - std::string tmp = load_all_query; - tmp.pop_back(); - load_all_query_update = tmp + " WHERE " + update_field + " > '" + date + "';"; + load_all_query_update = query_builder.composeUpdateQuery(update_field, date); } }