Skip to content

Commit

Permalink
Update JSON array tail function
Browse files Browse the repository at this point in the history
  • Loading branch information
PhictionalOne committed Mar 4, 2024
1 parent 048d08d commit afe96d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions extension/json/json_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ vector<ScalarFunctionSet> JSONFunctions::GetScalarFunctions() {
functions.push_back(GetSerializeSqlFunction());
functions.push_back(GetDeserializeSqlFunction());

functions.push_back(GetArrayTailFunction());
functions.push_back(GetArrayAppendFunction());
functions.push_back(GetObjectAddFunction());
return functions;
Expand Down
27 changes: 14 additions & 13 deletions extension/json/json_functions/json_array_tail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

namespace duckdb {

yyjson_mut_val *JSONArrayTail(yyjson_mut_val *arr, yyjson_mut_doc *doc, yyjson_alc *alc, Vector &result) {
if (!yyjson_mut_is_arr(arr)) {
throw InvalidInputException("JSON input not an JSON Array");
}

if (yyjson_mut_arr_size(arr) == 0) {
return yyjson_mut_arr(doc);
}

yyjson_mut_arr_remove_first(arr);
return arr;
}

static void ArrayTailFunction(DataChunk &args, ExpressionState &state, Vector &result) {
JSONExecutors::UnaryMutExecute(args, state, result,
[](yyjson_mut_val *arr, yyjson_mut_doc *doc, yyjson_alc *alc, Vector &result) {
if (!yyjson_mut_is_arr(arr)) {
throw InvalidInputException("JSON input not an JSON Array");
}

if (yyjson_mut_arr_size(arr) == 0) {
return yyjson_mut_arr(doc);
}

yyjson_mut_arr_remove_first(arr);
return arr;
});
JSONExecutors::UnaryMutExecute(args, state, result, JSONArrayTail);
}

static void GetArrayTailFunctionInternal(ScalarFunctionSet &set, const LogicalType &input_type) {
Expand Down

0 comments on commit afe96d4

Please sign in to comment.