Skip to content

Commit 56fd07c

Browse files
peterenescufacebook-github-bot
authored andcommitted
fix(array functions): Add support to array_has_duplicates for input of type json (facebookincubator#12158)
Summary: Minor update to function array_has_duplicates which registers json as input in array registration file. No need to cast input as json is already treated as a varchar. Reviewed By: kgpai Differential Revision: D68580104
1 parent c86c6b8 commit 56fd07c

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

velox/functions/prestosql/registration/ArrayFunctionsRegistration.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ void registerArrayFunctions(const std::string& prefix) {
316316
registerArrayHasDuplicatesFunctions<int64_t>(prefix);
317317
registerArrayHasDuplicatesFunctions<int128_t>(prefix);
318318
registerArrayHasDuplicatesFunctions<Varchar>(prefix);
319+
registerArrayHasDuplicatesFunctions<Json>(prefix);
319320

320321
registerArrayFrequencyFunctions<bool>(prefix);
321322
registerArrayFrequencyFunctions<int8_t>(prefix);

velox/functions/prestosql/tests/ArrayHasDuplicatesTest.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <optional>
1818
#include "velox/functions/prestosql/tests/utils/FunctionBaseTest.h"
19+
#include "velox/functions/prestosql/types/JsonType.h"
1920

2021
using namespace facebook::velox;
2122
using namespace facebook::velox::test;
@@ -145,3 +146,40 @@ TEST_F(ArrayHasDuplicatesTest, nullFreeStrings) {
145146
auto expected = makeFlatVector<bool>({false, true, false, true});
146147
testExpr(expected, "array_has_duplicates(C0)", {array});
147148
}
149+
150+
TEST_F(ArrayHasDuplicatesTest, json) {
151+
auto arrayVector = makeNullableArrayVector<StringView>(
152+
{{R"({"key":"value"})", R"({"key":"value"})"}}, ARRAY(JSON()));
153+
testExpr(
154+
makeFlatVector<bool>(true), "array_has_duplicates(C0)", {arrayVector});
155+
156+
auto test = makeNullableArrayVector<StringView>(
157+
{{R"({"key":"value"})", R"({"key":"another_value"})"},
158+
{R"({"key":"value"})"},
159+
{R"({"key":"same_value"})",
160+
R"({"key":"another_value"})",
161+
R"({"key":"same_value"})"},
162+
{std::nullopt, std::nullopt},
163+
{R"({"key":"value"})",
164+
R"({"key":"another_value"})",
165+
R"({"another_key":"value"})"},
166+
{R"({"key": "value\with\backslash"})",
167+
R"({"key": "value\with\backslash"})"},
168+
{R"({"key": "value\nwith\nnewline"})",
169+
R"({"key": "value\nwith\nnewline"})"},
170+
{R"({"key": "value with \u00A9 and \u20AC"})",
171+
R"({"key": "value with \u00A9 and \u20AC"})"},
172+
{R"({"key": "!@#$%^&*()_+-={}:<>?,./~`"})",
173+
R"({"key": "!@#$%^&*()_+-={}:<>?,./~`"})"},
174+
{R"({"key":"value"})",
175+
std::nullopt,
176+
R"({"key":"another_value"})",
177+
R"({"another_key":"value"})",
178+
std::nullopt}},
179+
ARRAY(JSON()));
180+
testExpr(
181+
makeFlatVector<bool>(
182+
{false, false, true, true, false, true, true, true, true, true}),
183+
"array_has_duplicates(C0)",
184+
{test});
185+
}

0 commit comments

Comments
 (0)