25 #include <boost/algorithm/string.hpp>
26 #include <boost/filesystem.hpp>
33 namespace import_export {
36 const std::string& file_path) {
60 if (add_metadata_columns.length() == 0u) {
67 std::vector<std::string> add_metadata_column_strings;
68 boost::split(add_metadata_column_strings, add_metadata_columns, boost::is_any_of(
";"));
69 if (add_metadata_column_strings.size() == 0u) {
76 auto const fn = boost::filesystem::path(file_path).filename().string();
77 auto const fd = boost::filesystem::path(file_path).parent_path().string();
78 auto const fp = file_path;
86 for (
auto const& add_metadata_column_string : add_metadata_column_strings) {
88 auto const add_metadata_column =
strip(add_metadata_column_string);
91 std::vector<std::string> tokens;
92 boost::split(tokens, add_metadata_column, boost::is_any_of(
","));
93 if (tokens.size() < 3u) {
94 throw std::runtime_error(
"Invalid metadata column info '" + add_metadata_column +
95 "' (must be of the form 'name,type,expression')");
97 auto token_itr = tokens.begin();
98 auto const column_name =
strip(*token_itr++);
100 tokens.erase(tokens.begin(), token_itr);
105 double range_min{0.0}, range_max{0.0};
106 if (data_type ==
"tinyint") {
108 range_min =
static_cast<double>(std::numeric_limits<int8_t>::min());
109 range_max =
static_cast<double>(std::numeric_limits<int8_t>::max());
110 }
else if (data_type ==
"smallint") {
112 range_min =
static_cast<double>(std::numeric_limits<int16_t>::min());
113 range_max =
static_cast<double>(std::numeric_limits<int16_t>::max());
114 }
else if (data_type ==
"int") {
116 range_min =
static_cast<double>(std::numeric_limits<int32_t>::min());
117 range_max =
static_cast<double>(std::numeric_limits<int32_t>::max());
118 }
else if (data_type ==
"bigint") {
120 range_min =
static_cast<double>(std::numeric_limits<int64_t>::min());
121 range_max =
static_cast<double>(std::numeric_limits<int64_t>::max());
122 }
else if (data_type ==
"float") {
124 range_min =
static_cast<double>(std::numeric_limits<float>::min());
125 range_max =
static_cast<double>(std::numeric_limits<float>::max());
126 }
else if (data_type ==
"double") {
128 range_min =
static_cast<double>(std::numeric_limits<double>::min());
129 range_max =
static_cast<double>(std::numeric_limits<double>::max());
130 }
else if (data_type ==
"date") {
132 }
else if (data_type ==
"time") {
134 }
else if (data_type ==
"timestamp") {
136 }
else if (data_type ==
"text") {
139 throw std::runtime_error(
"Invalid metadata column data type '" + data_type +
140 "' for column '" + column_name +
"'");
152 if (sql_type ==
kDATE) {
153 dateTimeParse<kDATE>(value, 0);
154 }
else if (sql_type ==
kTIME) {
155 dateTimeParse<kTIME>(value, 0);
157 dateTimeParse<kTIMESTAMP>(value, 0);
159 }
catch (std::runtime_error& e) {
160 throw std::runtime_error(
"Invalid metadata column " +
to_string(sql_type) +
161 " value '" + value +
"' for column '" + column_name +
"'");
167 size_t num_chars{0u};
168 auto const v =
static_cast<double>(std::stod(value, &num_chars));
169 if (v < range_min || v > range_max) {
170 throw std::out_of_range(
to_string(sql_type));
172 if (num_chars == 0u) {
173 throw std::invalid_argument(
"empty value");
176 }
catch (std::invalid_argument& e) {
177 throw std::runtime_error(
"Invalid metadata column " +
to_string(sql_type) +
178 " value '" + value +
"' for column '" + column_name +
179 "' (" + e.what() +
")");
180 }
catch (std::out_of_range& e) {
181 throw std::runtime_error(
"Out-of-range metadata column " +
to_string(sql_type) +
182 " value '" + value +
"' for column '" + column_name +
183 "' (" + e.what() +
")");
191 if (sql_type ==
kTEXT) {
197 metadata_column_infos.push_back({std::move(cd), std::move(value)});
201 return metadata_column_infos;
void set_compression(EncodingType c)
specifies the content in-memory of a row in the column metadata table
void set_comp_param(int p)
MetadataColumnInfos parse_add_metadata_columns(const std::string &add_metadata_columns, const std::string &file_path)
std::string evalAsString()
void setStringConstant(const std::string &name, const std::string &value)
void setExpression(const std::string &expression)
std::vector< MetadataColumnInfo > MetadataColumnInfos
HOST DEVICE void set_type(SQLTypes t)