| 1 | #include <Common/SipHash.h> |
| 2 | #include <Common/FieldVisitors.h> |
| 3 | #include <Parsers/ASTLiteral.h> |
| 4 | #include <IO/WriteHelpers.h> |
| 5 | |
| 6 | |
| 7 | namespace DB |
| 8 | { |
| 9 | |
| 10 | void ASTLiteral::updateTreeHashImpl(SipHash & hash_state) const |
| 11 | { |
| 12 | const char * prefix = "Literal_" ; |
| 13 | hash_state.update(prefix, strlen(prefix)); |
| 14 | applyVisitor(FieldVisitorHash(hash_state), value); |
| 15 | } |
| 16 | |
| 17 | void ASTLiteral::appendColumnNameImpl(WriteBuffer & ostr) const |
| 18 | { |
| 19 | /// Special case for very large arrays. Instead of listing all elements, will use hash of them. |
| 20 | /// (Otherwise column name will be too long, that will lead to significant slowdown of expression analysis.) |
| 21 | if (value.getType() == Field::Types::Array |
| 22 | && value.get<const Array &>().size() > 100) /// 100 - just arbitrary value. |
| 23 | { |
| 24 | SipHash hash; |
| 25 | applyVisitor(FieldVisitorHash(hash), value); |
| 26 | UInt64 low, high; |
| 27 | hash.get128(low, high); |
| 28 | |
| 29 | writeCString("__array_" , ostr); |
| 30 | writeText(low, ostr); |
| 31 | ostr.write('_'); |
| 32 | writeText(high, ostr); |
| 33 | } |
| 34 | else |
| 35 | { |
| 36 | String column_name = applyVisitor(FieldVisitorToString(), value); |
| 37 | writeString(column_name, ostr); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | } |
| 42 | |