jackjlli commented on a change in pull request #6583:
URL: https://github.com/apache/incubator-pinot/pull/6583#discussion_r580704347



##########
File path: 
pinot-integration-tests/src/test/java/org/apache/pinot/compat/tests/QueryOp.java
##########
@@ -55,7 +72,97 @@ public void setExpectedResultsFileName(String 
expectedResultsFileName) {
 
   @Override
   boolean runOp() {
-    System.out.println("Verifying queries in " + _queryFileName + " against 
results in " + _expectedResultsFileName);
-    return true;
+    System.out.printf("Verifying queries in %s against results in %s\n", 
_queryFileName, _expectedResultsFileName);

Review comment:
       Why not use the `LOGGER` you specified in Line 41?

##########
File path: 
pinot-integration-tests/src/test/java/org/apache/pinot/compat/tests/QueryOp.java
##########
@@ -55,7 +72,97 @@ public void setExpectedResultsFileName(String 
expectedResultsFileName) {
 
   @Override
   boolean runOp() {
-    System.out.println("Verifying queries in " + _queryFileName + " against 
results in " + _expectedResultsFileName);
-    return true;
+    System.out.printf("Verifying queries in %s against results in %s\n", 
_queryFileName, _expectedResultsFileName);
+    try {
+      return verifyQueries();
+    } catch (Exception e) {
+      LOGGER.error("FAILED to verify queries in {}: {}", _queryFileName, e);
+      return false;
+    }
+  }
+
+  boolean verifyQueries()
+      throws Exception {
+    BufferedReader expectedResultReader = null;
+    boolean testPassed = false;
+
+    try (BufferedReader queryReader = new BufferedReader(
+        new InputStreamReader(new FileInputStream(_queryFileName), 
StandardCharsets.UTF_8))) {
+      if (_queryFileName == null) {
+        LOGGER.error("Result file is missing!");
+        return testPassed;
+      } else {
+        expectedResultReader = new BufferedReader(
+            new InputStreamReader(new 
FileInputStream(_expectedResultsFileName), StandardCharsets.UTF_8));
+      }
+
+      int passed = 0;
+      int total = 0;
+      int queryLineNum = 0;
+      String query;
+
+      while ((query = queryReader.readLine()) != null) {
+        queryLineNum++;
+        if (shouldIgnore(query)) {
+          continue;
+        }
+
+        JsonNode expectedJson = null;
+        try {
+          String expectedResultLine = expectedResultReader.readLine();
+          while (shouldIgnore(expectedResultLine)) {
+            expectedResultLine = expectedResultReader.readLine();
+          }
+          expectedJson = JsonUtils.stringToJsonNode(expectedResultLine);
+        } catch (Exception e) {
+          LOGGER.error("Comparison FAILED: Line: {} Exception caught while 
getting expected response for query: '{}'",

Review comment:
       If an exception was caught when parsing the expected results, should we 
skip firing queries to the cluster and stop the comparison immediately?

##########
File path: 
pinot-integration-tests/src/test/java/org/apache/pinot/compat/tests/QueryOp.java
##########
@@ -55,7 +72,97 @@ public void setExpectedResultsFileName(String 
expectedResultsFileName) {
 
   @Override
   boolean runOp() {
-    System.out.println("Verifying queries in " + _queryFileName + " against 
results in " + _expectedResultsFileName);
-    return true;
+    System.out.printf("Verifying queries in %s against results in %s\n", 
_queryFileName, _expectedResultsFileName);
+    try {
+      return verifyQueries();
+    } catch (Exception e) {
+      LOGGER.error("FAILED to verify queries in {}: {}", _queryFileName, e);
+      return false;
+    }
+  }
+
+  boolean verifyQueries()
+      throws Exception {
+    BufferedReader expectedResultReader = null;
+    boolean testPassed = false;
+
+    try (BufferedReader queryReader = new BufferedReader(
+        new InputStreamReader(new FileInputStream(_queryFileName), 
StandardCharsets.UTF_8))) {
+      if (_queryFileName == null) {
+        LOGGER.error("Result file is missing!");
+        return testPassed;
+      } else {
+        expectedResultReader = new BufferedReader(

Review comment:
       I think you can put this to the same try bracket in  Line 89 as well, so 
that you don't need to specify the finally block at the end.

##########
File path: 
pinot-integration-tests/src/test/java/org/apache/pinot/compat/tests/SegmentOp.java
##########
@@ -241,6 +242,27 @@ private boolean verifySegmentInState(String state)
     return true;
   }
 
+  private boolean verifyRoutingTableUpdated()
+      throws Exception {
+    String query = "SELECT count(*) FROM " + _tableName;
+    JsonNode result = QueryProcessor.postSqlQuery(query);
+    System.out.println(result);

Review comment:
       remove this System.out.println()?

##########
File path: 
pinot-integration-tests/src/test/java/org/apache/pinot/compat/tests/QueryOp.java
##########
@@ -30,13 +38,22 @@
  */
 @JsonIgnoreProperties(ignoreUnknown = true)
 public class QueryOp extends BaseOp {
+  private static final Logger LOGGER = LoggerFactory.getLogger(QueryOp.class);
+
+  private static final String NUM_DOCS_SCANNED = "numDocsScanned";
+  private static final String TIME_USED_MS = "timeUsedMs";
   private String _queryFileName;
   private String _expectedResultsFileName;
 
   public QueryOp() {
     super(OpType.QUERY_OP);
   }
 
+  private boolean shouldIgnore(String line) {
+    String trimmedLine = line.trim();
+    return trimmedLine.isEmpty() || trimmedLine.startsWith("#");

Review comment:
       Put "#" into a constant.

##########
File path: 
pinot-integration-tests/src/test/java/org/apache/pinot/compat/tests/QueryOp.java
##########
@@ -30,13 +38,22 @@
  */
 @JsonIgnoreProperties(ignoreUnknown = true)
 public class QueryOp extends BaseOp {
+  private static final Logger LOGGER = LoggerFactory.getLogger(QueryOp.class);
+
+  private static final String NUM_DOCS_SCANNED = "numDocsScanned";

Review comment:
       Rename it to `NUM_DOCS_SCANNED_KEY`. Same for the following one.

##########
File path: 
pinot-integration-tests/src/test/java/org/apache/pinot/compat/tests/QueryOp.java
##########
@@ -55,7 +72,97 @@ public void setExpectedResultsFileName(String 
expectedResultsFileName) {
 
   @Override
   boolean runOp() {
-    System.out.println("Verifying queries in " + _queryFileName + " against 
results in " + _expectedResultsFileName);
-    return true;
+    System.out.printf("Verifying queries in %s against results in %s\n", 
_queryFileName, _expectedResultsFileName);
+    try {
+      return verifyQueries();
+    } catch (Exception e) {
+      LOGGER.error("FAILED to verify queries in {}: {}", _queryFileName, e);
+      return false;
+    }
+  }
+
+  boolean verifyQueries()
+      throws Exception {
+    BufferedReader expectedResultReader = null;
+    boolean testPassed = false;
+
+    try (BufferedReader queryReader = new BufferedReader(
+        new InputStreamReader(new FileInputStream(_queryFileName), 
StandardCharsets.UTF_8))) {
+      if (_queryFileName == null) {

Review comment:
       I'm not sure whether this if statement can ever be satisfied. Maybe we 
should check that before the try block?

##########
File path: 
pinot-integration-tests/src/test/java/org/apache/pinot/compat/tests/QueryProcessor.java
##########
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.compat.tests;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.Map;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+public class QueryProcessor {
+
+  private static final String _brokerBaseApiUrl = 
ClusterDescriptor.CONTROLLER_URL;

Review comment:
       Use snake case instead of camel case for static constant?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to