thomasrebele commented on code in PR #6225:
URL: https://github.com/apache/hive/pull/6225#discussion_r2585560061


##########
itests/hive-unit/src/test/java/org/apache/hive/beeline/TestHplSqlViaBeeLine.java:
##########
@@ -1411,8 +1404,174 @@ private void testScriptFile(String scriptText, 
List<String> argList, String expe
     testScriptFile(scriptText, argList, expectedPattern, OutStream.OUT);
   }
 
+  /**
+   * Checks that the pattern appears in the output.
+   * <p><b>Warning:</b> If the output depends on the time of the execution,
+   * use {@link #testTimeScriptFile}. This may be the case if
+   * the script contains CURRENT_DATE, CURRENT_TIME_MILLIS, etc.</p>
+   */
   private void testScriptFile(String scriptText, List<String> argList, String 
expectedPattern,
           TestBeeLineWithArgs.OutStream outStream) throws Throwable {
+    String output = runScriptFile(scriptText, argList, outStream);
+    if (!Pattern.compile(".*" + expectedPattern + ".*", 
Pattern.DOTALL).matcher(output).matches()) {
+      fail("Output: '" + output + "' should match " + expectedPattern);
+    }
+  }
+
+  interface TimeCheckHelper {
+
+    /** Supports timestamps in second resolution such as 1764680360 */
+    TimeCheckHelper TIMESTAMP_SECONDS = new TimeCheckHelper() {
+      // works for timestamps a few hours after the epoch (1970-01-01 00:00:00 
GMT)
+      Pattern PATTERN = Pattern.compile("[0-9]{5,}");
+
+      @Override
+      public long getCurrentTime() {
+        return System.currentTimeMillis() / 1000;
+      }
+
+      @Override
+      public long strToTime(String str) {
+        return Long.parseLong(str);
+      }
+
+      @Override
+      public Pattern getPattern() {
+        return PATTERN;
+      }
+    };
+
+    /** Supports timestamps in millisecond resolution such as 1764680360883 */
+    TimeCheckHelper TIMESTAMP_MILLISECONDS = new TimeCheckHelper() {
+      Pattern PATTERN = Pattern.compile("[0-9]{5,}");

Review Comment:
   During some refactoring I forgot to add `static` again. I'll fix it (and the 
other Sonar Qube warnings) later.



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

Reply via email to