1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2026, Salesforce, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Data format specification for COPY operations.
//!
//! This module defines the supported data formats for bulk data insertion
//! via the COPY protocol.
/// Data format for COPY operations.
///
/// Hyper supports multiple binary formats for efficient data transfer.
/// The format determines how data is encoded when sent to the server.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub(crate) enum DataFormat {
/// Hyper's native binary format (default).
///
/// This is the most efficient format for row-by-row data building
/// using the [`Inserter`](crate::Inserter) API.
#[default]
HyperBinary,
/// Apache Arrow IPC stream format.
///
/// Use this format with [`ArrowInserter`](crate::ArrowInserter) to insert
/// pre-formatted Arrow IPC stream data. This is useful when integrating
/// with Arrow-based data pipelines.
ArrowStream,
}
impl DataFormat {
#[expect(
clippy::trivially_copy_pass_by_ref,
reason = "signature kept for API consistency with the trait family that unifies Copy and non-Copy implementers"
)]
/// Returns the SQL format string for COPY commands.
///
/// This is used internally to construct COPY statements.
#[inline]
pub(crate) fn as_sql_str(&self) -> &'static str {
match self {
DataFormat::HyperBinary => "HYPERBINARY",
DataFormat::ArrowStream => "ARROWSTREAM",
}
}
}
impl std::fmt::Display for DataFormat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DataFormat::HyperBinary => write!(f, "HyperBinary"),
DataFormat::ArrowStream => write!(f, "ArrowStream"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_data_format_sql_str() {
assert_eq!(DataFormat::HyperBinary.as_sql_str(), "HYPERBINARY");
assert_eq!(DataFormat::ArrowStream.as_sql_str(), "ARROWSTREAM");
}
#[test]
fn test_data_format_default() {
assert_eq!(DataFormat::default(), DataFormat::HyperBinary);
}
#[test]
fn test_data_format_display() {
assert_eq!(format!("{}", DataFormat::HyperBinary), "HyperBinary");
assert_eq!(format!("{}", DataFormat::ArrowStream), "ArrowStream");
}
}