twalthr commented on a change in pull request #9312: [FLINK-13436][end-to-end-tests] Add TPC-H queries as E2E tests URL: https://github.com/apache/flink/pull/9312#discussion_r309605512
########## File path: flink-end-to-end-tests/flink-tpch-test/src/main/java/org/apache/flink/table/tpch/TpchResultComparator.java ########## @@ -0,0 +1,123 @@ +/* + * 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.tpch; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +/** + * Result comparator for TPCH test, according to the TPCH standard specification v2.18.0. + */ +public class TpchResultComparator { + + public static void main(String[] args) throws IOException { + if (args.length != 2) { + System.out.println( + "Exactly 2 paths must be provided, the expected result path and the actual result path"); + System.exit(1); + } + + String expectedPath = args[0]; + String actualPath = args[1]; + + try ( + BufferedReader expectedReader = new BufferedReader(new FileReader(expectedPath)); + BufferedReader actualReader = new BufferedReader(new FileReader(actualPath)) + ) { + int expectedLineNum = 0; + int actualLineNum = 0; + + String expectedLine, actualLine; + while ( + (expectedLine = expectedReader.readLine()) != null && + (actualLine = actualReader.readLine()) != null + ) { + String[] expected = expectedLine.split("\\|"); + expectedLineNum++; + String[] actual = actualLine.split("\\|"); + actualLineNum++; + + if (expected.length != actual.length) { + System.out.println( + "Incorrect number of columns on line " + actualLineNum + + "! Expecting " + expected.length + " columns, but found " + actual.length + " columns."); + System.exit(1); + } + for (int i = 0; i < expected.length; i++) { + boolean failed; + try { + long e = Long.valueOf(expected[i]); + long a = Long.valueOf(actual[i]); + failed = (e != a); + } catch (NumberFormatException nfe) { + try { + double e = Double.valueOf(expected[i]); + double a = Double.valueOf(actual[i]); + if (e < 0 && a > 0 || e > 0 && a < 0) { + failed = true; + } else { + if (e < 0) { + e = -e; + a = -a; + } + double t = round(a, 2); + // defined in TPCH standard specification v2.18.0 section 2.1.3.5 Review comment: nit: could you string replace `TPCH` for `TPC-H` in this PR for all comments and the name of the e2e test. ---------------------------------------------------------------- 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] With regards, Apache Git Services
