summaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Functions/JSONPath/Parsers/ParserJSONPathQuery.cpp
diff options
context:
space:
mode:
authorvitalyisaev <[email protected]>2023-11-14 09:58:56 +0300
committervitalyisaev <[email protected]>2023-11-14 10:20:20 +0300
commitc2b2dfd9827a400a8495e172a56343462e3ceb82 (patch)
treecd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Functions/JSONPath/Parsers/ParserJSONPathQuery.cpp
parentd4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff)
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Functions/JSONPath/Parsers/ParserJSONPathQuery.cpp')
-rw-r--r--contrib/clickhouse/src/Functions/JSONPath/Parsers/ParserJSONPathQuery.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Functions/JSONPath/Parsers/ParserJSONPathQuery.cpp b/contrib/clickhouse/src/Functions/JSONPath/Parsers/ParserJSONPathQuery.cpp
new file mode 100644
index 00000000000..d8d633a1ec9
--- /dev/null
+++ b/contrib/clickhouse/src/Functions/JSONPath/Parsers/ParserJSONPathQuery.cpp
@@ -0,0 +1,51 @@
+#include <Functions/JSONPath/ASTs/ASTJSONPathQuery.h>
+#include <Functions/JSONPath/Parsers/ParserJSONPathQuery.h>
+#include <Functions/JSONPath/Parsers/ParserJSONPathRoot.h>
+#include <Functions/JSONPath/Parsers/ParserJSONPathMemberAccess.h>
+#include <Functions/JSONPath/Parsers/ParserJSONPathMemberSquareBracketAccess.h>
+#include <Functions/JSONPath/Parsers/ParserJSONPathRange.h>
+#include <Functions/JSONPath/Parsers/ParserJSONPathStar.h>
+
+namespace DB
+
+{
+/**
+ *
+ * @param pos token iterator
+ * @param query node of ASTJSONPathQuery
+ * @param expected stuff for logging
+ * @return was parse successful
+ */
+bool ParserJSONPathQuery::parseImpl(Pos & pos, ASTPtr & query, Expected & expected)
+{
+ query = std::make_shared<ASTJSONPathQuery>();
+ ParserJSONPathMemberAccess parser_jsonpath_member_access;
+ ParserJSONPathMemberSquareBracketAccess parser_jsonpath_member_square_bracket_access;
+ ParserJSONPathRange parser_jsonpath_range;
+ ParserJSONPathStar parser_jsonpath_star;
+ ParserJSONPathRoot parser_jsonpath_root;
+
+ ASTPtr path_root;
+ if (!parser_jsonpath_root.parse(pos, path_root, expected))
+ {
+ return false;
+ }
+ query->children.push_back(path_root);
+
+ ASTPtr accessor;
+ while (parser_jsonpath_member_access.parse(pos, accessor, expected)
+ || parser_jsonpath_member_square_bracket_access.parse(pos, accessor, expected)
+ || parser_jsonpath_range.parse(pos, accessor, expected)
+ || parser_jsonpath_star.parse(pos, accessor, expected))
+ {
+ if (accessor)
+ {
+ query->children.push_back(accessor);
+ accessor = nullptr;
+ }
+ }
+ /// parsing was successful if we reached the end of query by this point
+ return pos->type == TokenType::EndOfStream;
+}
+
+}