[feature](jsonb) jsonb functions (#13366)

Issue Number: Step3 of DSIP-016: Support JSON type
This commit is contained in:
Kang
2022-10-19 08:44:08 +08:00
committed by GitHub
parent ac037e57f5
commit 755a946516
7 changed files with 1286 additions and 70 deletions

View File

@ -35,7 +35,7 @@ TEST(FunctionJsonbTEST, JsonbParseTest) {
{{STRING("false")}, STRING("false")},
{{STRING("100")}, STRING("100")}, //int8
{{STRING("10000")}, STRING("10000")}, // int16
{{STRING("1073741820")}, STRING("1073741820")}, // int32
{{STRING("1000000000")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18")}, STRING("6.18")}, // double
{{STRING(R"("abcd")")}, STRING(R"("abcd")")}, // string
@ -56,37 +56,37 @@ TEST(FunctionJsonbTEST, JsonbParseTest) {
DataSet data_set_invalid = {
{{STRING("abc")}, Null()}, // invalid string
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("'abc'")}, Null()}, // invalid string
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("100x")}, Null()}, // invalid int
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("6.a8")}, Null()}, // invalid double
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("{x")}, Null()}, // invalid object
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("[123, abc]")}, Null()} // invalid array
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
}
@ -100,7 +100,7 @@ TEST(FunctionJsonbTEST, JsonbParseErrorToNullTest) {
{{STRING("false")}, STRING("false")},
{{STRING("100")}, STRING("100")}, //int8
{{STRING("10000")}, STRING("10000")}, // int16
{{STRING("1073741820")}, STRING("1073741820")}, // int32
{{STRING("1000000000")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18")}, STRING("6.18")}, // double
{{STRING(R"("abcd")")}, STRING(R"("abcd")")}, // string
@ -135,7 +135,7 @@ TEST(FunctionJsonbTEST, JsonbParseErrorToValueTest) {
{{STRING("false"), STRING("{}")}, STRING("false")},
{{STRING("100"), STRING("{}")}, STRING("100")}, //int8
{{STRING("10000"), STRING("{}")}, STRING("10000")}, // int16
{{STRING("1073741820"), STRING("{}")}, STRING("1073741820")}, // int32
{{STRING("1000000000"), STRING("{}")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976"), STRING("{}")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18"), STRING("{}")}, STRING("6.18")}, // double
{{STRING(R"("abcd")"), STRING("{}")}, STRING(R"("abcd")")}, // string
@ -173,7 +173,7 @@ TEST(FunctionJsonbTEST, JsonbParseErrorToInvalidTest) {
{{STRING("false")}, STRING("false")},
{{STRING("100")}, STRING("100")}, //int8
{{STRING("10000")}, STRING("10000")}, // int16
{{STRING("1073741820")}, STRING("1073741820")}, // int32
{{STRING("1000000000")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18")}, STRING("6.18")}, // double
{{STRING(R"("abcd")")}, STRING(R"("abcd")")}, // string
@ -208,7 +208,7 @@ TEST(FunctionJsonbTEST, JsonbParseNullableTest) {
{{STRING("false")}, STRING("false")},
{{STRING("100")}, STRING("100")}, //int8
{{STRING("10000")}, STRING("10000")}, // int16
{{STRING("1073741820")}, STRING("1073741820")}, // int32
{{STRING("1000000000")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18")}, STRING("6.18")}, // double
{{STRING(R"("abcd")")}, STRING(R"("abcd")")}, // string
@ -229,37 +229,37 @@ TEST(FunctionJsonbTEST, JsonbParseNullableTest) {
DataSet data_set_invalid = {
{{STRING("abc")}, Null()}, // invalid string
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("'abc'")}, Null()}, // invalid string
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("100x")}, Null()}, // invalid int
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("6.a8")}, Null()}, // invalid double
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("{x")}, Null()}, // invalid object
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("[123, abc]")}, Null()} // invalid array
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
}
@ -273,7 +273,7 @@ TEST(FunctionJsonbTEST, JsonbParseNullableErrorToNullTest) {
{{STRING("false")}, STRING("false")},
{{STRING("100")}, STRING("100")}, //int8
{{STRING("10000")}, STRING("10000")}, // int16
{{STRING("1073741820")}, STRING("1073741820")}, // int32
{{STRING("1000000000")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18")}, STRING("6.18")}, // double
{{STRING(R"("abcd")")}, STRING(R"("abcd")")}, // string
@ -308,7 +308,7 @@ TEST(FunctionJsonbTEST, JsonbParseNullableErrorToValueTest) {
{{STRING("false"), STRING("{}")}, STRING("false")},
{{STRING("100"), STRING("{}")}, STRING("100")}, //int8
{{STRING("10000"), STRING("{}")}, STRING("10000")}, // int16
{{STRING("1073741820"), STRING("{}")}, STRING("1073741820")}, // int32
{{STRING("1000000000"), STRING("{}")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976"), STRING("{}")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18"), STRING("{}")}, STRING("6.18")}, // double
{{STRING(R"("abcd")"), STRING("{}")}, STRING(R"("abcd")")}, // string
@ -346,7 +346,7 @@ TEST(FunctionJsonbTEST, JsonbParseNullableErrorToInvalidTest) {
{{STRING("false")}, STRING("false")},
{{STRING("100")}, STRING("100")}, //int8
{{STRING("10000")}, STRING("10000")}, // int16
{{STRING("1073741820")}, STRING("1073741820")}, // int32
{{STRING("1000000000")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18")}, STRING("6.18")}, // double
{{STRING(R"("abcd")")}, STRING(R"("abcd")")}, // string
@ -381,7 +381,7 @@ TEST(FunctionJsonbTEST, JsonbParseNotnullTest) {
{{STRING("false")}, STRING("false")},
{{STRING("100")}, STRING("100")}, //int8
{{STRING("10000")}, STRING("10000")}, // int16
{{STRING("1073741820")}, STRING("1073741820")}, // int32
{{STRING("1000000000")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18")}, STRING("6.18")}, // double
{{STRING(R"("abcd")")}, STRING(R"("abcd")")}, // string
@ -402,37 +402,37 @@ TEST(FunctionJsonbTEST, JsonbParseNotnullTest) {
DataSet data_set_invalid = {
{{STRING("abc")}, Null()}, // invalid string
};
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("'abc'")}, Null()}, // invalid string
};
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("100x")}, Null()}, // invalid int
};
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("6.a8")}, Null()}, // invalid double
};
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("{x")}, Null()}, // invalid object
};
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
data_set_invalid = {
{{STRING("[123, abc]")}, Null()} // invalid array
};
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid);
st = check_function<DataTypeJsonb, false>(func_name, input_types, data_set_invalid, true);
EXPECT_NE(Status::OK(), st);
}
@ -446,7 +446,7 @@ TEST(FunctionJsonbTEST, JsonbParseNotnullErrorToValueTest) {
{{STRING("false"), STRING("{}")}, STRING("false")},
{{STRING("100"), STRING("{}")}, STRING("100")}, //int8
{{STRING("10000"), STRING("{}")}, STRING("10000")}, // int16
{{STRING("1073741820"), STRING("{}")}, STRING("1073741820")}, // int32
{{STRING("1000000000"), STRING("{}")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976"), STRING("{}")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18"), STRING("{}")}, STRING("6.18")}, // double
{{STRING(R"("abcd")"), STRING("{}")}, STRING(R"("abcd")")}, // string
@ -484,7 +484,7 @@ TEST(FunctionJsonbTEST, JsonbParseNotnullErrorToInvalidTest) {
{{STRING("false")}, STRING("false")},
{{STRING("100")}, STRING("100")}, //int8
{{STRING("10000")}, STRING("10000")}, // int16
{{STRING("1073741820")}, STRING("1073741820")}, // int32
{{STRING("1000000000")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18")}, STRING("6.18")}, // double
{{STRING(R"("abcd")")}, STRING(R"("abcd")")}, // string
@ -509,4 +509,717 @@ TEST(FunctionJsonbTEST, JsonbParseNotnullErrorToInvalidTest) {
EXPECT_EQ(Status::OK(), st);
}
TEST(FunctionJsonbTEST, JsonbExtractTest) {
std::string func_name = "jsonb_extract";
InputTypeSet input_types = {TypeIndex::JSONB, TypeIndex::String};
// jsonb_extract root
DataSet data_set = {
{{STRING("null"), STRING("$")}, STRING("null")},
{{STRING("true"), STRING("$")}, STRING("true")},
{{STRING("false"), STRING("$")}, STRING("false")},
{{STRING("100"), STRING("$")}, STRING("100")}, //int8
{{STRING("10000"), STRING("$")}, STRING("10000")}, // int16
{{STRING("1000000000"), STRING("$")}, STRING("1000000000")}, // int32
{{STRING("1152921504606846976"), STRING("$")}, STRING("1152921504606846976")}, // int64
{{STRING("6.18"), STRING("$")}, STRING("6.18")}, // double
{{STRING(R"("abcd")"), STRING("$")}, STRING(R"("abcd")")}, // string
{{STRING("{}"), STRING("$")}, STRING("{}")}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$")},
STRING(R"({"k1":"v31","k2":300})")}, // object
{{STRING("[]"), STRING("$")}, STRING("[]")}, // empty array
{{STRING("[123, 456]"), STRING("$")}, STRING("[123,456]")}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$")},
STRING(R"(["abc","def"])")}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$")},
STRING(R"([null,true,false,100,6.18,"abc"])")}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$")},
STRING(R"([{"k1":"v41","k2":400},1,"a",3.14])")}, // complex array
};
auto st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract obejct
data_set = {
{{STRING("null"), STRING("$.k1")}, Null()},
{{STRING("true"), STRING("$.k1")}, Null()},
{{STRING("false"), STRING("$.k1")}, Null()},
{{STRING("100"), STRING("$.k1")}, Null()}, //int8
{{STRING("10000"), STRING("$.k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$.k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$.k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$.k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$.k1")}, Null()}, // string
{{STRING("{}"), STRING("$.k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$.k1")}, STRING(R"("v31")")}, // object
{{STRING("[]"), STRING("$.k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$.k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$.k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$.k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$.k1")},
Null()}, // complex array
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract array
data_set = {
{{STRING("null"), STRING("$[0]")}, Null()},
{{STRING("true"), STRING("$[0]")}, Null()},
{{STRING("false"), STRING("$[0]")}, Null()},
{{STRING("100"), STRING("$[0]")}, Null()}, //int8
{{STRING("10000"), STRING("$[0]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0]")}, Null()}, // string
{{STRING("{}"), STRING("$[0]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0]")}, Null()}, // object
{{STRING("[]"), STRING("$[0]")}, Null()}, // empty array
{{STRING("null"), STRING("$[1]")}, Null()},
{{STRING("true"), STRING("$[1]")}, Null()},
{{STRING("false"), STRING("$[1]")}, Null()},
{{STRING("100"), STRING("$[1]")}, Null()}, //int8
{{STRING("10000"), STRING("$[1]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[1]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[1]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[1]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[1]")}, Null()}, // string
{{STRING("{}"), STRING("$[1]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[1]")}, Null()}, // object
{{STRING("[]"), STRING("$[1]")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0]")}, STRING("123")}, // int array
{{STRING("[123, 456]"), STRING("$[1]")}, STRING("456")}, // int array
{{STRING("[123, 456]"), STRING("$[2]")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0]")}, STRING(R"("abc")")}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[1]")}, STRING(R"("def")")}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[2]")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0]")},
STRING("null")}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[1]")},
STRING("true")}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[2]")},
STRING("false")}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[3]")},
STRING("100")}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[4]")},
STRING("6.18")}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[5]")},
STRING(R"("abc")")}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[6]")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0]")},
STRING(R"({"k1":"v41","k2":400})")}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[1]")},
STRING("1")}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[2]")},
STRING(R"("a")")}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[3]")},
STRING("3.14")}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[4]")},
Null()}, // complex array
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract $[0].k1
data_set = {
{{STRING("null"), STRING("$[0].k1")}, Null()},
{{STRING("true"), STRING("$[0].k1")}, Null()},
{{STRING("false"), STRING("$[0].k1")}, Null()},
{{STRING("100"), STRING("$[0].k1")}, Null()}, //int8
{{STRING("10000"), STRING("$[0].k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0].k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0].k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0].k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0].k1")}, Null()}, // string
{{STRING("{}"), STRING("$[0].k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0].k1")}, Null()}, // object
{{STRING("[]"), STRING("$[0].k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0].k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0].k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0].k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0].k1")},
STRING(R"("v41")")}, // complex array
};
st = check_function<DataTypeJsonb, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
}
TEST(FunctionJsonbTEST, JsonbExtractStringTest) {
std::string func_name = "jsonb_extract_string";
InputTypeSet input_types = {TypeIndex::JSONB, TypeIndex::String};
// jsonb_extract root
DataSet data_set = {
{{STRING("null"), STRING("$")}, Null()},
{{STRING("true"), STRING("$")}, Null()},
{{STRING("false"), STRING("$")}, Null()},
{{STRING("100"), STRING("$")}, Null()}, //int8
{{STRING("10000"), STRING("$")}, Null()}, // int16
{{STRING("1000000000"), STRING("$")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$")}, Null()}, // int64
{{STRING("6.18"), STRING("$")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$")}, STRING("abcd")}, // string
{{STRING("{}"), STRING("$")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$")}, Null()}, // object
{{STRING("[]"), STRING("$")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$")},
Null()}, // complex array
};
auto st = check_function<DataTypeString, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract obejct
data_set = {
{{STRING("null"), STRING("$.k1")}, Null()},
{{STRING("true"), STRING("$.k1")}, Null()},
{{STRING("false"), STRING("$.k1")}, Null()},
{{STRING("100"), STRING("$.k1")}, Null()}, //int8
{{STRING("10000"), STRING("$.k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$.k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$.k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$.k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$.k1")}, Null()}, // string
{{STRING("{}"), STRING("$.k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$.k1")}, STRING("v31")}, // object
{{STRING("[]"), STRING("$.k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$.k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$.k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$.k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$.k1")},
Null()}, // complex array
};
st = check_function<DataTypeString, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract array
data_set = {
{{STRING("null"), STRING("$[0]")}, Null()},
{{STRING("true"), STRING("$[0]")}, Null()},
{{STRING("false"), STRING("$[0]")}, Null()},
{{STRING("100"), STRING("$[0]")}, Null()}, //int8
{{STRING("10000"), STRING("$[0]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0]")}, Null()}, // string
{{STRING("{}"), STRING("$[0]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0]")}, Null()}, // object
{{STRING("[]"), STRING("$[0]")}, Null()}, // empty array
{{STRING("null"), STRING("$[1]")}, Null()},
{{STRING("true"), STRING("$[1]")}, Null()},
{{STRING("false"), STRING("$[1]")}, Null()},
{{STRING("100"), STRING("$[1]")}, Null()}, //int8
{{STRING("10000"), STRING("$[1]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[1]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[1]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[1]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[1]")}, Null()}, // string
{{STRING("{}"), STRING("$[1]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[1]")}, Null()}, // object
{{STRING("[]"), STRING("$[1]")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0]")}, Null()}, // int array
{{STRING("[123, 456]"), STRING("$[1]")}, Null()}, // int array
{{STRING("[123, 456]"), STRING("$[2]")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0]")}, STRING("abc")}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[1]")}, STRING("def")}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[2]")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[1]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[2]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[3]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[4]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[5]")},
STRING("abc")}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[6]")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0]")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[1]")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[2]")},
STRING("a")}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[3]")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[4]")},
Null()}, // complex array
};
st = check_function<DataTypeString, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract $[0].k1
data_set = {
{{STRING("null"), STRING("$[0].k1")}, Null()},
{{STRING("true"), STRING("$[0].k1")}, Null()},
{{STRING("false"), STRING("$[0].k1")}, Null()},
{{STRING("100"), STRING("$[0].k1")}, Null()}, //int8
{{STRING("10000"), STRING("$[0].k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0].k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0].k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0].k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0].k1")}, Null()}, // string
{{STRING("{}"), STRING("$[0].k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0].k1")}, Null()}, // object
{{STRING("[]"), STRING("$[0].k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0].k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0].k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0].k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0].k1")},
STRING("v41")}, // complex array
};
st = check_function<DataTypeString, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
}
TEST(FunctionJsonbTEST, JsonbExtractIntTest) {
std::string func_name = "jsonb_extract_int";
InputTypeSet input_types = {TypeIndex::JSONB, TypeIndex::String};
// jsonb_extract root
DataSet data_set = {
{{STRING("null"), STRING("$")}, Null()},
{{STRING("true"), STRING("$")}, Null()},
{{STRING("false"), STRING("$")}, Null()},
{{STRING("100"), STRING("$")}, INT(100)}, //int8
{{STRING("10000"), STRING("$")}, INT(10000)}, // int16
{{STRING("1000000000"), STRING("$")}, INT(1000000000)}, // int32
{{STRING("1152921504606846976"), STRING("$")}, Null()}, // int64
{{STRING("6.18"), STRING("$")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$")}, Null()}, // string
{{STRING("{}"), STRING("$")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$")}, Null()}, // object
{{STRING("[]"), STRING("$")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$")},
Null()}, // complex array
};
auto st = check_function<DataTypeInt32, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract obejct
data_set = {
{{STRING("null"), STRING("$.k1")}, Null()},
{{STRING("true"), STRING("$.k1")}, Null()},
{{STRING("false"), STRING("$.k1")}, Null()},
{{STRING("100"), STRING("$.k1")}, Null()}, //int8
{{STRING("10000"), STRING("$.k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$.k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$.k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$.k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$.k1")}, Null()}, // string
{{STRING("{}"), STRING("$.k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$.k1")}, Null()}, // object
{{STRING("[]"), STRING("$.k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$.k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$.k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$.k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$.k1")},
Null()}, // complex array
};
st = check_function<DataTypeInt32, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract array
data_set = {
{{STRING("null"), STRING("$[0]")}, Null()},
{{STRING("true"), STRING("$[0]")}, Null()},
{{STRING("false"), STRING("$[0]")}, Null()},
{{STRING("100"), STRING("$[0]")}, Null()}, //int8
{{STRING("10000"), STRING("$[0]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0]")}, Null()}, // string
{{STRING("{}"), STRING("$[0]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0]")}, Null()}, // object
{{STRING("[]"), STRING("$[0]")}, Null()}, // empty array
{{STRING("null"), STRING("$[1]")}, Null()},
{{STRING("true"), STRING("$[1]")}, Null()},
{{STRING("false"), STRING("$[1]")}, Null()},
{{STRING("100"), STRING("$[1]")}, Null()}, //int8
{{STRING("10000"), STRING("$[1]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[1]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[1]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[1]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[1]")}, Null()}, // string
{{STRING("{}"), STRING("$[1]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[1]")}, Null()}, // object
{{STRING("[]"), STRING("$[1]")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0]")}, INT(123)}, // int array
{{STRING("[123, 456]"), STRING("$[1]")}, INT(456)}, // int array
{{STRING("[123, 456]"), STRING("$[2]")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0]")}, Null()}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[1]")}, Null()}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[2]")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[1]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[2]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[3]")},
INT(100)}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[4]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[5]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[6]")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0]")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[1]")},
INT(1)}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[2]")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[3]")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[4]")},
Null()}, // complex array
};
st = check_function<DataTypeInt32, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract $[0].k1
data_set = {
{{STRING("null"), STRING("$[0].k1")}, Null()},
{{STRING("true"), STRING("$[0].k1")}, Null()},
{{STRING("false"), STRING("$[0].k1")}, Null()},
{{STRING("100"), STRING("$[0].k1")}, Null()}, //int8
{{STRING("10000"), STRING("$[0].k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0].k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0].k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0].k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0].k1")}, Null()}, // string
{{STRING("{}"), STRING("$[0].k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0].k1")}, Null()}, // object
{{STRING("[]"), STRING("$[0].k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0].k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0].k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0].k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0].k1")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0].k2")},
INT(400)}, // complex array
};
st = check_function<DataTypeInt32, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
}
TEST(FunctionJsonbTEST, JsonbExtractBigIntTest) {
std::string func_name = "jsonb_extract_bigint";
InputTypeSet input_types = {TypeIndex::JSONB, TypeIndex::String};
// jsonb_extract root
DataSet data_set = {
{{STRING("null"), STRING("$")}, Null()},
{{STRING("true"), STRING("$")}, Null()},
{{STRING("false"), STRING("$")}, Null()},
{{STRING("100"), STRING("$")}, BIGINT(100)}, //int8
{{STRING("10000"), STRING("$")}, BIGINT(10000)}, // int16
{{STRING("1000000000"), STRING("$")}, BIGINT(1000000000)}, // int32
{{STRING("1152921504606846976"), STRING("$")}, BIGINT(1152921504606846976)}, // int64
{{STRING("6.18"), STRING("$")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$")}, Null()}, // string
{{STRING("{}"), STRING("$")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$")}, Null()}, // object
{{STRING("[]"), STRING("$")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$")},
Null()}, // complex array
};
auto st = check_function<DataTypeInt64, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract obejct
data_set = {
{{STRING("null"), STRING("$.k1")}, Null()},
{{STRING("true"), STRING("$.k1")}, Null()},
{{STRING("false"), STRING("$.k1")}, Null()},
{{STRING("100"), STRING("$.k1")}, Null()}, //int8
{{STRING("10000"), STRING("$.k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$.k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$.k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$.k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$.k1")}, Null()}, // string
{{STRING("{}"), STRING("$.k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$.k1")}, Null()}, // object
{{STRING("[]"), STRING("$.k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$.k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$.k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$.k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$.k1")},
Null()}, // complex array
};
st = check_function<DataTypeInt64, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract array
data_set = {
{{STRING("null"), STRING("$[0]")}, Null()},
{{STRING("true"), STRING("$[0]")}, Null()},
{{STRING("false"), STRING("$[0]")}, Null()},
{{STRING("100"), STRING("$[0]")}, Null()}, //int8
{{STRING("10000"), STRING("$[0]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0]")}, Null()}, // string
{{STRING("{}"), STRING("$[0]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0]")}, Null()}, // object
{{STRING("[]"), STRING("$[0]")}, Null()}, // empty array
{{STRING("null"), STRING("$[1]")}, Null()},
{{STRING("true"), STRING("$[1]")}, Null()},
{{STRING("false"), STRING("$[1]")}, Null()},
{{STRING("100"), STRING("$[1]")}, Null()}, //int8
{{STRING("10000"), STRING("$[1]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[1]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[1]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[1]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[1]")}, Null()}, // string
{{STRING("{}"), STRING("$[1]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[1]")}, Null()}, // object
{{STRING("[]"), STRING("$[1]")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0]")}, BIGINT(123)}, // int array
{{STRING("[123, 456]"), STRING("$[1]")}, BIGINT(456)}, // int array
{{STRING("[123, 456]"), STRING("$[2]")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0]")}, Null()}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[1]")}, Null()}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[2]")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[1]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[2]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[3]")},
BIGINT(100)}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[4]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[5]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[6]")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0]")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[1]")},
BIGINT(1)}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[2]")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[3]")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[4]")},
Null()}, // complex array
};
st = check_function<DataTypeInt64, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract $[0].k1
data_set = {
{{STRING("null"), STRING("$[0].k1")}, Null()},
{{STRING("true"), STRING("$[0].k1")}, Null()},
{{STRING("false"), STRING("$[0].k1")}, Null()},
{{STRING("100"), STRING("$[0].k1")}, Null()}, //int8
{{STRING("10000"), STRING("$[0].k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0].k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0].k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0].k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0].k1")}, Null()}, // string
{{STRING("{}"), STRING("$[0].k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0].k1")}, Null()}, // object
{{STRING("[]"), STRING("$[0].k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0].k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0].k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0].k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0].k1")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0].k2")},
BIGINT(400)}, // complex array
};
st = check_function<DataTypeInt64, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
}
TEST(FunctionJsonbTEST, JsonbExtractDoubleTest) {
std::string func_name = "jsonb_extract_double";
InputTypeSet input_types = {TypeIndex::JSONB, TypeIndex::String};
// jsonb_extract root
DataSet data_set = {
{{STRING("null"), STRING("$")}, Null()},
{{STRING("true"), STRING("$")}, Null()},
{{STRING("false"), STRING("$")}, Null()},
{{STRING("100"), STRING("$")}, DOUBLE(100)}, //int8
{{STRING("10000"), STRING("$")}, DOUBLE(10000)}, // int16
{{STRING("1000000000"), STRING("$")}, DOUBLE(1000000000)}, // int32
{{STRING("1152921504606846976"), STRING("$")}, DOUBLE(1152921504606846976)}, // int64
{{STRING("6.18"), STRING("$")}, DOUBLE(6.18)}, // double
{{STRING(R"("abcd")"), STRING("$")}, Null()}, // string
{{STRING("{}"), STRING("$")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$")}, Null()}, // object
{{STRING("[]"), STRING("$")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$")},
Null()}, // complex array
};
auto st = check_function<DataTypeFloat64, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract obejct
data_set = {
{{STRING("null"), STRING("$.k1")}, Null()},
{{STRING("true"), STRING("$.k1")}, Null()},
{{STRING("false"), STRING("$.k1")}, Null()},
{{STRING("100"), STRING("$.k1")}, Null()}, //int8
{{STRING("10000"), STRING("$.k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$.k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$.k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$.k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$.k1")}, Null()}, // string
{{STRING("{}"), STRING("$.k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$.k1")}, Null()}, // object
{{STRING("[]"), STRING("$.k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$.k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$.k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$.k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$.k1")},
Null()}, // complex array
};
st = check_function<DataTypeFloat64, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract array
data_set = {
{{STRING("null"), STRING("$[0]")}, Null()},
{{STRING("true"), STRING("$[0]")}, Null()},
{{STRING("false"), STRING("$[0]")}, Null()},
{{STRING("100"), STRING("$[0]")}, Null()}, //int8
{{STRING("10000"), STRING("$[0]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0]")}, Null()}, // string
{{STRING("{}"), STRING("$[0]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0]")}, Null()}, // object
{{STRING("[]"), STRING("$[0]")}, Null()}, // empty array
{{STRING("null"), STRING("$[1]")}, Null()},
{{STRING("true"), STRING("$[1]")}, Null()},
{{STRING("false"), STRING("$[1]")}, Null()},
{{STRING("100"), STRING("$[1]")}, Null()}, //int8
{{STRING("10000"), STRING("$[1]")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[1]")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[1]")}, Null()}, // int64
{{STRING("6.18"), STRING("$[1]")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[1]")}, Null()}, // string
{{STRING("{}"), STRING("$[1]")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[1]")}, Null()}, // object
{{STRING("[]"), STRING("$[1]")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0]")}, DOUBLE(123)}, // int array
{{STRING("[123, 456]"), STRING("$[1]")}, DOUBLE(456)}, // int array
{{STRING("[123, 456]"), STRING("$[2]")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0]")}, Null()}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[1]")}, Null()}, // string array
{{STRING(R"(["abc", "def"])"), STRING("$[2]")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[1]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[2]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[3]")},
DOUBLE(100)}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[4]")},
DOUBLE(6.18)}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[5]")},
Null()}, // multi type array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[6]")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0]")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[1]")},
DOUBLE(1)}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[2]")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[3]")},
DOUBLE(3.14)}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[4]")},
Null()}, // complex array
};
st = check_function<DataTypeFloat64, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
// jsonb_extract $[0].k1
data_set = {
{{STRING("null"), STRING("$[0].k1")}, Null()},
{{STRING("true"), STRING("$[0].k1")}, Null()},
{{STRING("false"), STRING("$[0].k1")}, Null()},
{{STRING("100"), STRING("$[0].k1")}, Null()}, //int8
{{STRING("10000"), STRING("$[0].k1")}, Null()}, // int16
{{STRING("1000000000"), STRING("$[0].k1")}, Null()}, // int32
{{STRING("1152921504606846976"), STRING("$[0].k1")}, Null()}, // int64
{{STRING("6.18"), STRING("$[0].k1")}, Null()}, // double
{{STRING(R"("abcd")"), STRING("$[0].k1")}, Null()}, // string
{{STRING("{}"), STRING("$[0].k1")}, Null()}, // empty object
{{STRING(R"({"k1":"v31", "k2": 300})"), STRING("$[0].k1")}, Null()}, // object
{{STRING("[]"), STRING("$[0].k1")}, Null()}, // empty array
{{STRING("[123, 456]"), STRING("$[0].k1")}, Null()}, // int array
{{STRING(R"(["abc", "def"])"), STRING("$[0].k1")}, Null()}, // string array
{{STRING(R"([null, true, false, 100, 6.18, "abc"])"), STRING("$[0].k1")},
Null()}, // multi type array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0].k1")},
Null()}, // complex array
{{STRING(R"([{"k1":"v41", "k2": 400}, 1, "a", 3.14])"), STRING("$[0].k2")},
DOUBLE(400)}, // complex array
};
st = check_function<DataTypeFloat64, true>(func_name, input_types, data_set);
EXPECT_EQ(Status::OK(), st);
}
} // namespace doris::vectorized