leekeiabstraction commented on code in PR #214:
URL: https://github.com/apache/fluss-rust/pull/214#discussion_r2727732487


##########
crates/fluss/src/util/partition.rs:
##########
@@ -0,0 +1,805 @@
+// 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.
+
+//! Utils for partition.
+
+#![allow(dead_code)]
+
+use crate::error::Error::IllegalArgument;
+use crate::error::{Error, Result};
+use crate::metadata::{DataType, PartitionSpec, ResolvedPartitionSpec, 
TablePath};
+use crate::row::{Date, Datum, Time, TimestampLtz, TimestampNtz};
+use jiff::ToSpan;
+use jiff::Zoned;
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum AutoPartitionTimeUnit {
+    Year,
+    Quarter,
+    Month,
+    Day,
+    Hour,
+}
+
+pub fn validate_partition_spec(
+    table_path: &TablePath,
+    partition_keys: &[String],
+    partition_spec: &PartitionSpec,
+    is_create: bool,
+) -> Result<()> {
+    let partition_spec_map = partition_spec.get_spec_map();
+    if partition_keys.len() != partition_spec_map.len() {
+        return Err(Error::InvalidPartition {
+            message: format!(
+                "PartitionSpec size is not equal to partition keys size for 
partitioned table {}.",
+                table_path
+            ),
+        });
+    }
+
+    let mut reordered_partition_values: Vec<&str> = 
Vec::with_capacity(partition_keys.len());
+    for partition_key in partition_keys {
+        if let Some(value) = partition_spec_map.get(partition_key) {
+            reordered_partition_values.push(value);
+        } else {
+            return Err(Error::InvalidPartition {
+                message: format!(
+                    "PartitionSpec {} does not contain partition key '{}' for 
partitioned table {}.",
+                    partition_spec, partition_key, table_path
+                ),
+            });
+        }
+    }
+
+    validate_partition_values(&reordered_partition_values, is_create)
+}
+
+fn validate_partition_values(partition_values: &[&str], is_create: bool) -> 
Result<()> {
+    for value in partition_values {
+        let invalid_name_error = TablePath::detect_invalid_name(value);
+        let prefix_error = if is_create {
+            TablePath::validate_prefix(value)
+        } else {
+            None
+        };
+
+        if invalid_name_error.is_some() || prefix_error.is_some() {
+            let error_msg = invalid_name_error.unwrap_or_else(|| 
prefix_error.unwrap());
+            return Err(Error::InvalidPartition {
+                message: format!("The partition value {} is invalid: {}", 
value, error_msg),
+            });
+        }
+    }
+    Ok(())
+}
+
+/// Generate [`ResolvedPartitionSpec`] for auto partition in server. When we 
auto creating a
+/// partition, we need to first generate a [`ResolvedPartitionSpec`].
+///
+/// The value is the formatted time with the specified time unit.
+pub fn generate_auto_partition<'a>(

Review Comment:
   Good catch, removed



##########
crates/fluss/src/client/admin.rs:
##########
@@ -140,7 +140,10 @@ impl FlussAdmin {
     }
 
     /// List all partitions in the given table.
-    pub async fn list_partition_infos(&self, table_path: &TablePath) -> 
Result<Vec<PartitionInfo>> {
+    pub async fn list_partition_infos(
+        &self,
+        table_path: &TablePath,
+    ) -> Result<Vec<PartitionInfo<'_>>> {

Review Comment:
   PartitionInfo has lifetime param because ResolvedPartitionSpec has lifetime 
param. This was added in response to Copilot's comment: 
https://github.com/apache/fluss-rust/pull/214#discussion_r2725548055
   
   The cloning of partition keys are what Copilot refers to in that comment.
   
   LMK if you prefer cloning without lifetime param and I can revert.



-- 
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]

Reply via email to