1#include "append_info.h"
2#include "append_info.hpp"
3#include "config.h"
4#include "porting.h"
5#include "nulls.h"
6#include "date.h"
7
8#include "duckdb/common/types/date.hpp"
9#include "duckdb/common/exception.hpp"
10#include "duckdb/storage/data_table.hpp"
11#include <cstring>
12#include <memory>
13
14using namespace tpcds;
15
16append_info *append_info_get(void *info_list, int table_id) {
17 auto &append_vector = *((std::vector<std::unique_ptr<tpcds_append_information>> *)info_list);
18 return (append_info *)append_vector[table_id].get();
19}
20
21void append_row_start(append_info *info) {
22 auto append_info = (tpcds_append_information *)info;
23 append_info->appender.BeginRow();
24}
25
26void append_row_end(append_info *info) {
27 auto append_info = (tpcds_append_information *)info;
28 append_info->appender.EndRow();
29}
30
31void append_varchar(append_info *info, const char *value) {
32 auto append_info = (tpcds_append_information *)info;
33 if (!nullCheck(append_info->appender.CurrentColumn())) {
34 append_info->appender.Append<const char*>(value);
35 } else {
36 append_info->appender.Append(nullptr);
37 }
38}
39
40// TODO: use direct array manipulation for speed, but not now
41static void append_value(append_info *info, duckdb::Value v) {
42 auto append_info = (tpcds_append_information *)info;
43 append_info->appender.Append<duckdb::Value>(v);
44}
45
46void append_key(append_info *info, int64_t value) {
47 auto append_info = (tpcds_append_information *)info;
48 append_info->appender.Append<int64_t>(value);
49}
50
51void append_integer(append_info *info, int32_t value) {
52 auto append_info = (tpcds_append_information *)info;
53 append_info->appender.Append<int32_t>(value);
54}
55
56void append_boolean(append_info *info, int32_t value) {
57 auto append_info = (tpcds_append_information *)info;
58 append_info->appender.Append<bool>(value != 0);
59}
60
61// value is a Julian date
62// FIXME: direct int conversion, offsets should be constant
63void append_date(append_info *info, int64_t value) {
64 date_t dTemp;
65 jtodt(&dTemp, (int)value);
66 auto ddate = duckdb::Date::FromDate(dTemp.year, dTemp.month, dTemp.day);
67 append_integer(info, (int32_t) ddate);
68}
69
70void append_decimal(append_info *info, decimal_t *val) {
71 double dTemp = val->number;
72 for (int i = 0; i < val->precision; i++) {
73 dTemp /= 10.0;
74 }
75 auto append_info = (tpcds_append_information *)info;
76 append_info->appender.Append<double>(dTemp);
77}
78