Tpt commented on code in PR #5822: URL: https://github.com/apache/arrow-rs/pull/5822#discussion_r1927507731
########## arrow-schema/src/extension/canonical/json.rs: ########## @@ -0,0 +1,189 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! JSON +//! +//! <https://arrow.apache.org/docs/format/CanonicalExtensions.html#json> + +use serde_json::Value; + +use crate::{extension::ExtensionType, ArrowError, DataType}; + +/// The extension type for `JSON`. +/// +/// Extension name: `arrow.json`. +/// +/// The storage type of this extension is `String` or `LargeString` or +/// `StringView`. Only UTF-8 encoded JSON as specified in [rfc8259](https://datatracker.ietf.org/doc/html/rfc8259) +/// is supported. +/// +/// This type does not have any parameters. +/// +/// Metadata is either an empty string or a JSON string with an empty Review Comment: Based on implementation I guess it's not "an empty string" but "a JSON string with an empty string" (ie `"\"\""` and not `""`) ########## arrow-schema/src/extension/canonical/bool8.rs: ########## @@ -0,0 +1,143 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! 8-bit Boolean +//! +//! <https://arrow.apache.org/docs/format/CanonicalExtensions.html#bit-boolean> + +use crate::{extension::ExtensionType, ArrowError, DataType}; + +/// The extension type for `8-bit Boolean`. +/// +/// Extension name: `arrow.bool8`. +/// +/// The storage type of the extension is `Int8` where: +/// - false is denoted by the value 0. +/// - true can be specified using any non-zero value. Preferably 1. +/// +/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#bit-boolean> +#[derive(Debug, Default, Clone, Copy, PartialEq)] +pub struct Bool8; + +impl ExtensionType for Bool8 { + const NAME: &'static str = "arrow.bool8"; + + type Metadata = &'static str; + + fn metadata(&self) -> &Self::Metadata { + &"" + } + + fn serialize_metadata(&self) -> Option<String> { + Some(String::default()) + } + + fn deserialize_metadata(metadata: Option<&str>) -> Result<Self::Metadata, ArrowError> { + const ERR: &str = "Bool8 extension type expects an empty string as metadata"; + metadata.map_or_else( + || Err(ArrowError::InvalidArgumentError(ERR.to_owned())), + |value| match value { + "" => Ok(""), + _ => Err(ArrowError::InvalidArgumentError(ERR.to_owned())), + }, + ) Review Comment: slightly shorter: ```suggestion if metadata.map_or(false, str::is_empty) { Ok("") } else { Err(ArrowError::InvalidArgumentError("Bool8 extension type expects an empty string as metadata".into())) } ``` ########## arrow-schema/src/extension/canonical/bool8.rs: ########## @@ -0,0 +1,143 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! 8-bit Boolean +//! +//! <https://arrow.apache.org/docs/format/CanonicalExtensions.html#bit-boolean> + +use crate::{extension::ExtensionType, ArrowError, DataType}; + +/// The extension type for `8-bit Boolean`. +/// +/// Extension name: `arrow.bool8`. +/// +/// The storage type of the extension is `Int8` where: +/// - false is denoted by the value 0. +/// - true can be specified using any non-zero value. Preferably 1. +/// +/// <https://arrow.apache.org/docs/format/CanonicalExtensions.html#bit-boolean> +#[derive(Debug, Default, Clone, Copy, PartialEq)] +pub struct Bool8; + +impl ExtensionType for Bool8 { + const NAME: &'static str = "arrow.bool8"; + + type Metadata = &'static str; Review Comment: Maybe bad idea: use `()` here. This way it's not possible to encode bad metadata value (any string that is not empty) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
