| 1 | #include "duckdb/common/exception.hpp" |
| 2 | #include "duckdb/main/connection.hpp" |
| 3 | #include "duckdb/storage/data_table.hpp" |
| 4 | |
| 5 | #include "tpce_generated.hpp" |
| 6 | #include "tpce.hpp" |
| 7 | |
| 8 | #include "main/EGenLoader_stdafx.h" |
| 9 | #include "input/DataFileManager.h" |
| 10 | |
| 11 | using namespace duckdb; |
| 12 | using namespace TPCE; |
| 13 | using namespace std; |
| 14 | |
| 15 | namespace tpce { |
| 16 | |
| 17 | TIdent iStartFromCustomer = iDefaultStartFromCustomer; |
| 18 | TIdent iCustomerCount = iDefaultCustomerCount; // # of customers for this instance |
| 19 | TIdent iTotalCustomerCount = iDefaultCustomerCount; // total number of customers in the database |
| 20 | UINT iLoadUnitSize = iDefaultLoadUnitSize; // # of customers in one load unit |
| 21 | UINT iDaysOfInitialTrades = 300; |
| 22 | |
| 23 | void dbgen(duckdb::DuckDB &db, uint32_t sf, std::string schema, std::string suffix) { |
| 24 | unique_ptr<CBaseLoaderFactory> pLoaderFactory; // class factory that creates table loaders |
| 25 | CGenerateAndLoadStandardOutput Output; |
| 26 | unique_ptr<CGenerateAndLoad> pGenerateAndLoad; |
| 27 | |
| 28 | Connection con(db); |
| 29 | con.Query("BEGIN TRANSACTION" ); |
| 30 | |
| 31 | CreateTPCESchema(db, con, schema, suffix); |
| 32 | |
| 33 | if (sf == 0) { |
| 34 | // schema only |
| 35 | con.Query("COMMIT" ); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | pLoaderFactory = make_unique<DuckDBLoaderFactory>(con, schema, suffix); |
| 40 | |
| 41 | // Create log formatter and logger instance |
| 42 | CLogFormatTab fmt; |
| 43 | CEGenLogger logger(eDriverEGenLoader, 0, nullptr, &fmt); |
| 44 | |
| 45 | // Set up data file manager for lazy load. |
| 46 | const DataFileManager dfm(iTotalCustomerCount, iTotalCustomerCount); |
| 47 | |
| 48 | // Create the main class instance |
| 49 | pGenerateAndLoad = unique_ptr<CGenerateAndLoad>( |
| 50 | new CGenerateAndLoad(dfm, iCustomerCount, iStartFromCustomer, iTotalCustomerCount, iLoadUnitSize, sf, |
| 51 | iDaysOfInitialTrades, pLoaderFactory.get(), &logger, &Output, true)); |
| 52 | |
| 53 | // The generate and load phase starts here. |
| 54 | // Generate static tables |
| 55 | pGenerateAndLoad->GenerateAndLoadFixedTables(); |
| 56 | |
| 57 | // Generate dynamic scaling tables |
| 58 | pGenerateAndLoad->GenerateAndLoadScalingTables(); |
| 59 | |
| 60 | // Generate dynamic trade tables |
| 61 | pGenerateAndLoad->GenerateAndLoadGrowingTables(); |
| 62 | |
| 63 | con.Query("COMMIT" ); |
| 64 | } |
| 65 | |
| 66 | } // namespace tpce |
| 67 | |