JingsongLi 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_r309637444
########## File path: flink-end-to-end-tests/flink-tpch-test/src/main/java/org/apache/flink/table/tpch/TpchDataGenerator.java ########## @@ -0,0 +1,107 @@ +/* + * 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 io.airlift.tpch.TpchEntity; +import io.airlift.tpch.TpchTable; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +/** + * Tpch test data generator. + */ +public class TpchDataGenerator { + + public static final int QUERY_NUM = 22; + + public static void main(String[] args) throws IOException { + if (args.length != 2) { + System.out.println("Exactly 1 double value and 1 path should be provided as argument"); + return; + } + + double scale = Double.valueOf(args[0]); + String path = args[1]; + generateTable(scale, path); + generateExpected(path); + } + + private static void generateTable(double scale, String path) throws IOException { + File dir = new File(path + "/table"); + dir.mkdir(); + + for (TpchTable table : TpchTable.getTables()) { + Iterable generator = table.createGenerator(scale, 1, 1); + + StringBuilder builder = new StringBuilder(); + generator.forEach(s -> { + String line = ((TpchEntity) s).toLine().trim(); + if (line.charAt(line.length() - 1) == '|') { + line = line.substring(0, line.length() - 1); + } + builder.append(line).append('\n'); + }); + + try (BufferedWriter writer = new BufferedWriter( + new OutputStreamWriter( + new FileOutputStream(path + "/table/" + table.getTableName() + ".csv"))) + ) { + writer.write(builder.toString()); + } + } + } + + private static void generateExpected(String path) throws IOException { + File dir = new File(path + "/expected"); + dir.mkdir(); + + for (int i = 0; i < QUERY_NUM; i++) { + try ( + BufferedReader reader = new BufferedReader( + new InputStreamReader(TpchDataGenerator.class.getResourceAsStream( + "/io/airlift/tpch/queries/q" + (i + 1) + ".result"))); + BufferedWriter writer = new BufferedWriter( + new OutputStreamWriter( + new FileOutputStream(path + "/expected/q" + (i + 1) + ".csv"))) + ) { + StringBuilder builder = new StringBuilder(); Review comment: Why not directly write to writer? ---------------------------------------------------------------- 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
