Skip to content

Commit

Permalink
Rename prestosql/SIMDJsonXxx structs to JsonXxx (facebookincubator#10070
Browse files Browse the repository at this point in the history
)

Summary:
Pull Request resolved: facebookincubator#10070

We no longer have two versions of json functions. We replaced all(*) folly-based
functions with simdjson. Hence, no need for SIMD prefix.

(*) The only json function that still uses folly is json_format. That's because simdjson library only supports parsing JSON.

Reviewed By: Yuhta

Differential Revision: D58206474

fbshipit-source-id: db6cab7c934b8efde61195857425d4ce5a4f3aae
  • Loading branch information
mbasmanova authored and facebook-github-bot committed Jun 6, 2024
1 parent 72f470b commit 82cad27
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace facebook::velox::functions {

template <typename T>
struct SIMDIsJsonScalarFunction {
struct IsJsonScalarFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE Status call(bool& result, const arg_type<Json>& json) {
Expand All @@ -52,7 +52,7 @@ struct SIMDIsJsonScalarFunction {
};

template <typename TExec>
struct SIMDJsonArrayContainsFunction {
struct JsonArrayContainsFunction {
VELOX_DEFINE_FUNCTION_TYPES(TExec);

template <typename T>
Expand Down Expand Up @@ -122,7 +122,7 @@ struct SIMDJsonArrayContainsFunction {
};

template <typename T>
struct SIMDJsonArrayLengthFunction {
struct JsonArrayLengthFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE bool call(int64_t& len, const arg_type<Json>& json) {
Expand All @@ -148,7 +148,7 @@ struct SIMDJsonArrayLengthFunction {
};

template <typename TExec>
struct SIMDJsonArrayGetFunction {
struct JsonArrayGetFunction {
VELOX_DEFINE_FUNCTION_TYPES(TExec);

FOLLY_ALWAYS_INLINE bool
Expand Down Expand Up @@ -194,7 +194,7 @@ struct SIMDJsonArrayGetFunction {
// to being encoded as JSON). The value referenced by json_path must be a scalar
// (boolean, number or string)
template <typename T>
struct SIMDJsonExtractScalarFunction {
struct JsonExtractScalarFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE bool call(
Expand Down Expand Up @@ -257,7 +257,7 @@ struct SIMDJsonExtractScalarFunction {
};

template <typename T>
struct SIMDJsonExtractFunction {
struct JsonExtractFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

bool call(
Expand Down Expand Up @@ -337,7 +337,7 @@ struct SIMDJsonExtractFunction {
};

template <typename T>
struct SIMDJsonSizeFunction {
struct JsonSizeFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE bool call(
Expand Down
55 changes: 25 additions & 30 deletions velox/functions/prestosql/benchmarks/JsonExprBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
#include <folly/init/Init.h>
#include "velox/functions/Registerer.h"
#include "velox/functions/lib/benchmarks/FunctionBenchmarkBase.h"
#include "velox/functions/prestosql/SIMDJsonFunctions.h"
#include "velox/functions/prestosql/JsonFunctions.h"
#include "velox/functions/prestosql/json/JsonExtractor.h"
#include "velox/functions/prestosql/types/JsonType.h"

namespace facebook::velox::functions::prestosql {
namespace {

template <typename T>
struct IsJsonScalarFunction {
struct FollyIsJsonScalarFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE void call(bool& result, const arg_type<Json>& json) {
Expand All @@ -45,7 +45,7 @@ struct IsJsonScalarFunction {
// to being encoded as JSON). The value referenced by json_path must be a scalar
// (boolean, number or string)
template <typename T>
struct JsonExtractScalarFunction {
struct FollyJsonExtractScalarFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE bool call(
Expand All @@ -59,15 +59,14 @@ struct JsonExtractScalarFunction {
if (extractResult.hasValue()) {
UDFOutputString::assign(result, *extractResult);
return true;

} else {
return false;
}
}
};

template <typename T>
struct JsonExtractFunction {
struct FollyJsonExtractFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE bool call(
Expand All @@ -91,7 +90,7 @@ struct JsonExtractFunction {
};

template <typename T>
struct JsonArrayLengthFunction {
struct FollyJsonArrayLengthFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE bool call(int64_t& result, const arg_type<Json>& json) {
Expand All @@ -106,7 +105,7 @@ struct JsonArrayLengthFunction {
};

template <typename T>
struct JsonArrayContainsFunction {
struct FollyJsonArrayContainsFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

template <typename TInput>
Expand Down Expand Up @@ -146,7 +145,7 @@ struct JsonArrayContainsFunction {
};

template <typename T>
struct JsonSizeFunction {
struct FollyJsonSizeFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE bool call(
Expand Down Expand Up @@ -177,30 +176,28 @@ class JsonBenchmark : public velox::functions::test::FunctionBenchmarkBase {
public:
JsonBenchmark() : FunctionBenchmarkBase() {
registerJsonType();
registerFunction<IsJsonScalarFunction, bool, Json>(
registerFunction<IsJsonScalarFunction, bool, Json>({"is_json_scalar"});
registerFunction<FollyIsJsonScalarFunction, bool, Json>(
{"folly_is_json_scalar"});
registerFunction<SIMDIsJsonScalarFunction, bool, Json>(
{"simd_is_json_scalar"});
registerFunction<JsonArrayContainsFunction, bool, Json, bool>(
{"json_array_contains"});
registerFunction<FollyJsonArrayContainsFunction, bool, Json, bool>(
{"folly_json_array_contains"});
registerFunction<SIMDJsonArrayContainsFunction, bool, Json, bool>(
{"simd_json_array_contains"});
registerFunction<JsonArrayLengthFunction, int64_t, Json>(
{"json_array_length"});
registerFunction<FollyJsonArrayLengthFunction, int64_t, Json>(
{"folly_json_array_length"});
registerFunction<SIMDJsonArrayLengthFunction, int64_t, Json>(
{"simd_json_array_length"});
registerFunction<JsonExtractScalarFunction, Varchar, Json, Varchar>(
{"json_extract_scalar"});
registerFunction<FollyJsonExtractScalarFunction, Varchar, Json, Varchar>(
{"folly_json_extract_scalar"});
registerFunction<SIMDJsonExtractScalarFunction, Varchar, Json, Varchar>(
{"simd_json_extract_scalar"});
registerFunction<JsonExtractFunction, Varchar, Json, Varchar>(
{"json_extract"});
registerFunction<FollyJsonExtractFunction, Varchar, Json, Varchar>(
{"folly_json_extract"});
registerFunction<SIMDJsonExtractFunction, Varchar, Json, Varchar>(
{"simd_json_extract"});
registerFunction<JsonSizeFunction, int64_t, Json, Varchar>(
registerFunction<JsonSizeFunction, int64_t, Json, Varchar>({"json_size"});
registerFunction<FollyJsonSizeFunction, int64_t, Json, Varchar>(
{"folly_json_size"});
registerFunction<SIMDJsonSizeFunction, int64_t, Json, Varchar>(
{"simd_json_size"});
}

std::string prepareData(int jsonSize) {
Expand Down Expand Up @@ -298,7 +295,7 @@ void SIMDIsJsonScalar(int iter, int vectorSize, int jsonSize) {
JsonBenchmark benchmark;
auto json = benchmark.prepareData(jsonSize);
suspender.dismiss();
benchmark.runWithJson(iter, vectorSize, "simd_is_json_scalar", json);
benchmark.runWithJson(iter, vectorSize, "is_json_scalar", json);
}

void FollyJsonArrayContains(int iter, int vectorSize, int jsonSize) {
Expand All @@ -315,8 +312,7 @@ void SIMDJsonArrayContains(int iter, int vectorSize, int jsonSize) {
JsonBenchmark benchmark;
auto json = benchmark.prepareData(jsonSize);
suspender.dismiss();
benchmark.runWithJsonContains(
iter, vectorSize, "simd_json_array_contains", json);
benchmark.runWithJsonContains(iter, vectorSize, "json_array_contains", json);
}

void FollyJsonArrayLength(int iter, int vectorSize, int jsonSize) {
Expand All @@ -332,7 +328,7 @@ void SIMDJsonArrayLength(int iter, int vectorSize, int jsonSize) {
JsonBenchmark benchmark;
auto json = benchmark.prepareData(jsonSize);
suspender.dismiss();
benchmark.runWithJson(iter, vectorSize, "simd_json_array_length", json);
benchmark.runWithJson(iter, vectorSize, "json_array_length", json);
}

void FollyJsonExtractScalar(int iter, int vectorSize, int jsonSize) {
Expand All @@ -350,7 +346,7 @@ void SIMDJsonExtractScalar(int iter, int vectorSize, int jsonSize) {
auto json = benchmark.prepareData(jsonSize);
suspender.dismiss();
benchmark.runWithJsonExtract(
iter, vectorSize, "simd_json_extract_scalar", json, "$.key[7].k1");
iter, vectorSize, "json_extract_scalar", json, "$.key[7].k1");
}

void FollyJsonExtract(int iter, int vectorSize, int jsonSize) {
Expand All @@ -368,7 +364,7 @@ void SIMDJsonExtract(int iter, int vectorSize, int jsonSize) {
auto json = benchmark.prepareData(jsonSize);
suspender.dismiss();
benchmark.runWithJsonExtract(
iter, vectorSize, "simd_json_extract", json, "$.key[*].k1");
iter, vectorSize, "json_extract", json, "$.key[*].k1");
}

void FollyJsonSize(int iter, int vectorSize, int jsonSize) {
Expand All @@ -385,8 +381,7 @@ void SIMDJsonSize(int iter, int vectorSize, int jsonSize) {
JsonBenchmark benchmark;
auto json = benchmark.prepareData(jsonSize);
suspender.dismiss();
benchmark.runWithJsonExtract(
iter, vectorSize, "simd_json_size", json, "$.key");
benchmark.runWithJsonExtract(iter, vectorSize, "json_size", json, "$.key");
}

BENCHMARK_DRAW_LINE();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,57 @@
*/

#include "velox/functions/Registerer.h"
#include "velox/functions/prestosql/SIMDJsonFunctions.h"
#include "velox/functions/prestosql/JsonFunctions.h"

namespace facebook::velox::functions {
void registerJsonFunctions(const std::string& prefix) {
registerJsonType();

registerFunction<SIMDIsJsonScalarFunction, bool, Json>(
registerFunction<IsJsonScalarFunction, bool, Json>(
{prefix + "is_json_scalar"});
registerFunction<SIMDIsJsonScalarFunction, bool, Varchar>(
registerFunction<IsJsonScalarFunction, bool, Varchar>(
{prefix + "is_json_scalar"});

registerFunction<SIMDJsonExtractScalarFunction, Varchar, Json, Varchar>(
registerFunction<JsonExtractScalarFunction, Varchar, Json, Varchar>(
{prefix + "json_extract_scalar"});
registerFunction<SIMDJsonExtractScalarFunction, Varchar, Varchar, Varchar>(
registerFunction<JsonExtractScalarFunction, Varchar, Varchar, Varchar>(
{prefix + "json_extract_scalar"});

registerFunction<SIMDJsonExtractFunction, Json, Json, Varchar>(
registerFunction<JsonExtractFunction, Json, Json, Varchar>(
{prefix + "json_extract"});
registerFunction<SIMDJsonExtractFunction, Json, Varchar, Varchar>(
registerFunction<JsonExtractFunction, Json, Varchar, Varchar>(
{prefix + "json_extract"});

registerFunction<SIMDJsonArrayLengthFunction, int64_t, Json>(
registerFunction<JsonArrayLengthFunction, int64_t, Json>(
{prefix + "json_array_length"});
registerFunction<SIMDJsonArrayLengthFunction, int64_t, Varchar>(
registerFunction<JsonArrayLengthFunction, int64_t, Varchar>(
{prefix + "json_array_length"});

registerFunction<SIMDJsonArrayContainsFunction, bool, Json, bool>(
registerFunction<JsonArrayContainsFunction, bool, Json, bool>(
{prefix + "json_array_contains"});
registerFunction<SIMDJsonArrayContainsFunction, bool, Varchar, bool>(
registerFunction<JsonArrayContainsFunction, bool, Varchar, bool>(
{prefix + "json_array_contains"});
registerFunction<SIMDJsonArrayContainsFunction, bool, Json, int64_t>(
registerFunction<JsonArrayContainsFunction, bool, Json, int64_t>(
{prefix + "json_array_contains"});
registerFunction<SIMDJsonArrayContainsFunction, bool, Varchar, int64_t>(
registerFunction<JsonArrayContainsFunction, bool, Varchar, int64_t>(
{prefix + "json_array_contains"});
registerFunction<SIMDJsonArrayContainsFunction, bool, Json, double>(
registerFunction<JsonArrayContainsFunction, bool, Json, double>(
{prefix + "json_array_contains"});
registerFunction<SIMDJsonArrayContainsFunction, bool, Varchar, double>(
registerFunction<JsonArrayContainsFunction, bool, Varchar, double>(
{prefix + "json_array_contains"});
registerFunction<SIMDJsonArrayContainsFunction, bool, Json, Varchar>(
registerFunction<JsonArrayContainsFunction, bool, Json, Varchar>(
{prefix + "json_array_contains"});
registerFunction<SIMDJsonArrayContainsFunction, bool, Varchar, Varchar>(
registerFunction<JsonArrayContainsFunction, bool, Varchar, Varchar>(
{prefix + "json_array_contains"});

registerFunction<SIMDJsonArrayGetFunction, Json, Json, int64_t>(
registerFunction<JsonArrayGetFunction, Json, Json, int64_t>(
{prefix + "json_array_get"});
registerFunction<SIMDJsonArrayGetFunction, Json, Varchar, int64_t>(
registerFunction<JsonArrayGetFunction, Json, Varchar, int64_t>(
{prefix + "json_array_get"});

registerFunction<SIMDJsonSizeFunction, int64_t, Json, Varchar>(
registerFunction<JsonSizeFunction, int64_t, Json, Varchar>(
{prefix + "json_size"});
registerFunction<SIMDJsonSizeFunction, int64_t, Varchar, Varchar>(
registerFunction<JsonSizeFunction, int64_t, Varchar, Varchar>(
{prefix + "json_size"});

VELOX_REGISTER_VECTOR_FUNCTION(udf_json_format, prefix + "json_format");
Expand Down

0 comments on commit 82cad27

Please sign in to comment.