Skip to content

Commit 7781bc2

Browse files
authored
chore: add docs, part of #37 (#6453)
* chore: add docs, part of #37 - add pragma `#![warn(missing_docs)]` to the following - `arrow-flight` - `arrow-ipc` - `arrow-integration-test` - `arrow-integration-testing` - `object_store` - also document the caveat with using level 10 GZIP compression in parquet. See #6282. * chore: resolve PR comments from #6453
1 parent 1e9e5a2 commit 7781bc2

File tree

38 files changed

+269
-64
lines changed

38 files changed

+269
-64
lines changed

arrow-flight/examples/flight_sql_server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use arrow_flight::sql::server::PeekableFlightDataStream;
1919
use arrow_flight::sql::DoPutPreparedStatementResult;
2020
use base64::prelude::BASE64_STANDARD;
2121
use base64::Engine;
22+
use core::str;
2223
use futures::{stream, Stream, TryStreamExt};
2324
use once_cell::sync::Lazy;
2425
use prost::Message;
@@ -168,7 +169,7 @@ impl FlightSqlService for FlightSqlServiceImpl {
168169
let bytes = BASE64_STANDARD
169170
.decode(base64)
170171
.map_err(|e| status!("authorization not decodable", e))?;
171-
let str = String::from_utf8(bytes).map_err(|e| status!("authorization not parsable", e))?;
172+
let str = str::from_utf8(&bytes).map_err(|e| status!("authorization not parsable", e))?;
172173
let parts: Vec<_> = str.split(':').collect();
173174
let (user, pass) = match parts.as_slice() {
174175
[user, pass] => (user, pass),

arrow-flight/src/bin/flight_sql_client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use arrow_flight::{
2626
};
2727
use arrow_schema::Schema;
2828
use clap::{Parser, Subcommand};
29+
use core::str;
2930
use futures::TryStreamExt;
3031
use tonic::{
3132
metadata::MetadataMap,

arrow-flight/src/decode.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,33 +388,38 @@ struct FlightStreamState {
388388
/// FlightData and the decoded payload (Schema, RecordBatch), if any
389389
#[derive(Debug)]
390390
pub struct DecodedFlightData {
391+
/// The original FlightData message
391392
pub inner: FlightData,
393+
/// The decoded payload
392394
pub payload: DecodedPayload,
393395
}
394396

395397
impl DecodedFlightData {
398+
/// Create a new DecodedFlightData with no payload
396399
pub fn new_none(inner: FlightData) -> Self {
397400
Self {
398401
inner,
399402
payload: DecodedPayload::None,
400403
}
401404
}
402405

406+
/// Create a new DecodedFlightData with a [`Schema`] payload
403407
pub fn new_schema(inner: FlightData, schema: SchemaRef) -> Self {
404408
Self {
405409
inner,
406410
payload: DecodedPayload::Schema(schema),
407411
}
408412
}
409413

414+
/// Create a new [`DecodedFlightData`] with a [`RecordBatch`] payload
410415
pub fn new_record_batch(inner: FlightData, batch: RecordBatch) -> Self {
411416
Self {
412417
inner,
413418
payload: DecodedPayload::RecordBatch(batch),
414419
}
415420
}
416421

417-
/// return the metadata field of the inner flight data
422+
/// Return the metadata field of the inner flight data
418423
pub fn app_metadata(&self) -> Bytes {
419424
self.inner.app_metadata.clone()
420425
}

arrow-flight/src/encode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ impl Default for FlightDataEncoderBuilder {
144144
}
145145

146146
impl FlightDataEncoderBuilder {
147+
/// Create a new [`FlightDataEncoderBuilder`].
147148
pub fn new() -> Self {
148149
Self::default()
149150
}
@@ -1403,7 +1404,7 @@ mod tests {
14031404
let input_rows = batch.num_rows();
14041405

14051406
let split = split_batch_for_grpc_response(batch.clone(), max_flight_data_size_bytes);
1406-
let sizes: Vec<_> = split.iter().map(|batch| batch.num_rows()).collect();
1407+
let sizes: Vec<_> = split.iter().map(RecordBatch::num_rows).collect();
14071408
let output_rows: usize = sizes.iter().sum();
14081409

14091410
assert_eq!(sizes, expected_sizes, "mismatch for {batch:?}");

arrow-flight/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub enum FlightError {
3737
}
3838

3939
impl FlightError {
40+
/// Generate a new `FlightError::ProtocolError` variant.
4041
pub fn protocol(message: impl Into<String>) -> Self {
4142
Self::ProtocolError(message.into())
4243
}
@@ -98,6 +99,7 @@ impl From<FlightError> for tonic::Status {
9899
}
99100
}
100101

102+
/// Result type for the Apache Arrow Flight crate
101103
pub type Result<T> = std::result::Result<T, FlightError>;
102104

103105
#[cfg(test)]

arrow-flight/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
//!
3838
//! [Flight SQL]: https://arrow.apache.org/docs/format/FlightSql.html
3939
#![allow(rustdoc::invalid_html_tags)]
40+
#![warn(missing_docs)]
4041

4142
use arrow_ipc::{convert, writer, writer::EncodedData, writer::IpcWriteOptions};
4243
use arrow_schema::{ArrowError, Schema};
@@ -52,6 +53,8 @@ type ArrowResult<T> = std::result::Result<T, ArrowError>;
5253

5354
#[allow(clippy::all)]
5455
mod gen {
56+
// Since this file is auto-generated, we suppress all warnings
57+
#![allow(missing_docs)]
5558
include!("arrow.flight.protocol.rs");
5659
}
5760

@@ -125,6 +128,7 @@ use flight_descriptor::DescriptorType;
125128

126129
/// SchemaAsIpc represents a pairing of a `Schema` with IpcWriteOptions
127130
pub struct SchemaAsIpc<'a> {
131+
/// Data type representing a schema and its IPC write options
128132
pub pair: (&'a Schema, &'a IpcWriteOptions),
129133
}
130134

@@ -684,6 +688,7 @@ impl PollInfo {
684688
}
685689

686690
impl<'a> SchemaAsIpc<'a> {
691+
/// Create a new `SchemaAsIpc` from a `Schema` and `IpcWriteOptions`
687692
pub fn new(schema: &'a Schema, options: &'a IpcWriteOptions) -> Self {
688693
SchemaAsIpc {
689694
pair: (schema, options),

arrow-flight/src/sql/client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,11 @@ fn flight_error_to_arrow_error(err: FlightError) -> ArrowError {
695695
}
696696
}
697697

698-
// A polymorphic structure to natively represent different types of data contained in `FlightData`
698+
/// A polymorphic structure to natively represent different types of data contained in `FlightData`
699699
pub enum ArrowFlightData {
700+
/// A record batch
700701
RecordBatch(RecordBatch),
702+
/// A schema
701703
Schema(Schema),
702704
}
703705

arrow-flight/src/sql/metadata/sql_info.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl SqlInfoUnionBuilder {
331331
///
332332
/// Servers constuct - usually static - [`SqlInfoData`] via the [`SqlInfoDataBuilder`],
333333
/// and build responses using [`CommandGetSqlInfo::into_builder`]
334-
#[derive(Debug, Clone, PartialEq)]
334+
#[derive(Debug, Clone, PartialEq, Default)]
335335
pub struct SqlInfoDataBuilder {
336336
/// Use BTreeMap to ensure the values are sorted by value as
337337
/// to make output consistent
@@ -341,17 +341,10 @@ pub struct SqlInfoDataBuilder {
341341
infos: BTreeMap<u32, SqlInfoValue>,
342342
}
343343

344-
impl Default for SqlInfoDataBuilder {
345-
fn default() -> Self {
346-
Self::new()
347-
}
348-
}
349-
350344
impl SqlInfoDataBuilder {
345+
/// Create a new SQL info builder
351346
pub fn new() -> Self {
352-
Self {
353-
infos: BTreeMap::new(),
354-
}
347+
Self::default()
355348
}
356349

357350
/// register the specific sql metadata item

arrow-flight/src/sql/metadata/xdbc_info.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,43 @@ use crate::sql::{CommandGetXdbcTypeInfo, Nullable, Searchable, XdbcDataType, Xdb
4141
/// Data structure representing type information for xdbc types.
4242
#[derive(Debug, Clone, Default)]
4343
pub struct XdbcTypeInfo {
44+
/// The name of the type
4445
pub type_name: String,
46+
/// The data type of the type
4547
pub data_type: XdbcDataType,
48+
/// The column size of the type
4649
pub column_size: Option<i32>,
50+
/// The prefix of the type
4751
pub literal_prefix: Option<String>,
52+
/// The suffix of the type
4853
pub literal_suffix: Option<String>,
54+
/// The create parameters of the type
4955
pub create_params: Option<Vec<String>>,
56+
/// The nullability of the type
5057
pub nullable: Nullable,
58+
/// Whether the type is case sensitive
5159
pub case_sensitive: bool,
60+
/// Whether the type is searchable
5261
pub searchable: Searchable,
62+
/// Whether the type is unsigned
5363
pub unsigned_attribute: Option<bool>,
64+
/// Whether the type has fixed precision and scale
5465
pub fixed_prec_scale: bool,
66+
/// Whether the type is auto-incrementing
5567
pub auto_increment: Option<bool>,
68+
/// The local type name of the type
5669
pub local_type_name: Option<String>,
70+
/// The minimum scale of the type
5771
pub minimum_scale: Option<i32>,
72+
/// The maximum scale of the type
5873
pub maximum_scale: Option<i32>,
74+
/// The SQL data type of the type
5975
pub sql_data_type: XdbcDataType,
76+
/// The optional datetime subcode of the type
6077
pub datetime_subcode: Option<XdbcDatetimeSubcode>,
78+
/// The number precision radix of the type
6179
pub num_prec_radix: Option<i32>,
80+
/// The interval precision of the type
6281
pub interval_precision: Option<i32>,
6382
}
6483

@@ -93,16 +112,6 @@ impl XdbcTypeInfoData {
93112
}
94113
}
95114

96-
pub struct XdbcTypeInfoDataBuilder {
97-
infos: Vec<XdbcTypeInfo>,
98-
}
99-
100-
impl Default for XdbcTypeInfoDataBuilder {
101-
fn default() -> Self {
102-
Self::new()
103-
}
104-
}
105-
106115
/// A builder for [`XdbcTypeInfoData`] which is used to create [`CommandGetXdbcTypeInfo`] responses.
107116
///
108117
/// # Example
@@ -138,6 +147,16 @@ impl Default for XdbcTypeInfoDataBuilder {
138147
/// // to access the underlying record batch
139148
/// let batch = info_list.record_batch(None);
140149
/// ```
150+
pub struct XdbcTypeInfoDataBuilder {
151+
infos: Vec<XdbcTypeInfo>,
152+
}
153+
154+
impl Default for XdbcTypeInfoDataBuilder {
155+
fn default() -> Self {
156+
Self::new()
157+
}
158+
}
159+
141160
impl XdbcTypeInfoDataBuilder {
142161
/// Create a new instance of [`XdbcTypeInfoDataBuilder`].
143162
pub fn new() -> Self {

arrow-flight/src/sql/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ use bytes::Bytes;
4343
use paste::paste;
4444
use prost::Message;
4545

46+
#[allow(clippy::all)]
4647
mod gen {
47-
#![allow(clippy::all)]
4848
#![allow(rustdoc::unportable_markdown)]
49+
// Since this file is auto-generated, we suppress all warnings
50+
#![allow(missing_docs)]
4951
include!("arrow.flight.protocol.sql.rs");
5052
}
5153

@@ -163,7 +165,9 @@ macro_rules! prost_message_ext {
163165
/// ```
164166
#[derive(Clone, Debug, PartialEq)]
165167
pub enum Command {
166-
$($name($name),)*
168+
$(
169+
#[doc = concat!(stringify!($name), "variant")]
170+
$name($name),)*
167171

168172
/// Any message that is not any FlightSQL command.
169173
Unknown(Any),
@@ -297,10 +301,12 @@ pub struct Any {
297301
}
298302

299303
impl Any {
304+
/// Checks whether the message is of type `M`
300305
pub fn is<M: ProstMessageExt>(&self) -> bool {
301306
M::type_url() == self.type_url
302307
}
303308

309+
/// Unpacks the contents of the message if it is of type `M`
304310
pub fn unpack<M: ProstMessageExt>(&self) -> Result<Option<M>, ArrowError> {
305311
if !self.is::<M>() {
306312
return Ok(None);
@@ -310,6 +316,7 @@ impl Any {
310316
Ok(Some(m))
311317
}
312318

319+
/// Packs a message into an [`Any`] message
313320
pub fn pack<M: ProstMessageExt>(message: &M) -> Result<Any, ArrowError> {
314321
Ok(message.as_any())
315322
}

arrow-flight/src/utils.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,12 @@ pub fn batches_to_flight_data(
160160
dictionaries.extend(encoded_dictionaries.into_iter().map(Into::into));
161161
flight_data.push(encoded_batch.into());
162162
}
163-
let mut stream = vec![schema_flight_data];
163+
164+
let mut stream = Vec::with_capacity(1 + dictionaries.len() + flight_data.len());
165+
166+
stream.push(schema_flight_data);
164167
stream.extend(dictionaries);
165168
stream.extend(flight_data);
166-
let flight_data: Vec<_> = stream.into_iter().collect();
169+
let flight_data = stream;
167170
Ok(flight_data)
168171
}

0 commit comments

Comments
 (0)