What is your question?
I am tyring to implement my udf jsonToArray , and my cpu udf function is
public List<Map<String, String>> evaluate(String jsonArrayStr) {
List<Map<String, String>> result = new ArrayList<Map<String, String>>();
try {
Object json = new JSONTokener(jsonArrayStr).nextValue();
if (json instanceof JSONObject) {
Map<String, String> newMap = new HashMap<String, String>();
JSONObject newItem = new JSONObject(jsonArrayStr);
Iterator keys = newItem.keys();
while (keys != null && keys.hasNext()) {
String key = String.valueOf(keys.next());
String value = ((JSONObject) json).get(key).toString();
if (StringUtils.isNotBlank(key))
newMap.put(key, value);
}
result.add(newMap);
} else if (json instanceof JSONArray) {
JSONArray jsonArray = new JSONArray(jsonArrayStr);
for (int j = 0; j < jsonArray.length(); j++) {
if (jsonArray.get(j) instanceof JSONObject) {
JSONObject item = jsonArray.getJSONObject(j);
if (item != null) {
Map<String, String> newItem = new HashMap<String, String>();
Iterator keys = item.keys();
while (keys != null && keys.hasNext()) {
String key = String.valueOf(keys.next());
String value = item.get(key).toString();
if (StringUtils.isNotBlank(key))
newItem.put(key, value);
}
result.add(newItem);
}
}
}
}
} catch (Exception e) {
System.out.println(e);
}
return result;
}
I am ready to finish this udf in udf-example reference stringWordCount, but i am confused about return type , cpu udf return List<Map<String, String>>, while cudf only can make column type List<Struct<String, String>, i think they are same for me , right ? if i am wrong , please correct me.
In addition , for jsonToArray udf , my thinking step is
- read json string object by
cudf_io::read_json
- make column by call
cudf::make_structs_column and cudf::make_List_column in cudf
- return
std::unique_ptr<cudf::column>
please give me some advise if it's wrong, thanks a lot ! @jlowe
What is your question?
I am tyring to implement my udf jsonToArray , and my cpu udf function is
I am ready to finish this udf in udf-example reference
stringWordCount, but i am confused about return type , cpu udf returnList<Map<String, String>>, whilecudfonly can make column typeList<Struct<String, String>, i think they are same for me , right ? if i am wrong , please correct me.In addition , for
jsonToArrayudf , my thinking step iscudf_io::read_jsoncudf::make_structs_columnandcudf::make_List_columnin cudfstd::unique_ptr<cudf::column>please give me some advise if it's wrong, thanks a lot ! @jlowe