| 1 | #include "dsdgen.hpp" |
| 2 | #include "duckdb/common/exception.hpp" |
| 3 | #include "duckdb/common/types/data_chunk.hpp" |
| 4 | #include "duckdb/storage/data_table.hpp" |
| 5 | #include "tpcds_constants.hpp" |
| 6 | #include "append_info.hpp" |
| 7 | #include "dsdgen_helpers.hpp" |
| 8 | |
| 9 | using namespace duckdb; |
| 10 | using namespace std; |
| 11 | |
| 12 | namespace tpcds { |
| 13 | |
| 14 | void dbgen(double flt_scale, DuckDB &db, string schema, string suffix) { |
| 15 | Connection con(db); |
| 16 | |
| 17 | con.Query("BEGIN TRANSACTION" ); |
| 18 | // FIXME: No restart support yet, suspect only fix is init_rand |
| 19 | // FIXME: no schema/suffix support yet |
| 20 | |
| 21 | for (int t = 0; t < TPCDS_TABLE_COUNT; t++) { |
| 22 | con.Query(TPCDS_TABLE_DDL_NOKEYS[t]); |
| 23 | } |
| 24 | |
| 25 | con.Query("COMMIT" ); |
| 26 | |
| 27 | if (flt_scale == 0) { |
| 28 | // schema only |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | InitializeDSDgen(); |
| 33 | |
| 34 | // populate append info |
| 35 | vector<unique_ptr<tpcds_append_information>> append_info; |
| 36 | append_info.resize(DBGEN_VERSION); |
| 37 | |
| 38 | int tmin = CALL_CENTER, tmax = DBGEN_VERSION; |
| 39 | |
| 40 | for (int table_id = tmin; table_id < tmax; table_id++) { |
| 41 | auto table_def = GetTDefByNumber(table_id); |
| 42 | assert(table_def.name); |
| 43 | auto append = make_unique<tpcds_append_information>(db, schema, table_def.name); |
| 44 | append->table_def = table_def; |
| 45 | append_info[table_id] = move(append); |
| 46 | } |
| 47 | |
| 48 | // actually generate tables using modified data generator functions |
| 49 | for (int table_id = tmin; table_id < tmax; table_id++) { |
| 50 | // child tables are created in parent loaders |
| 51 | if (append_info[table_id]->table_def.fl_child) { |
| 52 | continue; |
| 53 | } |
| 54 | |
| 55 | ds_key_t kRowCount = GetRowCount(table_id), kFirstRow = 1; |
| 56 | |
| 57 | // TODO: verify this is correct and required here |
| 58 | /* |
| 59 | * small tables use a constrained set of geography information |
| 60 | */ |
| 61 | if (append_info[table_id]->table_def.fl_small) { |
| 62 | ResetCountCount(); |
| 63 | } |
| 64 | |
| 65 | auto builder_func = GetTDefFunctionByNumber(table_id); |
| 66 | assert(builder_func); |
| 67 | |
| 68 | for (ds_key_t i = kFirstRow; kRowCount; i++, kRowCount--) { |
| 69 | // append happens directly in builders since they dump child tables |
| 70 | // immediately |
| 71 | if (builder_func((void *)&append_info, i)) { |
| 72 | throw Exception("Table generation failed" ); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // flush any incomplete chunks |
| 78 | for (int table_id = tmin; table_id < tmax; table_id++) { |
| 79 | append_info[table_id]->appender.Close(); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | string get_query(int query) { |
| 84 | if (query <= 0 || query > TPCDS_QUERIES_COUNT) { |
| 85 | throw SyntaxException("Out of range TPC-DS query number %d" , query); |
| 86 | } |
| 87 | return TPCDS_QUERIES[query - 1]; |
| 88 | } |
| 89 | |
| 90 | string get_answer(double sf, int query) { |
| 91 | if (query <= 0 || query > TPCDS_QUERIES_COUNT) { |
| 92 | throw SyntaxException("Out of range TPC-DS query number %d" , query); |
| 93 | } |
| 94 | return "" ; |
| 95 | } |
| 96 | |
| 97 | } // namespace tpcds |
| 98 | |