Commit 7d0afaf 1 parent 404c4dd commit 7d0afaf Copy full SHA for 7d0afaf
File tree 5 files changed +46
-74
lines changed
5 files changed +46
-74
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -379,4 +379,49 @@ struct JsonSizeFunction {
379
379
}
380
380
};
381
381
382
+ // / json_array_length(jsonString) -> length
383
+ // /
384
+ // / Returns the number of elements in the outermost JSON array from jsonString.
385
+ // / If jsonString is not a valid JSON array or NULL, the function returns null.
386
+ // / Presto:
387
+ // / https://prestodb.io/docs/current/functions/json.html#json_array_length-json-bigint
388
+ // / SparkSQL:
389
+ // / https://spark.apache.org/docs/latest/api/sql/index.html#json_array_length
390
+ template <typename T>
391
+ struct JsonArrayLengthFunction {
392
+ VELOX_DEFINE_FUNCTION_TYPES (T);
393
+
394
+ template <typename TOutput>
395
+ FOLLY_ALWAYS_INLINE bool call (TOutput& len, const arg_type<Json>& json) {
396
+ simdjson::ondemand::document jsonDoc;
397
+
398
+ simdjson::padded_string paddedJson (json.data (), json.size ());
399
+ if (simdjsonParse (paddedJson).get (jsonDoc)) {
400
+ return false ;
401
+ }
402
+ if (jsonDoc.type ().error ()) {
403
+ return false ;
404
+ }
405
+
406
+ if (jsonDoc.type () != simdjson::ondemand::json_type::array) {
407
+ return false ;
408
+ }
409
+
410
+ size_t numElements;
411
+ if (jsonDoc.count_elements ().get (numElements)) {
412
+ return false ;
413
+ }
414
+
415
+ VELOX_USER_CHECK_LE (
416
+ numElements,
417
+ std::numeric_limits<TOutput>::max (),
418
+ " The json array length {} is bigger than the max value of output type {}." ,
419
+ numElements,
420
+ std::numeric_limits<TOutput>::max ());
421
+
422
+ len = numElements;
423
+ return true ;
424
+ }
425
+ };
426
+
382
427
} // namespace facebook::velox::functions
Original file line number Diff line number Diff line change 20
20
#include < folly/Benchmark.h>
21
21
#include < folly/init/Init.h>
22
22
#include " velox/functions/Registerer.h"
23
- #include " velox/functions/lib/JsonArrayLength.h"
24
23
#include " velox/functions/lib/benchmarks/FunctionBenchmarkBase.h"
25
24
#include " velox/functions/prestosql/JsonFunctions.h"
26
25
#include " velox/functions/prestosql/json/JsonExtractor.h"
Original file line number Diff line number Diff line change 15
15
*/
16
16
17
17
#include " velox/functions/Registerer.h"
18
- #include " velox/functions/lib/JsonArrayLength.h"
19
18
#include " velox/functions/prestosql/JsonFunctions.h"
20
19
#include " velox/functions/prestosql/types/JsonRegistration.h"
21
20
Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
- #include " velox/functions/lib/JsonArrayLength.h"
18
17
#include " velox/functions/lib/RegistrationHelpers.h"
18
+ #include " velox/functions/prestosql/JsonFunctions.h"
19
19
#include " velox/functions/sparksql/GetJsonObject.h"
20
20
#include " velox/functions/sparksql/JsonObjectKeys.h"
21
21
You can’t perform that action at this time.
0 commit comments