sumitagrawl commented on code in PR #6976:
URL: https://github.com/apache/ozone/pull/6976#discussion_r1714677386
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ValueSchema.java:
##########
@@ -101,7 +101,7 @@ public Void call() throws Exception {
return null;
}
- private boolean getValueFields(String dbPath, Map<String, Object>
valueSchema) {
+ public boolean getValueFields(String dbPath, Map<String, Object>
valueSchema, int d, String table) {
Review Comment:
we can make this method static, as used as utility by other class
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ValueSchema.java:
##########
@@ -148,7 +148,7 @@ private Object getFieldsStructure(Class<?> clazz, int
currentDepth) {
}
}
- private List<Field> getAllFields(Class clazz) {
+ public List<Field> getAllFields(Class clazz) {
Review Comment:
we can make this method as static.
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBScanner.java:
##########
@@ -515,16 +572,79 @@ 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 (String field : valueFields.split(",")) {
Review Comment:
re-construct field outside loop
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBScanner.java:
##########
@@ -515,16 +572,79 @@ 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 (String field : valueFields.split(",")) {
+ String[] subfields = field.split("\\.");
+ try {
+ Field valueClassField =
getRequiredFieldFromAllFields(dbColumnFamilyDefinition.getValueType(),
+ subfields[0]);
+ Object valueObject = valueClassField.get(o);
+ if (subfields.length == 1) {
+ filteredValue.put(field, 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();
+ }
+
+ Field classSubField =
getRequiredFieldFromAllFields(typeOfClassField, subfields[1]);
+
+ if
(Collection.class.isAssignableFrom(valueObject.getClass())) {
+ List<Map<String, Object>> subfieldObjectsList = new
ArrayList<>();
+ for (Object ob : (List) valueObject) {
+ Map<String, Object> subfieldValueMap = new HashMap<>();
+ subfieldValueMap.put(subfields[1],
classSubField.get(ob));
+ subfieldObjectsList.add(subfieldValueMap);
+ }
+ filteredValue.put(field, subfieldObjectsList);
+ } else {
+ filteredValue.put(field, classSubField.get(valueObject));
+ }
+ }
+ } catch (NoSuchFieldException ex) {
+ err().println("ERROR: no such field: " + valueFields);
+ }
+ }
+ sb.append(WRITER.writeValueAsString(filteredValue));
+
+ } else {
+ sb.append(WRITER.writeValueAsString(o));
+ }
+
results.add(sb.toString());
}
logWriter.log(results, sequenceId);
- } catch (Exception e) {
+ } catch (IOException | IllegalAccessException e) {
exception = true;
LOG.error("Exception parse Object", e);
}
return null;
}
+
+ Field getRequiredFieldFromAllFields(Class clazz, String fieldName) throws
NoSuchFieldException {
+ List<Field> classFieldList = new ValueSchema().getAllFields(clazz);
Review Comment:
can avoid creating ValueSchema object my making method static, in all places
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBScanner.java:
##########
@@ -405,6 +419,47 @@ private boolean printTable(List<ColumnFamilyHandle>
columnFamilyHandleList,
IOUtils.closeQuietly(iterator, readOptions, slice);
}
}
+ boolean checkValidValueFields(String dbPath, String valueFields,
+ DBColumnFamilyDefinition<?, ?>
columnFamilyDefinition) {
Review Comment:
validation may not be required, will give all matching data.
--
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]