MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / encodeDataTypeImpl

Function encodeDataTypeImpl

src/DataTypes/DataTypesBinaryEncoding.cpp:315–541  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313
314template <bool encode_for_hash_calculation>
315void encodeDataTypeImpl(const DataTypePtr & type, WriteBuffer & buf)
316{
317 /// First, write the BinaryTypeIndex byte.
318 auto binary_type_index = getBinaryTypeIndex(type);
319 buf.write(UInt8(binary_type_index));
320 /// Then, write additional information depending on the data type.
321 switch (binary_type_index)
322 {
323 case BinaryTypeIndex::DateTimeWithTimezone:
324 {
325 const auto & datetime_type = assert_cast<const DataTypeDateTime &>(*type);
326 writeStringBinary(getDateLUTTimeZone(datetime_type.getTimeZone()), buf);
327 break;
328 }
329 case BinaryTypeIndex::DateTime64UTC:
330 {
331 const auto & datetime64_type = assert_cast<const DataTypeDateTime64 &>(*type);
332 /// Maximum scale for DateTime64 is 9, so we can write it as 1 byte.
333 buf.write(UInt8(datetime64_type.getScale()));
334 break;
335 }
336 case BinaryTypeIndex::DateTime64WithTimezone:
337 {
338 const auto & datetime64_type = assert_cast<const DataTypeDateTime64 &>(*type);
339 buf.write(UInt8(datetime64_type.getScale()));
340 writeStringBinary(getDateLUTTimeZone(datetime64_type.getTimeZone()), buf);
341 break;
342 }
343 case BinaryTypeIndex::Time64:
344 {
345 const auto & time64_type = assert_cast<const DataTypeTime64 &>(*type);
346 /// Maximum scale for Time64 is 9, so we can write it as 1 byte.
347 buf.write(UInt8(time64_type.getScale()));
348 break;
349 }
350 case BinaryTypeIndex::FixedString:
351 {
352 const auto & fixed_string_type = assert_cast<const DataTypeFixedString &>(*type);
353 writeVarUInt(fixed_string_type.getN(), buf);
354 break;
355 }
356 case BinaryTypeIndex::Enum8:
357 {
358 encodeEnumValues<Int8>(type, buf);
359 break;
360 }
361 case BinaryTypeIndex::Enum16:
362 {
363 encodeEnumValues<Int16>(type, buf);
364 break;
365 }
366 case BinaryTypeIndex::Decimal32:
367 {
368 encodeDecimal<Decimal32>(type, buf);
369 break;
370 }
371 case BinaryTypeIndex::Decimal64:
372 {

Callers

nothing calls this directly

Calls 15

getBinaryTypeIndexFunction · 0.85
writeStringBinaryFunction · 0.85
writeVarUIntFunction · 0.85
getNestedTypeMethod · 0.80
getArgumentTypesMethod · 0.80
getArgumentsDataTypesMethod · 0.80
getCustomNameMethod · 0.80
writeBinaryFunction · 0.50
writeMethod · 0.45
getScaleMethod · 0.45
getNMethod · 0.45
getElementsMethod · 0.45

Tested by

no test coverage detected