Skip to main content

chdb_rust/
format.rs

1//! Input and output format definitions for chDB queries.
2//!
3//! This module defines the various data formats supported by chDB for reading
4//! input data and formatting query results.
5
6/// Input formats for reading data into chDB.
7///
8/// These formats specify how data should be parsed when reading from files or
9/// other sources. See the [ClickHouse documentation](https://clickhouse.com/docs/en/interfaces/formats/)
10/// for details on each format.
11#[derive(Debug, Clone, Copy)]
12pub enum InputFormat {
13    TabSeparated,
14    TabSeparatedRaw,
15    TabSeparatedWithNames,
16    TabSeparatedWithNamesAndTypes,
17    TabSeparatedRawWithNames,
18    TabSeparatedRawWithNamesAndTypes,
19    Template,
20    TemplateIgnoreSpaces,
21    CSV,
22    CSVWithNames,
23    CSVWithNamesAndTypes,
24    CustomSeparated,
25    CustomSeparatedWithNames,
26    CustomSeparatedWithNamesAndTypes,
27    Values,
28    JSON,
29    JSONAsString,
30    JSONAsObject,
31    JSONStrings,
32    JSONColumns,
33    JSONColumnsWithMetadata,
34    JSONCompact,
35    JSONCompactColumns,
36    JSONEachRow,
37    JSONStringsEachRow,
38    JSONCompactEachRow,
39    JSONCompactEachRowWithNames,
40    JSONCompactEachRowWithNamesAndTypes,
41    JSONCompactStringsEachRow,
42    JSONCompactStringsEachRowWithNames,
43    JSONCompactStringsEachRowWithNamesAndTypes,
44    JSONObjectEachRow,
45    BSONEachRow,
46    TSKV,
47    Protobuf,
48    ProtobufSingle,
49    ProtobufList,
50    Avro,
51    AvroConfluent,
52    Parquet,
53    ParquetMetadata,
54    Arrow,
55    ArrowStream,
56    ORC,
57    One,
58    Npy,
59    RowBinary,
60    RowBinaryWithNames,
61    RowBinaryWithNamesAndTypes,
62    RowBinaryWithDefaults,
63    Native,
64    CapnProto,
65    LineAsString,
66    Regexp,
67    RawBLOB,
68    MsgPack,
69    MySQLDump,
70    DWARF,
71    Form,
72}
73
74/// Output formats for query results.
75///
76/// These formats specify how query results should be formatted when returned.
77/// See the [ClickHouse documentation](https://clickhouse.com/docs/en/interfaces/formats/)
78/// for details on each format.
79#[derive(Debug, Clone, Copy)]
80pub enum OutputFormat {
81    TabSeparated,
82    TabSeparatedRaw,
83    TabSeparatedWithNames,
84    TabSeparatedWithNamesAndTypes,
85    TabSeparatedRawWithNames,
86    TabSeparatedRawWithNamesAndTypes,
87    Template,
88    CSV,
89    CSVWithNames,
90    CSVWithNamesAndTypes,
91    CustomSeparated,
92    CustomSeparatedWithNames,
93    CustomSeparatedWithNamesAndTypes,
94    Values,
95    JSON,
96    JSONStrings,
97    JSONColumns,
98    JSONColumnsWithMetadata,
99    JSONCompact,
100    JSONCompactStrings,
101    JSONCompactColumns,
102    JSONEachRow,
103    PrettyJSONEachRow,
104    JSONEachRowWithProgress,
105    JSONStringsEachRow,
106    JSONStringsEachRowWithProgress,
107    JSONCompactEachRow,
108    JSONCompactEachRowWithNames,
109    JSONCompactEachRowWithNamesAndTypes,
110    JSONCompactStringsEachRow,
111    JSONCompactStringsEachRowWithNames,
112    JSONCompactStringsEachRowWithNamesAndTypes,
113    JSONObjectEachRow,
114    BSONEachRow,
115    TSKV,
116    Pretty,
117    PrettyNoEscapes,
118    PrettyMonoBlock,
119    PrettyNoEscapesMonoBlock,
120    PrettyCompact,
121    PrettyCompactNoEscapes,
122    PrettyCompactMonoBlock,
123    PrettyCompactNoEscapesMonoBlock,
124    PrettySpace,
125    PrettySpaceNoEscapes,
126    PrettySpaceMonoBlock,
127    PrettySpaceNoEscapesMonoBlock,
128    Prometheus,
129    Protobuf,
130    ProtobufSingle,
131    ProtobufList,
132    Avro,
133    Parquet,
134    Arrow,
135    ArrowStream,
136    ORC,
137    Npy,
138    RowBinary,
139    RowBinaryWithNames,
140    RowBinaryWithNamesAndTypes,
141    Native,
142    Null,
143    XML,
144    CapnProto,
145    LineAsString,
146    RawBLOB,
147    MsgPack,
148    Markdown,
149    Vertical,
150}
151
152impl InputFormat {
153    /// Get the string representation of the input format.
154    ///
155    /// This returns the format name as it should be used in SQL queries
156    /// (e.g., in `file()` function calls).
157    ///
158    /// # Returns
159    ///
160    /// Returns the format name as a static string slice.
161    pub const fn as_str(self) -> &'static str {
162        match self {
163            Self::TabSeparated => "TabSeparated",
164            Self::TabSeparatedRaw => "TabSeparatedRaw",
165            Self::TabSeparatedWithNames => "TabSeparatedWithNames",
166            Self::TabSeparatedWithNamesAndTypes => "TabSeparatedWithNamesAndTypes",
167            Self::TabSeparatedRawWithNames => "TabSeparatedRawWithNames",
168            Self::TabSeparatedRawWithNamesAndTypes => "TabSeparatedRawWithNamesAndTypes",
169            Self::Template => "Template",
170            Self::TemplateIgnoreSpaces => "TemplateIgnoreSpaces",
171            Self::CSV => "CSV",
172            Self::CSVWithNames => "CSVWithNames",
173            Self::CSVWithNamesAndTypes => "CSVWithNamesAndTypes",
174            Self::CustomSeparated => "CustomSeparated",
175            Self::CustomSeparatedWithNames => "CustomSeparatedWithNames",
176            Self::CustomSeparatedWithNamesAndTypes => "CustomSeparatedWithNamesAndTypes",
177            Self::Values => "Values",
178            Self::JSON => "JSON",
179            Self::JSONAsString => "JSONAsString",
180            Self::JSONAsObject => "JSONAsObject",
181            Self::JSONStrings => "JSONStrings",
182            Self::JSONColumns => "JSONColumns",
183            Self::JSONColumnsWithMetadata => "JSONColumnsWithMetadata",
184            Self::JSONCompact => "JSONCompact",
185            Self::JSONCompactColumns => "JSONCompactColumns",
186            Self::JSONEachRow => "JSONEachRow",
187            Self::JSONStringsEachRow => "JSONStringsEachRow",
188            Self::JSONCompactEachRow => "JSONCompactEachRow",
189            Self::JSONCompactEachRowWithNames => "JSONCompactEachRowWithNames",
190            Self::JSONCompactEachRowWithNamesAndTypes => "JSONCompactEachRowWithNamesAndTypes",
191            Self::JSONCompactStringsEachRow => "JSONCompactStringsEachRow",
192            Self::JSONCompactStringsEachRowWithNames => "JSONCompactStringsEachRowWithNames",
193            Self::JSONCompactStringsEachRowWithNamesAndTypes => {
194                "JSONCompactStringsEachRowWithNamesAndTypes"
195            }
196            Self::JSONObjectEachRow => "JSONObjectEachRow",
197            Self::BSONEachRow => "BSONEachRow",
198            Self::TSKV => "TSKV",
199            Self::Protobuf => "Protobuf",
200            Self::ProtobufSingle => "ProtobufSingle",
201            Self::ProtobufList => "ProtobufList",
202            Self::Avro => "Avro",
203            Self::AvroConfluent => "AvroConfluent",
204            Self::Parquet => "Parquet",
205            Self::ParquetMetadata => "ParquetMetadata",
206            Self::Arrow => "Arrow",
207            Self::ArrowStream => "ArrowStream",
208            Self::ORC => "ORC",
209            Self::One => "One",
210            Self::Npy => "Npy",
211            Self::RowBinary => "RowBinary",
212            Self::RowBinaryWithNames => "RowBinaryWithNames",
213            Self::RowBinaryWithNamesAndTypes => "RowBinaryWithNamesAndTypes",
214            Self::RowBinaryWithDefaults => "RowBinaryWithDefaults",
215            Self::Native => "Native",
216            Self::CapnProto => "CapnProto",
217            Self::LineAsString => "LineAsString",
218            Self::Regexp => "Regexp",
219            Self::RawBLOB => "RawBLOB",
220            Self::MsgPack => "MsgPack",
221            Self::MySQLDump => "MySQLDump",
222            Self::DWARF => "DWARF",
223            Self::Form => "Form",
224        }
225    }
226}
227
228impl OutputFormat {
229    /// Get the string representation of the output format.
230    ///
231    /// This returns the format name as it should be used when executing queries.
232    ///
233    /// # Returns
234    ///
235    /// Returns the format name as a static string slice.
236    pub const fn as_str(self) -> &'static str {
237        match self {
238            Self::TabSeparated => "TabSeparated",
239            Self::TabSeparatedRaw => "TabSeparatedRaw",
240            Self::TabSeparatedWithNames => "TabSeparatedWithNames",
241            Self::TabSeparatedWithNamesAndTypes => "TabSeparatedWithNamesAndTypes",
242            Self::TabSeparatedRawWithNames => "TabSeparatedRawWithNames",
243            Self::TabSeparatedRawWithNamesAndTypes => "TabSeparatedRawWithNamesAndTypes",
244            Self::Template => "Template",
245            Self::CSV => "CSV",
246            Self::CSVWithNames => "CSVWithNames",
247            Self::CSVWithNamesAndTypes => "CSVWithNamesAndTypes",
248            Self::CustomSeparated => "CustomSeparated",
249            Self::CustomSeparatedWithNames => "CustomSeparatedWithNames",
250            Self::CustomSeparatedWithNamesAndTypes => "CustomSeparatedWithNamesAndTypes",
251            Self::Values => "Values",
252            Self::JSON => "JSON",
253            Self::JSONStrings => "JSONStrings",
254            Self::JSONColumns => "JSONColumns",
255            Self::JSONColumnsWithMetadata => "JSONColumnsWithMetadata",
256            Self::JSONCompact => "JSONCompact",
257            Self::JSONCompactStrings => "JSONCompactStrings",
258            Self::JSONCompactColumns => "JSONCompactColumns",
259            Self::JSONEachRow => "JSONEachRow",
260            Self::PrettyJSONEachRow => "PrettyJSONEachRow",
261            Self::JSONEachRowWithProgress => "JSONEachRowWithProgress",
262            Self::JSONStringsEachRow => "JSONStringsEachRow",
263            Self::JSONStringsEachRowWithProgress => "JSONStringsEachRowWithProgress",
264            Self::JSONCompactEachRow => "JSONCompactEachRow",
265            Self::JSONCompactEachRowWithNames => "JSONCompactEachRowWithNames",
266            Self::JSONCompactEachRowWithNamesAndTypes => "JSONCompactEachRowWithNamesAndTypes",
267            Self::JSONCompactStringsEachRow => "JSONCompactStringsEachRow",
268            Self::JSONCompactStringsEachRowWithNames => "JSONCompactStringsEachRowWithNames",
269            Self::JSONCompactStringsEachRowWithNamesAndTypes => {
270                "JSONCompactStringsEachRowWithNamesAndTypes"
271            }
272            Self::JSONObjectEachRow => "JSONObjectEachRow",
273            Self::BSONEachRow => "BSONEachRow",
274            Self::TSKV => "TSKV",
275            Self::Pretty => "Pretty",
276            Self::PrettyNoEscapes => "PrettyNoEscapes",
277            Self::PrettyMonoBlock => "PrettyMonoBlock",
278            Self::PrettyNoEscapesMonoBlock => "PrettyNoEscapesMonoBlock",
279            Self::PrettyCompact => "PrettyCompact",
280            Self::PrettyCompactNoEscapes => "PrettyCompactNoEscapes",
281            Self::PrettyCompactMonoBlock => "PrettyCompactMonoBlock",
282            Self::PrettyCompactNoEscapesMonoBlock => "PrettyCompactNoEscapesMonoBlock",
283            Self::PrettySpace => "PrettySpace",
284            Self::PrettySpaceNoEscapes => "PrettySpaceNoEscapes",
285            Self::PrettySpaceMonoBlock => "PrettySpaceMonoBlock",
286            Self::PrettySpaceNoEscapesMonoBlock => "PrettySpaceNoEscapesMonoBlock",
287            Self::Prometheus => "Prometheus",
288            Self::Protobuf => "Protobuf",
289            Self::ProtobufSingle => "ProtobufSingle",
290            Self::ProtobufList => "ProtobufList",
291            Self::Avro => "Avro",
292            Self::Parquet => "Parquet",
293            Self::Arrow => "Arrow",
294            Self::ArrowStream => "ArrowStream",
295            Self::ORC => "ORC",
296            Self::Npy => "Npy",
297            Self::RowBinary => "RowBinary",
298            Self::RowBinaryWithNames => "RowBinaryWithNames",
299            Self::RowBinaryWithNamesAndTypes => "RowBinaryWithNamesAndTypes",
300            Self::Native => "Native",
301            Self::Null => "Null",
302            Self::XML => "XML",
303            Self::CapnProto => "CapnProto",
304            Self::LineAsString => "LineAsString",
305            Self::RawBLOB => "RawBLOB",
306            Self::MsgPack => "MsgPack",
307            Self::Markdown => "Markdown",
308            Self::Vertical => "Vertical",
309        }
310    }
311}