paleolimbot commented on code in PR #599: URL: https://github.com/apache/sedona-db/pull/599#discussion_r2795180292
########## sedona-cli/src/pool_type.rs: ########## @@ -0,0 +1,48 @@ +// 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. + +use std::{ + fmt::{self, Display, Formatter}, + str::FromStr, +}; + +#[derive(PartialEq, Debug, Clone)] +pub enum PoolType { Review Comment: It seems like we will also need this in R and Python...should it go in `rust/sedona`? ########## sedona-cli/src/main.rs: ########## @@ -187,3 +237,80 @@ fn parse_command(command: &str) -> Result<String, String> { Err("-c flag expects only non empty commands".to_string()) } } + +#[derive(Debug, Clone, Copy)] +enum ByteUnit { + Byte, + KiB, + MiB, + GiB, + TiB, +} + +impl ByteUnit { + fn multiplier(&self) -> u64 { + match self { + ByteUnit::Byte => 1, + ByteUnit::KiB => 1 << 10, + ByteUnit::MiB => 1 << 20, + ByteUnit::GiB => 1 << 30, + ByteUnit::TiB => 1 << 40, + } + } +} + +fn parse_size_string(size: &str, label: &str) -> Result<usize, String> { + static BYTE_SUFFIXES: LazyLock<HashMap<&'static str, ByteUnit>> = LazyLock::new(|| { + let mut m = HashMap::new(); + m.insert("b", ByteUnit::Byte); + m.insert("k", ByteUnit::KiB); + m.insert("kb", ByteUnit::KiB); + m.insert("m", ByteUnit::MiB); + m.insert("mb", ByteUnit::MiB); + m.insert("g", ByteUnit::GiB); + m.insert("gb", ByteUnit::GiB); + m.insert("t", ByteUnit::TiB); + m.insert("tb", ByteUnit::TiB); + m + }); + + static SUFFIX_REGEX: LazyLock<regex::Regex> = + LazyLock::new(|| regex::Regex::new(r"^([0-9]+)([a-z]+)?$").unwrap()); Review Comment: ```suggestion LazyLock::new(|| regex::Regex::new(r"^([0-9.]+)\s*([a-z]+)?$").unwrap()); ``` (e.g., `9.5 gb`) ########## sedona-cli/src/main.rs: ########## @@ -187,3 +237,80 @@ fn parse_command(command: &str) -> Result<String, String> { Err("-c flag expects only non empty commands".to_string()) } } + +#[derive(Debug, Clone, Copy)] +enum ByteUnit { + Byte, + KiB, + MiB, + GiB, + TiB, +} + +impl ByteUnit { + fn multiplier(&self) -> u64 { + match self { + ByteUnit::Byte => 1, + ByteUnit::KiB => 1 << 10, + ByteUnit::MiB => 1 << 20, + ByteUnit::GiB => 1 << 30, + ByteUnit::TiB => 1 << 40, + } + } +} + +fn parse_size_string(size: &str, label: &str) -> Result<usize, String> { + static BYTE_SUFFIXES: LazyLock<HashMap<&'static str, ByteUnit>> = LazyLock::new(|| { Review Comment: Can you copy DataFusion's test for this? https://github.com/apache/datafusion/blob/ecf3b502cfd8c5baeaabb97737605ef66549c753/datafusion-cli/src/main.rs#L464-L510 This could also go in `rust/sedona` (we'll need it in R and Python, too?) -- 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]
