Skip to content

Script to export table to file (playground)

Alexander Löser edited this page Dec 19, 2018 · 1 revision
#include <tpch/tpch_db_generator.hpp>
#include <sql/sql_pipeline_builder.hpp>
#include <operators/table_wrapper.hpp>
#include <operators/export_csv.hpp>

#include "types.hpp"

using namespace opossum;  // NOLINT

int main() {
  const float scale_factor = 1.f;
  std::cout << "Starting to generate TCPH tables with scale factor " << scale_factor << "... " << std::endl;
  opossum::TpchDbGenerator(scale_factor).generate_and_store();
  std::cout << " done" << std::endl;
  std::cout << "Starting to compute join query part for TPCH-18 (modified)..." << std::endl;
  auto sql = "SELECT c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, l_quantity FROM customer, orders, lineitem WHERE o_orderkey in (SELECT l_orderkey FROM lineitem GROUP BY l_orderkey having SUM(l_quantity) > 200) AND c_custkey = o_custkey AND o_orderkey = l_orderkey";
  auto builder = SQLPipelineBuilder{sql}.dont_cleanup_temporaries();
  auto sql_pipeline = std::make_unique<SQLPipeline>(builder.create_pipeline());
  auto result = sql_pipeline->get_result_table();
  std::cout << std::endl;
  auto result_wrapper = std::make_shared<TableWrapper>(result);
  result_wrapper->execute();
  ExportCsv csv_export = ExportCsv(result_wrapper, "myTable.csv");
  std::cout << "starting export" << std::endl;
  csv_export.execute();
}