Xuanwo commented on code in PR #27: URL: https://github.com/apache/paimon-rust/pull/27#discussion_r1703134197
########## crates/paimon/src/spec/schema_change.rs: ########## @@ -0,0 +1,736 @@ +// 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 crate::spec::DataTypeRoot; Review Comment: `DataTypeRoot` has been removed. Please merge with main, thanks! ########## crates/paimon/src/spec/schema_change.rs: ########## @@ -0,0 +1,736 @@ +// 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 crate::spec::DataTypeRoot; +use serde::{Deserialize, Serialize}; + +/// Schema change to table. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L36> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub enum SchemaChange { + SetOption(SetOption), + RemoveOption(RemoveOption), + UpdateComment(UpdateComment), + AddColumn(AddColumn), + RenameColumn(RenameColumn), + DropColumn(DropColumn), + UpdateColumnType(UpdateColumnType), + UpdateColumnPosition(UpdateColumnPosition), + UpdateColumnNullability(UpdateColumnNullability), + UpdateColumnComment(UpdateColumnComment), +} + +/// A SchemaChange to set a table option. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L95> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct SetOption { + key: String, + value: String, +} + +impl SetOption { + /// Create a new `SetOption`. + pub fn new(key: String, value: String) -> Self { + SetOption { key, value } + } + + /// Get the key. + pub fn key(&self) -> &str { + &self.key + } + + /// Get the value. + pub fn value(&self) -> &str { + &self.value + } +} + +/// A SchemaChange to remove a table option. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L134> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct RemoveOption { + key: String, +} + +impl RemoveOption { + /// Create a new `RemoveOption`. + pub fn new(key: String) -> Self { + RemoveOption { key } + } + + /// Get the key. + pub fn key(&self) -> &str { + &self.key + } +} + +/// A SchemaChange to update a table comment. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L167> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct UpdateComment { + /// If comment is null, means to remove comment. + comment: Option<String>, +} + +impl UpdateComment { + /// Create a new `UpdateComment`. + pub fn new(comment: Option<String>) -> Self { + UpdateComment { comment } + } + + /// Get the comment. + pub fn comment(&self) -> Option<&str> { + self.comment.as_deref() + } +} + +/// A SchemaChange to add a new field. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L201> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct AddColumn { + field_name: String, + data_type: DataTypeRoot, + description: Option<String>, + #[serde(rename = "move")] + move_: Option<Move>, +} + +impl AddColumn { + /// Create a new `AddColumn`. + pub fn new( + field_name: String, + data_type: DataTypeRoot, + description: Option<String>, + move_: Option<Move>, + ) -> Self { + AddColumn { + field_name, + data_type, + description, + move_, + } + } + + /// Get the field name. + pub fn field_name(&self) -> &str { + &self.field_name + } + + /// Get the data type. + pub fn data_type(&self) -> &DataTypeRoot { + &self.data_type + } + + /// Get the description. + pub fn description(&self) -> Option<&str> { + self.description.as_deref() + } + + /// Get the move. + pub fn move_(&self) -> Option<&Move> { + self.move_.as_ref() + } +} + +/// A SchemaChange to rename a field. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L260> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct RenameColumn { + field_name: String, + new_name: String, +} + +impl RenameColumn { + /// Create a new `RenameColumn`. + pub fn new(field_name: String, new_name: String) -> Self { + RenameColumn { + field_name, + new_name, + } + } + + /// Get the field name. + pub fn field_name(&self) -> &str { + &self.field_name + } + + /// Get the new name. + pub fn new_name(&self) -> &str { + &self.new_name + } +} + +/// A SchemaChange to drop a field. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L302> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct DropColumn { + field_name: String, +} + +impl DropColumn { + /// Create a new `DropColumn`. + pub fn new(field_name: String) -> Self { + DropColumn { field_name } + } + + /// Get the field name. + pub fn field_name(&self) -> &str { + &self.field_name + } +} + +/// A SchemaChange to update the field's type. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L335> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UpdateColumnType { + field_name: String, + new_data_type: DataTypeRoot, +} + +impl UpdateColumnType { + /// Create a new `UpdateColumnType`. + pub fn new(field_name: String, new_data_type: DataTypeRoot) -> Self { + UpdateColumnType { + field_name, + new_data_type, + } + } + + /// Get the field name. + pub fn field_name(&self) -> &str { + &self.field_name + } + + /// Get the new data type. + pub fn new_data_type(&self) -> &DataTypeRoot { + &self.new_data_type + } +} + +/// A SchemaChange to update the field's position. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L377> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct UpdateColumnPosition { + #[serde(rename = "move")] + move_: Move, +} + +impl UpdateColumnPosition { + /// Create a new `UpdateColumnPosition`. + pub fn new(move_: Move) -> Self { + UpdateColumnPosition { move_ } + } + + /// Get the move. + pub fn move_(&self) -> &Move { + &self.move_ + } +} + +/// A SchemaChange to update the field's nullability. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L470> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UpdateColumnNullability { + field_names: Vec<String>, + new_nullability: bool, +} + +impl UpdateColumnNullability { + /// Create a new `UpdateColumnNullability`. + pub fn new(field_names: Vec<String>, new_nullability: bool) -> Self { + UpdateColumnNullability { + field_names, + new_nullability, + } + } + + /// Get the field names. + pub fn field_names(&self) -> &[String] { + &self.field_names + } + + /// Get the new nullability. + pub fn new_nullability(&self) -> bool { + self.new_nullability + } +} + +/// A SchemaChange to update the (nested) field's comment. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L512> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UpdateColumnComment { + field_names: Vec<String>, + new_description: String, +} + +impl UpdateColumnComment { + /// Create a new `UpdateColumnComment`. + pub fn new(field_names: Vec<String>, new_description: String) -> Self { + UpdateColumnComment { + field_names, + new_description, + } + } + + /// Get the field names. + pub fn field_names(&self) -> &[String] { + &self.field_names + } + + /// Get the new description. + pub fn new_description(&self) -> &str { + &self.new_description + } +} + +impl SchemaChange { + /// impl the `set_option`. + pub fn set_option(key: String, value: String) -> Self { + SchemaChange::SetOption(SetOption::new(key, value)) + } + + /// impl the `remove_option`. + pub fn remove_option(key: String) -> Self { + SchemaChange::RemoveOption(RemoveOption::new(key)) + } + + /// impl the `update_comment`. + pub fn update_comment(comment: Option<String>) -> Self { + SchemaChange::UpdateComment(UpdateComment::new(comment)) + } + + /// impl the `add_column`. + pub fn add_column(field_name: String, data_type: DataTypeRoot) -> Self { + SchemaChange::AddColumn(AddColumn::new(field_name, data_type, None, None)) + } + + /// impl the `add_column_with_comment`. + pub fn add_column_with_comment( + field_name: String, + data_type: DataTypeRoot, + comment: String, + ) -> Self { + SchemaChange::AddColumn(AddColumn::new(field_name, data_type, Some(comment), None)) + } + + /// impl the `add_column_with_comment_and_move`. + pub fn add_column_with_comment_and_move( + field_name: String, + data_type: DataTypeRoot, + comment: String, + move_: Move, + ) -> Self { + SchemaChange::AddColumn(AddColumn::new( + field_name, + data_type, + Some(comment), + Some(move_), + )) + } + + /// impl the `rename_column`. + pub fn rename_column(field_name: String, new_name: String) -> Self { + SchemaChange::RenameColumn(RenameColumn::new(field_name, new_name)) + } + + /// impl the `drop_column`. + pub fn drop_column(field_name: String) -> Self { + SchemaChange::DropColumn(DropColumn::new(field_name)) + } + + /// impl the `update_column_type`. + pub fn update_column_type(field_name: String, new_data_type: DataTypeRoot) -> Self { + SchemaChange::UpdateColumnType(UpdateColumnType::new(field_name, new_data_type)) + } + + /// impl the `update_column_position`. + pub fn update_column_nullability(field_name: String, new_nullability: bool) -> Self { + SchemaChange::UpdateColumnNullability(UpdateColumnNullability { + field_names: vec![field_name], + new_nullability, + }) + } + + /// impl the `update_columns_nullability`. + pub fn update_columns_nullability(field_names: Vec<String>, new_nullability: bool) -> Self { + SchemaChange::UpdateColumnNullability(UpdateColumnNullability { + field_names, + new_nullability, + }) + } + + /// impl the `update_column_comment`. + pub fn update_column_comment(field_name: String, comment: String) -> Self { + SchemaChange::UpdateColumnComment(UpdateColumnComment { + field_names: vec![field_name], + new_description: comment, + }) + } + + /// impl the `update_columns_comment`. + pub fn update_columns_comment(field_names: Vec<String>, comment: String) -> Self { + SchemaChange::UpdateColumnComment(UpdateColumnComment { + field_names, + new_description: comment, + }) + } + + /// impl the `update_column_position`. + pub fn update_column_position(move_: Move) -> Self { + SchemaChange::UpdateColumnPosition(UpdateColumnPosition::new(move_)) + } +} + +/// The type of move. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L412> +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] +pub enum MoveType { + FIRST, + AFTER, + BEFORE, + LAST, +} + +/// Represents a requested column move in a struct. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L410> +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct Move { Review Comment: Move is a keyword in rust, how about naming it `ColumnMove` and `ColumnMoveType`? ########## crates/paimon/src/spec/schema_change.rs: ########## @@ -0,0 +1,736 @@ +// 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 crate::spec::DataTypeRoot; +use serde::{Deserialize, Serialize}; + +/// Schema change to table. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L36> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub enum SchemaChange { + SetOption(SetOption), + RemoveOption(RemoveOption), + UpdateComment(UpdateComment), + AddColumn(AddColumn), + RenameColumn(RenameColumn), + DropColumn(DropColumn), + UpdateColumnType(UpdateColumnType), + UpdateColumnPosition(UpdateColumnPosition), + UpdateColumnNullability(UpdateColumnNullability), + UpdateColumnComment(UpdateColumnComment), +} + +/// A SchemaChange to set a table option. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L95> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct SetOption { + key: String, + value: String, +} + +impl SetOption { + /// Create a new `SetOption`. + pub fn new(key: String, value: String) -> Self { + SetOption { key, value } + } + + /// Get the key. + pub fn key(&self) -> &str { + &self.key + } + + /// Get the value. + pub fn value(&self) -> &str { + &self.value + } +} + +/// A SchemaChange to remove a table option. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L134> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct RemoveOption { + key: String, +} + +impl RemoveOption { + /// Create a new `RemoveOption`. + pub fn new(key: String) -> Self { + RemoveOption { key } + } + + /// Get the key. + pub fn key(&self) -> &str { + &self.key + } +} + +/// A SchemaChange to update a table comment. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L167> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct UpdateComment { + /// If comment is null, means to remove comment. + comment: Option<String>, +} + +impl UpdateComment { + /// Create a new `UpdateComment`. + pub fn new(comment: Option<String>) -> Self { + UpdateComment { comment } + } + + /// Get the comment. + pub fn comment(&self) -> Option<&str> { + self.comment.as_deref() + } +} + +/// A SchemaChange to add a new field. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L201> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct AddColumn { + field_name: String, + data_type: DataTypeRoot, + description: Option<String>, + #[serde(rename = "move")] + move_: Option<Move>, +} + +impl AddColumn { + /// Create a new `AddColumn`. + pub fn new( + field_name: String, + data_type: DataTypeRoot, + description: Option<String>, + move_: Option<Move>, + ) -> Self { + AddColumn { + field_name, + data_type, + description, + move_, + } + } + + /// Get the field name. + pub fn field_name(&self) -> &str { + &self.field_name + } + + /// Get the data type. + pub fn data_type(&self) -> &DataTypeRoot { + &self.data_type + } + + /// Get the description. + pub fn description(&self) -> Option<&str> { + self.description.as_deref() + } + + /// Get the move. + pub fn move_(&self) -> Option<&Move> { + self.move_.as_ref() + } +} + +/// A SchemaChange to rename a field. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L260> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct RenameColumn { + field_name: String, + new_name: String, +} + +impl RenameColumn { + /// Create a new `RenameColumn`. + pub fn new(field_name: String, new_name: String) -> Self { + RenameColumn { + field_name, + new_name, + } + } + + /// Get the field name. + pub fn field_name(&self) -> &str { + &self.field_name + } + + /// Get the new name. + pub fn new_name(&self) -> &str { + &self.new_name + } +} + +/// A SchemaChange to drop a field. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L302> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct DropColumn { + field_name: String, +} + +impl DropColumn { + /// Create a new `DropColumn`. + pub fn new(field_name: String) -> Self { + DropColumn { field_name } + } + + /// Get the field name. + pub fn field_name(&self) -> &str { + &self.field_name + } +} + +/// A SchemaChange to update the field's type. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L335> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UpdateColumnType { + field_name: String, + new_data_type: DataTypeRoot, +} + +impl UpdateColumnType { + /// Create a new `UpdateColumnType`. + pub fn new(field_name: String, new_data_type: DataTypeRoot) -> Self { + UpdateColumnType { + field_name, + new_data_type, + } + } + + /// Get the field name. + pub fn field_name(&self) -> &str { + &self.field_name + } + + /// Get the new data type. + pub fn new_data_type(&self) -> &DataTypeRoot { + &self.new_data_type + } +} + +/// A SchemaChange to update the field's position. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L377> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct UpdateColumnPosition { + #[serde(rename = "move")] + move_: Move, +} + +impl UpdateColumnPosition { + /// Create a new `UpdateColumnPosition`. + pub fn new(move_: Move) -> Self { + UpdateColumnPosition { move_ } + } + + /// Get the move. + pub fn move_(&self) -> &Move { + &self.move_ + } +} + +/// A SchemaChange to update the field's nullability. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L470> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UpdateColumnNullability { + field_names: Vec<String>, + new_nullability: bool, +} + +impl UpdateColumnNullability { + /// Create a new `UpdateColumnNullability`. + pub fn new(field_names: Vec<String>, new_nullability: bool) -> Self { + UpdateColumnNullability { + field_names, + new_nullability, + } + } + + /// Get the field names. + pub fn field_names(&self) -> &[String] { + &self.field_names + } + + /// Get the new nullability. + pub fn new_nullability(&self) -> bool { + self.new_nullability + } +} + +/// A SchemaChange to update the (nested) field's comment. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L512> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UpdateColumnComment { + field_names: Vec<String>, + new_description: String, +} + +impl UpdateColumnComment { + /// Create a new `UpdateColumnComment`. + pub fn new(field_names: Vec<String>, new_description: String) -> Self { + UpdateColumnComment { + field_names, + new_description, + } + } + + /// Get the field names. + pub fn field_names(&self) -> &[String] { + &self.field_names + } + + /// Get the new description. + pub fn new_description(&self) -> &str { + &self.new_description + } +} + +impl SchemaChange { + /// impl the `set_option`. + pub fn set_option(key: String, value: String) -> Self { + SchemaChange::SetOption(SetOption::new(key, value)) + } + + /// impl the `remove_option`. + pub fn remove_option(key: String) -> Self { + SchemaChange::RemoveOption(RemoveOption::new(key)) + } + + /// impl the `update_comment`. + pub fn update_comment(comment: Option<String>) -> Self { + SchemaChange::UpdateComment(UpdateComment::new(comment)) + } + + /// impl the `add_column`. + pub fn add_column(field_name: String, data_type: DataTypeRoot) -> Self { + SchemaChange::AddColumn(AddColumn::new(field_name, data_type, None, None)) + } + + /// impl the `add_column_with_comment`. + pub fn add_column_with_comment( + field_name: String, + data_type: DataTypeRoot, + comment: String, + ) -> Self { + SchemaChange::AddColumn(AddColumn::new(field_name, data_type, Some(comment), None)) + } + + /// impl the `add_column_with_comment_and_move`. + pub fn add_column_with_comment_and_move( + field_name: String, + data_type: DataTypeRoot, + comment: String, + move_: Move, + ) -> Self { + SchemaChange::AddColumn(AddColumn::new( + field_name, + data_type, + Some(comment), + Some(move_), + )) + } + + /// impl the `rename_column`. + pub fn rename_column(field_name: String, new_name: String) -> Self { + SchemaChange::RenameColumn(RenameColumn::new(field_name, new_name)) + } + + /// impl the `drop_column`. + pub fn drop_column(field_name: String) -> Self { + SchemaChange::DropColumn(DropColumn::new(field_name)) + } + + /// impl the `update_column_type`. + pub fn update_column_type(field_name: String, new_data_type: DataTypeRoot) -> Self { + SchemaChange::UpdateColumnType(UpdateColumnType::new(field_name, new_data_type)) + } + + /// impl the `update_column_position`. + pub fn update_column_nullability(field_name: String, new_nullability: bool) -> Self { + SchemaChange::UpdateColumnNullability(UpdateColumnNullability { + field_names: vec![field_name], + new_nullability, + }) + } + + /// impl the `update_columns_nullability`. + pub fn update_columns_nullability(field_names: Vec<String>, new_nullability: bool) -> Self { + SchemaChange::UpdateColumnNullability(UpdateColumnNullability { + field_names, + new_nullability, + }) + } + + /// impl the `update_column_comment`. + pub fn update_column_comment(field_name: String, comment: String) -> Self { + SchemaChange::UpdateColumnComment(UpdateColumnComment { + field_names: vec![field_name], + new_description: comment, + }) + } + + /// impl the `update_columns_comment`. + pub fn update_columns_comment(field_names: Vec<String>, comment: String) -> Self { + SchemaChange::UpdateColumnComment(UpdateColumnComment { + field_names, + new_description: comment, + }) + } + + /// impl the `update_column_position`. + pub fn update_column_position(move_: Move) -> Self { + SchemaChange::UpdateColumnPosition(UpdateColumnPosition::new(move_)) + } +} + +/// The type of move. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L412> +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] +pub enum MoveType { + FIRST, Review Comment: The java version seems to have only: ```java public enum MoveType { FIRST, AFTER } ``` ########## crates/paimon/src/spec/schema_change.rs: ########## @@ -0,0 +1,736 @@ +// 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 crate::spec::DataTypeRoot; +use serde::{Deserialize, Serialize}; + +/// Schema change to table. +/// +/// Reference: <https://github.com/apache/paimon/blob/release-0.8.2/paimon-core/src/main/java/org/apache/paimon/schema/SchemaChange.java#L36> +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub enum SchemaChange { Review Comment: I think we don't need to specify types for every enum value. It's unlikely that we'll use `SetOption` without `SchemaChange`. How about embedding the struct directly in this enum? ```rust pub enum SchemaChange { SetOption { key: String, value: String, } ... } ``` -- 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: issues-unsubscr...@paimon.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org