Skip to content

Commit fe78a83

Browse files
committed
Feedback
1 parent 7b71349 commit fe78a83

8 files changed

Lines changed: 52 additions & 20 deletions

File tree

datafusion-examples/examples/extension_types/temperature.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn create_session_context() -> Result<SessionContext> {
5656
|storage_type, metadata| {
5757
Ok(Arc::new(TemperatureExtensionType::try_new(
5858
storage_type,
59-
TemperatureUnit::try_from(metadata)?,
59+
TemperatureUnit::deserialize(metadata)?,
6060
)?))
6161
},
6262
);
@@ -181,14 +181,10 @@ impl TemperatureUnit {
181181
};
182182
result.to_owned()
183183
}
184-
}
185-
186-
/// Inverse operation of [`TemperatureUnit::serialize`]. This creates the [`TemperatureUnit`]
187-
/// value from the serialized string.
188-
impl TryFrom<Option<&str>> for TemperatureUnit {
189-
type Error = ArrowError;
190184

191-
fn try_from(value: Option<&str>) -> std::result::Result<Self, Self::Error> {
185+
/// Inverse operation of [`TemperatureUnit::serialize`]. This creates the [`TemperatureUnit`]
186+
/// value from the serialized string.
187+
pub fn deserialize(value: Option<&str>) -> std::result::Result<Self, ArrowError> {
192188
match value {
193189
Some("celsius") => Ok(TemperatureUnit::Celsius),
194190
Some("fahrenheit") => Ok(TemperatureUnit::Fahrenheit),

datafusion/common/src/types/canonical_extensions/bool8.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,28 @@ use arrow::util::display::{ArrayFormatter, DisplayIndex, FormatOptions, FormatRe
2424
use arrow_schema::extension::{Bool8, ExtensionType};
2525
use std::fmt::Write;
2626

27-
/// Defines the extension type logic for the canonical `arrow.bool8` extension type.
27+
/// Defines the extension type logic for the canonical `arrow.bool8` extension type. This extension
28+
/// type allows storing a Boolean value in a single byte, instead of a single bit.
2829
///
29-
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism.
30+
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism. See also
31+
/// [`Bool8`] for the implementation of arrow-rs, which this type uses internally.
32+
///
33+
/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#bit-boolean>
3034
#[derive(Debug, Clone)]
3135
pub struct DFBool8(Bool8);
3236

3337
impl DFBool8 {
3438
/// Creates a new [`DFBool8`], validating that the storage type is compatible with the
3539
/// extension type.
40+
///
41+
/// Even though [`DFBool8`] only supports a single storage type ([`DataType::Int8`]), passing-in
42+
/// the storage type allows conveniently validating whether this extension type is compatible
43+
/// with a given [`DataType`].
3644
pub fn try_new(
3745
data_type: &DataType,
3846
metadata: <Bool8 as ExtensionType>::Metadata,
3947
) -> Result<Self> {
48+
// Validates the storage type
4049
Ok(Self(<Bool8 as ExtensionType>::try_new(
4150
data_type, metadata,
4251
)?))
@@ -72,7 +81,7 @@ impl DFExtensionType for DFBool8 {
7281
}
7382
}
7483

75-
/// Pretty printer for binary UUID values.
84+
/// Pretty printer for binary bool8 values.
7685
#[derive(Debug, Clone, Copy)]
7786
struct Bool8ValueDisplayIndex<'a> {
7887
array: &'a Int8Array,

datafusion/common/src/types/canonical_extensions/fixed_shape_tensor.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ use arrow::datatypes::DataType;
2121
use arrow_schema::extension::{ExtensionType, FixedShapeTensor};
2222

2323
/// Defines the extension type logic for the canonical `arrow.fixed_shape_tensor` extension type.
24+
/// This extension type can be used to store a [tensor](https://en.wikipedia.org/wiki/Tensor) of
25+
/// a fixed shape.
2426
///
25-
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism.
27+
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism. See also
28+
/// [`FixedShapeTensor`] for the implementation of arrow-rs, which this type uses internally.
29+
///
30+
/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#fixed-shape-tensor>
2631
#[derive(Debug, Clone)]
2732
pub struct DFFixedShapeTensor {
2833
inner: FixedShapeTensor,

datafusion/common/src/types/canonical_extensions/json.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ use crate::types::extension::DFExtensionType;
2020
use arrow::datatypes::DataType;
2121
use arrow_schema::extension::{ExtensionType, Json};
2222

23-
/// Defines the extension type logic for the canonical `arrow.json` extension type.
23+
/// Defines the extension type logic for the canonical `arrow.json` extension type. This extension
24+
/// type defines that a particular string field stores JSON values.
2425
///
25-
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism.
26+
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism. See also
27+
/// [`Json`] for the implementation of arrow-rs, which this type uses internally.
28+
///
29+
/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#json>
2630
#[derive(Debug, Clone)]
2731
pub struct DFJson {
2832
inner: Json,

datafusion/common/src/types/canonical_extensions/opaque.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ use crate::types::extension::DFExtensionType;
2020
use arrow::datatypes::DataType;
2121
use arrow_schema::extension::{ExtensionType, Opaque};
2222

23-
/// Defines the extension type logic for the canonical `arrow.opaque` extension type.
23+
/// Defines the extension type logic for the canonical `arrow.opaque` extension type. This extension
24+
/// type represents types that DataFusion cannot interpret.
2425
///
25-
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism.
26+
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism. See also
27+
/// [`Opaque`] for the implementation of arrow-rs, which this type uses internally.
28+
///
29+
/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#opaque>
2630
#[derive(Debug, Clone)]
2731
pub struct DFOpaque {
2832
inner: Opaque,

datafusion/common/src/types/canonical_extensions/timestamp_with_offset.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ use arrow_schema::extension::{ExtensionType, TimestampWithOffset};
3232
use std::fmt::Write;
3333

3434
/// Defines the extension type logic for the canonical `arrow.timestamp_with_offset` extension type.
35+
/// This extension type allows associating a different offset for each timestamp in a column.
3536
///
36-
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism.
37+
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism. See also
38+
/// [`TimestampWithOffset`] for the implementation of arrow-rs, which this type uses internally.
39+
///
40+
/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#timestamp-with-offset>
3741
#[derive(Debug, Clone)]
3842
pub struct DFTimestampWithOffset {
3943
inner: TimestampWithOffset,

datafusion/common/src/types/canonical_extensions/uuid.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ use arrow_schema::extension::{ExtensionType, Uuid};
2525
use std::fmt::Write;
2626
use uuid::Bytes;
2727

28-
/// Defines the extension type logic for the canonical `arrow.uuid` extension type.
28+
/// Defines the extension type logic for the canonical `arrow.uuid` extension type. This extension
29+
/// type defines that a field should be interpreted as a
30+
/// [UUID](https://de.wikipedia.org/wiki/Universally_Unique_Identifier).
2931
///
30-
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism.
32+
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism. See also
33+
/// [`Uuid`] for the implementation of arrow-rs, which this type uses internally.
34+
///
35+
/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#uuid>
3136
#[derive(Debug, Clone)]
3237
pub struct DFUuid(Uuid);
3338

datafusion/common/src/types/canonical_extensions/variable_shape_tensor.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ use arrow::datatypes::DataType;
2121
use arrow_schema::extension::{ExtensionType, VariableShapeTensor};
2222

2323
/// Defines the extension type logic for the canonical `arrow.variable_shape_tensor` extension type.
24+
/// This extension type can be used to store a [tensor](https://en.wikipedia.org/wiki/Tensor) with
25+
/// variable shape that can change for each element.
2426
///
25-
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism.
27+
/// See [`DFExtensionType`] for information on DataFusion's extension type mechanism. See also
28+
/// [`VariableShapeTensor`] for the implementation of arrow-rs, which this type uses internally.
29+
///
30+
/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#variable-shape-tensor>
2631
#[derive(Debug, Clone)]
2732
pub struct DFVariableShapeTensor {
2833
inner: VariableShapeTensor,

0 commit comments

Comments
 (0)