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