Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rust): derive Copy on some public enums #2329

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/core/src/kernel/expressions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl ExpressionEvaluator for DefaultExpressionEvaluator {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
/// A binary operator.
pub enum BinaryOperator {
/// Arithmetic Plus
Expand All @@ -121,7 +121,7 @@ pub enum BinaryOperator {
}

/// Variadic operators
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum VariadicOperator {
/// AND
And,
Expand All @@ -148,7 +148,7 @@ impl Display for BinaryOperator {
}
}

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq)]
/// A unary operator.
pub enum UnaryOperator {
/// Unary Not
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/kernel/expressions/scalars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl From<String> for Scalar {

impl PrimitiveType {
fn data_type(&self) -> DataType {
DataType::Primitive(self.clone())
DataType::Primitive(*self)
}

/// Parses a string into a scalar value.
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/kernel/models/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl From<&parquet::record::Field> for WriterFeatures {
}

///Storage type of deletion vector
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq, Eq)]
pub enum StorageType {
/// Stored at relative path derived from a UUID.
#[serde(rename = "u")]
Expand Down Expand Up @@ -768,7 +768,7 @@ pub struct Sidecar {
pub tags: Option<HashMap<String, Option<String>>>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
/// The isolation level applied during transaction
pub enum IsolationLevel {
/// The strongest isolation level. It ensures that committed write operations
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/kernel/models/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ pub const DECIMAL_MAX_PRECISION: u8 = 38;
/// The maximum scale for [PrimitiveType::Decimal] values
pub const DECIMAL_MAX_SCALE: i8 = 38;

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq, Hash)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Copy, Clone, Eq, Hash)]
#[serde(rename_all = "snake_case")]
/// Primitive types supported by Delta
pub enum PrimitiveType {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/operations/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl CreateBuilder {
}

let operation = DeltaOperation::Create {
mode: self.mode.clone(),
mode: self.mode,
metadata: metadata.clone(),
location: storage_url,
protocol: protocol.clone(),
Expand All @@ -327,7 +327,7 @@ impl std::future::IntoFuture for CreateBuilder {
fn into_future(self) -> Self::IntoFuture {
let this = self;
Box::pin(async move {
let mode = this.mode.clone();
let mode = this.mode;
let app_metadata = this.metadata.clone().unwrap_or_default();
let (mut table, actions, operation) = this.into_table_and_actions()?;
let log_store = table.log_store();
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/operations/merge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ async fn execute(

let source_schema = source.schema();
let target_schema = target.schema();
let join_schema_df = build_join_schema(source_schema, &target_schema, &JoinType::Full)?;
let join_schema_df = build_join_schema(source_schema, target_schema, &JoinType::Full)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not a reference anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a clippy warning, because target.schema() already returns a reference, so that double reference was being automatically dereferenced.

let predicate = match predicate {
Expression::DataFusion(expr) => expr,
Expression::String(s) => parse_predicate_expression(&join_schema_df, s, &state)?,
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/operations/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ impl<'a> std::future::IntoFuture for PreparedCommit<'a> {
Err(err) => {
this.log_store
.object_store()
.delete_with_retries(&tmp_commit, 15)
.delete_with_retries(tmp_commit, 15)
.await?;
return Err(TransactionError::CommitConflict(err).into());
}
Expand All @@ -522,7 +522,7 @@ impl<'a> std::future::IntoFuture for PreparedCommit<'a> {
Err(err) => {
this.log_store
.object_store()
.delete_with_retries(&tmp_commit, 15)
.delete_with_retries(tmp_commit, 15)
.await?;
return Err(err.into());
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/operations/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl PartitionWriter {
self.flush_arrow_writer().await?;
}
}
self.arrow_writer.flush();
self.arrow_writer.flush()?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also included this non-related change, because the arrow result was not being used, but it should.

Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ impl DeltaOperation {
}

/// The SaveMode used when performing a DeltaOperation
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
pub enum SaveMode {
/// Files will be appended to the target location.
Append,
Expand Down Expand Up @@ -582,7 +582,7 @@ impl FromStr for SaveMode {
}

/// The OutputMode used in streaming operations.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub enum OutputMode {
/// Only new rows will be written when new data is available.
Append,
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/table/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl From<BuilderError> for DeltaTableError {
}

/// possible version specifications for loading a delta table
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
pub enum DeltaVersion {
/// load the newest version
#[default]
Expand Down Expand Up @@ -321,7 +321,7 @@ impl DeltaTableBuilder {

/// Build the [`DeltaTable`] and load its state
pub async fn load(self) -> DeltaResult<DeltaTable> {
let version = self.options.version.clone();
let version = self.options.version;
let mut table = self.build()?;
match version {
DeltaVersion::Newest => table.load().await?,
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/table/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl<'a> TableConfig<'a> {
}
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq)]
/// The isolation level applied during transaction
pub enum IsolationLevel {
/// The strongest isolation level. It ensures that committed write operations
Expand Down Expand Up @@ -460,7 +460,7 @@ impl FromStr for CheckpointPolicy {
}
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq)]
/// The Column Mapping modes used for reading and writing data
#[serde(rename_all = "camelCase")]
pub enum ColumnMappingMode {
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/table/state_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl DeltaTableState {

for add in files {
if let Some(value) = &add.deletion_vector {
storage_type.append_value(&value.storage_type);
storage_type.append_value(value.storage_type);
path_or_inline_div.append_value(value.path_or_inline_dv.clone());
if let Some(ofs) = value.offset {
offset.append_value(ofs);
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl From<DeltaWriterError> for DeltaTableError {
}

/// Write mode for the [DeltaWriter]
#[derive(Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum WriteMode {
/// Default write mode which will return an error if schemas do not match correctly
Default,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/writer/record_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl DeltaWriter<RecordBatch> for RecordBatchWriter {

for result in self.divide_by_partition_values(&values)? {
let schema = self
.write_partition(result.record_batch, &result.partition_values, mode.clone())
.write_partition(result.record_batch, &result.partition_values, mode)
.await?;
self.arrow_schema_ref = schema;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ macro_rules! parser_err {
};
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum DescribeOperation {
Detail,
History,
Expand Down
4 changes: 2 additions & 2 deletions python/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl PrimitiveType {

#[pyo3(text_signature = "($self)")]
fn to_json(&self) -> PyResult<String> {
let inner_type = DataType::Primitive(self.inner_type.clone());
let inner_type = DataType::Primitive(self.inner_type);
serde_json::to_string(&inner_type).map_err(|err| PyException::new_err(err.to_string()))
}

Expand All @@ -160,7 +160,7 @@ impl PrimitiveType {

#[pyo3(text_signature = "($self)")]
fn to_pyarrow(&self) -> PyResult<PyArrowType<ArrowDataType>> {
let inner_type = DataType::Primitive(self.inner_type.clone());
let inner_type = DataType::Primitive(self.inner_type);
Ok(PyArrowType((&inner_type).try_into().map_err(
|err: ArrowError| PyException::new_err(err.to_string()),
)?))
Expand Down
Loading