chore: apply cargo fmt with import organization (#1303)

* Apply nightly format to organize imports consistently

* Set matrix for cargo fmt

* Revert "Set matrix for cargo fmt"

This reverts commit 85119050e3da16d72cc5a7e4ebaa2e4a494dbcc4.

* Instead of creating a large matrix just add one workflow for nightly fmt

* Intentionally cause cargo fmt to fail in nightly

* Apply nightly fmt
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index ed5cae6..99457b8 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -79,10 +79,6 @@
           path: ~/.cargo
           key: cargo-cache-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('Cargo.lock') }}
 
-      - name: Check Formatting
-        if: ${{ matrix.python-version == '3.10' && matrix.toolchain == 'stable' }}
-        run: cargo fmt -- --check
-
       - name: Run Clippy
         if: ${{ matrix.python-version == '3.10' && matrix.toolchain == 'stable' }}
         run: cargo clippy --all-targets --all-features -- -D clippy::all -D warnings -A clippy::redundant_closure
@@ -125,3 +121,19 @@
           cd examples/tpch
           uv run --no-project python convert_data_to_parquet.py
           uv run --no-project pytest _tests.py
+
+  nightly-fmt:
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v5
+
+      - name: Setup Rust Toolchain
+        uses: dtolnay/rust-toolchain@stable
+        id: rust-toolchain
+        with:
+          toolchain: "nightly"
+          components: clippy,rustfmt
+
+      - name: Check Formatting
+        run: cargo +nightly fmt -- --check
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index e8c4512..bcefa40 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -33,7 +33,7 @@
           - id: rust-fmt
             name: Rust fmt
             description: Run cargo fmt on files included in the commit. rustfmt should be installed before-hand.
-            entry: cargo fmt --all --
+            entry: cargo +nightly fmt --all --
             pass_filenames: true
             types: [file, rust]
             language: system
diff --git a/ci/scripts/rust_fmt.sh b/ci/scripts/rust_fmt.sh
index 9d83258..05cb6b2 100755
--- a/ci/scripts/rust_fmt.sh
+++ b/ci/scripts/rust_fmt.sh
@@ -18,4 +18,4 @@
 # under the License.
 
 set -ex
-cargo fmt --all -- --check
+cargo +nightly fmt --all -- --check
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..d04700d
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1,19 @@
+# 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.
+
+group_imports = "StdExternalCrate"
+imports_granularity = "Module"
diff --git a/src/catalog.rs b/src/catalog.rs
index 398c588..6f949f8 100644
--- a/src/catalog.rs
+++ b/src/catalog.rs
@@ -15,25 +15,26 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::dataset::Dataset;
-use crate::errors::{py_datafusion_err, to_datafusion_err, PyDataFusionError, PyDataFusionResult};
-use crate::table::PyTable;
-use crate::utils::{validate_pycapsule, wait_for_future};
+use std::any::Any;
+use std::collections::HashSet;
+use std::sync::Arc;
+
 use async_trait::async_trait;
