tpctools 0.7.0

Utilities for generating and converting TPC-H and TPC-DS data sets
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
// Licensed 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.

use async_trait::async_trait;
use datafusion::arrow::datatypes::{DataType, Field, Schema};
use std::fs;
use std::io::Result;
use std::path::Path;
use std::process::Command;
use std::thread;
use std::time::Instant;

use crate::{move_or_copy, Tpc};

pub struct TpcDs {}

impl TpcDs {
    pub fn new() -> Self {
        Self {}
    }
}

#[async_trait]
impl Tpc for TpcDs {
    fn generate(
        &self,
        scale: usize,
        partitions: usize,
        generator_path: &str,
        output_path: &str,
    ) -> Result<()> {
        let mut handles = vec![];

        let start = Instant::now();

        for i in 1..=partitions {
            let generator_path = generator_path.to_owned();
            let output_path = output_path.to_owned();
            let scale = scale;
            let partitions = partitions;
            handles.push(thread::spawn(move || {
                let output = Command::new("./dsdgen")
                    .current_dir(generator_path.clone())
                    .arg("-FORCE")
                    .arg("-DIR")
                    .arg(output_path)
                    .arg("-SCALE")
                    .arg(format!("{}", scale))
                    .arg("-CHILD")
                    .arg(format!("{}", i))
                    .arg("-PARALLEL")
                    .arg(format!("{}", partitions))
                    .output();

                match output {
                    Ok(x) => println!("{:?}", x),
                    Err(e) => println!(
                        "Failed to build dsdgen command with path {}: {:?}",
                        generator_path, e
                    ),
                }
            }));
        }

        // wait for all threads to finish
        for h in handles {
            h.join().unwrap();
        }

        let duration = start.elapsed();

        println!(
            "Generated TPC-DS data at scale factor {} with {} partitions in: {:?}",
            scale, partitions, duration
        );

        let tables = self.get_table_names();

        for table in &tables {
            let output_dir = format!("{}/{}.dat", output_path, table);
            if !Path::new(&output_dir).exists() {
                println!("Creating directory {}", output_dir);
                fs::create_dir(&output_dir)?;
            }
            for i in 1..=partitions {
                let filename = format!("{}/{}_{}_{}.dat", output_path, table, i, partitions);
                let filename2 = format!("{}/part-{}.dat", output_dir, i);
                if Path::new(&filename).exists() {
                    move_or_copy(&Path::new(&filename), &Path::new(&filename2))?;
                }
            }
        }

        Ok(())
    }

    fn get_table_names(&self) -> Vec<&str> {
        vec![
            "call_center",
            "catalog_page",
            "catalog_sales",
            "catalog_returns",
            "customer",
            "customer_address",
            "customer_demographics",
            "date_dim",
            "income_band",
            "household_demographics",
            "inventory",
            "store",
            "ship_mode",
            "reason",
            "promotion",
            "item",
            "store_sales",
            "store_returns",
            "web_page",
            "warehouse",
            "time_dim",
            "web_site",
            "web_sales",
            "web_returns",
        ]
    }

