Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ public ArgValue convert(String s) {
Map.entry(BETWEEN, "(%1$s >= %2$s && %1$s <= %3$s)")
);

private static final String JSONB_PATH_EXISTS = "jsonb_path_exists";

private static final String JSONB_PATH_EXISTS_TZ = "jsonb_path_exists_tz";

private final ComparisonOperator operator;
private final String keyPath;
private final List<ArgValue> values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public class JsonbSupport {

public static boolean DATE_TIME_SUPPORT = false;

/**
* Postgresql {@code jsonb_path_exists} function to use
*/
public static String JSONB_PATH_EXISTS = "jsonb_path_exists";

/**
* Postgresql {@code jsonb_path_exists_tz} function to use
*/
public static String JSONB_PATH_EXISTS_TZ = "jsonb_path_exists_tz";

private static final Set<Database> JSON_SUPPORT = EnumSet.of(Database.POSTGRESQL);

private static final Map<ComparisonOperator, ComparisonOperator> NEGATE_OPERATORS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ void testJsonbPathExpressionWithTemporal(ComparisonOperator operator, String key
assertEquals(expectedJsonbPath, expression.jsonbPath());
}

@ParameterizedTest
@MethodSource("customized")
void testJsonbPathExpressionCustomized(ComparisonOperator operator, String keyPath, List<String> arguments, String expectedJsonbFunction, String expectedJsonbPath) {
String jsonbPathExists = JsonbSupport.JSONB_PATH_EXISTS;
String jsonbPathExistsTz = JsonbSupport.JSONB_PATH_EXISTS_TZ;
try {
JsonbSupport.JSONB_PATH_EXISTS = "my_jsonb_path_exists";
JsonbSupport.JSONB_PATH_EXISTS_TZ = "my_jsonb_path_exists_tz";
JsonbSupport.DATE_TIME_SUPPORT = true;
JsonbExpressionBuilder builder = new JsonbExpressionBuilder(operator, keyPath, arguments);
var expression = builder.getJsonPathExpression();
assertEquals(expectedJsonbFunction, expression.jsonbFunction());
assertEquals(expectedJsonbPath, expression.jsonbPath());
} catch (Exception e) {
throw e;
} finally {
JsonbSupport.JSONB_PATH_EXISTS = jsonbPathExists;
JsonbSupport.JSONB_PATH_EXISTS_TZ = jsonbPathExistsTz;
}
}

static Stream<Arguments> data() {
return Stream.of(
allOperators(),
Expand Down Expand Up @@ -78,6 +99,17 @@ static Stream<Arguments> conversion() {
).filter(Objects::nonNull);
}

static Stream<Arguments> customized() {

return Stream.of(
arguments(RSQLOperators.EQUAL, "json.equal_key", Collections.singletonList("value"), "my_jsonb_path_exists", "$.equal_key ? (@ == \"value\")"),
arguments(RSQLOperators.GREATER_THAN, "json.greater_than_key", Collections.singletonList("value"), "my_jsonb_path_exists", "$.greater_than_key ? (@ > \"value\")"),
arguments(RSQLOperators.EQUAL, "json.equal_key", Collections.singletonList("1970-01-01T00:00:00.000"), "my_jsonb_path_exists", "$.equal_key ? (@.datetime() == \"1970-01-01T00:00:00.000\".datetime())"),
arguments(RSQLOperators.EQUAL, "json.equal_key", Collections.singletonList("1970-01-01T00:00:00.000Z"), "my_jsonb_path_exists_tz", "$.equal_key ? (@.datetime() == \"1970-01-01T00:00:00.000Z\".datetime())"),
null
).filter(Objects::nonNull);
}

static Stream<Arguments> temporal() {

return Stream.of(
Expand Down