Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions src/client/sea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl SeaRestTransport {
}

/// Convert SEA response to internal ExecuteResultData.
fn convert_result_data(result: &crate::types::sea::ResultData) -> Result<ExecuteResultData> {
fn convert_result_data(result: crate::types::sea::ResultData) -> Result<ExecuteResultData> {
let external_links = if let Some(ref links) = result.external_links {
let converted: Result<Vec<CloudFetchLink>> = links
.iter()
Expand All @@ -329,9 +329,9 @@ impl SeaRestTransport {
};

Ok(ExecuteResultData {
next_chunk_internal_link: result.next_chunk_internal_link.clone(),
next_chunk_internal_link: result.next_chunk_internal_link,
external_links,
inline_arrow_data: result.attachment.clone(),
inline_arrow_data: result.attachment,
inline_chunk_index: result.chunk_index,
inline_row_offset: result.row_offset,
inline_row_count: result.row_count,
Expand Down Expand Up @@ -365,15 +365,18 @@ impl SeaRestTransport {
.http_client
.execute(request, RequestType::GetStatementStatus)
.await?;
// Parse the raw bytes: `text()` would copy a multi-MB inline-Arrow
// body into a `String` first.
let body = response
.text()
.bytes()
.await
.map_err(|e| Error::network_error().message(format!("Failed to read response: {e}")))?;

let sea_response: StatementExecutionResponse =
serde_json::from_str(&body).map_err(|e| {
serde_json::from_slice(&body).map_err(|e| {
Error::data_loss().message(format!(
"Failed to parse status response: {e} - body: {body}"
"Failed to parse status response: {e} - body: {}",
String::from_utf8_lossy(&body)
))
})?;

Expand Down Expand Up @@ -692,15 +695,18 @@ impl SeaRestTransport {
})?;

let response = self.http_client.execute(request, request_type).await?;
// Parse the raw bytes: `text()` would copy a multi-MB inline-Arrow
// body into a `String` first.
let body = response
.text()
.bytes()
.await
.map_err(|e| Error::network_error().message(format!("Failed to read response: {e}")))?;

let sea_response: StatementExecutionResponse =
serde_json::from_str(&body).map_err(|e| {
serde_json::from_slice(&body).map_err(|e| {
Error::data_loss().message(format!(
"Failed to parse execute response: {e} - body: {body}"
"Failed to parse execute response: {e} - body: {}",
String::from_utf8_lossy(&body)
))
})?;

Expand All @@ -716,11 +722,7 @@ impl SeaRestTransport {

/// Convert SEA response to internal ExecuteResponse.
fn convert_response(response: StatementExecutionResponse) -> Result<ExecuteResponse> {
let result = if let Some(ref result) = response.result {
Some(Self::convert_result_data(result)?)
} else {
None
};
let result = response.result.map(Self::convert_result_data).transpose()?;

Ok(ExecuteResponse {
statement_id: response.statement_id,
Expand Down Expand Up @@ -1438,14 +1440,17 @@ impl Transport for SeaRestTransport {
.http_client
.execute(request, RequestType::GetResultChunks)
.await?;
// Parse the raw bytes: `text()` would copy a multi-MB inline-Arrow
// body into a `String` first.
let body = response
.text()
.bytes()
.await
.map_err(|e| Error::network_error().message(format!("Failed to read response: {e}")))?;

let chunks_response: GetChunksResponse = serde_json::from_str(&body).map_err(|e| {
let chunks_response: GetChunksResponse = serde_json::from_slice(&body).map_err(|e| {
Error::data_loss().message(format!(
"Failed to parse inline chunk response: {e} - body: {body}"
"Failed to parse inline chunk response: {e} - body: {}",
String::from_utf8_lossy(&body)
))
})?;

Expand All @@ -1459,7 +1464,8 @@ impl Transport for SeaRestTransport {
"Inline chunk {} response missing `attachment` field — \
server may have ignored the INLINE disposition and \
returned a CloudFetch response. Body: {}",
chunk_index, body
chunk_index,
String::from_utf8_lossy(&body)
))
})?;

Expand All @@ -1484,7 +1490,8 @@ impl Transport for SeaRestTransport {
Error::data_loss().message(format!(
"Inline chunk {} response carries `attachment` but no `row_count` — \
cannot derive next-fetch row_offset safely. Body: {}",
chunk_idx, body,
chunk_idx,
String::from_utf8_lossy(&body),
))
})?;
let next_chunk_index = chunks_response.next_chunk_index;
Expand Down Expand Up @@ -2297,7 +2304,7 @@ mod tests {
attachment: None,
};

let converted = SeaRestTransport::convert_result_data(&result).unwrap();
let converted = SeaRestTransport::convert_result_data(result).unwrap();
assert!(converted.external_links.is_none());
assert!(converted.inline_arrow_data.is_none());
}
Expand All @@ -2317,7 +2324,7 @@ mod tests {
attachment: Some(test_data.clone()),
};

let converted = SeaRestTransport::convert_result_data(&result).unwrap();
let converted = SeaRestTransport::convert_result_data(result).unwrap();
assert!(converted.inline_arrow_data.is_some());
assert_eq!(converted.inline_arrow_data.unwrap(), test_data);
}
Expand Down
16 changes: 8 additions & 8 deletions src/reader/inline/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl InlineArrowProvider {
/// - If Arrow IPC parsing fails
pub fn new(
statement_id: &str,
attachment: Vec<u8>,
attachment: &[u8],
compression: CompressionCodec,
total_row_count: Option<i64>,
) -> Result<Self> {
Expand All @@ -123,7 +123,7 @@ impl InlineArrowProvider {
);

// Reuse the shared Arrow IPC parser (same format as CloudFetch)
let parsed = parse_arrow_ipc(&attachment, compression).map_err(|e| {
let parsed = parse_arrow_ipc(attachment, compression).map_err(|e| {
Error::io().message(format!("Failed to parse inline Arrow data: {}", e))
})?;

Expand Down Expand Up @@ -214,7 +214,7 @@ mod tests {
let ipc_data = create_test_arrow_ipc(&[batch]);

let mut provider =
InlineArrowProvider::new("test-stmt", ipc_data, CompressionCodec::None, None).unwrap();
InlineArrowProvider::new("test-stmt", &ipc_data, CompressionCodec::None, None).unwrap();

// Check schema
assert!(provider.schema().is_some());
Expand Down Expand Up @@ -247,7 +247,7 @@ mod tests {
}

let mut provider =
InlineArrowProvider::new("test-stmt", compressed, CompressionCodec::Lz4Frame, None)
InlineArrowProvider::new("test-stmt", &compressed, CompressionCodec::Lz4Frame, None)
.unwrap();

let batch = provider.next_batch().unwrap().unwrap();
Expand All @@ -261,7 +261,7 @@ mod tests {
let ipc_data = create_test_arrow_ipc(&[batch1, batch2]);

let mut provider =
InlineArrowProvider::new("test-stmt", ipc_data, CompressionCodec::None, None).unwrap();
InlineArrowProvider::new("test-stmt", &ipc_data, CompressionCodec::None, None).unwrap();

// First batch
let batch = provider.next_batch().unwrap().unwrap();
Expand All @@ -278,7 +278,7 @@ mod tests {
#[test]
fn test_inline_provider_with_empty_data() {
let provider =
InlineArrowProvider::new("test-stmt", vec![], CompressionCodec::None, None).unwrap();
InlineArrowProvider::new("test-stmt", &[], CompressionCodec::None, None).unwrap();

assert!(provider.schema().is_none());
assert!(!provider.has_more());
Expand All @@ -289,7 +289,7 @@ mod tests {
let invalid_data = b"this is not valid arrow ipc data".to_vec();

let result =
InlineArrowProvider::new("test-stmt", invalid_data, CompressionCodec::None, None);
InlineArrowProvider::new("test-stmt", &invalid_data, CompressionCodec::None, None);
assert!(result.is_err());
}

Expand Down Expand Up @@ -329,7 +329,7 @@ mod tests {
let batch = create_test_batch(11);
let ipc = create_test_arrow_ipc(&[batch]);
let mut provider =
InlineArrowProvider::new("test-stmt", ipc, CompressionCodec::None, Some(10)).unwrap();
InlineArrowProvider::new("test-stmt", &ipc, CompressionCodec::None, Some(10)).unwrap();
let mut total = 0;
while let Some(b) = provider.next_batch().unwrap() {
total += b.num_rows();
Expand Down
30 changes: 15 additions & 15 deletions src/reader/inline/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl InlineStreamingProvider {
pub(crate) fn new(
source: Arc<dyn InlineChunkSource>,
statement_id: impl Into<String>,
initial_attachment: Vec<u8>,
initial_attachment: &[u8],
initial_chunk_index: i64,
initial_row_offset: i64,
initial_row_count: i64,
Expand All @@ -237,7 +237,7 @@ impl InlineStreamingProvider {
) -> Result<Arc<Self>> {
// Decode the initial chunk synchronously so we can return a
// schema-bearing provider to the caller.
let initial_batches = parse_arrow_ipc(&initial_attachment, compression)?;
let initial_batches = parse_arrow_ipc(initial_attachment, compression)?;

// Schema source priority:
// 1. The first batch of the initial chunk (most-authoritative,
Expand Down Expand Up @@ -678,7 +678,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
initial_bytes,
&initial_bytes,
c0.chunk_index,
c0.row_offset,
c0.row_count,
Expand Down Expand Up @@ -715,7 +715,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
initial_bytes,
&initial_bytes,
c0.chunk_index,
c0.row_offset,
c0.row_count,
Expand Down Expand Up @@ -755,7 +755,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
initial.bytes.clone(),
&initial.bytes,
initial.chunk_index,
initial.row_offset,
initial.row_count,
Expand Down Expand Up @@ -783,7 +783,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
initial_bytes,
&initial_bytes,
c0.chunk_index,
c0.row_offset,
c0.row_count,
Expand Down Expand Up @@ -822,7 +822,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
initial_bytes,
&initial_bytes,
c0.chunk_index,
c0.row_offset,
c0.row_count,
Expand Down Expand Up @@ -864,7 +864,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
initial_bytes,
&initial_bytes,
c0.chunk_index,
c0.row_offset,
c0.row_count,
Expand Down Expand Up @@ -910,7 +910,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
empty_bytes,
&empty_bytes,
0,
0,
0,
Expand Down Expand Up @@ -944,7 +944,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
initial_bytes,
&initial_bytes,
c0.chunk_index,
c0.row_offset,
c0.row_count,
Expand Down Expand Up @@ -1005,7 +1005,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
initial_bytes,
&initial_bytes,
c0.chunk_index,
c0.row_offset,
c0.row_count,
Expand Down Expand Up @@ -1075,7 +1075,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
initial_bytes,
&initial_bytes,
0, // initial_chunk_index
0, // initial_row_offset
1, // initial_row_count
Expand Down Expand Up @@ -1148,7 +1148,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
build_ipc_bytes(&[10, 20]),
&build_ipc_bytes(&[10, 20]),
0, // initial_chunk_index
0, // initial_row_offset
2, // initial_row_count
Expand Down Expand Up @@ -1183,7 +1183,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
build_ipc_bytes(&[1]),
&build_ipc_bytes(&[1]),
0,
0,
1,
Expand Down Expand Up @@ -1243,7 +1243,7 @@ mod tests {
let provider = InlineStreamingProvider::new(
source,
"stmt-1",
build_ipc_bytes(&[7, 8]),
&build_ipc_bytes(&[7, 8]),
0, // initial_chunk_index
0, // initial_row_offset
2, // initial_row_count
Expand Down
12 changes: 4 additions & 8 deletions src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl ResultReaderFactory {
});
return self.create_inline_streaming_reader(
statement_id,
inline_data.clone(),
inline_data,
inline_chunk_index,
inline_row_offset,
inline_row_count,
Expand Down Expand Up @@ -548,12 +548,8 @@ impl ResultReaderFactory {
total_row_count
);

let provider = InlineArrowProvider::new(
statement_id,
inline_data.to_vec(),
compression,
total_row_count,
)?;
let provider =
InlineArrowProvider::new(statement_id, inline_data, compression, total_row_count)?;

Ok(Box::new(InlineArrowReader::new(provider)))
}
Expand All @@ -571,7 +567,7 @@ impl ResultReaderFactory {
fn create_inline_streaming_reader(
&self,
statement_id: &str,
initial_attachment: Vec<u8>,
initial_attachment: &[u8],
initial_chunk_index: i64,
initial_row_offset: i64,
initial_row_count: i64,
Expand Down
Loading
Loading