19 #include <boost/variant/get.hpp>
24 namespace import_export {
31 const std::string& layer_name,
33 const std::vector<TargetMetaInfo>& column_infos,
39 auto actual_file_path{file_path};
42 throw std::runtime_error(
"Compression not yet supported for this file type");
48 throw std::runtime_error(
"Failed to create file '" + actual_file_path +
"'");
53 bool not_first{
false};
55 for (
auto const& column_info : column_infos) {
57 auto column_name =
safeColumnName(column_info.get_resname(), column_index + 1);
77 auto nptr = boost::get<void*>(&str);
82 auto sptr = boost::get<std::string>(&str);
89 const std::string& delim) {
91 const auto array_tv = boost::get<ArrayTargetValue>(&tv);
93 if (array_tv->is_initialized()) {
94 const auto& vec = array_tv->get();
95 std::vector<std::string> elem_strs;
96 elem_strs.reserve(vec.size());
98 for (
const auto& elem_tv : vec) {
105 const auto scalar_tv = boost::get<ScalarTargetValue>(&tv);
111 datum.
bigintval = *boost::get<int64_t>(scalar_tv);
118 const auto bool_val = *boost::get<int64_t>(scalar_tv);
119 return bool_val ==
NULL_BOOLEAN ?
"NULL" : (bool_val ?
"true" :
"false");
121 auto iptr = boost::get<int64_t>(scalar_tv);
125 auto fptr = boost::get<float>(scalar_tv);
129 auto dptr = boost::get<double>(scalar_tv);
135 auto sptr = boost::get<NullableString>(scalar_tv);
143 for (
auto& agg_result : query_results) {
144 auto results = agg_result.rs;
145 auto const& targets = agg_result.targets_meta;
148 auto const crt_row = results->getNextRow(
true,
true);
149 if (crt_row.empty()) {
152 bool not_first =
false;
153 for (
size_t i = 0; i < results->colCount(); ++i) {
155 auto const tv = crt_row[i];
156 auto const scalar_tv = boost::get<ScalarTargetValue>(&tv);
165 auto const& ti = targets[i].get_type_info();
173 if (boost::get<int64_t>(scalar_tv)) {
174 auto int_val = *(boost::get<int64_t>(scalar_tv));
175 switch (ti.get_type()) {
201 }
else if (ti.is_time()) {
203 }
else if (ti.is_boolean()) {
204 outfile_ << (int_val ?
"true" :
"false");
208 }
else if (boost::get<double>(scalar_tv)) {
209 auto real_val = *(boost::get<double>(scalar_tv));
210 if (ti.get_type() ==
kFLOAT) {
217 }
else if (ti.get_type() ==
kNUMERIC) {
218 outfile_ << std::setprecision(ti.get_precision()) << real_val;
220 outfile_ << std::setprecision(std::numeric_limits<double>::digits10 + 1)
223 }
else if (boost::get<float>(scalar_tv)) {
225 auto real_val = *(boost::get<float>(scalar_tv));
229 outfile_ << std::setprecision(std::numeric_limits<float>::digits10 + 1)
233 auto s = boost::get<NullableString>(scalar_tv);
234 is_null = !s || boost::get<void*>(s);
238 auto s_notnull = boost::get<std::string>(s);
244 if (q == std::string::npos) {
247 std::string str(*s_notnull);
248 while (q != std::string::npos) {
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
std::string convert_temporal_to_iso_format(const SQLTypeInfo &type_info, int64_t unix_time)
std::string safeColumnName(const std::string &resname, const int column_index)
~QueryExporterCSV() override
std::string target_value_to_string(const TargetValue &tv, const SQLTypeInfo &ti, const std::string &delim)
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
void exportResults(const std::vector< AggregatedResult > &query_results) final
std::string nullable_str_to_string(const NullableString &str)
ImportHeaderRow has_header
CONSTEXPR DEVICE bool is_null(const T &value)
boost::variant< std::string, void * > NullableString
void beginExport(const std::string &file_path, const std::string &layer_name, const CopyParams ©_params, const std::vector< TargetMetaInfo > &column_infos, const FileCompression file_compression, const ArrayNullHandling array_null_handling) final
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
Basic constructors and methods of the row set interface.
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
SQLTypeInfo get_elem_type() const
void validateFileExtensions(const std::string &file_path, const std::string &file_type, const std::unordered_set< std::string > &valid_extensions) const