    fn get_schema(&self, table: &str) -> Schema {
        match table {
            "customer_address" => Schema::new(vec![
                Field::new("ca_address_sk", DataType::Int32, false),
                Field::new("ca_address_id", DataType::Utf8, false),
                Field::new("ca_street_number", DataType::Utf8, true),
                Field::new("ca_street_name", DataType::Utf8, true),
                Field::new("ca_street_type", DataType::Utf8, true),
                Field::new("ca_suite_number", DataType::Utf8, true),
                Field::new("ca_city", DataType::Utf8, true),
                Field::new("ca_county", DataType::Utf8, true),
                Field::new("ca_state", DataType::Utf8, true),
                Field::new("ca_zip", DataType::Utf8, true),
                Field::new("ca_country", DataType::Utf8, true),
                Field::new("ca_gmt_offset", make_decimal_type(5, 2), true),
                Field::new("ca_location_type", DataType::Utf8, true),
            ]),

            "customer_demographics" => Schema::new(vec![
                Field::new("cd_demo_sk", DataType::Int32, false),
                Field::new("cd_gender", DataType::Utf8, true),
                Field::new("cd_marital_status", DataType::Utf8, true),
                Field::new("cd_education_status", DataType::Utf8, true),
                Field::new("cd_purchase_estimate", DataType::Int32, true),
                Field::new("cd_credit_rating", DataType::Utf8, true),
                Field::new("cd_dep_count", DataType::Int32, true),
                Field::new("cd_dep_employed_count", DataType::Int32, true),
                Field::new("cd_dep_college_count", DataType::Int32, true),
            ]),

            "date_dim" => Schema::new(vec![
                Field::new("d_date_sk", DataType::Int32, false),
                Field::new("d_date_id", DataType::Utf8, false),
                Field::new("d_date", DataType::Date32, true),
                Field::new("d_month_seq", DataType::Int32, true),
                Field::new("d_week_seq", DataType::Int32, true),
                Field::new("d_quarter_seq", DataType::Int32, true),
                Field::new("d_year", DataType::Int32, true),
                Field::new("d_dow", DataType::Int32, true),
                Field::new("d_moy", DataType::Int32, true),
                Field::new("d_dom", DataType::Int32, true),
                Field::new("d_qoy", DataType::Int32, true),
                Field::new("d_fy_year", DataType::Int32, true),
                Field::new("d_fy_quarter_seq", DataType::Int32, true),
                Field::new("d_fy_week_seq", DataType::Int32, true),
                Field::new("d_day_name", DataType::Utf8, true),
                Field::new("d_quarter_name", DataType::Utf8, true),
                Field::new("d_holiday", DataType::Utf8, true),
                Field::new("d_weekend", DataType::Utf8, true),
                Field::new("d_following_holiday", DataType::Utf8, true),
                Field::new("d_first_dom", DataType::Int32, true),
                Field::new("d_last_dom", DataType::Int32, true),
                Field::new("d_same_day_ly", DataType::Int32, true),
                Field::new("d_same_day_lq", DataType::Int32, true),
                Field::new("d_current_day", DataType::Utf8, true),
                Field::new("d_current_week", DataType::Utf8, true),
                Field::new("d_current_month", DataType::Utf8, true),
                Field::new("d_current_quarter", DataType::Utf8, true),
                Field::new("d_current_year", DataType::Utf8, true),
            ]),

            "warehouse" => Schema::new(vec![
                Field::new("w_warehouse_sk", DataType::Int32, false),
                Field::new("w_warehouse_id", DataType::Utf8, false),
                Field::new("w_warehouse_name", DataType::Utf8, true),
                Field::new("w_warehouse_sq_ft", DataType::Int32, true),
                Field::new("w_street_number", DataType::Utf8, true),
                Field::new("w_street_name", DataType::Utf8, true),
                Field::new("w_street_type", DataType::Utf8, true),
                Field::new("w_suite_number", DataType::Utf8, true),
                Field::new("w_city", DataType::Utf8, true),
                Field::new("w_county", DataType::Utf8, true),
                Field::new("w_state", DataType::Utf8, true),
                Field::new("w_zip", DataType::Utf8, true),
                Field::new("w_country", DataType::Utf8, true),
                Field::new("w_gmt_offset", make_decimal_type(5, 2), true),
            ]),

            "ship_mode" => Schema::new(vec![
                Field::new("sm_ship_mode_sk", DataType::Int32, false),
                Field::new("sm_ship_mode_id", DataType::Utf8, false),
                Field::new("sm_type", DataType::Utf8, true),
                Field::new("sm_code", DataType::Utf8, true),
                Field::new("sm_carrier", DataType::Utf8, true),
                Field::new("sm_contract", DataType::Utf8, true),
            ]),

            "time_dim" => Schema::new(vec![
                Field::new("t_time_sk", DataType::Int32, false),
                Field::new("t_time_id", DataType::Utf8, false),
                Field::new("t_time", DataType::Int32, true),
                Field::new("t_hour", DataType::Int32, true),
                Field::new("t_minute", DataType::Int32, true),
                Field::new("t_second", DataType::Int32, true),
                Field::new("t_am_pm", DataType::Utf8, true),
                Field::new("t_shift", DataType::Utf8, true),
                Field::new("t_sub_shift", DataType::Utf8, true),
                Field::new("t_meal_time", DataType::Utf8, true),
            ]),

            "reason" => Schema::new(vec![
                Field::new("r_reason_sk", DataType::Int32, false),
                Field::new("r_reason_id", DataType::Utf8, false),
                Field::new("r_reason_desc", DataType::Utf8, true),
            ]),

            "income_band" => Schema::new(vec![
                Field::new("ib_income_band_sk", DataType::Int32, false),
                Field::new("ib_lower_bound", DataType::Int32, true),
                Field::new("ib_upper_bound", DataType::Int32, true),
            ]),

            "item" => Schema::new(vec![
                Field::new("i_item_sk", DataType::Int32, false),
                Field::new("i_item_id", DataType::Utf8, false),
                Field::new("i_rec_start_date", DataType::Date32, true),
                Field::new("i_rec_end_date", DataType::Date32, true),
                Field::new("i_item_desc", DataType::Utf8, true),
                Field::new("i_current_price", make_decimal_type(7, 2), true),
                Field::new("i_wholesale_cost", make_decimal_type(7, 2), true),
                Field::new("i_brand_id", DataType::Int32, true),
                Field::new("i_brand", DataType::Utf8, true),
                Field::new("i_class_id", DataType::Int32, true),
                Field::new("i_class", DataType::Utf8, true),
                Field::new("i_category_id", DataType::Int32, true),
                Field::new("i_category", DataType::Utf8, true),
                Field::new("i_manufact_id", DataType::Int32, true),
                Field::new("i_manufact", DataType::Utf8, true),
                Field::new("i_size", DataType::Utf8, true),
                Field::new("i_formulation", DataType::Utf8, true),
                Field::new("i_color", DataType::Utf8, true),
                Field::new("i_units", DataType::Utf8, true),
                Field::new("i_container", DataType::Utf8, true),
                Field::new("i_manager_id", DataType::Int32, true),
                Field::new("i_product_name", DataType::Utf8, true),
            ]),

            "store" => Schema::new(vec![
                Field::new("s_store_sk", DataType::Int32, false),
                Field::new("s_store_id", DataType::Utf8, false),
                Field::new("s_rec_start_date", DataType::Date32, true),
                Field::new("s_rec_end_date", DataType::Date32, true),
                Field::new("s_closed_date_sk", DataType::Int32, true),
                Field::new("s_store_name", DataType::Utf8, true),
                Field::new("s_number_employees", DataType::Int32, true),
                Field::new("s_floor_space", DataType::Int32, true),
                Field::new("s_hours", DataType::Utf8, true),
                Field::new("s_manager", DataType::Utf8, true),
                Field::new("s_market_id", DataType::Int32, true),
                Field::new("s_geography_class", DataType::Utf8, true),
                Field::new("s_market_desc", DataType::Utf8, true),
                Field::new("s_market_manager", DataType::Utf8, true),
                Field::new("s_division_id", DataType::Int32, true),
                Field::new("s_division_name", DataType::Utf8, true),
                Field::new("s_company_id", DataType::Int32, true),
                Field::new("s_company_name", DataType::Utf8, true),
                Field::new("s_street_number", DataType::Utf8, true),
                Field::new("s_street_name", DataType::Utf8, true),
                Field::new("s_street_type", DataType::Utf8, true),
                Field::new("s_suite_number", DataType::Utf8, true),
                Field::new("s_city", DataType::Utf8, true),
                Field::new("s_county", DataType::Utf8, true),
                Field::new("s_state", DataType::Utf8, true),
                Field::new("s_zip", DataType::Utf8, true),
                Field::new("s_country", DataType::Utf8, true),
                Field::new("s_gmt_offset", make_decimal_type(5, 2), true),
                Field::new("s_tax_precentage", make_decimal_type(5, 2), true),
            ]),

            "call_center" => Schema::new(vec![
                Field::new("cc_call_center_sk", DataType::Int32, false),
                Field::new("cc_call_center_id", DataType::Utf8, false),
                Field::new("cc_rec_start_date", DataType::Date32, true),
                Field::new("cc_rec_end_date", DataType::Date32, true),
                Field::new("cc_closed_date_sk", DataType::Int32, true),
                Field::new("cc_open_date_sk", DataType::Int32, true),
                Field::new("cc_name", DataType::Utf8, true),
                Field::new("cc_class", DataType::Utf8, true),
                Field::new("cc_employees", DataType::Int32, true),
                Field::new("cc_sq_ft", DataType::Int32, true),
                Field::new("cc_hours", DataType::Utf8, true),
                Field::new("cc_manager", DataType::Utf8, true),
                Field::new("cc_mkt_id", DataType::Int32, true),
                Field::new("cc_mkt_class", DataType::Utf8, true),
                Field::new("cc_mkt_desc", DataType::Utf8, true),
                Field::new("cc_market_manager", DataType::Utf8, true),
                Field::new("cc_division", DataType::Int32, true),
                Field::new("cc_division_name", DataType::Utf8, true),
                Field::new("cc_company", DataType::Int32, true),
                Field::new("cc_company_name", DataType::Utf8, true),
                Field::new("cc_street_number", DataType::Utf8, true),
                Field::new("cc_street_name", DataType::Utf8, true),
                Field::new("cc_street_type", DataType::Utf8, true),
                Field::new("cc_suite_number", DataType::Utf8, true),
                Field::new("cc_city", DataType::Utf8, true),
                Field::new("cc_county", DataType::Utf8, true),
                Field::new("cc_state", DataType::Utf8, true),
                Field::new("cc_zip", DataType::Utf8, true),
                Field::new("cc_country", DataType::Utf8, true),
                Field::new("cc_gmt_offset", make_decimal_type(5, 2), true),
                Field::new("cc_tax_percentage", make_decimal_type(5, 2), true),
            ]),

            "customer" => Schema::new(vec![
                Field::new("c_customer_sk", DataType::Int32, false),
                Field::new("c_customer_id", DataType::Utf8, false),
                Field::new("c_current_cdemo_sk", DataType::Int32, true),
                Field::new("c_current_hdemo_sk", DataType::Int32, true),
                Field::new("c_current_addr_sk", DataType::Int32, true),
                Field::new("c_first_shipto_date_sk", DataType::Int32, true),
                Field::new("c_first_sales_date_sk", DataType::Int32, true),
                Field::new("c_salutation", DataType::Utf8, true),
                Field::new("c_first_name", DataType::Utf8, true),
                Field::new("c_last_name", DataType::Utf8, true),
                Field::new("c_preferred_cust_flag", DataType::Utf8, true),
                Field::new("c_birth_day", DataType::Int32, true),
                Field::new("c_birth_month", DataType::Int32, true),
                Field::new("c_birth_year", DataType::Int32, true),
                Field::new("c_birth_country", DataType::Utf8, true),
                Field::new("c_login", DataType::Utf8, true),
                Field::new("c_email_address", DataType::Utf8, true),
                Field::new("c_last_review_date_sk", DataType::Utf8, true),
            ]),

            "web_site" => Schema::new(vec![
                Field::new("web_site_sk", DataType::Int32, false),
                Field::new("web_site_id", DataType::Utf8, false),
                Field::new("web_rec_start_date", DataType::Date32, true),
                Field::new("web_rec_end_date", DataType::Date32, true),
                Field::new("web_name", DataType::Utf8, true),
                Field::new("web_open_date_sk", DataType::Int32, true),
                Field::new("web_close_date_sk", DataType::Int32, true),
                Field::new("web_class", DataType::Utf8, true),
                Field::new("web_manager", DataType::Utf8, true),
                Field::new("web_mkt_id", DataType::Int32, true),
                Field::new("web_mkt_class", DataType::Utf8, true),
                Field::new("web_mkt_desc", DataType::Utf8, true),
                Field::new("web_market_manager", DataType::Utf8, true),
                Field::new("web_company_id", DataType::Int32, true),
                Field::new("web_company_name", DataType::Utf8, true),
                Field::new("web_street_number", DataType::Utf8, true),
                Field::new("web_street_name", DataType::Utf8, true),
                Field::new("web_street_type", DataType::Utf8, true),
                Field::new("web_suite_number", DataType::Utf8, true),
                Field::new("web_city", DataType::Utf8, true),
                Field::new("web_county", DataType::Utf8, true),
                Field::new("web_state", DataType::Utf8, true),
                Field::new("web_zip", DataType::Utf8, true),
                Field::new("web_country", DataType::Utf8, true),
                Field::new("web_gmt_offset", make_decimal_type(5, 2), true),
                Field::new("web_tax_percentage", make_decimal_type(5, 2), true),
            ]),

            "store_returns" => Schema::new(vec![
                Field::new("sr_returned_date_sk", DataType::Int32, true),
                Field::new("sr_return_time_sk", DataType::Int32, true),
                Field::new("sr_item_sk", DataType::Int32, false),
                Field::new("sr_customer_sk", DataType::Int32, true),
                Field::new("sr_cdemo_sk", DataType::Int32, true),
                Field::new("sr_hdemo_sk", DataType::Int32, true),
                Field::new("sr_addr_sk", DataType::Int32, true),
                Field::new("sr_store_sk", DataType::Int32, true),
                Field::new("sr_reason_sk", DataType::Int32, true),
                Field::new("sr_ticket_number", DataType::Int32, false),
                Field::new("sr_return_quantity", DataType::Int32, true),
                Field::new("sr_return_amt", make_decimal_type(7, 2), true),
                Field::new("sr_return_tax", make_decimal_type(7, 2), true),
                Field::new("sr_return_amt_inc_tax", make_decimal_type(7, 2), true),
                Field::new("sr_fee", make_decimal_type(7, 2), true),
                Field::new("sr_return_ship_cost", make_decimal_type(7, 2), true),
                Field::new("sr_refunded_cash", make_decimal_type(7, 2), true),
                Field::new("sr_reversed_charge", make_decimal_type(7, 2), true),
                Field::new("sr_store_credit", make_decimal_type(7, 2), true),
                Field::new("sr_net_loss", make_decimal_type(7, 2), true),
            ]),

            "household_demographics" => Schema::new(vec![
                Field::new("hd_demo_sk", DataType::Int32, false),
                Field::new("hd_income_band_sk", DataType::Int32, true),
                Field::new("hd_buy_potential", DataType::Utf8, true),
                Field::new("hd_dep_count", DataType::Int32, true),
                Field::new("hd_vehicle_count", DataType::Int32, true),
            ]),

            "web_page" => Schema::new(vec![
                Field::new("wp_web_page_sk", DataType::Int32, false),
                Field::new("wp_web_page_id", DataType::Utf8, false),
                Field::new("wp_rec_start_date", DataType::Date32, true),
                Field::new("wp_rec_end_date", DataType::Date32, true),
                Field::new("wp_creation_date_sk", DataType::Int32, true),
                Field::new("wp_access_date_sk", DataType::Int32, true),
                Field::new("wp_autogen_flag", DataType::Utf8, true),
                Field::new("wp_customer_sk", DataType::Int32, true),
                Field::new("wp_url", DataType::Utf8, true),
                Field::new("wp_type", DataType::Utf8, true),
                Field::new("wp_char_count", DataType::Int32, true),
                Field::new("wp_link_count", DataType::Int32, true),
                Field::new("wp_image_count", DataType::Int32, true),
                Field::new("wp_max_ad_count", DataType::Int32, true),
            ]),

            "promotion" => Schema::new(vec![
                Field::new("p_promo_sk", DataType::Int32, false),
                Field::new("p_promo_id", DataType::Utf8, false),
                Field::new("p_start_date_sk", DataType::Int32, true),
                Field::new("p_end_date_sk", DataType::Int32, true),
                Field::new("p_item_sk", DataType::Int32, true),
                Field::new("p_cost", make_decimal_type(15, 2), true),
                Field::new("p_response_target", DataType::Int32, true),
                Field::new("p_promo_name", DataType::Utf8, true),
                Field::new("p_channel_dmail", DataType::Utf8, true),
                Field::new("p_channel_email", DataType::Utf8, true),
                Field::new("p_channel_catalog", DataType::Utf8, true),
                Field::new("p_channel_tv", DataType::Utf8, true),
                Field::new("p_channel_radio", DataType::Utf8, true),
                Field::new("p_channel_press", DataType::Utf8, true),
                Field::new("p_channel_event", DataType::Utf8, true),
                Field::new("p_channel_demo", DataType::Utf8, true),
                Field::new("p_channel_details", DataType::Utf8, true),
                Field::new("p_purpose", DataType::Utf8, true),
                Field::new("p_discount_active", DataType::Utf8, true),
            ]),

            "catalog_page" => Schema::new(vec![
                Field::new("cp_catalog_page_sk", DataType::Int32, false),
                Field::new("cp_catalog_page_id", DataType::Utf8, false),
                Field::new("cp_start_date_sk", DataType::Int32, true),
                Field::new("cp_end_date_sk", DataType::Int32, true),
                Field::new("cp_department", DataType::Utf8, true),
                Field::new("cp_catalog_number", DataType::Int32, true),
                Field::new("cp_catalog_page_number", DataType::Int32, true),
                Field::new("cp_description", DataType::Utf8, true),
                Field::new("cp_type", DataType::Utf8, true),
            ]),

            "inventory" => Schema::new(vec![
                Field::new("inv_date_sk", DataType::Int32, false),
                Field::new("inv_item_sk", DataType::Int32, false),
                Field::new("inv_warehouse_sk", DataType::Int32, false),
                Field::new("inv_quantity_on_hand", DataType::Int32, true),
            ]),

            "catalog_returns" => Schema::new(vec![
                Field::new("cr_returned_date_sk", DataType::Int32, true),
                Field::new("cr_returned_time_sk", DataType::Int32, true),
                Field::new("cr_item_sk", DataType::Int32, false),
                Field::new("cr_refunded_customer_sk", DataType::Int32, true),
                Field::new("cr_refunded_cdemo_sk", DataType::Int32, true),
                Field::new("cr_refunded_hdemo_sk", DataType::Int32, true),
                Field::new("cr_refunded_addr_sk", DataType::Int32, true),
                Field::new("cr_returning_customer_sk", DataType::Int32, true),
                Field::new("cr_returning_cdemo_sk", DataType::Int32, true),
                Field::new("cr_returning_hdemo_sk", DataType::Int32, true),
                Field::new("cr_returning_addr_sk", DataType::Int32, true),
                Field::new("cr_call_center_sk", DataType::Int32, true),
                Field::new("cr_catalog_page_sk", DataType::Int32, true),
                Field::new("cr_ship_mode_sk", DataType::Int32, true),
                Field::new("cr_warehouse_sk", DataType::Int32, true),
                Field::new("cr_reason_sk", DataType::Int32, true),
                Field::new("cr_order_number", DataType::Int32, false),
                Field::new("cr_return_quantity", DataType::Int32, true),
                Field::new("cr_return_amount", make_decimal_type(7, 2), true),
                Field::new("cr_return_tax", make_decimal_type(7, 2), true),
                Field::new("cr_return_amt_inc_tax", make_decimal_type(7, 2), true),
                Field::new("cr_fee", make_decimal_type(7, 2), true),
                Field::new("cr_return_ship_cost", make_decimal_type(7, 2), true),
                Field::new("cr_refunded_cash", make_decimal_type(7, 2), true),
                Field::new("cr_reversed_charge", make_decimal_type(7, 2), true),
                Field::new("cr_store_credit", make_decimal_type(7, 2), true),
                Field::new("cr_net_loss", make_decimal_type(7, 2), true),
            ]),

            "web_returns" => Schema::new(vec![
                Field::new("wr_returned_date_sk", DataType::Int32, true),
                Field::new("wr_returned_time_sk", DataType::Int32, true),
                Field::new("wr_item_sk", DataType::Int32, false),
                Field::new("wr_refunded_customer_sk", DataType::Int32, true),
                Field::new("wr_refunded_cdemo_sk", DataType::Int32, true),
                Field::new("wr_refunded_hdemo_sk", DataType::Int32, true),
                Field::new("wr_refunded_addr_sk", DataType::Int32, true),
                Field::new("wr_returning_customer_sk", DataType::Int32, true),
                Field::new("wr_returning_cdemo_sk", DataType::Int32, true),
                Field::new("wr_returning_hdemo_sk", DataType::Int32, true),
                Field::new("wr_returning_addr_sk", DataType::Int32, true),
                Field::new("wr_web_page_sk", DataType::Int32, true),
                Field::new("wr_reason_sk", DataType::Int32, true),
                Field::new("wr_order_number", DataType::Int32, false),
                Field::new("wr_return_quantity", DataType::Int32, true),
                Field::new("wr_return_amt", make_decimal_type(7, 2), true),
                Field::new("wr_return_tax", make_decimal_type(7, 2), true),
                Field::new("wr_return_amt_inc_tax", make_decimal_type(7, 2), true),
                Field::new("wr_fee", make_decimal_type(7, 2), true),
                Field::new("wr_return_ship_cost", make_decimal_type(7, 2), true),
                Field::new("wr_refunded_cash", make_decimal_type(7, 2), true),
                Field::new("wr_reversed_charge", make_decimal_type(7, 2), true),
                Field::new("wr_account_credit", make_decimal_type(7, 2), true),
                Field::new("wr_net_loss", make_decimal_type(7, 2), true),
            ]),

            "web_sales" => Schema::new(vec![
                Field::new("ws_sold_date_sk", DataType::Int32, true),
                Field::new("ws_sold_time_sk", DataType::Int32, true),
                Field::new("ws_ship_date_sk", DataType::Int32, true),
                Field::new("ws_item_sk", DataType::Int32, false),
                Field::new("ws_bill_customer_sk", DataType::Int32, true),
                Field::new("ws_bill_cdemo_sk", DataType::Int32, true),
                Field::new("ws_bill_hdemo_sk", DataType::Int32, true),
                Field::new("ws_bill_addr_sk", DataType::Int32, true),
                Field::new("ws_ship_customer_sk", DataType::Int32, true),
                Field::new("ws_ship_cdemo_sk", DataType::Int32, true),
                Field::new("ws_ship_hdemo_sk", DataType::Int32, true),
                Field::new("ws_ship_addr_sk", DataType::Int32, true),
                Field::new("ws_web_page_sk", DataType::Int32, true),
                Field::new("ws_web_site_sk", DataType::Int32, true),
                Field::new("ws_ship_mode_sk", DataType::Int32, true),
                Field::new("ws_warehouse_sk", DataType::Int32, true),
                Field::new("ws_promo_sk", DataType::Int32, true),
                Field::new("ws_order_number", DataType::Int32, false),
                Field::new("ws_quantity", DataType::Int32, true),
                Field::new("ws_wholesale_cost", make_decimal_type(7, 2), true),
                Field::new("ws_list_price", make_decimal_type(7, 2), true),
                Field::new("ws_sales_price", make_decimal_type(7, 2), true),
                Field::new("ws_ext_discount_amt", make_decimal_type(7, 2), true),
                Field::new("ws_ext_sales_price", make_decimal_type(7, 2), true),
                Field::new("ws_ext_wholesale_cost", make_decimal_type(7, 2), true),
                Field::new("ws_ext_list_price", make_decimal_type(7, 2), true),
                Field::new("ws_ext_tax", make_decimal_type(7, 2), true),
                Field::new("ws_coupon_amt", make_decimal_type(7, 2), true),
                Field::new("ws_ext_ship_cost", make_decimal_type(7, 2), true),
                Field::new("ws_net_paid", make_decimal_type(7, 2), true),
                Field::new("ws_net_paid_inc_tax", make_decimal_type(7, 2), true),
                Field::new("ws_net_paid_inc_ship", make_decimal_type(7, 2), true),
                Field::new("ws_net_paid_inc_ship_tax", make_decimal_type(7, 2), true),
                Field::new("ws_net_profit", make_decimal_type(7, 2), true),
            ]),

            "catalog_sales" => Schema::new(vec![
                Field::new("cs_sold_date_sk", DataType::Int32, true),
                Field::new("cs_sold_time_sk", DataType::Int32, true),
                Field::new("cs_ship_date_sk", DataType::Int32, true),
                Field::new("cs_bill_customer_sk", DataType::Int32, true),
                Field::new("cs_bill_cdemo_sk", DataType::Int32, true),
                Field::new("cs_bill_hdemo_sk", DataType::Int32, true),
                Field::new("cs_bill_addr_sk", DataType::Int32, true),
                Field::new("cs_ship_customer_sk", DataType::Int32, true),
                Field::new("cs_ship_cdemo_sk", DataType::Int32, true),
                Field::new("cs_ship_hdemo_sk", DataType::Int32, true),
                Field::new("cs_ship_addr_sk", DataType::Int32, true),
                Field::new("cs_call_center_sk", DataType::Int32, true),
                Field::new("cs_catalog_page_sk", DataType::Int32, true),
                Field::new("cs_ship_mode_sk", DataType::Int32, true),
                Field::new("cs_warehouse_sk", DataType::Int32, true),
                Field::new("cs_item_sk", DataType::Int32, false),
                Field::new("cs_promo_sk", DataType::Int32, true),
                Field::new("cs_order_number", DataType::Int32, false),
                Field::new("cs_quantity", DataType::Int32, true),
                Field::new("cs_wholesale_cost", make_decimal_type(7, 2), true),
                Field::new("cs_list_price", make_decimal_type(7, 2), true),
                Field::new("cs_sales_price", make_decimal_type(7, 2), true),
                Field::new("cs_ext_discount_amt", make_decimal_type(7, 2), true),
                Field::new("cs_ext_sales_price", make_decimal_type(7, 2), true),
                Field::new("cs_ext_wholesale_cost", make_decimal_type(7, 2), true),
                Field::new("cs_ext_list_price", make_decimal_type(7, 2), true),
                Field::new("cs_ext_tax", make_decimal_type(7, 2), true),
                Field::new("cs_coupon_amt", make_decimal_type(7, 2), true),
                Field::new("cs_ext_ship_cost", make_decimal_type(7, 2), true),
                Field::new("cs_net_paid", make_decimal_type(7, 2), true),
                Field::new("cs_net_paid_inc_tax", make_decimal_type(7, 2), true),
                Field::new("cs_net_paid_inc_ship", make_decimal_type(7, 2), true),
                Field::new("cs_net_paid_inc_ship_tax", make_decimal_type(7, 2), true),
                Field::new("cs_net_profit", make_decimal_type(7, 2), true),
            ]),

            "store_sales" => Schema::new(vec![
                Field::new("ss_sold_date_sk", DataType::Int32, true),
                Field::new("ss_sold_time_sk", DataType::Int32, true),
                Field::new("ss_item_sk", DataType::Int32, false),
                Field::new("ss_customer_sk", DataType::Int32, true),
                Field::new("ss_cdemo_sk", DataType::Int32, true),
                Field::new("ss_hdemo_sk", DataType::Int32, true),
                Field::new("ss_addr_sk", DataType::Int32, true),
                Field::new("ss_store_sk", DataType::Int32, true),
                Field::new("ss_promo_sk", DataType::Int32, true),
                Field::new("ss_ticket_number", DataType::Int32, false),
                Field::new("ss_quantity", DataType::Int32, true),
                Field::new("ss_wholesale_cost", make_decimal_type(7, 2), true),
                Field::new("ss_list_price", make_decimal_type(7, 2), true),
                Field::new("ss_sales_price", make_decimal_type(7, 2), true),
                Field::new("ss_ext_discount_amt", make_decimal_type(7, 2), true),
                Field::new("ss_ext_sales_price", make_decimal_type(7, 2), true),
                Field::new("ss_ext_wholesale_cost", make_decimal_type(7, 2), true),
                Field::new("ss_ext_list_price", make_decimal_type(7, 2), true),
                Field::new("ss_ext_tax", make_decimal_type(7, 2), true),
                Field::new("ss_coupon_amt", make_decimal_type(7, 2), true),
                Field::new("ss_net_paid", make_decimal_type(7, 2), true),
                Field::new("ss_net_paid_inc_tax", make_decimal_type(7, 2), true),
                Field::new("ss_net_profit", make_decimal_type(7, 2), true),
            ]),

            _ => panic!(),
        }
    }

    fn get_table_ext(&self) -> &str {
        "dat"
    }
}

fn make_decimal_type(p: u8, s: i8) -> DataType {
    DataType::Decimal128(p, s)
}