mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-10-09 10:00:54 +00:00
97f2a2213e
* Move some code outside dbms/src folder * Fix paths
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
#include <Common/SipHash.h>
|
|
#include <Common/FieldVisitors.h>
|
|
#include <Parsers/ASTLiteral.h>
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
void ASTLiteral::updateTreeHashImpl(SipHash & hash_state) const
|
|
{
|
|
const char * prefix = "Literal_";
|
|
hash_state.update(prefix, strlen(prefix));
|
|
applyVisitor(FieldVisitorHash(hash_state), value);
|
|
}
|
|
|
|
void ASTLiteral::appendColumnNameImpl(WriteBuffer & ostr) const
|
|
{
|
|
/// 100 - just arbitrary value.
|
|
constexpr auto min_elements_for_hashing = 100;
|
|
|
|
/// Special case for very large arrays and tuples. Instead of listing all elements, will use hash of them.
|
|
/// (Otherwise column name will be too long, that will lead to significant slowdown of expression analysis.)
|
|
auto type = value.getType();
|
|
if ((type == Field::Types::Array && value.get<const Array &>().size() > min_elements_for_hashing)
|
|
|| (type == Field::Types::Tuple && value.get<const Tuple &>().size() > min_elements_for_hashing))
|
|
{
|
|
SipHash hash;
|
|
applyVisitor(FieldVisitorHash(hash), value);
|
|
UInt64 low, high;
|
|
hash.get128(low, high);
|
|
|
|
writeCString(type == Field::Types::Array ? "__array_" : "__tuple_", ostr);
|
|
writeText(low, ostr);
|
|
ostr.write('_');
|
|
writeText(high, ostr);
|
|
}
|
|
else
|
|
{
|
|
String column_name = applyVisitor(FieldVisitorToString(), value);
|
|
writeString(column_name, ostr);
|
|
}
|
|
}
|
|
|
|
}
|