feldera_types/query.rs
1use serde::{Deserialize, Serialize};
2use std::fmt::{Debug, Display, Formatter, Result};
3use utoipa::ToSchema;
4
5/// The maximum size of a WebSocket frames we're sending in bytes.
6pub const MAX_WS_FRAME_SIZE: usize = 1024 * 1024 * 2;
7
8/// URL-encoded `format` argument to the `/query` endpoint.
9#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy, ToSchema)]
10#[serde(rename_all = "snake_case")]
11pub enum AdHocResultFormat {
12 /// Serialize results as a human-readable text table.
13 Text,
14 /// Serialize results as new-line delimited JSON records.
15 ///
16 /// # Deprecation Notice
17 /// This format is deprecated and will be removed in the future.
18 /// Users are encouraged to use the `arrow_ipc` format instead,
19 /// See <https://github.com/feldera/feldera/issues/4219> for more details.
20 Json,
21 /// Download results in a parquet file.
22 Parquet,
23 /// Stream data in the arrow IPC format.
24 ArrowIpc,
25}
26
27impl Display for AdHocResultFormat {
28 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
29 match self {
30 AdHocResultFormat::Text => write!(f, "text"),
31 AdHocResultFormat::Json => write!(f, "json"),
32 AdHocResultFormat::Parquet => write!(f, "parquet"),
33 AdHocResultFormat::ArrowIpc => write!(f, "arrow_ipc"),
34 }
35 }
36}
37
38impl Default for AdHocResultFormat {
39 fn default() -> Self {
40 Self::Text
41 }
42}
43
44fn default_format() -> AdHocResultFormat {
45 AdHocResultFormat::default()
46}
47
48/// Arguments to the `/query` endpoint.
49///
50/// The arguments can be provided in two ways:
51///
52/// - In case a normal HTTP connection is established to the endpoint,
53/// these arguments are passed as URL-encoded parameters.
54/// Note: this mode is deprecated and will be removed in the future.
55///
56/// - If a Websocket connection is opened to `/query`, the arguments are passed
57/// to the server over the websocket as a JSON encoded string.
58#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
59pub struct AdhocQueryArgs {
60 /// The SQL query to run.
61 #[serde(default)]
62 pub sql: String,
63 /// In what format the data is sent to the client.
64 #[serde(default = "default_format")]
65 pub format: AdHocResultFormat,
66}