asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Till Westmann (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: [NO ISSUE] Slightly friendlier variable names
Date Sat, 30 Sep 2017 19:59:24 GMT
Till Westmann has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/2040

Change subject: [NO ISSUE] Slightly friendlier variable names
......................................................................

[NO ISSUE] Slightly friendlier variable names

Change-Id: Id1a6b3c5a75ee4eb1abad809603f1f6f5436a7d2
---
M asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java
1 file changed, 19 insertions(+), 21 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/40/2040/1

diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java
b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java
index 01b280d..834c104 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java
@@ -112,37 +112,35 @@
         LOGGER.fine("+++++++\n" + result + "\n+++++++\n");
 
         final StringBuilder resultBuilder = new StringBuilder();
-        String field;
-        String fieldPrefix;
-        for (Iterator<String> sIter = result.fieldNames(); sIter.hasNext(); ) {
-            field = sIter.next();
-            fieldPrefix = field.split("-")[0];
-            final ResultField extractedResultField = ResultField.ofFieldName(fieldPrefix);
-            if (extractedResultField == null) {
-                throw new AsterixException("Unanticipated field \"" + field + "\"");
+        for (Iterator<String> fieldNameIter = result.fieldNames(); fieldNameIter.hasNext();)
{
+            final String fieldName = fieldNameIter.next();
+            final ResultField fieldKind = ResultField.ofFieldName(fieldName.split("-")[0]);
+            if (fieldKind == null) {
+                throw new AsterixException("Unanticipated field \"" + fieldName + "\"");
             }
-            if (!resultFields.contains(extractedResultField)) {
+            if (!resultFields.contains(fieldKind)) {
                 continue;
             }
-            switch (extractedResultField) {
+            final JsonNode fieldValue = result.get(fieldName);
+            switch (fieldKind) {
                 case RESULTS:
-                    if (result.get(field).size() <= 1) {
-                        if (result.get(field).size() == 0) {
+                    if (fieldValue.size() <= 1) {
+                        if (fieldValue.size() == 0) {
                             resultBuilder.append("");
-                        } else if (result.get(field).isArray()) {
-                            if (result.get(field).get(0).isTextual()) {
-                                resultBuilder.append(result.get(field).get(0).asText());
+                        } else if (fieldValue.isArray()) {
+                            if (fieldValue.get(0).isTextual()) {
+                                resultBuilder.append(fieldValue.get(0).asText());
                             } else {
                                 ObjectMapper omm = new ObjectMapper();
                                 omm.setDefaultPrettyPrinter(singleLine);
                                 omm.enable(SerializationFeature.INDENT_OUTPUT);
-                                resultBuilder.append(omm.writer(singleLine).writeValueAsString(result.get(field)));
+                                resultBuilder.append(omm.writer(singleLine).writeValueAsString(fieldValue));
                             }
                         } else {
-                            resultBuilder.append(OBJECT_MAPPER.writeValueAsString(result.get(field)));
+                            resultBuilder.append(OBJECT_MAPPER.writeValueAsString(fieldValue));
                         }
                     } else {
-                        JsonNode[] fields = Iterators.toArray(result.get(field).elements(),
JsonNode.class);
+                        JsonNode[] fields = Iterators.toArray(fieldValue.elements(), JsonNode.class);
                         if (fields.length > 1) {
                             for (JsonNode f : fields) {
                                 if (f.isObject()) {
@@ -157,7 +155,7 @@
                     }
                     break;
                 case ERRORS:
-                    final JsonNode errors = result.get(field).get(0).get("msg");
+                    final JsonNode errors = fieldValue.get(0).get("msg");
                     if (!result.get(ResultField.METRICS.getFieldName()).has("errorCount"))
{
                         throw new AsterixException("Request reported error but not an errorCount");
                     }
@@ -168,10 +166,10 @@
                 case SIGNATURE:
                 case STATUS:
                 case TYPE:
-                    resultBuilder.append(OBJECT_MAPPER.writeValueAsString(result.get(field)));
+                    resultBuilder.append(OBJECT_MAPPER.writeValueAsString(fieldValue));
                     break;
                 default:
-                    throw new IllegalStateException("Unexpected result field: " + extractedResultField);
+                    throw new IllegalStateException("Unexpected result field: " + fieldKind);
             }
         }
         return IOUtils.toInputStream(resultBuilder.toString(), StandardCharsets.UTF_8);

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/2040
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1a6b3c5a75ee4eb1abad809603f1f6f5436a7d2
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <tillw@apache.org>

Mime
View raw message