Kùzu 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
30 : escapeChar{CopyConstants::DEFAULT_CSV_ESCAPE_CHAR},
31 delimiter{CopyConstants::DEFAULT_CSV_DELIMITER},
32 quoteChar{CopyConstants::DEFAULT_CSV_QUOTE_CHAR},
33 hasHeader{CopyConstants::DEFAULT_CSV_HAS_HEADER},
34 skipNum{CopyConstants::DEFAULT_CSV_SKIP_NUM},
35 sampleSize{CopyConstants::DEFAULT_CSV_TYPE_DEDUCTION_SAMPLE_SIZE},
36 allowUnbracedList{CopyConstants::DEFAULT_CSV_ALLOW_UNBRACED_LIST},
37 ignoreErrors(CopyConstants::DEFAULT_IGNORE_ERRORS),
38 autoDetection{CopyConstants::DEFAULT_CSV_AUTO_DETECT},
39 setEscape{CopyConstants::DEFAULT_CSV_SET_DIALECT},
40 setDelim{CopyConstants::DEFAULT_CSV_SET_DIALECT},
41 setQuote{CopyConstants::DEFAULT_CSV_SET_DIALECT},
42 setHeader{CopyConstants::DEFAULT_CSV_SET_DIALECT} {}
43
45
46 // TODO: COPY FROM and COPY TO should support transform special options, like '\'.
47 std::string toCypher() const {
48 std::string result;
49
50 // Add the option IFF option is set by user.
51 if (setHeader) {
52 std::string header = hasHeader ? "true" : "false";
53 result += "header=" + header;
54 }
55 if (setEscape) {
56 if (!result.empty())
57 result += ", "; // Add separator if not the first option
58 result += stringFormat("escape='\\{}'", escapeChar);
59 }
60 if (setDelim) {
61 if (!result.empty())
62 result += ", ";
63 result += stringFormat("delim='{}'", delimiter);
64 }
65 if (setQuote) {
66 if (!result.empty())
67 result += ", ";
68 result += stringFormat("quote='\\{}'", quoteChar);
69 }
70
71 // If no options, return empty string.
72 if (result.empty()) {
73 return "";
74 }
75
76 return "(" + result + ")";
77 }
78
79 // Explicit copy constructor
80 CSVOption(const CSVOption& other)
82 hasHeader{other.hasHeader}, skipNum{other.skipNum},
83 sampleSize{other.sampleSize == 0 ?
84 CopyConstants::DEFAULT_CSV_TYPE_DEDUCTION_SAMPLE_SIZE :
85 other.sampleSize}, // Set to DEFAULT_CSV_TYPE_DEDUCTION_SAMPLE_SIZE if
86 // sampleSize is 0
89 setQuote{other.setQuote}, setHeader{other.setHeader} {}
90};
91
105
106} // namespace common
107} // namespace kuzu
std::string stringFormat(std::string_view format, Args... args)
Definition string_format.h:99
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
bool setQuote
Definition csv_reader_config.h:26
bool setEscape
Definition csv_reader_config.h:24
CSVOption()
Definition csv_reader_config.h:29
bool hasHeader
Definition csv_reader_config.h:16
char quoteChar
Definition csv_reader_config.h:15
bool setHeader
Definition csv_reader_config.h:27
std::string toCypher() const
Definition csv_reader_config.h:47
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
CSVOption(const CSVOption &other)
Definition csv_reader_config.h:80
uint64_t sampleSize
Definition csv_reader_config.h:18
bool allowUnbracedList
Definition csv_reader_config.h:19
Definition csv_reader_config.h:92
CSVReaderConfig()
Definition csv_reader_config.h:96
CSVOption option
Definition csv_reader_config.h:93
bool parallel
Definition csv_reader_config.h:94
EXPLICIT_COPY_DEFAULT_MOVE(CSVReaderConfig)
static CSVReaderConfig construct(const case_insensitive_map_t< common::Value > &options)
Definition constants.h:130