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