From 261f10f4d02edb74032106c578e1ac3c8ac4a471 Mon Sep 17 00:00:00 2001 From: Lorenzo Mangani Date: Wed, 23 Oct 2024 23:53:32 +0200 Subject: [PATCH] dictGet emulation with Variables ``` D SET VARIABLE my_map = MAP {'k1': 10, 'k2': 20}; D SELECT dictGet('my_map', 'k1'); ``` --- chsql/src/chsql_extension.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chsql/src/chsql_extension.cpp b/chsql/src/chsql_extension.cpp index 61bddbb..b775f2f 100644 --- a/chsql/src/chsql_extension.cpp +++ b/chsql/src/chsql_extension.cpp @@ -142,6 +142,9 @@ static DefaultMacro chsql_macros[] = { {DEFAULT_SCHEMA, "generateUUIDv4", {nullptr}, {{nullptr, nullptr}}, R"(toString(uuid()))"}, {DEFAULT_SCHEMA, "parseURL", {"url", "part", nullptr}, {{nullptr, nullptr}}, R"(CASE part WHEN 'protocol' THEN REGEXP_EXTRACT(url, '^(\w+)://') WHEN 'domain' THEN REGEXP_EXTRACT(url, '://([^/:]+)') WHEN 'port' THEN REGEXP_EXTRACT(url, ':(\d+)') WHEN 'path' THEN REGEXP_EXTRACT(url, '://[^/]+(/.+?)(\?|#|$)') WHEN 'query' THEN REGEXP_EXTRACT(url, '\?([^#]+)') WHEN 'fragment' THEN REGEXP_EXTRACT(url, '#(.+)$') END)"}, {DEFAULT_SCHEMA, "bitCount", {"num", nullptr}, {{nullptr, nullptr}}, R"(BIT_COUNT(num))"}, + // Dictionary Emulation using MAP VARIABLES + {DEFAULT_SCHEMA, "dictGet", {"dict","attr", nullptr}, {{nullptr, nullptr}}, R"(getvariable(dict)[attr][1])"}, + // -- End Macro {nullptr, nullptr, {nullptr}, {{nullptr, nullptr}}, nullptr}}; // To add a new table SQL macro, add a new macro to this array!