Skip to content

Commit

Permalink
Change json_format to return java null when java null is received (ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
gortiz authored Sep 27, 2023
1 parent b1cc3e3 commit 1f93870
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static String toJsonMapStr(@Nullable Map map)
/**
* Convert object to Json String
*/
@ScalarFunction(nullableParameters = true)
@ScalarFunction
public static String jsonFormat(Object object)
throws JsonProcessingException {
return JsonUtils.objectToString(object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,19 @@ public Object[][] jsonFunctionsDataProvider()
});
return inputs.toArray(new Object[0][]);
}

@Test(description = "jsonFormat(Java null) should return Java null")
public void jsonFormatWithJavaNullReturnsJavaNull() {
GenericRow row = new GenericRow();
row.putValue("jsonMap", null);
testFunction("json_format(jsonMap)", Lists.newArrayList("jsonMap"), row, null);
}

@Test(description = "jsonFormat(JSON null) should return \"null\"")
public void jsonFormatWithJsonNullReturnsStringNull()
throws IOException {
GenericRow row = new GenericRow();
row.putValue("jsonMap", JsonUtils.stringToJsonNode("null"));
testFunction("json_format(jsonMap)", Lists.newArrayList("jsonMap"), row, "null");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@

boolean enabled() default true;

// If empty, FunctionsRegistry registers the method name as function name;
// If not empty, FunctionsRegistry only registers the function names specified here, the method name is ignored.
/**
* If empty, FunctionsRegistry registers the method name as function name;
* If not empty, FunctionsRegistry only registers the function names specified here, the method name is ignored.
*/
String[] names() default {};

// Whether the scalar function expects and can handle null arguments.
/**
* Whether the scalar function expects and can handle null arguments.
*
*/
boolean nullableParameters() default false;

boolean isPlaceholder() default false;
Expand Down

0 comments on commit 1f93870

Please sign in to comment.