improve lib cmakefiles, add state docs and minor changes

This commit is contained in:
Arthur Passos 2022-12-15 09:47:36 -03:00
parent e1c6d15714
commit 383e9264b7
5 changed files with 18 additions and 11 deletions

View File

@ -1,4 +1,8 @@
add_library(clickhouse_functions_extractkeyvaluepairs KeyValuePairExtractor.h impl/state/KeyStateHandler.cpp impl/state/KeyStateHandler.h impl/state/State.h impl/state/ValueStateHandler.cpp impl/state/ValueStateHandler.h impl/state/StateHandler.cpp impl/state/StateHandler.h impl/SimpleKeyValuePairEscapingProcessor.h impl/SimpleKeyValuePairEscapingProcessor.cpp KeyValuePairExtractorBuilder.h KeyValuePairEscapingProcessor.h)
include("${ClickHouse_SOURCE_DIR}/cmake/dbms_glob_sources.cmake")
add_headers_and_sources(clickhouse_functions_extractkeyvaluepairs .)
add_headers_and_sources(clickhouse_functions_extractkeyvaluepairs impl)
add_headers_and_sources(clickhouse_functions_extractkeyvaluepairs impl/state)
add_library(clickhouse_functions_extractkeyvaluepairs ${clickhouse_functions_extractkeyvaluepairs_sources} ${clickhouse_functions_extractkeyvaluepairs_headers})
target_link_libraries(clickhouse_functions_extractkeyvaluepairs PRIVATE dbms)

View File

@ -26,7 +26,7 @@ struct KeyValuePairExtractor
virtual ~KeyValuePairExtractor() = default;
virtual Response extract(const std::string & file) = 0;
virtual Response extract(const std::string & data) = 0;
};
}

View File

@ -60,7 +60,7 @@ public:
if (!escaping_processor)
{
throw std::runtime_error{"Escaping processor must be set, cannot build KeyValuePairExtractor without one"};
throw DB::Exception(ErrorCodes::LOGICAL_ERROR, "Escaping processor must be set, cannot build KeyValuePairExtractor without one");
}
return std::make_shared<LazyEscapingKeyValuePairExtractor<Response>>(key_state_handler, value_state_handler, escaping_processor);

View File

@ -42,7 +42,7 @@ public:
{
auto next_state = processState(file, pos, state);
pos = next_state.pos;
pos = next_state.position_in_string;
state = next_state.state;
}

View File

@ -7,28 +7,31 @@ namespace DB
enum State
{
// Skip characters until it finds a valid first key character. Might jump to READING_KEY, READING_ENCLOSED_KEY or END.
WAITING_KEY,
// Tries to read a key. Might jump to WAITING_KEY, WAITING_VALUE or END.
READING_KEY,
// Tries to read an enclosed/ quoted key. Might jump to WAITING_KEY, READING_KV_DELIMITER or END.
READING_ENCLOSED_KEY,
// Tries to read the key value pair delimiter. Might jump to WAITING_KEY, WAITING_VALUE or END.
READING_KV_DELIMITER,
// Skip characters until it finds a valid first value character. Might jump to READING_ENCLOSED_VALUE, READING_EMPTY_VALUE or READING_VALUE.
WAITING_VALUE,
// Tries to read a value. Jumps to FLUSH_PAIR.
READING_VALUE,
// Tries to read an enclosed/ quoted value. Might jump to FLUSH_PAIR or END.
READING_ENCLOSED_VALUE,
// "Reads" an empty value. Jumps to FLUSH_PAIR.
READING_EMPTY_VALUE,
// In this state, both key and value have already been collected and should be flushed. Might jump to WAITING_KEY or END.
FLUSH_PAIR,
END
};
struct NextState
{
std::size_t pos;
std::size_t position_in_string;
State state;
};
struct NextStateWithElement
{
NextState state;
std::string_view element;
};
}