diff --git a/src/Processors/Formats/Impl/BSONEachRowRowInputFormat.cpp b/src/Processors/Formats/Impl/BSONEachRowRowInputFormat.cpp index d70bbd8d9d6..37d92527579 100644 --- a/src/Processors/Formats/Impl/BSONEachRowRowInputFormat.cpp +++ b/src/Processors/Formats/Impl/BSONEachRowRowInputFormat.cpp @@ -11,8 +11,6 @@ namespace DB namespace ErrorCodes { extern const int INCORRECT_DATA; - extern const int CANNOT_READ_ALL_DATA; - extern const int LOGICAL_ERROR; } namespace diff --git a/src/Processors/Formats/Impl/BSONUtils.cpp b/src/Processors/Formats/Impl/BSONUtils.cpp index ae5dd449037..40e4f9e1de7 100644 --- a/src/Processors/Formats/Impl/BSONUtils.cpp +++ b/src/Processors/Formats/Impl/BSONUtils.cpp @@ -1,8 +1,8 @@ #include -#include -#include #include +#include +#include #include #include @@ -15,23 +15,23 @@ namespace DB { +namespace ErrorCodes +{ + extern const int INCORRECT_DATA; +} + namespace BSONUtils { - bool readField( - ReadBuffer & in, - IColumn & column, - char type, - UInt32 & already_read - ) + bool readField(ReadBuffer & in, IColumn & column, char type, UInt32 & already_read) { try { switch (type) { - case BSONDataTypeIndex::DOUBLE: - { - union { + case BSONDataTypeIndex::DOUBLE: { + union + { char buf[BSON_64]; Float64 value; } read_value; @@ -40,15 +40,16 @@ namespace BSONUtils already_read += BSON_64; return true; } - case BSONDataTypeIndex::STRING: - { - union { + case BSONDataTypeIndex::STRING: { + union + { char buf[BSON_32]; UInt32 size; } read_value; in.read(read_value.buf, BSON_32); already_read += BSON_32; - if (read_value.size != 0) { + if (read_value.size != 0) + { String str; str.resize(read_value.size - 1); for (size_t i = 0; i + 1 < read_value.size; ++i) @@ -60,13 +61,13 @@ namespace BSONUtils char str_end; in.read(str_end); - if (str_end != 0) throw Exception("Wrong BSON syntax", ErrorCodes::INCORRECT_DATA); + if (str_end != 0) + throw Exception("Wrong BSON syntax", ErrorCodes::INCORRECT_DATA); } return true; } // case BSONDataTypeIndex::EMB_DOCUMENT: - Not supported - case BSONDataTypeIndex::ARRAY: - { + case BSONDataTypeIndex::ARRAY: { if (in.eof()) return false; @@ -74,7 +75,8 @@ namespace BSONUtils UInt32 arr_size; { - union { + union + { char buf[BSON_32]; UInt32 size; } read_value; @@ -91,14 +93,17 @@ namespace BSONUtils IColumn & nested_column = column_array.getData(); size_t key_index = 0; - for (; already_read - pre_array_size < arr_size; ++key_index) { + for (; already_read - pre_array_size < arr_size; ++key_index) + { char name_byte = 1; - while(name_byte != 0) { + while (name_byte != 0) + { in.read(name_byte); ++already_read; } BSONUtils::readField(in, nested_column, nested_type, already_read); - if (already_read - pre_array_size + 1 >= arr_size) { + if (already_read - pre_array_size + 1 >= arr_size) + { in.read(nested_type); ++already_read; } @@ -109,9 +114,9 @@ namespace BSONUtils } // case BSONDataTypeIndex::BINARY: - Not supported // case BSONDataTypeIndex::UNDEFINED: - Deprecated - case BSONDataTypeIndex::OID: - { - union { + case BSONDataTypeIndex::OID: { + union + { char buf[BSON_128]; UInt128 value; } read_value; @@ -120,9 +125,9 @@ namespace BSONUtils already_read += BSON_128; return true; } - case BSONDataTypeIndex::BOOL: - { - union { + case BSONDataTypeIndex::BOOL: { + union + { char f; UInt8 value; } read_value; @@ -131,9 +136,9 @@ namespace BSONUtils already_read += BSON_8; return true; } - case BSONDataTypeIndex::DATETIME: - { - union { + case BSONDataTypeIndex::DATETIME: { + union + { char buf[BSON_64]; Int64 value; } read_value; @@ -142,8 +147,7 @@ namespace BSONUtils already_read += BSON_64; return true; } - case BSONDataTypeIndex::NULLVALUE: - { + case BSONDataTypeIndex::NULLVALUE: { assert_cast(column).insertData(nullptr, 0); return true; } @@ -152,9 +156,9 @@ namespace BSONUtils // case BSONDataTypeIndex::JAVASCRIPT_CODE: - Not supported // case BSONDataTypeIndex::SYMBOL: - Deprecated // case BSONDataTypeIndex::JAVASCRIPT_CODE_WITH_SCOPE: - Deprecated - case BSONDataTypeIndex::INT32: - { - union { + case BSONDataTypeIndex::INT32: { + union + { char buf[BSON_32]; Int32 value; } read_value; @@ -163,9 +167,9 @@ namespace BSONUtils already_read += BSON_32; return true; } - case BSONDataTypeIndex::UINT64: - { - union { + case BSONDataTypeIndex::UINT64: { + union + { char buf[BSON_64]; UInt64 value; } read_value; @@ -174,9 +178,9 @@ namespace BSONUtils already_read += BSON_64; return true; } - case BSONDataTypeIndex::INT64: - { - union { + case BSONDataTypeIndex::INT64: { + union + { char buf[BSON_64]; Int64 value; } read_value; @@ -185,9 +189,9 @@ namespace BSONUtils already_read += BSON_64; return true; } - case BSONDataTypeIndex::DECIMAL128: - { - union { + case BSONDataTypeIndex::DECIMAL128: { + union + { char buf[BSON_128]; Decimal128 value; } read_value; @@ -196,8 +200,8 @@ namespace BSONUtils already_read += BSON_128; return true; } - // case BSONDataTypeIndex::MIN_KEY: - Not supported - // case BSONDataTypeIndex::MAX_KEY: - Not supported + // case BSONDataTypeIndex::MIN_KEY: - Not supported + // case BSONDataTypeIndex::MAX_KEY: - Not supported } } catch (Exception &) diff --git a/src/Processors/Formats/Impl/BSONUtils.h b/src/Processors/Formats/Impl/BSONUtils.h index ae7e264966f..8b16ac994ff 100644 --- a/src/Processors/Formats/Impl/BSONUtils.h +++ b/src/Processors/Formats/Impl/BSONUtils.h @@ -1,6 +1,8 @@ -#include +#pragma once + #include #include +#include namespace DB @@ -24,31 +26,27 @@ enum BSONDataTypeIndex SYMBOL = 0x0E, JAVASCRIPT_CODE_WITH_SCOPE = 0x0F, INT32 = 0x10, - TIMESTAMP = 0x11, // The same as UINT64 - UINT64 = 0x11, // The same as TIMESTAMP + TIMESTAMP = 0x11, // The same as UINT64 + UINT64 = 0x11, // The same as TIMESTAMP INT64 = 0x12, DECIMAL128 = 0x13, MIN_KEY = 0xFF, MAX_KEY = 0x7F, }; -enum { +enum +{ BSON_TYPE = 1, BSON_ZERO = 1, - BSON_8 = 1, - BSON_32 = 4, - BSON_64 = 8, - BSON_128 = 16, + BSON_8 = 1, + BSON_32 = 4, + BSON_64 = 8, + BSON_128 = 16, }; namespace BSONUtils { - bool readField( - ReadBuffer & in, - IColumn & column, - char type, - UInt32 & already_read - ); + bool readField(ReadBuffer & in, IColumn & column, char type, UInt32 & already_read); } }