1#include "include/imdb.hpp"
2#include "imdb_constants.hpp"
3#include "duckdb/common/file_system.hpp"
4
5
6using namespace duckdb;
7using namespace std;
8
9namespace imdb {
10
11void dbgen(DuckDB &db) {
12 Connection con(db);
13 con.Query("BEGIN TRANSACTION");
14 for (int t = 0; t < IMDB_TABLE_COUNT; t++) {
15 con.Query(IMDB_TABLE_DDL[t]);
16 string table_name = string(IMDB_TABLE_NAMES[t]);
17 string data_file_name = "third_party/imdb/data/"+table_name+".csv.gz";
18 auto file_system = make_unique<FileSystem>();
19 if (!file_system->FileExists(data_file_name)) {
20 throw Exception("IMDB data file missing, try `make imdb` to download.");
21 }
22 con.Query("COPY "+table_name+" FROM '"+data_file_name+"' DELIMITER ',' ESCAPE '\\';");
23 }
24 con.Query("COMMIT");
25}
26
27string get_query(int query) {
28 if (query <= 0 || query > IMDB_QUERIES_COUNT) {
29 throw SyntaxException("Out of range IMDB query number %d", query);
30 }
31 return IMDB_QUERIES[query - 1];
32}
33} // namespace imdb
34