flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [flink] StephanEwen commented on a change in pull request #10239: [Flink-11491][Test] Support all TPC-DS queries
Date Thu, 21 Nov 2019 11:51:50 GMT
StephanEwen commented on a change in pull request #10239: [Flink-11491][Test] Support all TPC-DS
queries
URL: https://github.com/apache/flink/pull/10239#discussion_r349041294
 
 

 ##########
 File path: flink-end-to-end-tests/flink-tpcds-test/src/main/java/org/apache/flink/table/tpcds/utils/TpcdsResultComparator.java
 ##########
 @@ -0,0 +1,232 @@
+/*
+ * 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.flink.table.tpcds.utils;
+
+import org.apache.flink.api.java.utils.ParameterTool;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Result comparator for TPC-DS test, according to the TPC-DS standard specification v2.11.0.
+ * skip validate query 6、19、30、31、46、67、68、81 temporary,
+ * because they can not match answer set perfectly from now and
+ * we'd take some effort to address it.
+ */
+public class TpcdsResultComparator {
+
+	private static final int VALIDATE_QUERY_NUM = 95;
+	private static final List<String> VALIDATE_QUERIES = Arrays.asList(
+		"1", "2", "3", "4", "5", "7", "8", "9", "10",
+		"11", "12", "13", "14a", "14b", "15", "16", "17", "18", "20",
+		"21", "22", "23a", "23b", "24a", "24b", "25", "26", "27", "28", "29",
+		"32", "33", "34", "35", "36", "37", "38", "39a", "39b", "40",
+		"41", "42", "43", "44", "45", "47", "48", "49", "50",
+		"51", "52", "53", "54", "55", "56", "57", "58", "59", "60",
+		"61", "62", "63", "64", "65", "66", "69", "70",
+		"71", "72", "73", "74", "75", "76", "77", "78", "79", "80",
+		"82", "83", "84", "85", "86", "87", "88", "89", "90",
+		"91", "92", "93", "94", "95", "96", "97", "98", "99"
+	);
+
+	private static final String REGEX_SPLIT_BAR = "\\|";
+	private static final String FILE_SEPARATOR = "/";
+	private static final String RESULT_SUFFIX = ".ans";
+	private static final double TOLERATED_DOUBLE_DEVIATION = 0.01d;
+
+	public static void main(String[] args) {
+		ParameterTool params = ParameterTool.fromArgs(args);
+		String expectedDir = params.getRequired("expectedDir");
+		String actualDir = params.getRequired("actualDir");
+		int passCnt = 0;
+		for (String queryId : VALIDATE_QUERIES) {
+			File expectedFile = new File(expectedDir + FILE_SEPARATOR + queryId + RESULT_SUFFIX);
+			File actualFile = new File(actualDir + FILE_SEPARATOR + queryId + RESULT_SUFFIX);
+
+			if (compareResult(expectedFile, actualFile)) {
+				passCnt++;
+				System.out.println("[INFO] validate success, file: " + expectedFile.getName() + " cnt:"
+ passCnt);
+			} else {
+				System.out.println("[WARN] validate fail, file: " + expectedFile.getName() + "\n");
+			}
+		}
+		if (passCnt == VALIDATE_QUERY_NUM) {
+			System.exit(0);
+		}
+		System.exit(1);
+	}
+
+	private static boolean compareResult(File expectedFile, File actualFile) {
+		try {
+			BufferedReader expectedReader = new BufferedReader(new FileReader(expectedFile));
+			BufferedReader actualReader = new BufferedReader(new FileReader(actualFile));
+
+			int expectedLineNum = 0;
+			int actualLineNum = 0;
+
+			String expectedLine, actualLine;
+			while ((expectedLine = expectedReader.readLine()) != null &&
+				(actualLine = actualReader.readLine()) != null) {
+				expectedLineNum++;
+				actualLineNum++;
+
+				// reslut top 8 line of query 34,
+				// result line  2、3  0f query 77
+				// result line 18、 19 of query 79
+				// have different order with answer set, because of Flink keep nulls last for DESC, nulls
first for ASC.
+				// it's up to TPC-DS standard.
+				if ("34.ans".equals(expectedFile.getName()) && expectedLineNum == 1) {
+					List<String> expectedTop8Line = new ArrayList<>(8);
+					List<String> actualTop8Line = new ArrayList<>(8);
+
+					String expectedLine2 = expectedReader.readLine();
+					expectedLineNum++;
+					while (expectedLineNum < 8) {
+						expectedTop8Line.add(expectedReader.readLine());
+						expectedLineNum++;
+					}
+					expectedTop8Line.add(expectedLine);
+					expectedTop8Line.add(expectedLine2);
+
+					actualTop8Line.add(actualLine);
+					while (actualLineNum < 8) {
+						actualTop8Line.add(actualReader.readLine());
+						actualLineNum++;
+					}
+					for (int i = 0; i < 8; i++){
+						if (!isEqualLine(expectedTop8Line.get(i), actualTop8Line.get(i), i)) {
+							return false;
+						}
+					}
+					continue;
+				}
+				if ("77.ans".equals(expectedFile.getName()) && expectedLineNum == 2) {
+					String expectedLine3 = expectedReader.readLine();
+					String actualLine3 = actualReader.readLine();
+					expectedLineNum++;
+					actualLineNum++;
+
+					if (isEqualLine(expectedLine, actualLine, 2) && isEqualLine(expectedLine3, actualLine3,
3)) {
+						continue;
+					}
+					if (isEqualLine(expectedLine, actualLine3, 2) && isEqualLine(expectedLine3,
actualLine, 3)) {
+						continue;
+					}
+					return false;
+				}
+
+				if ("79.ans".equals(expectedFile.getName()) && expectedLineNum == 18) {
+					String expectedLine19 = expectedReader.readLine();
+					String actualLine19 = actualReader.readLine();
+					expectedLineNum++;
+					actualLineNum++;
+
+					if (isEqualLine(expectedLine, actualLine, 18) && isEqualLine(expectedLine19,
actualLine19, 19)) {
+						continue;
+					}
+					if (isEqualLine(expectedLine, actualLine19, 18) && isEqualLine(expectedLine19,
actualLine, 19)) {
+						continue;
+					}
+					return false;
+				}
+
+				if (!isEqualLine(expectedLine, actualLine, expectedLineNum)) {
+					return false;
+				}
+			}
+
+			while (expectedReader.readLine() != null) {
+				expectedLineNum++;
+			}
+			while (actualReader.readLine() != null) {
+				actualLineNum++;
+			}
+
+			if (expectedLineNum != actualLineNum) {
+				System.out.println(
+					"[ERROR]incorrect number of lines! Expecting " + expectedLineNum +
+						" lines, but found " + actualLineNum + " lines.");
+				return false;
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+			return false;
+		}
+		return true;
+	}
+
+	private static boolean isEqualLine(String expectedLine, String actualLine, int lineNum)
{
+		String[] expected = expectedLine.split(REGEX_SPLIT_BAR, -1);
+		String[] actual = actualLine.split(REGEX_SPLIT_BAR, -1);
+		if (expected.length != actual.length) {
+			return false;
+		}
+		for (int i = 0; i < expected.length; i++) {
+			if (!isEqualCol(expected[i].trim(), actual[i].trim())) {
+				return false;
+			}
+		}
+		return true;
+	}
+
+	private static boolean isEqualCol(String expected, String actual) {
+		if (canConvert2Double(expected, actual) && isEqualNumber(expected, actual)) {
 
 Review comment:
   Does double parsing twice, can reduce this to once.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message