-use datafusion::catalog::{MemoryCatalogProvider, MemorySchemaProvider};
-use datafusion::common::DataFusionError;
-use datafusion::{
-    catalog::{CatalogProvider, SchemaProvider},
-    datasource::TableProvider,
+use datafusion::catalog::{
+    CatalogProvider, MemoryCatalogProvider, MemorySchemaProvider, SchemaProvider,
 };
+use datafusion::common::DataFusionError;
+use datafusion::datasource::TableProvider;
 use datafusion_ffi::schema_provider::{FFI_SchemaProvider, ForeignSchemaProvider};
 use pyo3::exceptions::PyKeyError;
 use pyo3::prelude::*;
 use pyo3::types::PyCapsule;
 use pyo3::IntoPyObjectExt;
-use std::any::Any;
-use std::collections::HashSet;
-use std::sync::Arc;
+
+use crate::dataset::Dataset;
+use crate::errors::{py_datafusion_err, to_datafusion_err, PyDataFusionError, PyDataFusionResult};
+use crate::table::PyTable;
+use crate::utils::{validate_pycapsule, wait_for_future};
 
 #[pyclass(frozen, name = "RawCatalog", module = "datafusion.catalog", subclass)]
 #[derive(Clone)]
diff --git a/src/common/data_type.rs b/src/common/data_type.rs
index 3cbe313..69f686f 100644
--- a/src/common/data_type.rs
+++ b/src/common/data_type.rs
@@ -19,8 +19,8 @@
 use datafusion::arrow::datatypes::{DataType, IntervalUnit, TimeUnit};
 use datafusion::common::ScalarValue;
 use datafusion::logical_expr::sqlparser::ast::NullTreatment as DFNullTreatment;
-use pyo3::exceptions::PyNotImplementedError;
-use pyo3::{exceptions::PyValueError, prelude::*};
+use pyo3::exceptions::{PyNotImplementedError, PyValueError};
+use pyo3::prelude::*;
 
 #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd)]
 pub struct PyScalarValue(pub ScalarValue);
diff --git a/src/common/schema.rs b/src/common/schema.rs
index 14ab630..4e46592 100644
--- a/src/common/schema.rs
+++ b/src/common/schema.rs
@@ -15,26 +15,25 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::any::Any;
+use std::borrow::Cow;
 use std::fmt::{self, Display, Formatter};
 use std::sync::Arc;
-use std::{any::Any, borrow::Cow};
 
 use arrow::datatypes::Schema;
 use arrow::pyarrow::PyArrowType;
 use datafusion::arrow::datatypes::SchemaRef;
 use datafusion::common::Constraints;
 use datafusion::datasource::TableType;
+use datafusion::logical_expr::utils::split_conjunction;
 use datafusion::logical_expr::{Expr, TableProviderFilterPushDown, TableSource};
+use parking_lot::RwLock;
 use pyo3::prelude::*;
 
-use datafusion::logical_expr::utils::split_conjunction;
-
+use super::data_type::DataTypeMap;
+use super::function::SqlFunction;
 use crate::sql::logical::PyLogicalPlan;
 
-use super::{data_type::DataTypeMap, function::SqlFunction};
-
-use parking_lot::RwLock;
-
 #[pyclass(name = "SqlSchema", module = "datafusion.common", subclass, frozen)]
 #[derive(Debug, Clone)]
 pub struct SqlSchema {
diff --git a/src/config.rs b/src/config.rs
index 1726e5d..a25a407 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -17,14 +17,13 @@
 
 use std::sync::Arc;
 
+use datafusion::config::ConfigOptions;
+use parking_lot::RwLock;
 use pyo3::prelude::*;
 use pyo3::types::*;
 
-use datafusion::config::ConfigOptions;
-
 use crate::errors::PyDataFusionResult;
 use crate::utils::py_obj_to_scalar_value;
-use parking_lot::RwLock;
 #[pyclass(name = "Config", module = "datafusion", subclass, frozen)]
 #[derive(Clone)]
 pub(crate) struct PyConfig {
diff --git a/src/context.rs b/src/context.rs
index e8d8758..f64cc16 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -23,13 +23,36 @@
 use arrow::array::RecordBatchReader;
 use arrow::ffi_stream::ArrowArrayStreamReader;
 use arrow::pyarrow::FromPyArrow;
+use datafusion::arrow::datatypes::{DataType, Schema, SchemaRef};
+use datafusion::arrow::pyarrow::PyArrowType;
+use datafusion::arrow::record_batch::RecordBatch;
+use datafusion::catalog::CatalogProvider;
+use datafusion::common::{exec_err, ScalarValue, TableReference};
+use datafusion::datasource::file_format::file_compression_type::FileCompressionType;
+use datafusion::datasource::file_format::parquet::ParquetFormat;
+use datafusion::datasource::listing::{
+    ListingOptions, ListingTable, ListingTableConfig, ListingTableUrl,
+};
+use datafusion::datasource::{MemTable, TableProvider};
+use datafusion::execution::context::{
+    DataFilePaths, SQLOptions, SessionConfig, SessionContext, TaskContext,
+};
+use datafusion::execution::disk_manager::DiskManagerMode;
+use datafusion::execution::memory_pool::{FairSpillPool, GreedyMemoryPool, UnboundedMemoryPool};
+use datafusion::execution::options::ReadOptions;
+use datafusion::execution::runtime_env::RuntimeEnvBuilder;
 use datafusion::execution::session_state::SessionStateBuilder;
+use datafusion::prelude::{
+    AvroReadOptions, CsvReadOptions, DataFrame, NdJsonReadOptions, ParquetReadOptions,
+};
+use datafusion_ffi::catalog_provider::{FFI_CatalogProvider, ForeignCatalogProvider};
 use object_store::ObjectStore;
-use url::Url;
-use uuid::Uuid;
-
 use pyo3::exceptions::{PyKeyError, PyValueError};
 use pyo3::prelude::*;
+use pyo3::types::{PyCapsule, PyDict, PyList, PyTuple, PyType};
+use pyo3::IntoPyObjectExt;
+use url::Url;
+use uuid::Uuid;
 
 use crate::catalog::{PyCatalog, RustWrappedPyCatalogProvider};
 use crate::dataframe::PyDataFrame;
@@ -47,32 +70,6 @@
 use crate::udtf::PyTableFunction;
 use crate::udwf::PyWindowUDF;
 use crate::utils::{get_global_ctx, spawn_future, validate_pycapsule, wait_for_future};
-use datafusion::arrow::datatypes::{DataType, Schema, SchemaRef};
-use datafusion::arrow::pyarrow::PyArrowType;
-use datafusion::arrow::record_batch::RecordBatch;
-use datafusion::catalog::CatalogProvider;
-use datafusion::common::TableReference;
-use datafusion::common::{exec_err, ScalarValue};
-use datafusion::datasource::file_format::file_compression_type::FileCompressionType;
-use datafusion::datasource::file_format::parquet::ParquetFormat;
-use datafusion::datasource::listing::{
-    ListingOptions, ListingTable, ListingTableConfig, ListingTableUrl,
-};
-use datafusion::datasource::MemTable;
-use datafusion::datasource::TableProvider;
-use datafusion::execution::context::{
-    DataFilePaths, SQLOptions, SessionConfig, SessionContext, TaskContext,
-};
-use datafusion::execution::disk_manager::DiskManagerMode;
-use datafusion::execution::memory_pool::{FairSpillPool, GreedyMemoryPool, UnboundedMemoryPool};
-use datafusion::execution::options::ReadOptions;
-use datafusion::execution::runtime_env::RuntimeEnvBuilder;
-use datafusion::prelude::{
-    AvroReadOptions, CsvReadOptions, DataFrame, NdJsonReadOptions, ParquetReadOptions,
-};
-use datafusion_ffi::catalog_provider::{FFI_CatalogProvider, ForeignCatalogProvider};
-use pyo3::types::{PyCapsule, PyDict, PyList, PyTuple, PyType};
-use pyo3::IntoPyObjectExt;
 
 /// Configuration options for a SessionContext
 #[pyclass(frozen, name = "SessionConfig", module = "datafusion", subclass)]
diff --git a/src/dataframe.rs b/src/dataframe.rs
index 9071d58..21eb6e0 100644
--- a/src/dataframe.rs
+++ b/src/dataframe.rs
@@ -15,7 +15,6 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use cstr::cstr;
 use std::collections::HashMap;
 use std::ffi::{CStr, CString};
 use std::sync::Arc;
@@ -26,6 +25,7 @@
 use arrow::ffi::FFI_ArrowSchema;
 use arrow::ffi_stream::FFI_ArrowArrayStream;
 use arrow::pyarrow::FromPyArrow;
+use cstr::cstr;
 use datafusion::arrow::datatypes::{Schema, SchemaRef};
 use datafusion::arrow::pyarrow::{PyArrowType, ToPyArrow};
 use datafusion::arrow::util::pretty;
@@ -40,14 +40,16 @@
 use datafusion::parquet::basic::{BrotliLevel, Compression, GzipLevel, ZstdLevel};
 use datafusion::prelude::*;
 use futures::{StreamExt, TryStreamExt};
+use parking_lot::Mutex;
 use pyo3::exceptions::PyValueError;
 use pyo3::prelude::*;
 use pyo3::pybacked::PyBackedStr;
 use pyo3::types::{PyCapsule, PyList, PyTuple, PyTupleMethods};
 use pyo3::PyErr;
 
-use crate::errors::{py_datafusion_err, PyDataFusionError};
-use crate::expr::sort_expr::to_sort_expressions;
+use crate::errors::{py_datafusion_err, PyDataFusionError, PyDataFusionResult};
+use crate::expr::sort_expr::{to_sort_expressions, PySortExpr};
+use crate::expr::PyExpr;
 use crate::physical_plan::PyExecutionPlan;
 use crate::record_batch::{poll_next_batch, PyRecordBatchStream};
 use crate::sql::logical::PyLogicalPlan;
@@ -55,12 +57,6 @@
 use crate::utils::{
     is_ipython_env, py_obj_to_scalar_value, spawn_future, validate_pycapsule, wait_for_future,
 };
-use crate::{
-    errors::PyDataFusionResult,
-    expr::{sort_expr::PySortExpr, PyExpr},
-};
-
-use parking_lot::Mutex;
 
 /// File-level static CStr for the Arrow array stream capsule name.
 static ARROW_ARRAY_STREAM_NAME: &CStr = cstr!("arrow_array_stream");
diff --git a/src/dataset.rs b/src/dataset.rs
index 0baf4da..6abe8ae 100644
--- a/src/dataset.rs
+++ b/src/dataset.rs
@@ -15,26 +15,23 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::any::Any;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use datafusion::arrow::datatypes::SchemaRef;
+use datafusion::arrow::pyarrow::PyArrowType;
 use datafusion::catalog::Session;
+use datafusion::datasource::{TableProvider, TableType};
+use datafusion::error::{DataFusionError, Result as DFResult};
+use datafusion::logical_expr::{Expr, TableProviderFilterPushDown};
+use datafusion::physical_plan::ExecutionPlan;
 use pyo3::exceptions::PyValueError;
 /// Implements a Datafusion TableProvider that delegates to a PyArrow Dataset
 /// This allows us to use PyArrow Datasets as Datafusion tables while pushing down projections and filters
 use pyo3::prelude::*;
 use pyo3::types::PyType;
 
-use std::any::Any;
-use std::sync::Arc;
-
-use async_trait::async_trait;
-
-use datafusion::arrow::datatypes::SchemaRef;
-use datafusion::arrow::pyarrow::PyArrowType;
-use datafusion::datasource::{TableProvider, TableType};
-use datafusion::error::{DataFusionError, Result as DFResult};
-use datafusion::logical_expr::Expr;
-use datafusion::logical_expr::TableProviderFilterPushDown;
-use datafusion::physical_plan::ExecutionPlan;
-
 use crate::dataset_exec::DatasetExec;
 use crate::pyarrow_filter_expression::PyArrowFilterExpression;
 
diff --git a/src/dataset_exec.rs b/src/dataset_exec.rs
index aab8d75..a359513 100644
--- a/src/dataset_exec.rs
+++ b/src/dataset_exec.rs
@@ -15,20 +15,11 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use datafusion::physical_plan::execution_plan::{Boundedness, EmissionType};
-/// Implements a Datafusion physical ExecutionPlan that delegates to a PyArrow Dataset
-/// This actually performs the projection, filtering and scanning of a Dataset
-use pyo3::prelude::*;
-use pyo3::types::{PyDict, PyIterator, PyList};
-
 use std::any::Any;
 use std::sync::Arc;
 
-use futures::{stream, TryStreamExt};
-
 use datafusion::arrow::datatypes::SchemaRef;
-use datafusion::arrow::error::ArrowError;
-use datafusion::arrow::error::Result as ArrowResult;
+use datafusion::arrow::error::{ArrowError, Result as ArrowResult};
 use datafusion::arrow::pyarrow::PyArrowType;
 use datafusion::arrow::record_batch::RecordBatch;
 use datafusion::error::{DataFusionError as InnerDataFusionError, Result as DFResult};
@@ -36,11 +27,17 @@
 use datafusion::logical_expr::utils::conjunction;
 use datafusion::logical_expr::Expr;
 use datafusion::physical_expr::{EquivalenceProperties, LexOrdering};
+use datafusion::physical_plan::execution_plan::{Boundedness, EmissionType};
 use datafusion::physical_plan::stream::RecordBatchStreamAdapter;
 use datafusion::physical_plan::{
     DisplayAs, DisplayFormatType, ExecutionPlan, ExecutionPlanProperties, Partitioning,
     SendableRecordBatchStream, Statistics,
 };
+use futures::{stream, TryStreamExt};
+/// Implements a Datafusion physical ExecutionPlan that delegates to a PyArrow Dataset
+/// This actually performs the projection, filtering and scanning of a Dataset
+use pyo3::prelude::*;
+use pyo3::types::{PyDict, PyIterator, PyList};
 
 use crate::errors::PyDataFusionResult;
 use crate::pyarrow_filter_expression::PyArrowFilterExpression;
diff --git a/src/errors.rs b/src/errors.rs
index d4f4f22..fc079eb 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -22,7 +22,8 @@
 use datafusion::arrow::error::ArrowError;
 use datafusion::error::DataFusionError as InnerDataFusionError;
 use prost::EncodeError;
-use pyo3::{exceptions::PyException, PyErr};
+use pyo3::exceptions::PyException;
+use pyo3::PyErr;
 
 pub type PyDataFusionResult<T> = std::result::Result<T, PyDataFusionError>;
 
diff --git a/src/expr.rs b/src/expr.rs
index c9eddaa..78bee3d 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -15,27 +15,34 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use datafusion::logical_expr::expr::{AggregateFunctionParams, FieldMetadata};
-use datafusion::logical_expr::utils::exprlist_to_fields;
-use datafusion::logical_expr::{
-    lit_with_metadata, ExprFuncBuilder, ExprFunctionExt, LogicalPlan, WindowFunctionDefinition,
-};
-use pyo3::IntoPyObjectExt;
-use pyo3::{basic::CompareOp, prelude::*};
 use std::collections::HashMap;
 use std::convert::{From, Into};
 use std::sync::Arc;
-use window::PyWindowFrame;
 
 use datafusion::arrow::datatypes::{DataType, Field};
 use datafusion::arrow::pyarrow::PyArrowType;
 use datafusion::functions::core::expr_ext::FieldAccessor;
-use datafusion::logical_expr::{
-    col,
-    expr::{AggregateFunction, InList, InSubquery, ScalarFunction, WindowFunction},
-    lit, Between, BinaryExpr, Case, Cast, Expr, Like, Operator, TryCast,
+use datafusion::logical_expr::expr::{
+    AggregateFunction, AggregateFunctionParams, FieldMetadata, InList, InSubquery, ScalarFunction,
+    WindowFunction,
 };
+use datafusion::logical_expr::utils::exprlist_to_fields;
+use datafusion::logical_expr::{
+    col, lit, lit_with_metadata, Between, BinaryExpr, Case, Cast, Expr, ExprFuncBuilder,
+    ExprFunctionExt, Like, LogicalPlan, Operator, TryCast, WindowFunctionDefinition,
+};
+use pyo3::basic::CompareOp;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
+use window::PyWindowFrame;
 
+use self::alias::PyAlias;
+use self::bool_expr::{
+    PyIsFalse, PyIsNotFalse, PyIsNotNull, PyIsNotTrue, PyIsNotUnknown, PyIsNull, PyIsTrue,
+    PyIsUnknown, PyNegative, PyNot,
+};
+use self::like::{PyILike, PyLike, PySimilarTo};
+use self::scalar_variable::PyScalarVariable;
 use crate::common::data_type::{DataTypeMap, NullTreatment, PyScalarValue, RexType};
 use crate::errors::{py_runtime_err, py_type_err, py_unsupported_variant_err, PyDataFusionResult};
 use crate::expr::aggregate_expr::PyAggregateFunction;
@@ -46,14 +53,6 @@
 use crate::pyarrow_util::scalar_to_pyarrow;
 use crate::sql::logical::PyLogicalPlan;
 
-use self::alias::PyAlias;
-use self::bool_expr::{
-    PyIsFalse, PyIsNotFalse, PyIsNotNull, PyIsNotTrue, PyIsNotUnknown, PyIsNull, PyIsTrue,
-    PyIsUnknown, PyNegative, PyNot,
-};
-use self::like::{PyILike, PyLike, PySimilarTo};
-use self::scalar_variable::PyScalarVariable;
-
 pub mod aggregate;
 pub mod aggregate_expr;
 pub mod alias;
diff --git a/src/expr/aggregate.rs b/src/expr/aggregate.rs
index 4af7c75..4cb41b2 100644
--- a/src/expr/aggregate.rs
+++ b/src/expr/aggregate.rs
@@ -15,12 +15,14 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::fmt::{self, Display, Formatter};
+
 use datafusion::common::DataFusionError;
 use datafusion::logical_expr::expr::{AggregateFunction, AggregateFunctionParams, Alias};
 use datafusion::logical_expr::logical_plan::Aggregate;
 use datafusion::logical_expr::Expr;
-use pyo3::{prelude::*, IntoPyObjectExt};
-use std::fmt::{self, Display, Formatter};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
 use crate::common::df_schema::PyDFSchema;
diff --git a/src/expr/aggregate_expr.rs b/src/expr/aggregate_expr.rs
index 72ba063..d3b695a 100644
--- a/src/expr/aggregate_expr.rs
+++ b/src/expr/aggregate_expr.rs
@@ -15,10 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::expr::PyExpr;
+use std::fmt::{Display, Formatter};
+
 use datafusion::logical_expr::expr::AggregateFunction;
 use pyo3::prelude::*;
-use std::fmt::{Display, Formatter};
+
+use crate::expr::PyExpr;
 
 #[pyclass(
     frozen,
diff --git a/src/expr/alias.rs b/src/expr/alias.rs
index 588c00f..c6d4862 100644
--- a/src/expr/alias.rs
+++ b/src/expr/alias.rs
@@ -15,11 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::expr::PyExpr;
-use pyo3::prelude::*;
 use std::fmt::{self, Display, Formatter};
 
 use datafusion::logical_expr::expr::Alias;
+use pyo3::prelude::*;
+
+use crate::expr::PyExpr;
 
 #[pyclass(frozen, name = "Alias", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/analyze.rs b/src/expr/analyze.rs
index c7caeeb..05ec8dc 100644
--- a/src/expr/analyze.rs
+++ b/src/expr/analyze.rs
@@ -15,10 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use datafusion::logical_expr::logical_plan::Analyze;
-use pyo3::{prelude::*, IntoPyObjectExt};
 use std::fmt::{self, Display, Formatter};
 
+use datafusion::logical_expr::logical_plan::Analyze;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
+
 use super::logical_node::LogicalNode;
 use crate::common::df_schema::PyDFSchema;
 use crate::sql::logical::PyLogicalPlan;
diff --git a/src/expr/between.rs b/src/expr/between.rs
index 1f61599..4f0b34a 100644
--- a/src/expr/between.rs
+++ b/src/expr/between.rs
@@ -15,10 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::expr::PyExpr;
+use std::fmt::{self, Display, Formatter};
+
 use datafusion::logical_expr::expr::Between;
 use pyo3::prelude::*;
-use std::fmt::{self, Display, Formatter};
+
+use crate::expr::PyExpr;
 
 #[pyclass(frozen, name = "Between", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/binary_expr.rs b/src/expr/binary_expr.rs
index 9437958..f67a08c 100644
--- a/src/expr/binary_expr.rs
+++ b/src/expr/binary_expr.rs
@@ -15,10 +15,11 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::expr::PyExpr;
 use datafusion::logical_expr::BinaryExpr;
 use pyo3::prelude::*;
 
+use crate::expr::PyExpr;
+
 #[pyclass(frozen, name = "BinaryExpr", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
 pub struct PyBinaryExpr {
diff --git a/src/expr/bool_expr.rs b/src/expr/bool_expr.rs
index 0d2b051..abd2594 100644
--- a/src/expr/bool_expr.rs
+++ b/src/expr/bool_expr.rs
@@ -15,9 +15,10 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::fmt::{self, Display, Formatter};
+
 use datafusion::logical_expr::Expr;
 use pyo3::prelude::*;
-use std::fmt::{self, Display, Formatter};
 
 use super::PyExpr;
 
diff --git a/src/expr/case.rs b/src/expr/case.rs
index 1a73698..b49c190 100644
--- a/src/expr/case.rs
+++ b/src/expr/case.rs
@@ -15,10 +15,11 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::expr::PyExpr;
 use datafusion::logical_expr::Case;
 use pyo3::prelude::*;
 
+use crate::expr::PyExpr;
+
 #[pyclass(frozen, name = "Case", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
 pub struct PyCase {
diff --git a/src/expr/cast.rs b/src/expr/cast.rs
index 03e2b84..1aca9ea 100644
--- a/src/expr/cast.rs
+++ b/src/expr/cast.rs
@@ -15,10 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::{common::data_type::PyDataType, expr::PyExpr};
 use datafusion::logical_expr::{Cast, TryCast};
 use pyo3::prelude::*;
 
+use crate::common::data_type::PyDataType;
+use crate::expr::PyExpr;
+
 #[pyclass(frozen, name = "Cast", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
 pub struct PyCast {
diff --git a/src/expr/conditional_expr.rs b/src/expr/conditional_expr.rs
index 21f538b..da6102d 100644
--- a/src/expr/conditional_expr.rs
+++ b/src/expr/conditional_expr.rs
@@ -15,11 +15,13 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::{errors::PyDataFusionResult, expr::PyExpr};
 use datafusion::logical_expr::conditional_expressions::CaseBuilder;
 use datafusion::prelude::Expr;
 use pyo3::prelude::*;
 
+use crate::errors::PyDataFusionResult;
+use crate::expr::PyExpr;
+
 // TODO(tsaucer) replace this all with CaseBuilder after it implements Clone
 #[derive(Clone, Debug)]
 #[pyclass(name = "CaseBuilder", module = "datafusion.expr", subclass, frozen)]
diff --git a/src/expr/copy_to.rs b/src/expr/copy_to.rs
index 422ab77..0b874e3 100644
--- a/src/expr/copy_to.rs
+++ b/src/expr/copy_to.rs
@@ -15,18 +15,17 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::{
-    collections::HashMap,
-    fmt::{self, Display, Formatter},
-    sync::Arc,
-};
+use std::collections::HashMap;
+use std::fmt::{self, Display, Formatter};
+use std::sync::Arc;
 
-use datafusion::{common::file_options::file_type::FileType, logical_expr::dml::CopyTo};
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::sql::logical::PyLogicalPlan;
+use datafusion::common::file_options::file_type::FileType;
+use datafusion::logical_expr::dml::CopyTo;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "CopyTo", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/create_catalog.rs b/src/expr/create_catalog.rs
index 3613878..400246a 100644
--- a/src/expr/create_catalog.rs
+++ b/src/expr/create_catalog.rs
@@ -15,17 +15,16 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::{
-    fmt::{self, Display, Formatter},
-    sync::Arc,
-};
+use std::fmt::{self, Display, Formatter};
+use std::sync::Arc;
 
 use datafusion::logical_expr::CreateCatalog;
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::{common::df_schema::PyDFSchema, sql::logical::PyLogicalPlan};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::common::df_schema::PyDFSchema;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "CreateCatalog", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/create_catalog_schema.rs b/src/expr/create_catalog_schema.rs
index cb3be2d..641e211 100644
--- a/src/expr/create_catalog_schema.rs
+++ b/src/expr/create_catalog_schema.rs
@@ -15,17 +15,16 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::{
-    fmt::{self, Display, Formatter},
-    sync::Arc,
-};
+use std::fmt::{self, Display, Formatter};
+use std::sync::Arc;
 
 use datafusion::logical_expr::CreateCatalogSchema;
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::{common::df_schema::PyDFSchema, sql::logical::PyLogicalPlan};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::common::df_schema::PyDFSchema;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(
     frozen,
diff --git a/src/expr/create_external_table.rs b/src/expr/create_external_table.rs
index 920d0d6..1bd37b3 100644
--- a/src/expr/create_external_table.rs
+++ b/src/expr/create_external_table.rs
@@ -15,19 +15,20 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::{common::schema::PyConstraints, expr::PyExpr, sql::logical::PyLogicalPlan};
-use std::{
-    collections::HashMap,
-    fmt::{self, Display, Formatter},
-    sync::Arc,
-};
+use std::collections::HashMap;
+use std::fmt::{self, Display, Formatter};
+use std::sync::Arc;
 
 use datafusion::logical_expr::CreateExternalTable;
-use pyo3::{prelude::*, IntoPyObjectExt};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
+use super::logical_node::LogicalNode;
+use super::sort_expr::PySortExpr;
 use crate::common::df_schema::PyDFSchema;
-
-use super::{logical_node::LogicalNode, sort_expr::PySortExpr};
+use crate::common::schema::PyConstraints;
+use crate::expr::PyExpr;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(
     frozen,
diff --git a/src/expr/create_function.rs b/src/expr/create_function.rs
index 1b663b4..2a35635 100644
--- a/src/expr/create_function.rs
+++ b/src/expr/create_function.rs
@@ -15,19 +15,19 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::{
-    fmt::{self, Display, Formatter},
-    sync::Arc,
-};
+use std::fmt::{self, Display, Formatter};
+use std::sync::Arc;
 
 use datafusion::logical_expr::{
     CreateFunction, CreateFunctionBody, OperateFunctionArg, Volatility,
 };
-use pyo3::{prelude::*, IntoPyObjectExt};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
 use super::PyExpr;
-use crate::common::{data_type::PyDataType, df_schema::PyDFSchema};
+use crate::common::data_type::PyDataType;
+use crate::common::df_schema::PyDFSchema;
 use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "CreateFunction", module = "datafusion.expr", subclass)]
diff --git a/src/expr/create_index.rs b/src/expr/create_index.rs
index 7b68df3..5c37833 100644
--- a/src/expr/create_index.rs
+++ b/src/expr/create_index.rs
@@ -15,17 +15,17 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::{
-    fmt::{self, Display, Formatter},
-    sync::Arc,
-};
+use std::fmt::{self, Display, Formatter};
+use std::sync::Arc;
 
 use datafusion::logical_expr::CreateIndex;
-use pyo3::{prelude::*, IntoPyObjectExt};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
-use crate::{common::df_schema::PyDFSchema, sql::logical::PyLogicalPlan};
-
-use super::{logical_node::LogicalNode, sort_expr::PySortExpr};
+use super::logical_node::LogicalNode;
+use super::sort_expr::PySortExpr;
+use crate::common::df_schema::PyDFSchema;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "CreateIndex", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/create_memory_table.rs b/src/expr/create_memory_table.rs
index 15aaa81..7759eb4 100644
--- a/src/expr/create_memory_table.rs
+++ b/src/expr/create_memory_table.rs
@@ -18,11 +18,11 @@
 use std::fmt::{self, Display, Formatter};
 
 use datafusion::logical_expr::CreateMemoryTable;
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::sql::logical::PyLogicalPlan;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(
     frozen,
diff --git a/src/expr/create_view.rs b/src/expr/create_view.rs
index 49b3b61..16faaf9 100644
--- a/src/expr/create_view.rs
+++ b/src/expr/create_view.rs
@@ -18,11 +18,12 @@
 use std::fmt::{self, Display, Formatter};
 
 use datafusion::logical_expr::{CreateView, DdlStatement, LogicalPlan};
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::{errors::py_type_err, sql::logical::PyLogicalPlan};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::errors::py_type_err;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "CreateView", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/describe_table.rs b/src/expr/describe_table.rs
index 315026f..9b139ed 100644
--- a/src/expr/describe_table.rs
+++ b/src/expr/describe_table.rs
@@ -15,18 +15,18 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::{
-    fmt::{self, Display, Formatter},
-    sync::Arc,
-};
+use std::fmt::{self, Display, Formatter};
+use std::sync::Arc;
 
-use arrow::{datatypes::Schema, pyarrow::PyArrowType};
+use arrow::datatypes::Schema;
+use arrow::pyarrow::PyArrowType;
 use datafusion::logical_expr::DescribeTable;
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::{common::df_schema::PyDFSchema, sql::logical::PyLogicalPlan};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::common::df_schema::PyDFSchema;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "DescribeTable", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/distinct.rs b/src/expr/distinct.rs
index 5770b84..1505ec3 100644
--- a/src/expr/distinct.rs
+++ b/src/expr/distinct.rs
@@ -18,11 +18,11 @@
 use std::fmt::{self, Display, Formatter};
 
 use datafusion::logical_expr::Distinct;
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::sql::logical::PyLogicalPlan;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "Distinct", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/dml.rs b/src/expr/dml.rs
index 4437a9d..091dcbc 100644
--- a/src/expr/dml.rs
+++ b/src/expr/dml.rs
@@ -17,12 +17,13 @@
 
 use datafusion::logical_expr::dml::InsertOp;
 use datafusion::logical_expr::{DmlStatement, WriteOp};
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::common::schema::PyTableSource;
-use crate::{common::df_schema::PyDFSchema, sql::logical::PyLogicalPlan};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::common::df_schema::PyDFSchema;
+use crate::common::schema::PyTableSource;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "DmlStatement", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/drop_catalog_schema.rs b/src/expr/drop_catalog_schema.rs
index 7008bcd..db6041a 100644
--- a/src/expr/drop_catalog_schema.rs
+++ b/src/expr/drop_catalog_schema.rs
@@ -15,17 +15,18 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::{
-    fmt::{self, Display, Formatter},
-    sync::Arc,
-};
+use std::fmt::{self, Display, Formatter};
+use std::sync::Arc;
 
-use datafusion::{common::SchemaReference, logical_expr::DropCatalogSchema, sql::TableReference};
-use pyo3::{exceptions::PyValueError, prelude::*, IntoPyObjectExt};
-
-use crate::common::df_schema::PyDFSchema;
+use datafusion::common::SchemaReference;
+use datafusion::logical_expr::DropCatalogSchema;
+use datafusion::sql::TableReference;
+use pyo3::exceptions::PyValueError;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::common::df_schema::PyDFSchema;
 use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(
diff --git a/src/expr/drop_function.rs b/src/expr/drop_function.rs
index 42ad3e1..070d157 100644
--- a/src/expr/drop_function.rs
+++ b/src/expr/drop_function.rs
@@ -15,13 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::{
-    fmt::{self, Display, Formatter},
-    sync::Arc,
-};
+use std::fmt::{self, Display, Formatter};
+use std::sync::Arc;
 
 use datafusion::logical_expr::DropFunction;
-use pyo3::{prelude::*, IntoPyObjectExt};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
 use crate::common::df_schema::PyDFSchema;
diff --git a/src/expr/drop_table.rs b/src/expr/drop_table.rs
index 6ff4f01..ffb56e4 100644
--- a/src/expr/drop_table.rs
+++ b/src/expr/drop_table.rs
@@ -18,11 +18,11 @@
 use std::fmt::{self, Display, Formatter};
 
 use datafusion::logical_expr::logical_plan::DropTable;
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::sql::logical::PyLogicalPlan;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "DropTable", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/drop_view.rs b/src/expr/drop_view.rs
index b2aff4e..9d72f20 100644
--- a/src/expr/drop_view.rs
+++ b/src/expr/drop_view.rs
@@ -15,17 +15,15 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::{
-    fmt::{self, Display, Formatter},
-    sync::Arc,
-};
+use std::fmt::{self, Display, Formatter};
+use std::sync::Arc;
 
 use datafusion::logical_expr::DropView;
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::common::df_schema::PyDFSchema;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::common::df_schema::PyDFSchema;
 use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "DropView", module = "datafusion.expr", subclass)]
diff --git a/src/expr/empty_relation.rs b/src/expr/empty_relation.rs
index 797a8c0..35c3fa7 100644
--- a/src/expr/empty_relation.rs
+++ b/src/expr/empty_relation.rs
@@ -15,12 +15,15 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::{common::df_schema::PyDFSchema, sql::logical::PyLogicalPlan};
-use datafusion::logical_expr::EmptyRelation;
-use pyo3::{prelude::*, IntoPyObjectExt};
 use std::fmt::{self, Display, Formatter};
 
+use datafusion::logical_expr::EmptyRelation;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
+
 use super::logical_node::LogicalNode;
+use crate::common::df_schema::PyDFSchema;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "EmptyRelation", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/explain.rs b/src/expr/explain.rs
index 71b7b2c..c6884e9 100644
--- a/src/expr/explain.rs
+++ b/src/expr/explain.rs
@@ -17,12 +17,15 @@
 
 use std::fmt::{self, Display, Formatter};
 
-use datafusion::logical_expr::{logical_plan::Explain, LogicalPlan};
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::{common::df_schema::PyDFSchema, errors::py_type_err, sql::logical::PyLogicalPlan};
+use datafusion::logical_expr::logical_plan::Explain;
+use datafusion::logical_expr::LogicalPlan;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::common::df_schema::PyDFSchema;
+use crate::errors::py_type_err;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "Explain", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/extension.rs b/src/expr/extension.rs
index 7d913ff..b4c688b 100644
--- a/src/expr/extension.rs
+++ b/src/expr/extension.rs
@@ -16,11 +16,11 @@
 // under the License.
 
 use datafusion::logical_expr::Extension;
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::sql::logical::PyLogicalPlan;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "Extension", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/filter.rs b/src/expr/filter.rs
index 76338d1..25a1e76 100644
--- a/src/expr/filter.rs
+++ b/src/expr/filter.rs
@@ -15,10 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use datafusion::logical_expr::logical_plan::Filter;
-use pyo3::{prelude::*, IntoPyObjectExt};
 use std::fmt::{self, Display, Formatter};
 
+use datafusion::logical_expr::logical_plan::Filter;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
+
 use crate::common::df_schema::PyDFSchema;
 use crate::expr::logical_node::LogicalNode;
 use crate::expr::PyExpr;
diff --git a/src/expr/in_list.rs b/src/expr/in_list.rs
index e2e6d78..128c3f4 100644
--- a/src/expr/in_list.rs
+++ b/src/expr/in_list.rs
@@ -15,10 +15,11 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::expr::PyExpr;
 use datafusion::logical_expr::expr::InList;
 use pyo3::prelude::*;
 
+use crate::expr::PyExpr;
+
 #[pyclass(frozen, name = "InList", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
 pub struct PyInList {
diff --git a/src/expr/in_subquery.rs b/src/expr/in_subquery.rs
index 6d4a38e..5cff86c 100644
--- a/src/expr/in_subquery.rs
+++ b/src/expr/in_subquery.rs
@@ -18,7 +18,8 @@
 use datafusion::logical_expr::expr::InSubquery;
 use pyo3::prelude::*;
 
-use super::{subquery::PySubquery, PyExpr};
+use super::subquery::PySubquery;
+use super::PyExpr;
 
 #[pyclass(frozen, name = "InSubquery", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/join.rs b/src/expr/join.rs
index 3fde874..82cc2a6 100644
--- a/src/expr/join.rs
+++ b/src/expr/join.rs
@@ -15,13 +15,16 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use datafusion::common::NullEquality;
-use datafusion::logical_expr::logical_plan::{Join, JoinConstraint, JoinType};
-use pyo3::{prelude::*, IntoPyObjectExt};
 use std::fmt::{self, Display, Formatter};
 
+use datafusion::common::NullEquality;
+use datafusion::logical_expr::logical_plan::{Join, JoinConstraint, JoinType};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
+
 use crate::common::df_schema::PyDFSchema;
-use crate::expr::{logical_node::LogicalNode, PyExpr};
+use crate::expr::logical_node::LogicalNode;
+use crate::expr::PyExpr;
 use crate::sql::logical::PyLogicalPlan;
 
 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
diff --git a/src/expr/like.rs b/src/expr/like.rs
index 0a36dcd..94860bd 100644
--- a/src/expr/like.rs
+++ b/src/expr/like.rs
@@ -15,9 +15,10 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::fmt::{self, Display, Formatter};
+
 use datafusion::logical_expr::expr::Like;
 use pyo3::prelude::*;
-use std::fmt::{self, Display, Formatter};
 
 use crate::expr::PyExpr;
 
diff --git a/src/expr/limit.rs b/src/expr/limit.rs
index cf6971f..9318eff 100644
--- a/src/expr/limit.rs
+++ b/src/expr/limit.rs
@@ -15,10 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use datafusion::logical_expr::logical_plan::Limit;
-use pyo3::{prelude::*, IntoPyObjectExt};
 use std::fmt::{self, Display, Formatter};
 
+use datafusion::logical_expr::logical_plan::Limit;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
+
 use crate::common::df_schema::PyDFSchema;
 use crate::expr::logical_node::LogicalNode;
 use crate::sql::logical::PyLogicalPlan;
diff --git a/src/expr/literal.rs b/src/expr/literal.rs
index 8a589b5..3e8e229 100644
--- a/src/expr/literal.rs
+++ b/src/expr/literal.rs
@@ -15,9 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use datafusion::common::ScalarValue;
+use datafusion::logical_expr::expr::FieldMetadata;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
+
 use crate::errors::PyDataFusionError;
-use datafusion::{common::ScalarValue, logical_expr::expr::FieldMetadata};
-use pyo3::{prelude::*, IntoPyObjectExt};
 
 #[pyclass(name = "Literal", module = "datafusion.expr", subclass, frozen)]
 #[derive(Clone)]
diff --git a/src/expr/projection.rs b/src/expr/projection.rs
index b2d5db7..bd21418 100644
--- a/src/expr/projection.rs
+++ b/src/expr/projection.rs
@@ -15,10 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::fmt::{self, Display, Formatter};
+
 use datafusion::logical_expr::logical_plan::Projection;
 use datafusion::logical_expr::Expr;
-use pyo3::{prelude::*, IntoPyObjectExt};
-use std::fmt::{self, Display, Formatter};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use crate::common::df_schema::PyDFSchema;
 use crate::expr::logical_node::LogicalNode;
diff --git a/src/expr/recursive_query.rs b/src/expr/recursive_query.rs
index fe04731..0e1171e 100644
--- a/src/expr/recursive_query.rs
+++ b/src/expr/recursive_query.rs
@@ -18,11 +18,11 @@
 use std::fmt::{self, Display, Formatter};
 
 use datafusion::logical_expr::RecursiveQuery;
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::sql::logical::PyLogicalPlan;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "RecursiveQuery", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/repartition.rs b/src/expr/repartition.rs
index ee6d1dc..0b3cc4b 100644
--- a/src/expr/repartition.rs
+++ b/src/expr/repartition.rs
@@ -17,12 +17,15 @@
 
 use std::fmt::{self, Display, Formatter};
 
-use datafusion::logical_expr::{logical_plan::Repartition, Expr, Partitioning};
-use pyo3::{prelude::*, IntoPyObjectExt};
+use datafusion::logical_expr::logical_plan::Repartition;
+use datafusion::logical_expr::{Expr, Partitioning};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
-use crate::{errors::py_type_err, sql::logical::PyLogicalPlan};
-
-use super::{logical_node::LogicalNode, PyExpr};
+use super::logical_node::LogicalNode;
+use super::PyExpr;
+use crate::errors::py_type_err;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "Repartition", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/sort.rs b/src/expr/sort.rs
index d5ea07f..8914c8f 100644
--- a/src/expr/sort.rs
+++ b/src/expr/sort.rs
@@ -15,10 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::fmt::{self, Display, Formatter};
+
 use datafusion::common::DataFusionError;
 use datafusion::logical_expr::logical_plan::Sort;
-use pyo3::{prelude::*, IntoPyObjectExt};
-use std::fmt::{self, Display, Formatter};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use crate::common::df_schema::PyDFSchema;
 use crate::expr::logical_node::LogicalNode;
diff --git a/src/expr/sort_expr.rs b/src/expr/sort_expr.rs
index 3f27902..23c0661 100644
--- a/src/expr/sort_expr.rs
+++ b/src/expr/sort_expr.rs
@@ -15,10 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::expr::PyExpr;
+use std::fmt::{self, Display, Formatter};
+
 use datafusion::logical_expr::SortExpr;
 use pyo3::prelude::*;
-use std::fmt::{self, Display, Formatter};
+
+use crate::expr::PyExpr;
 
 #[pyclass(frozen, name = "SortExpr", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/statement.rs b/src/expr/statement.rs
index 1ea4f9f..47f5c43 100644
--- a/src/expr/statement.rs
+++ b/src/expr/statement.rs
@@ -19,11 +19,13 @@
     Deallocate, Execute, Prepare, SetVariable, TransactionAccessMode, TransactionConclusion,
     TransactionEnd, TransactionIsolationLevel, TransactionStart,
 };
-use pyo3::{prelude::*, IntoPyObjectExt};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
-use crate::{common::data_type::PyDataType, sql::logical::PyLogicalPlan};
-
-use super::{logical_node::LogicalNode, PyExpr};
+use super::logical_node::LogicalNode;
+use super::PyExpr;
+use crate::common::data_type::PyDataType;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(
     frozen,
diff --git a/src/expr/subquery.rs b/src/expr/subquery.rs
index 785cf7d..94c2583 100644
--- a/src/expr/subquery.rs
+++ b/src/expr/subquery.rs
@@ -18,11 +18,11 @@
 use std::fmt::{self, Display, Formatter};
 
 use datafusion::logical_expr::Subquery;
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::sql::logical::PyLogicalPlan;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "Subquery", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/subquery_alias.rs b/src/expr/subquery_alias.rs
index ab1229b..9bf1c9c 100644
--- a/src/expr/subquery_alias.rs
+++ b/src/expr/subquery_alias.rs
@@ -18,11 +18,12 @@
 use std::fmt::{self, Display, Formatter};
 
 use datafusion::logical_expr::SubqueryAlias;
-use pyo3::{prelude::*, IntoPyObjectExt};
-
-use crate::{common::df_schema::PyDFSchema, sql::logical::PyLogicalPlan};
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
 
 use super::logical_node::LogicalNode;
+use crate::common::df_schema::PyDFSchema;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "SubqueryAlias", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/table_scan.rs b/src/expr/table_scan.rs
index 34a140d..bbf225f 100644
--- a/src/expr/table_scan.rs
+++ b/src/expr/table_scan.rs
@@ -15,14 +15,17 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use datafusion::common::TableReference;
-use datafusion::logical_expr::logical_plan::TableScan;
-use pyo3::{prelude::*, IntoPyObjectExt};
 use std::fmt::{self, Display, Formatter};
 
+use datafusion::common::TableReference;
+use datafusion::logical_expr::logical_plan::TableScan;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
+
+use crate::common::df_schema::PyDFSchema;
 use crate::expr::logical_node::LogicalNode;
+use crate::expr::PyExpr;
 use crate::sql::logical::PyLogicalPlan;
-use crate::{common::df_schema::PyDFSchema, expr::PyExpr};
 
 #[pyclass(frozen, name = "TableScan", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/union.rs b/src/expr/union.rs
index b7b5896..c74d170 100644
--- a/src/expr/union.rs
+++ b/src/expr/union.rs
@@ -15,10 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use datafusion::logical_expr::logical_plan::Union;
-use pyo3::{prelude::*, IntoPyObjectExt};
 use std::fmt::{self, Display, Formatter};
 
+use datafusion::logical_expr::logical_plan::Union;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
+
 use crate::common::df_schema::PyDFSchema;
 use crate::expr::logical_node::LogicalNode;
 use crate::sql::logical::PyLogicalPlan;
diff --git a/src/expr/unnest.rs b/src/expr/unnest.rs
index 7ed7919..7e68c15 100644
--- a/src/expr/unnest.rs
+++ b/src/expr/unnest.rs
@@ -15,10 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use datafusion::logical_expr::logical_plan::Unnest;
-use pyo3::{prelude::*, IntoPyObjectExt};
 use std::fmt::{self, Display, Formatter};
 
+use datafusion::logical_expr::logical_plan::Unnest;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
+
 use crate::common::df_schema::PyDFSchema;
 use crate::expr::logical_node::LogicalNode;
 use crate::sql::logical::PyLogicalPlan;
diff --git a/src/expr/unnest_expr.rs b/src/expr/unnest_expr.rs
index 2cdf46a..dc6c4cb 100644
--- a/src/expr/unnest_expr.rs
+++ b/src/expr/unnest_expr.rs
@@ -15,9 +15,10 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::fmt::{self, Display, Formatter};
+
 use datafusion::logical_expr::expr::Unnest;
 use pyo3::prelude::*;
-use std::fmt::{self, Display, Formatter};
 
 use super::PyExpr;
 
diff --git a/src/expr/values.rs b/src/expr/values.rs
index 63d94ce..7ae7350 100644
--- a/src/expr/values.rs
+++ b/src/expr/values.rs
@@ -18,12 +18,13 @@
 use std::sync::Arc;
 
 use datafusion::logical_expr::Values;
-use pyo3::{prelude::*, IntoPyObjectExt};
-use pyo3::{pyclass, PyErr, PyResult, Python};
+use pyo3::prelude::*;
+use pyo3::{pyclass, IntoPyObjectExt, PyErr, PyResult, Python};
 
-use crate::{common::df_schema::PyDFSchema, sql::logical::PyLogicalPlan};
-
-use super::{logical_node::LogicalNode, PyExpr};
+use super::logical_node::LogicalNode;
+use super::PyExpr;
+use crate::common::df_schema::PyDFSchema;
+use crate::sql::logical::PyLogicalPlan;
 
 #[pyclass(frozen, name = "Values", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/expr/window.rs b/src/expr/window.rs
index 2723007..b93e813 100644
--- a/src/expr/window.rs
+++ b/src/expr/window.rs
@@ -15,6 +15,15 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::fmt::{self, Display, Formatter};
+
+use datafusion::common::{DataFusionError, ScalarValue};
+use datafusion::logical_expr::{Expr, Window, WindowFrame, WindowFrameBound, WindowFrameUnits};
+use pyo3::exceptions::PyNotImplementedError;
+use pyo3::prelude::*;
+use pyo3::IntoPyObjectExt;
+
+use super::py_expr_list;
 use crate::common::data_type::PyScalarValue;
 use crate::common::df_schema::PyDFSchema;
 use crate::errors::{py_type_err, PyDataFusionResult};
@@ -22,13 +31,6 @@
 use crate::expr::sort_expr::{py_sort_expr_list, PySortExpr};
 use crate::expr::PyExpr;
 use crate::sql::logical::PyLogicalPlan;
-use datafusion::common::{DataFusionError, ScalarValue};
-use datafusion::logical_expr::{Expr, Window, WindowFrame, WindowFrameBound, WindowFrameUnits};
-use pyo3::exceptions::PyNotImplementedError;
-use pyo3::{prelude::*, IntoPyObjectExt};
-use std::fmt::{self, Display, Formatter};
-
-use super::py_expr_list;
 
 #[pyclass(frozen, name = "WindowExpr", module = "datafusion.expr", subclass)]
 #[derive(Clone)]
diff --git a/src/functions.rs b/src/functions.rs
index 5956b67..38f54d1 100644
--- a/src/functions.rs
+++ b/src/functions.rs
@@ -17,32 +17,24 @@
 
 use std::collections::HashMap;
 
-use datafusion::functions_aggregate::all_default_aggregate_functions;
-use datafusion::functions_window::all_default_window_functions;
-use datafusion::logical_expr::expr::FieldMetadata;
-use datafusion::logical_expr::expr::WindowFunctionParams;
-use datafusion::logical_expr::ExprFunctionExt;
-use datafusion::logical_expr::WindowFrame;
-use pyo3::{prelude::*, wrap_pyfunction};
-
-use crate::common::data_type::NullTreatment;
-use crate::common::data_type::PyScalarValue;
-use crate::context::PySessionContext;
-use crate::errors::PyDataFusionError;
-use crate::errors::PyDataFusionResult;
-use crate::expr::conditional_expr::PyCaseBuilder;
-use crate::expr::sort_expr::to_sort_expressions;
-use crate::expr::sort_expr::PySortExpr;
-use crate::expr::window::PyWindowFrame;
-use crate::expr::PyExpr;
 use datafusion::common::{Column, ScalarValue, TableReference};
 use datafusion::execution::FunctionRegistry;
-use datafusion::functions;
-use datafusion::functions_aggregate;
-use datafusion::functions_window;
-use datafusion::logical_expr::expr::Alias;
+use datafusion::functions_aggregate::all_default_aggregate_functions;
+use datafusion::functions_window::all_default_window_functions;
+use datafusion::logical_expr::expr::{Alias, FieldMetadata, WindowFunction, WindowFunctionParams};
 use datafusion::logical_expr::sqlparser::ast::NullTreatment as DFNullTreatment;
-use datafusion::logical_expr::{expr::WindowFunction, lit, Expr, WindowFunctionDefinition};
+use datafusion::logical_expr::{lit, Expr, ExprFunctionExt, WindowFrame, WindowFunctionDefinition};
+use datafusion::{functions, functions_aggregate, functions_window};
+use pyo3::prelude::*;
+use pyo3::wrap_pyfunction;
+
+use crate::common::data_type::{NullTreatment, PyScalarValue};
+use crate::context::PySessionContext;
+use crate::errors::{PyDataFusionError, PyDataFusionResult};
+use crate::expr::conditional_expr::PyCaseBuilder;
+use crate::expr::sort_expr::{to_sort_expressions, PySortExpr};
+use crate::expr::window::PyWindowFrame;
+use crate::expr::PyExpr;
 
 fn add_builder_fns_to_aggregate(
     agg_fn: Expr,
diff --git a/src/lib.rs b/src/lib.rs
index 4f816d8..9483a52 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -15,20 +15,17 @@
 // specific language governing permissions and limitations
 // under the License.
 
+// Re-export Apache Arrow DataFusion dependencies
+pub use datafusion;
+pub use datafusion::{
+    common as datafusion_common, logical_expr as datafusion_expr, optimizer, sql as datafusion_sql,
+};
+#[cfg(feature = "substrait")]
+pub use datafusion_substrait;
 #[cfg(feature = "mimalloc")]
 use mimalloc::MiMalloc;
 use pyo3::prelude::*;
 
-// Re-export Apache Arrow DataFusion dependencies
-pub use datafusion;
-pub use datafusion::common as datafusion_common;
-pub use datafusion::logical_expr as datafusion_expr;
-pub use datafusion::optimizer;
-pub use datafusion::sql as datafusion_sql;
-
-#[cfg(feature = "substrait")]
-pub use datafusion_substrait;
-
 #[allow(clippy::borrow_deref_ref)]
 pub mod catalog;
 pub mod common;
diff --git a/src/physical_plan.rs b/src/physical_plan.rs
index 4994b01..62ec5e8 100644
--- a/src/physical_plan.rs
+++ b/src/physical_plan.rs
@@ -15,14 +15,17 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::sync::Arc;
+
 use datafusion::physical_plan::{displayable, ExecutionPlan, ExecutionPlanProperties};
 use datafusion_proto::physical_plan::{AsExecutionPlan, DefaultPhysicalExtensionCodec};
 use prost::Message;
-use std::sync::Arc;
+use pyo3::exceptions::PyRuntimeError;
+use pyo3::prelude::*;
+use pyo3::types::PyBytes;
 
-use pyo3::{exceptions::PyRuntimeError, prelude::*, types::PyBytes};
-
-use crate::{context::PySessionContext, errors::PyDataFusionResult};
+use crate::context::PySessionContext;
+use crate::errors::PyDataFusionResult;
 
 #[pyclass(frozen, name = "ExecutionPlan", module = "datafusion", subclass)]
 #[derive(Debug, Clone)]
diff --git a/src/pyarrow_filter_expression.rs b/src/pyarrow_filter_expression.rs
index 7fbb1dc..db61469 100644
--- a/src/pyarrow_filter_expression.rs
+++ b/src/pyarrow_filter_expression.rs
@@ -15,14 +15,14 @@
 // specific language governing permissions and limitations
 // under the License.
 
-/// Converts a Datafusion logical plan expression (Expr) into a PyArrow compute expression
-use pyo3::{prelude::*, IntoPyObjectExt};
-
 use std::convert::TryFrom;
 use std::result::Result;
 
 use datafusion::common::{Column, ScalarValue};
-use datafusion::logical_expr::{expr::InList, Between, BinaryExpr, Expr, Operator};
+use datafusion::logical_expr::expr::InList;
+use datafusion::logical_expr::{Between, BinaryExpr, Expr, Operator};
+/// Converts a Datafusion logical plan expression (Expr) into a PyArrow compute expression
+use pyo3::{prelude::*, IntoPyObjectExt};
 
 use crate::errors::{PyDataFusionError, PyDataFusionResult};
 use crate::pyarrow_util::scalar_to_pyarrow;
diff --git a/src/record_batch.rs b/src/record_batch.rs
index 00d023b..8c1933a 100644
--- a/src/record_batch.rs
+++ b/src/record_batch.rs
@@ -17,8 +17,6 @@
 
 use std::sync::Arc;
 
-use crate::errors::PyDataFusionError;
-use crate::utils::wait_for_future;
 use datafusion::arrow::pyarrow::ToPyArrow;
 use datafusion::arrow::record_batch::RecordBatch;
 use datafusion::physical_plan::SendableRecordBatchStream;
@@ -28,6 +26,9 @@
 use pyo3::{pyclass, pymethods, PyObject, PyResult, Python};
 use tokio::sync::Mutex;
 
+use crate::errors::PyDataFusionError;
+use crate::utils::wait_for_future;
+
 #[pyclass(name = "RecordBatch", module = "datafusion", subclass, frozen)]
 pub struct PyRecordBatch {
     batch: RecordBatch,
diff --git a/src/sql/logical.rs b/src/sql/logical.rs
index 47ea39f..86373fc 100644
--- a/src/sql/logical.rs
+++ b/src/sql/logical.rs
@@ -17,6 +17,13 @@
 
 use std::sync::Arc;
 
+use datafusion::logical_expr::{DdlStatement, LogicalPlan, Statement};
+use datafusion_proto::logical_plan::{AsLogicalPlan, DefaultLogicalExtensionCodec};
+use prost::Message;
+use pyo3::exceptions::PyRuntimeError;
+use pyo3::prelude::*;
+use pyo3::types::PyBytes;
+
 use crate::context::PySessionContext;
 use crate::errors::PyDataFusionResult;
 use crate::expr::aggregate::PyAggregate;
@@ -42,6 +49,7 @@
 use crate::expr::filter::PyFilter;
 use crate::expr::join::PyJoin;
 use crate::expr::limit::PyLimit;
+use crate::expr::logical_node::LogicalNode;
 use crate::expr::projection::PyProjection;
 use crate::expr::recursive_query::PyRecursiveQuery;
 use crate::expr::repartition::PyRepartition;
@@ -56,12 +64,6 @@
 use crate::expr::unnest::PyUnnest;
 use crate::expr::values::PyValues;
 use crate::expr::window::PyWindowExpr;
-use datafusion::logical_expr::{DdlStatement, LogicalPlan, Statement};
-use datafusion_proto::logical_plan::{AsLogicalPlan, DefaultLogicalExtensionCodec};
-use prost::Message;
-use pyo3::{exceptions::PyRuntimeError, prelude::*, types::PyBytes};
-
-use crate::expr::logical_node::LogicalNode;
 
 #[pyclass(frozen, name = "LogicalPlan", module = "datafusion", subclass)]
 #[derive(Debug, Clone)]
diff --git a/src/store.rs b/src/store.rs
index 08702e9..dcbcbd3 100644
--- a/src/store.rs
+++ b/src/store.rs
@@ -17,14 +17,13 @@
 
 use std::sync::Arc;
 
-use pyo3::prelude::*;
-
 use object_store::aws::{AmazonS3, AmazonS3Builder};
 use object_store::azure::{MicrosoftAzure, MicrosoftAzureBuilder};
 use object_store::gcp::{GoogleCloudStorage, GoogleCloudStorageBuilder};
 use object_store::http::{HttpBuilder, HttpStore};
 use object_store::local::LocalFileSystem;
 use pyo3::exceptions::PyValueError;
+use pyo3::prelude::*;
 use url::Url;
 
 #[derive(FromPyObject)]
diff --git a/src/substrait.rs b/src/substrait.rs
index 291892c..0e0305c 100644
--- a/src/substrait.rs
+++ b/src/substrait.rs
@@ -15,18 +15,18 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use pyo3::{prelude::*, types::PyBytes};
+use datafusion_substrait::logical_plan::{consumer, producer};
+use datafusion_substrait::serializer;
+use datafusion_substrait::substrait::proto::Plan;
+use prost::Message;
+use pyo3::prelude::*;
+use pyo3::types::PyBytes;
 
 use crate::context::PySessionContext;
 use crate::errors::{py_datafusion_err, PyDataFusionError, PyDataFusionResult};
 use crate::sql::logical::PyLogicalPlan;
 use crate::utils::wait_for_future;
 
-use datafusion_substrait::logical_plan::{consumer, producer};
-use datafusion_substrait::serializer;
-use datafusion_substrait::substrait::proto::Plan;
-use prost::Message;
-
 #[pyclass(frozen, name = "Plan", module = "datafusion.substrait", subclass)]
 #[derive(Debug, Clone)]
 pub struct PyPlan {
diff --git a/src/table.rs b/src/table.rs
index fdca4d3..1e85421 100644
--- a/src/table.rs
+++ b/src/table.rs
@@ -15,9 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::dataframe::PyDataFrame;
-use crate::dataset::Dataset;
-use crate::utils::table_provider_from_pycapsule;
+use std::any::Any;
+use std::sync::Arc;
+
 use arrow::datatypes::SchemaRef;
 use arrow::pyarrow::ToPyArrow;
 use async_trait::async_trait;
@@ -28,8 +28,10 @@
 use datafusion::physical_plan::ExecutionPlan;
 use datafusion::prelude::DataFrame;
 use pyo3::prelude::*;
-use std::any::Any;
-use std::sync::Arc;
+
+use crate::dataframe::PyDataFrame;
+use crate::dataset::Dataset;
+use crate::utils::table_provider_from_pycapsule;
 
 /// This struct is used as a common method for all TableProviders,
 /// whether they refer to an FFI provider, an internally known
diff --git a/src/udaf.rs b/src/udaf.rs
index e48e35f..b3d4975 100644
--- a/src/udaf.rs
+++ b/src/udaf.rs
@@ -17,12 +17,6 @@
 
 use std::sync::Arc;
 
-use pyo3::{prelude::*, types::PyTuple};
-
-use crate::common::data_type::PyScalarValue;
-use crate::errors::{py_datafusion_err, to_datafusion_err, PyDataFusionResult};
-use crate::expr::PyExpr;
-use crate::utils::{parse_volatility, validate_pycapsule};
 use datafusion::arrow::array::{Array, ArrayRef};
 use datafusion::arrow::datatypes::DataType;
 use datafusion::arrow::pyarrow::{PyArrowType, ToPyArrow};
@@ -32,7 +26,13 @@
     create_udaf, Accumulator, AccumulatorFactoryFunction, AggregateUDF,
 };
 use datafusion_ffi::udaf::{FFI_AggregateUDF, ForeignAggregateUDF};
-use pyo3::types::PyCapsule;
+use pyo3::prelude::*;
+use pyo3::types::{PyCapsule, PyTuple};
+
+use crate::common::data_type::PyScalarValue;
+use crate::errors::{py_datafusion_err, to_datafusion_err, PyDataFusionResult};
+use crate::expr::PyExpr;
+use crate::utils::{parse_volatility, validate_pycapsule};
 
 #[derive(Debug)]
 struct RustAccumulator {
diff --git a/src/udf.rs b/src/udf.rs
index a9249d6..25043d2 100644
--- a/src/udf.rs
+++ b/src/udf.rs
@@ -17,21 +17,17 @@
 
 use std::sync::Arc;
 
-use datafusion_ffi::udf::{FFI_ScalarUDF, ForeignScalarUDF};
-use pyo3::types::PyCapsule;
-use pyo3::{prelude::*, types::PyTuple};
-
 use datafusion::arrow::array::{make_array, Array, ArrayData, ArrayRef};
 use datafusion::arrow::datatypes::DataType;
-use datafusion::arrow::pyarrow::FromPyArrow;
-use datafusion::arrow::pyarrow::{PyArrowType, ToPyArrow};
+use datafusion::arrow::pyarrow::{FromPyArrow, PyArrowType, ToPyArrow};
 use datafusion::error::DataFusionError;
 use datafusion::logical_expr::function::ScalarFunctionImplementation;
-use datafusion::logical_expr::ScalarUDF;
-use datafusion::logical_expr::{create_udf, ColumnarValue};
+use datafusion::logical_expr::{create_udf, ColumnarValue, ScalarUDF};
+use datafusion_ffi::udf::{FFI_ScalarUDF, ForeignScalarUDF};
+use pyo3::prelude::*;
+use pyo3::types::{PyCapsule, PyTuple};
 
-use crate::errors::to_datafusion_err;
-use crate::errors::{py_datafusion_err, PyDataFusionResult};
+use crate::errors::{py_datafusion_err, to_datafusion_err, PyDataFusionResult};
 use crate::expr::PyExpr;
 use crate::utils::{parse_volatility, validate_pycapsule};
 
diff --git a/src/udtf.rs b/src/udtf.rs
index f6604e5..15006ed 100644
--- a/src/udtf.rs
+++ b/src/udtf.rs
@@ -15,18 +15,19 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use pyo3::prelude::*;
 use std::sync::Arc;
 
+use datafusion::catalog::{TableFunctionImpl, TableProvider};
+use datafusion::error::Result as DataFusionResult;
+use datafusion::logical_expr::Expr;
+use datafusion_ffi::udtf::{FFI_TableFunction, ForeignTableFunction};
+use pyo3::prelude::*;
+use pyo3::types::{PyCapsule, PyTuple};
+
 use crate::errors::{py_datafusion_err, to_datafusion_err};
 use crate::expr::PyExpr;
 use crate::table::PyTable;
 use crate::utils::validate_pycapsule;
-use datafusion::catalog::{TableFunctionImpl, TableProvider};
-use datafusion::error::Result as DataFusionResult;
-use datafusion::logical_expr::Expr;
-use datafusion_ffi::udtf::{FFI_TableFunction, ForeignTableFunction};
-use pyo3::types::{PyCapsule, PyTuple};
 
 /// Represents a user defined table function
 #[pyclass(frozen, name = "TableFunction", module = "datafusion")]
diff --git a/src/udwf.rs b/src/udwf.rs
index ceeaa0e..aae9f4c 100644
--- a/src/udwf.rs
+++ b/src/udwf.rs
@@ -20,25 +20,25 @@
 use std::sync::Arc;
 
 use arrow::array::{make_array, Array, ArrayData, ArrayRef};
+use datafusion::arrow::datatypes::DataType;
+use datafusion::arrow::pyarrow::{FromPyArrow, PyArrowType, ToPyArrow};
+use datafusion::error::{DataFusionError, Result};
 use datafusion::logical_expr::function::{PartitionEvaluatorArgs, WindowUDFFieldArgs};
+use datafusion::logical_expr::ptr_eq::PtrEq;
 use datafusion::logical_expr::window_state::WindowAggState;
+use datafusion::logical_expr::{
+    PartitionEvaluator, PartitionEvaluatorFactory, Signature, Volatility, WindowUDF, WindowUDFImpl,
+};
 use datafusion::scalar::ScalarValue;
+use datafusion_ffi::udwf::{FFI_WindowUDF, ForeignWindowUDF};
 use pyo3::exceptions::PyValueError;
 use pyo3::prelude::*;
+use pyo3::types::{PyCapsule, PyList, PyTuple};
 
 use crate::common::data_type::PyScalarValue;
 use crate::errors::{py_datafusion_err, to_datafusion_err, PyDataFusionResult};
 use crate::expr::PyExpr;
 use crate::utils::{parse_volatility, validate_pycapsule};
-use datafusion::arrow::datatypes::DataType;
-use datafusion::arrow::pyarrow::{FromPyArrow, PyArrowType, ToPyArrow};
-use datafusion::error::{DataFusionError, Result};
-use datafusion::logical_expr::ptr_eq::PtrEq;
-use datafusion::logical_expr::{
-    PartitionEvaluator, PartitionEvaluatorFactory, Signature, Volatility, WindowUDF, WindowUDFImpl,
-};
-use datafusion_ffi::udwf::{FFI_WindowUDF, ForeignWindowUDF};
-use pyo3::types::{PyCapsule, PyList, PyTuple};
 
 #[derive(Debug)]
 struct RustPartitionEvaluator {
diff --git a/src/unparser/mod.rs b/src/unparser/mod.rs
index f234345..908b59d 100644
--- a/src/unparser/mod.rs
+++ b/src/unparser/mod.rs
@@ -19,9 +19,11 @@
 
 use std::sync::Arc;
 
-use datafusion::sql::unparser::{dialect::Dialect, Unparser};
+use datafusion::sql::unparser::dialect::Dialect;
+use datafusion::sql::unparser::Unparser;
 use dialect::PyDialect;
-use pyo3::{exceptions::PyValueError, prelude::*};
+use pyo3::exceptions::PyValueError;
+use pyo3::prelude::*;
 
 use crate::sql::logical::PyLogicalPlan;
 
diff --git a/src/utils.rs b/src/utils.rs
index 9624f7d..ce7395e 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -15,25 +15,25 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::errors::py_datafusion_err;
-use crate::{
-    common::data_type::PyScalarValue,
-    errors::{to_datafusion_err, PyDataFusionError, PyDataFusionResult},
-    TokioRuntime,
-};
-use datafusion::{
-    common::ScalarValue, datasource::TableProvider, execution::context::SessionContext,
-    logical_expr::Volatility,
-};
+use std::future::Future;
+use std::sync::{Arc, OnceLock};
+use std::time::Duration;
+
+use datafusion::common::ScalarValue;
+use datafusion::datasource::TableProvider;
+use datafusion::execution::context::SessionContext;
+use datafusion::logical_expr::Volatility;
 use datafusion_ffi::table_provider::{FFI_TableProvider, ForeignTableProvider};
+use pyo3::exceptions::PyValueError;
 use pyo3::prelude::*;
-use pyo3::{exceptions::PyValueError, types::PyCapsule};
-use std::{
-    future::Future,
-    sync::{Arc, OnceLock},
-    time::Duration,
-};
-use tokio::{runtime::Runtime, task::JoinHandle, time::sleep};
+use pyo3::types::PyCapsule;
+use tokio::runtime::Runtime;
+use tokio::task::JoinHandle;
+use tokio::time::sleep;
+
+use crate::common::data_type::PyScalarValue;
+use crate::errors::{py_datafusion_err, to_datafusion_err, PyDataFusionError, PyDataFusionResult};
+use crate::TokioRuntime;
 
 /// Utility to get the Tokio Runtime from Python
 #[inline]