Skip to content

Commit

Permalink
[CHORE] Add rustfmt config file and run formatter (#2807)
Browse files Browse the repository at this point in the history
# Overview
The only file that I added was the `rustfmt.toml`. In that file, I
updated the styles on how imports should be ordered
("StdExternalCrate"). Then I ran the formatter. The formatter changed
updated all of our rust files to follow this convention.

This PR is obviously huge, but the only changes that are observed are
after running `cargo fmt` on the original code. I have not sneaked
anything else into here.

You can verify this via 2 ways:
1. Manually inspecting each file to make sure that only the imports have
been rearranged (obviously tiring and cumbersome).
2. Checking out the prior commit, adding the *exact same* `rustfmt.toml`
file, running `cargo fmt`, and checking to make sure your formatted code
has *NO* diffs against my commit. (Make sure your rust toolchain is
updated to the latest release!).
  • Loading branch information
raunakab authored Sep 17, 2024
1 parent 4ddc283 commit 32a4243
Show file tree
Hide file tree
Showing 421 changed files with 1,532 additions and 1,930 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d5e444d0a71409ae3701d4249ad877f1fb9e2235 # introduced `rustfmt.toml` and ran formatter; ignoring large formatting changes
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
group_imports = "StdExternalCrate"
ignore = ["src/arrow2", "src/parquet2"]
imports_granularity = "Crate"
1 change: 0 additions & 1 deletion src/common/arrow-ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::io::Cursor;

use arrow2::{array::Array, datatypes::Field, ffi};

#[cfg(feature = "python")]
use pyo3::ffi::Py_uintptr_t;
#[cfg(feature = "python")]
Expand Down
6 changes: 2 additions & 4 deletions src/common/daft-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,13 @@ impl DaftExecutionConfig {
#[cfg(feature = "python")]
mod python;

#[cfg(feature = "python")]
use pyo3::prelude::*;
#[cfg(feature = "python")]
pub use python::PyDaftExecutionConfig;

#[cfg(feature = "python")]
pub use python::PyDaftPlanningConfig;

#[cfg(feature = "python")]
use pyo3::prelude::*;

#[cfg(feature = "python")]
pub fn register_modules(parent: &Bound<PyModule>) -> PyResult<()> {
parent.add_class::<python::PyDaftExecutionConfig>()?;
Expand Down
2 changes: 1 addition & 1 deletion src/common/daft-config/src/python.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::sync::Arc;

use common_io_config::python::IOConfig as PyIOConfig;
use common_py_serde::impl_bincode_py_state_serialization;
use pyo3::prelude::*;
use serde::{Deserialize, Serialize};

use crate::{DaftExecutionConfig, DaftPlanningConfig};
use common_io_config::python::IOConfig as PyIOConfig;

#[derive(Clone, Default, Serialize, Deserialize)]
#[pyclass(module = "daft.daft")]
Expand Down
3 changes: 2 additions & 1 deletion src/common/display/src/mermaid.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use indexmap::IndexMap;
use std::fmt;

use indexmap::IndexMap;

use crate::{tree::TreeDisplay, DisplayLevel};

pub trait MermaidDisplay: TreeDisplay {
Expand Down
3 changes: 1 addition & 2 deletions src/common/error/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod error;
pub use error::DaftError;
pub use error::DaftResult;
pub use error::{DaftError, DaftResult};
#[cfg(feature = "python")]
mod python;
3 changes: 1 addition & 2 deletions src/common/error/src/python.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use pyo3::exceptions::PyFileNotFoundError;
use pyo3::import_exception;
use pyo3::{exceptions::PyFileNotFoundError, import_exception};

use crate::DaftError;

Expand Down
1 change: 0 additions & 1 deletion src/common/file-formats/src/file_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use common_error::{DaftError, DaftResult};
use common_py_serde::impl_bincode_py_state_serialization;
#[cfg(feature = "python")]
use pyo3::prelude::*;

use serde::{Deserialize, Serialize};

/// Format of a file, e.g. Parquet, CSV, JSON.
Expand Down
11 changes: 5 additions & 6 deletions src/common/file-formats/src/file_format_config.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use crate::FileFormat;
use daft_schema::{field::Field, time_unit::TimeUnit};
use serde::{Deserialize, Serialize};
use std::hash::Hash;
use std::{collections::BTreeMap, sync::Arc};
use std::{collections::BTreeMap, hash::Hash, sync::Arc};

use common_py_serde::impl_bincode_py_state_serialization;

use daft_schema::{field::Field, time_unit::TimeUnit};
use serde::{Deserialize, Serialize};
#[cfg(feature = "python")]
use {
common_py_serde::{deserialize_py_object, serialize_py_object},
daft_schema::python::{datatype::PyTimeUnit, field::PyField},
pyo3::{pyclass, pymethods, types::PyAnyMethods, PyObject, PyResult, Python},
};

use crate::FileFormat;

/// Configuration for parsing a particular file format.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum FileFormatConfig {
Expand Down
5 changes: 2 additions & 3 deletions src/common/file-formats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ mod file_format;
pub use file_format::FileFormat;

mod file_format_config;
#[cfg(feature = "python")]
pub use file_format_config::DatabaseSourceConfig;
pub use file_format_config::{
CsvSourceConfig, FileFormatConfig, JsonSourceConfig, ParquetSourceConfig,
};

#[cfg(feature = "python")]
pub use file_format_config::DatabaseSourceConfig;

#[cfg(feature = "python")]
pub mod python;

Expand Down
6 changes: 2 additions & 4 deletions src/common/io-config/src/azure.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::{Display, Formatter};

use serde::Deserialize;
use serde::Serialize;
use serde::{Deserialize, Serialize};

use crate::ObfuscatedString;

Expand Down
9 changes: 3 additions & 6 deletions src/common/io-config/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::{Display, Formatter};

use serde::Deserialize;
use serde::Serialize;
use serde::{Deserialize, Serialize};

use crate::HTTPConfig;
use crate::{AzureConfig, GCSConfig, S3Config};
use crate::{AzureConfig, GCSConfig, HTTPConfig, S3Config};
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct IOConfig {
pub s3: S3Config,
Expand Down
6 changes: 2 additions & 4 deletions src/common/io-config/src/gcs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::{Display, Formatter};

use serde::Deserialize;
use serde::Serialize;
use serde::{Deserialize, Serialize};

use crate::ObfuscatedString;

Expand Down
6 changes: 2 additions & 4 deletions src/common/io-config/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::{Display, Formatter};

use serde::Deserialize;
use serde::Serialize;
use serde::{Deserialize, Serialize};

use crate::ObfuscatedString;

Expand Down
7 changes: 5 additions & 2 deletions src/common/io-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ use secrecy::{ExposeSecret, Secret};
use serde::{Deserialize, Deserializer, Serialize};

pub use crate::{
azure::AzureConfig, config::IOConfig, gcs::GCSConfig, http::HTTPConfig, s3::S3Config,
s3::S3Credentials,
azure::AzureConfig,
config::IOConfig,
gcs::GCSConfig,
http::HTTPConfig,
s3::{S3Config, S3Credentials},
};

#[derive(Clone)]
Expand Down
3 changes: 1 addition & 2 deletions src/common/io-config/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ impl IOConfig {
}

pub fn __hash__(&self) -> PyResult<u64> {
use std::collections::hash_map::DefaultHasher;
use std::hash::Hash;
use std::{collections::hash_map::DefaultHasher, hash::Hash};

let mut hasher = DefaultHasher::new();
self.config.hash(&mut hasher);
Expand Down
20 changes: 9 additions & 11 deletions src/common/io-config/src/s3.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use std::{
any::Any,
fmt::{Debug, Display, Formatter},
hash::{Hash, Hasher},
time::SystemTime,
};

use aws_credential_types::provider::ProvideCredentials;
use chrono::offset::Utc;
use chrono::DateTime;
use serde::Deserialize;
use serde::Serialize;
use std::any::Any;
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use std::hash::Hash;
use std::hash::Hasher;
use std::time::SystemTime;
use chrono::{offset::Utc, DateTime};
use serde::{Deserialize, Serialize};

pub use crate::ObfuscatedString;

Expand Down
4 changes: 2 additions & 2 deletions src/common/py-serde/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod python;

pub use bincode;

#[cfg(feature = "python")]
pub use crate::{python::deserialize_py_object, python::serialize_py_object};

pub use bincode;
10 changes: 7 additions & 3 deletions src/common/py-serde/src/python.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::fmt;

#[cfg(feature = "python")]
use pyo3::{types::PyAnyMethods, PyObject, Python};

use serde::{de::Error as DeError, de::Visitor, ser::Error as SerError, Deserializer, Serializer};
use std::fmt;
use serde::{
de::{Error as DeError, Visitor},
ser::Error as SerError,
Deserializer, Serializer,
};
#[cfg(feature = "python")]

pub fn serialize_py_object<S>(obj: &PyObject, s: S) -> Result<S::Ok, S::Error>
Expand Down
9 changes: 5 additions & 4 deletions src/common/resource-request/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use std::{
hash::{Hash, Hasher},
ops::Add,
};

use common_hashable_float_wrapper::FloatWrapper;
use common_py_serde::impl_bincode_py_state_serialization;
#[cfg(feature = "python")]
Expand All @@ -8,10 +13,6 @@ use pyo3::{
types::{PyModule, PyModuleMethods},
Bound, PyObject, PyResult, Python,
};

use std::hash::{Hash, Hasher};
use std::ops::Add;

use serde::{Deserialize, Serialize};

/// Resource request for a query fragment task.
Expand Down
3 changes: 1 addition & 2 deletions src/common/treenode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,8 @@ impl<T: ConcreteTreeNode> TreeNode for T {
mod tests {
use std::fmt::Display;

use crate::Result;
use crate::{
Transformed, TreeNode, TreeNodeIterator, TreeNodeRecursion, TreeNodeRewriter,
Result, Transformed, TreeNode, TreeNodeIterator, TreeNodeRecursion, TreeNodeRewriter,
TreeNodeVisitor,
};

Expand Down
3 changes: 2 additions & 1 deletion src/daft-compression/src/compression.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{path::PathBuf, pin::Pin};

use async_compression::tokio::bufread::{
BrotliDecoder, BzDecoder, DeflateDecoder, GzipDecoder, LzmaDecoder, XzDecoder, ZlibDecoder,
ZstdDecoder,
};
use std::{path::PathBuf, pin::Pin};
use tokio::io::{AsyncBufRead, AsyncRead};
use url::Url;

Expand Down
3 changes: 1 addition & 2 deletions src/daft-core/src/array/boolean.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::datatypes::BooleanArray;

use super::ops::as_arrow::AsArrow;
use crate::datatypes::BooleanArray;

impl BooleanArray {
pub fn as_bitmap(&self) -> &arrow2::bitmap::Bitmap {
Expand Down
12 changes: 6 additions & 6 deletions src/daft-core/src/array/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::sync::Arc;

use common_error::{DaftError, DaftResult};

use crate::array::growable::{Growable, GrowableArray};
use crate::datatypes::DataType;
use crate::datatypes::{DaftArrayType, Field};
use crate::series::Series;
use crate::{
array::growable::{Growable, GrowableArray},
datatypes::{DaftArrayType, DataType, Field},
series::Series,
};

#[derive(Clone, Debug)]
pub struct FixedSizeListArray {
Expand Down Expand Up @@ -222,13 +223,12 @@ impl Iterator for FixedSizeListArrayIter<'_> {
mod tests {
use common_error::DaftResult;

use super::FixedSizeListArray;
use crate::{
datatypes::{DataType, Field, Int32Array},
series::IntoSeries,
};

use super::FixedSizeListArray;

/// Helper that returns a FixedSizeListArray, with each list element at len=3
fn get_i32_fixed_size_list_array(validity: &[bool]) -> FixedSizeListArray {
let field = Field::new("foo", DataType::FixedSizeList(Box::new(DataType::Int32), 3));
Expand Down
17 changes: 9 additions & 8 deletions src/daft-core/src/array/from.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::borrow::Cow;
use std::sync::Arc;
use std::{borrow::Cow, sync::Arc};

use crate::datatypes::{
BinaryArray, BooleanArray, DaftNumericType, DaftPhysicalType, DataType, Field,
FixedSizeBinaryArray, NullArray, Utf8Array, Utf8Type,
};

use crate::array::DataArray;
use common_error::{DaftError, DaftResult};

use crate::{
array::DataArray,
datatypes::{
BinaryArray, BooleanArray, DaftNumericType, DaftPhysicalType, DataType, Field,
FixedSizeBinaryArray, NullArray, Utf8Array, Utf8Type,
},
};

impl<T: DaftNumericType> From<(&str, Box<arrow2::array::PrimitiveArray<T::Native>>)>
for DataArray<T>
{
Expand Down
4 changes: 1 addition & 3 deletions src/daft-core/src/array/from_iter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::array::prelude::*;
use crate::datatypes::prelude::*;

use super::DataArray;
use crate::{array::prelude::*, datatypes::prelude::*};

impl<T> DataArray<T>
where
Expand Down
7 changes: 5 additions & 2 deletions src/daft-core/src/array/growable/arrow_growable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use std::{marker::PhantomData, sync::Arc};

use common_error::DaftResult;

use crate::{array::prelude::*, datatypes::prelude::*, series::IntoSeries, series::Series};

use super::Growable;
use crate::{
array::prelude::*,
datatypes::prelude::*,
series::{IntoSeries, Series},
};

pub struct ArrowBackedDataArrayGrowable<
'a,
Expand Down
Loading

0 comments on commit 32a4243

Please sign in to comment.