Tejaskriya commented on code in PR #6976:
URL: https://github.com/apache/ozone/pull/6976#discussion_r1728473225
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBScanner.java:
##########
@@ -515,16 +533,84 @@ public Void call() {
Object o = dbColumnFamilyDefinition.getValueCodec()
.fromPersistedFormat(byteArrayKeyValue.getValue());
- sb.append(WRITER.writeValueAsString(o));
+
+ if (valueFields != null) {
+ Map<String, Object> filteredValue = new HashMap<>();
+ for (List<String> subfields : fieldsSplit) {
+ try {
+ filteredValue.putAll(getFilteredObject(o, subfields,
dbColumnFamilyDefinition.getValueType()));
+ } catch (NoSuchFieldException ex) {
+ err().println("ERROR: no such field: " + subfields);
+ } catch (IllegalAccessException e) {
+ err().println("ERROR: Cannot get field from object: " +
subfields);
+ }
+ }
+ sb.append(WRITER.writeValueAsString(filteredValue));
+ } else {
+ sb.append(WRITER.writeValueAsString(o));
+ }
+
results.add(sb.toString());
}
logWriter.log(results, sequenceId);
- } catch (Exception e) {
+ } catch (IOException e) {
exception = true;
LOG.error("Exception parse Object", e);
}
return null;
}
+
+ Map<String, Object> getFilteredObject(Object o, List<String> subfields,
Class<?> fieldClass)
+ throws NoSuchFieldException, IllegalAccessException {
+ Field valueClassField = getRequiredFieldFromAllFields(fieldClass,
subfields.get(0));
+ Object valueObject = valueClassField.get(o);
+ int length = subfields.size();
+ Map<String, Object> valueMap = new HashMap<>();
+ if (length == 1) {
+ valueMap.put(subfields.get(0), valueObject);
+ } else {
+ Class<?> typeOfClassField;
+ try {
+ if (Collection.class.isAssignableFrom(valueClassField.getType())) {
+ typeOfClassField = (Class<?>)
+ ((ParameterizedType)
valueClassField.getGenericType()).getActualTypeArguments()[0];
+ } else {
+ typeOfClassField = valueClassField.getType();
+ }
+ } catch (ClassCastException ex) {
+ typeOfClassField = valueClassField.getType();
+ }
+
+ if (Collection.class.isAssignableFrom(valueObject.getClass())) {
Review Comment:
I have added handling for map values now, Could you please review it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]