Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-milovidov committed Sep 17, 2018
1 parent 8852660 commit 46ef387
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions dbms/src/Formats/JSONEachRowRowInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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('.');
Expand Down
10 changes: 5 additions & 5 deletions dbms/src/Formats/JSONEachRowRowInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<bool> read_columns;
std::vector<UInt8> read_columns;

/// Hash table match `field name -> position in the block`. NOTE You can use perfect hash map.
using NameMap = HashMap<StringRef, size_t, StringRefHash>;
Expand Down

0 comments on commit 46ef387

Please sign in to comment.