From 46ef387ce338cbf537a19b0bb9662528328ef99e Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 17 Sep 2018 23:35:21 +0300 Subject: [PATCH] Style #3144 --- .../src/Formats/JSONEachRowRowInputStream.cpp | 20 +++++++++---------- dbms/src/Formats/JSONEachRowRowInputStream.h | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dbms/src/Formats/JSONEachRowRowInputStream.cpp b/dbms/src/Formats/JSONEachRowRowInputStream.cpp index 781c374d571..8da319be00b 100644 --- a/dbms/src/Formats/JSONEachRowRowInputStream.cpp +++ b/dbms/src/Formats/JSONEachRowRowInputStream.cpp @@ -37,10 +37,10 @@ JSONEachRowRowInputStream::JSONEachRowRowInputStream(ReadBuffer & istr_, const B { const String& colname = columnName(i); name_map[colname] = i; /// NOTE You could place names more cache-locally. - if ( format_settings.import_nested_json ) + if (format_settings.import_nested_json) { const auto splitted = Nested::splitName(colname); - if ( ! splitted.second.empty() ) + if (!splitted.second.empty()) { const StringRef table_name(colname.data(), splitted.first.size()); name_map[table_name] = NESTED_FIELD; @@ -64,7 +64,7 @@ size_t JSONEachRowRowInputStream::columnIndex(const StringRef& name) const } /** Read the field name and convert it to column name - * (taking into account the current nested name prefix) + * (taking into account the current nested name prefix) */ StringRef JSONEachRowRowInputStream::readColumnName(ReadBuffer & buf) { @@ -97,7 +97,7 @@ static void skipColonDelimeter(ReadBuffer & istr) skipWhitespaceIfAny(istr); } -void JSONEachRowRowInputStream::skipUnknownField(const StringRef& name_ref) +void JSONEachRowRowInputStream::skipUnknownField(const StringRef & name_ref) { if (!format_settings.skip_unknown_fields) throw Exception("Unknown field found while parsing JSONEachRow format: " + name_ref.toString(), ErrorCodes::INCORRECT_DATA); @@ -110,8 +110,6 @@ void JSONEachRowRowInputStream::readField(size_t index, MutableColumns & columns if (read_columns[index]) throw Exception("Duplicate field found while parsing JSONEachRow format: " + columnName(index), ErrorCodes::INCORRECT_DATA); - read_columns[index] = true; - try { header.getByPosition(index).type->deserializeTextJSON(*columns[index], istr, format_settings); @@ -121,6 +119,8 @@ void JSONEachRowRowInputStream::readField(size_t index, MutableColumns & columns e.addMessage("(while read the value of key " + columnName(index) + ")"); throw; } + + read_columns[index] = true; } bool JSONEachRowRowInputStream::advanceToNextKey(size_t key_index) @@ -147,23 +147,23 @@ void JSONEachRowRowInputStream::readJSONObject(MutableColumns & columns) { assertChar('{', istr); - for ( size_t key_index = 0 ; advanceToNextKey(key_index) ; ++key_index ) + for (size_t key_index = 0; advanceToNextKey(key_index); ++key_index) { StringRef name_ref = readColumnName(istr); skipColonDelimeter(istr); const size_t column_index = columnIndex(name_ref); - if ( column_index == UNKNOWN_FIELD ) + if (column_index == UNKNOWN_FIELD) skipUnknownField(name_ref); - else if ( column_index == NESTED_FIELD ) + else if (column_index == NESTED_FIELD) readNestedData(name_ref.toString(), columns); else readField(column_index, columns); } } -void JSONEachRowRowInputStream::readNestedData(const String& name, MutableColumns & columns) +void JSONEachRowRowInputStream::readNestedData(const String & name, MutableColumns & columns) { current_column_name = name; current_column_name.push_back('.'); diff --git a/dbms/src/Formats/JSONEachRowRowInputStream.h b/dbms/src/Formats/JSONEachRowRowInputStream.h index c23d398400a..33b745082f8 100644 --- a/dbms/src/Formats/JSONEachRowRowInputStream.h +++ b/dbms/src/Formats/JSONEachRowRowInputStream.h @@ -27,14 +27,14 @@ class JSONEachRowRowInputStream : public IRowInputStream void syncAfterError() override; private: - const String& columnName(size_t i) const; - size_t columnIndex(const StringRef& name) const; + const String & columnName(size_t i) const; + size_t columnIndex(const StringRef & name) const; bool advanceToNextKey(size_t key_index); - void skipUnknownField(const StringRef& name_ref); + void skipUnknownField(const StringRef & name_ref); StringRef readColumnName(ReadBuffer & buf); void readField(size_t index, MutableColumns & columns); void readJSONObject(MutableColumns & columns); - void readNestedData(const String& name, MutableColumns & columns); + void readNestedData(const String & name, MutableColumns & columns); private: ReadBuffer & istr; @@ -55,7 +55,7 @@ class JSONEachRowRowInputStream : public IRowInputStream /// the nested column names are 'n.i' and 'n.s' and the nested prefix is 'n.' size_t nested_prefix_length = 0; - std::vector read_columns; + std::vector read_columns; /// Hash table match `field name -> position in the block`. NOTE You can use perfect hash map. using NameMap = HashMap;