Kuzu C++ API
Loading...
Searching...
No Matches
csv_reader_config.h
Go to the documentation of this file.
1#pragma once
2
4#include "constants.h"
5#include "copy_constructors.h"
6#include "value.h"
7
8namespace kuzu {
9namespace common {
10
11struct CSVOption {
12 // TODO(Xiyang): Add newline character option and delimiter can be a string.
17 uint64_t skipNum;
18 uint64_t sampleSize;
21
23 // These fields aim to identify whether the options are set by user, or set by default.
28 std::vector<std::string> nullStrings;
29
31 : escapeChar{CopyConstants::DEFAULT_CSV_ESCAPE_CHAR},
32 delimiter{CopyConstants::DEFAULT_CSV_DELIMITER},
33 quoteChar{CopyConstants::DEFAULT_CSV_QUOTE_CHAR},
34 hasHeader{CopyConstants::DEFAULT_CSV_HAS_HEADER},
35 skipNum{CopyConstants::DEFAULT_CSV_SKIP_NUM},
36 sampleSize{CopyConstants::DEFAULT_CSV_TYPE_DEDUCTION_SAMPLE_SIZE},
37 allowUnbracedList{CopyConstants::DEFAULT_CSV_ALLOW_UNBRACED_LIST},
38 ignoreErrors(CopyConstants::DEFAULT_IGNORE_ERRORS),
39 autoDetection{CopyConstants::DEFAULT_CSV_AUTO_DETECT},
40 setEscape{CopyConstants::DEFAULT_CSV_SET_DIALECT},
41 setDelim{CopyConstants::DEFAULT_CSV_SET_DIALECT},
42 setQuote{CopyConstants::DEFAULT_CSV_SET_DIALECT},
43 setHeader{CopyConstants::DEFAULT_CSV_SET_DIALECT},
44 nullStrings{CopyConstants::DEFAULT_CSV_NULL_STRINGS[0]} {}
45
47
48 // TODO: COPY FROM and COPY TO should support transform special options, like '\'.
49 std::unordered_map<std::string, std::string> toOptionsMap(const bool& parallel) const {
50 std::unordered_map<std::string, std::string> result;
51 result["parallel"] = parallel ? "true" : "false";
52 if (setHeader) {
53 result["header"] = hasHeader ? "true" : "false";
54 }
55 if (setEscape) {
56 result["escape"] = stringFormat("escape='\\{}'", escapeChar);
57 }
58 if (setDelim) {
59 result["delim"] = stringFormat("delim='{}'", delimiter);
60 }
61 if (setQuote) {
62 result["quote"] = stringFormat("quote='\\{}'", quoteChar);
63 }
65 result["auto_detect"] = autoDetection ? "true" : "false";
66 }
67 return result;
68 }
69
70 static std::string toCypher(const std::unordered_map<std::string, std::string>& options) {
71 if (options.empty()) {
72 return "";
73 }
74 std::string result = "";
75 for (const auto& [key, value] : options) {
76 if (!result.empty()) {
77 result += ", ";
78 }
79 result += key + "=" + value;
80 }
81 return "(" + result + ")";
82 }
83
84 // Explicit copy constructor
85 CSVOption(const CSVOption& other)
87 hasHeader{other.hasHeader}, skipNum{other.skipNum},
88 sampleSize{other.sampleSize == 0 ?
89 CopyConstants::DEFAULT_CSV_TYPE_DEDUCTION_SAMPLE_SIZE :
90 other.sampleSize}, // Set to DEFAULT_CSV_TYPE_DEDUCTION_SAMPLE_SIZE if
91 // sampleSize is 0
95};
96
100
101 CSVReaderConfig() : option{}, parallel{CopyConstants::DEFAULT_CSV_PARALLEL} {}
103
105
106private:
107 CSVReaderConfig(const CSVReaderConfig& other)
108 : option{other.option.copy()}, parallel{other.parallel} {}
109};
110
111} // namespace common
112} // namespace kuzu
Definition array_utils.h:7
std::string stringFormat(std::string_view format, Args &&... args)
Definition string_format.h:110
std::unordered_map< std::string, T, CaseInsensitiveStringHashFunction, CaseInsensitiveStringEquality > case_insensitive_map_t
Definition case_insensitive_map.h:22
Definition array_utils.h:7
Definition csv_reader_config.h:11
char escapeChar
Definition csv_reader_config.h:13
bool setDelim
Definition csv_reader_config.h:25
static std::string toCypher(const std::unordered_map< std::string, std::string > &options)
Definition csv_reader_config.h:70
bool setQuote
Definition csv_reader_config.h:26
bool setEscape
Definition csv_reader_config.h:24
CSVOption()
Definition csv_reader_config.h:30
std::vector< std::string > nullStrings
Definition csv_reader_config.h:28
bool hasHeader
Definition csv_reader_config.h:16
char quoteChar
Definition csv_reader_config.h:15
bool setHeader
Definition csv_reader_config.h:27
EXPLICIT_COPY_DEFAULT_MOVE(CSVOption)
char delimiter
Definition csv_reader_config.h:14
bool autoDetection
Definition csv_reader_config.h:22
uint64_t skipNum
Definition csv_reader_config.h:17
bool ignoreErrors
Definition csv_reader_config.h:20
std::unordered_map< std::string, std::string > toOptionsMap(const bool &parallel) const
Definition csv_reader_config.h:49
CSVOption(const CSVOption &other)
Definition csv_reader_config.h:85
uint64_t sampleSize
Definition csv_reader_config.h:18
bool allowUnbracedList
Definition csv_reader_config.h:19
CSVReaderConfig()
Definition csv_reader_config.h:101
CSVOption option
Definition csv_reader_config.h:98
bool parallel
Definition csv_reader_config.h:99
EXPLICIT_COPY_DEFAULT_MOVE(CSVReaderConfig)
static CSVReaderConfig construct(const case_insensitive_map_t< Value > &options)
Definition constants.h:95
static constexpr bool DEFAULT_CSV_AUTO_DETECT
Definition constants.h:123