Skip to content

WIP: Format imports in Rust code #811

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

Closed
wants to merge 7 commits into from
Closed
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
18 changes: 18 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ on:
workflow_dispatch:

jobs:
# cargo fmt
lint:
name: Lint
runs-on: ubuntu-latest
container:
image: amd64/rust
steps:
- uses: actions/checkout@v3
- name: Setup toolchain
run: |
rustup toolchain install nightly
rustup default nightly
rustup component add rustfmt
- name: Run
run: |
cd dask_planner
cargo +nightly fmt --all -- --check

# Check crate compiles
linux-build-lib:
name: cargo check
Expand Down
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ repos:
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
args: ['--manifest-path', './dask_planner/Cargo.toml', '--verbose', '--']
# disabled because the hook does not support running `cargo +nightly fmt`
# see https://github.com/dask-contrib/dask-sql/issues/810
# - id: fmt
# args: ['--manifest-path', './dask_planner/Cargo.toml', '--verbose', '--']
- id: cargo-check
args: ['--manifest-path', './dask_planner/Cargo.toml', '--verbose', '--']
- id: clippy
Expand Down
2 changes: 0 additions & 2 deletions dask_planner/rust-toolchain.toml

This file was deleted.

2 changes: 2 additions & 0 deletions dask_planner/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
4 changes: 2 additions & 2 deletions dask_planner/src/dialect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::iter::Peekable;
use core::str::Chars;
use core::{iter::Peekable, str::Chars};

use datafusion_sql::sqlparser::dialect::Dialect;

#[derive(Debug)]
Expand Down
18 changes: 11 additions & 7 deletions dask_planner/src/expression.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use crate::sql::exceptions::{py_runtime_err, py_type_err};
use crate::sql::logical;
use crate::sql::types::RexType;
use std::{convert::From, sync::Arc};

use arrow::datatypes::DataType;
use datafusion_common::{Column, DFField, DFSchema, Result, ScalarValue};
use datafusion_expr::Operator;
use datafusion_expr::{lit, utils::exprlist_to_fields, BuiltinScalarFunction, Expr, LogicalPlan};
use datafusion_expr::{
lit, utils::exprlist_to_fields, BuiltinScalarFunction, Expr, LogicalPlan, Operator,
};
use pyo3::prelude::*;
use std::convert::From;
use std::sync::Arc;

use crate::sql::{
exceptions::{py_runtime_err, py_type_err},
logical,
types::RexType,
};

/// An PyExpr that can be used on a DataFrame
#[pyclass(name = "Expression", module = "datafusion", subclass)]
Expand Down
7 changes: 4 additions & 3 deletions dask_planner/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
//!
//! Declares a SQL parser based on sqlparser that handles custom formats that we need.

use crate::dialect::DaskDialect;
use crate::sql::parser_utils::DaskParserUtils;
use std::collections::VecDeque;

use datafusion_sql::sqlparser::{
ast::{Expr, SelectItem, Statement as SQLStatement},
dialect::{keywords::Keyword, Dialect},
parser::{Parser, ParserError},
tokenizer::{Token, Tokenizer},
};
use std::collections::VecDeque;

use crate::{dialect::DaskDialect, sql::parser_utils::DaskParserUtils};

macro_rules! parser_err {
($MSG:expr) => {
Expand Down
51 changes: 23 additions & 28 deletions dask_planner/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,41 @@ pub mod statement;
pub mod table;
pub mod types;

use crate::sql::exceptions::{py_optimization_exp, py_parsing_exp, py_runtime_err};
use std::{collections::HashMap, sync::Arc};

use arrow::datatypes::{DataType, Field, Schema};
use datafusion_common::{DFSchema, DataFusionError};
use datafusion_expr::logical_plan::Extension;
use datafusion_expr::{
AccumulatorFunctionImplementation, AggregateUDF, LogicalPlan, PlanVisitor, ReturnTypeFunction,
ScalarFunctionImplementation, ScalarUDF, Signature, StateTypeFunction, TableSource,
TypeSignature, Volatility,
logical_plan::Extension, AccumulatorFunctionImplementation, AggregateUDF, LogicalPlan,
PlanVisitor, ReturnTypeFunction, ScalarFunctionImplementation, ScalarUDF, Signature,
StateTypeFunction, TableSource, TypeSignature, Volatility,
};
use datafusion_sql::{
parser::Statement as DFStatement,
planner::{ContextProvider, SqlToRel},
ResolvedTableReference, TableReference,
};

use std::collections::HashMap;
use std::sync::Arc;

use crate::dialect::DaskDialect;
use crate::parser::{DaskParser, DaskStatement};
use crate::sql::logical::analyze_table::AnalyzeTablePlanNode;
use crate::sql::logical::create_model::CreateModelPlanNode;
use crate::sql::logical::create_table::CreateTablePlanNode;
use crate::sql::logical::create_view::CreateViewPlanNode;
use crate::sql::logical::describe_model::DescribeModelPlanNode;
use crate::sql::logical::drop_model::DropModelPlanNode;
use crate::sql::logical::export_model::ExportModelPlanNode;
use crate::sql::logical::predict_model::PredictModelPlanNode;
use crate::sql::logical::show_columns::ShowColumnsPlanNode;
use crate::sql::logical::show_models::ShowModelsPlanNode;
use crate::sql::logical::show_schema::ShowSchemasPlanNode;
use crate::sql::logical::show_tables::ShowTablesPlanNode;

use crate::sql::logical::PyLogicalPlan;
use pyo3::prelude::*;

use self::logical::create_catalog_schema::CreateCatalogSchemaPlanNode;
use self::logical::drop_schema::DropSchemaPlanNode;
use self::logical::use_schema::UseSchemaPlanNode;
use self::logical::{
create_catalog_schema::CreateCatalogSchemaPlanNode, drop_schema::DropSchemaPlanNode,
use_schema::UseSchemaPlanNode,
};
use crate::{
dialect::DaskDialect,
parser::{DaskParser, DaskStatement},
sql::{
exceptions::{py_optimization_exp, py_parsing_exp, py_runtime_err},
logical::{
analyze_table::AnalyzeTablePlanNode, create_model::CreateModelPlanNode,
create_table::CreateTablePlanNode, create_view::CreateViewPlanNode,
describe_model::DescribeModelPlanNode, drop_model::DropModelPlanNode,
export_model::ExportModelPlanNode, predict_model::PredictModelPlanNode,
show_columns::ShowColumnsPlanNode, show_models::ShowModelsPlanNode,
show_schema::ShowSchemasPlanNode, show_tables::ShowTablesPlanNode, PyLogicalPlan,
},
},
};

/// DaskSQLContext is main interface used for interacting with DataFusion to
/// parse SQL queries, build logical plans, and optimize logical plans.
Expand Down
1 change: 0 additions & 1 deletion dask_planner/src/sql/column.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use datafusion_common::Column;

use pyo3::prelude::*;

#[pyclass(name = "Column", module = "dask_planner", subclass)]
Expand Down
3 changes: 2 additions & 1 deletion dask_planner/src/sql/exceptions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use pyo3::{create_exception, PyErr};
use std::fmt::Debug;

use pyo3::{create_exception, PyErr};

// Identifies expections that occur while attempting to generate a `LogicalPlan` from a SQL string
create_exception!(rust, ParsingException, pyo3::exceptions::PyException);

Expand Down
7 changes: 4 additions & 3 deletions dask_planner/src/sql/function.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::types::PyDataType;
use pyo3::prelude::*;
use std::collections::HashMap;

use arrow::datatypes::DataType;
use std::collections::HashMap;
use pyo3::prelude::*;

use super::types::PyDataType;

#[pyclass(name = "DaskFunction", module = "dask_planner", subclass)]
#[derive(Debug, Clone)]
Expand Down
35 changes: 15 additions & 20 deletions dask_planner/src/sql/logical.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::sql::table;
use crate::sql::types::rel_data_type::RelDataType;
use crate::sql::types::rel_data_type_field::RelDataTypeField;
use crate::sql::{
table,
types::{rel_data_type::RelDataType, rel_data_type_field::RelDataTypeField},
};

pub mod aggregate;
pub mod analyze_table;
Expand Down Expand Up @@ -33,25 +34,19 @@ pub mod window;

use datafusion_common::{DFSchemaRef, DataFusionError, Result};
use datafusion_expr::LogicalPlan;

use crate::sql::exceptions::py_type_err;
use pyo3::prelude::*;

use self::analyze_table::AnalyzeTablePlanNode;
use self::create_catalog_schema::CreateCatalogSchemaPlanNode;
use self::create_model::CreateModelPlanNode;
use self::create_table::CreateTablePlanNode;
use self::create_view::CreateViewPlanNode;
use self::describe_model::DescribeModelPlanNode;
use self::drop_model::DropModelPlanNode;
use self::drop_schema::DropSchemaPlanNode;
use self::export_model::ExportModelPlanNode;
use self::predict_model::PredictModelPlanNode;
use self::show_columns::ShowColumnsPlanNode;
use self::show_models::ShowModelsPlanNode;
use self::show_schema::ShowSchemasPlanNode;
use self::show_tables::ShowTablesPlanNode;
use self::use_schema::UseSchemaPlanNode;
use self::{
analyze_table::AnalyzeTablePlanNode, create_catalog_schema::CreateCatalogSchemaPlanNode,
create_model::CreateModelPlanNode, create_table::CreateTablePlanNode,
create_view::CreateViewPlanNode, describe_model::DescribeModelPlanNode,
drop_model::DropModelPlanNode, drop_schema::DropSchemaPlanNode,
export_model::ExportModelPlanNode, predict_model::PredictModelPlanNode,
show_columns::ShowColumnsPlanNode, show_models::ShowModelsPlanNode,
show_schema::ShowSchemasPlanNode, show_tables::ShowTablesPlanNode,
use_schema::UseSchemaPlanNode,
};
use crate::sql::exceptions::py_type_err;

#[pyclass(name = "LogicalPlan", module = "dask_planner", subclass)]
#[derive(Debug, Clone)]
Expand Down
14 changes: 9 additions & 5 deletions dask_planner/src/sql/logical/aggregate.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use crate::expression::{py_expr_list, PyExpr};

use datafusion_expr::{logical_plan::Aggregate, logical_plan::Distinct, Expr, LogicalPlan};

use crate::sql::exceptions::py_type_err;
use datafusion_expr::{
logical_plan::{Aggregate, Distinct},
Expr, LogicalPlan,
};
use pyo3::prelude::*;

use crate::{
expression::{py_expr_list, PyExpr},
sql::exceptions::py_type_err,
};

#[pyclass(name = "Aggregate", module = "dask_planner", subclass)]
#[derive(Clone)]
pub struct PyAggregate {
Expand Down
16 changes: 8 additions & 8 deletions dask_planner/src/sql/logical/analyze_table.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::sql::exceptions::py_type_err;
use crate::sql::logical;
use pyo3::prelude::*;

use datafusion_expr::logical_plan::{Extension, UserDefinedLogicalNode};
use datafusion_expr::{Expr, LogicalPlan};

use fmt::Debug;
use std::{any::Any, fmt, sync::Arc};

use datafusion_common::{DFSchema, DFSchemaRef};
use datafusion_expr::{
logical_plan::{Extension, UserDefinedLogicalNode},
Expr, LogicalPlan,
};
use fmt::Debug;
use pyo3::prelude::*;

use crate::sql::{exceptions::py_type_err, logical};

#[derive(Clone)]
pub struct AnalyzeTablePlanNode {
Expand Down
11 changes: 4 additions & 7 deletions dask_planner/src/sql/logical/create_catalog_schema.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use crate::sql::exceptions::py_type_err;
use crate::sql::logical;
use std::{any::Any, fmt, sync::Arc};

use datafusion_common::{DFSchema, DFSchemaRef};
use datafusion_expr::logical_plan::UserDefinedLogicalNode;
use datafusion_expr::{Expr, LogicalPlan};

use datafusion_expr::{logical_plan::UserDefinedLogicalNode, Expr, LogicalPlan};
use fmt::Debug;
use std::{any::Any, fmt, sync::Arc};

use pyo3::prelude::*;

use crate::sql::{exceptions::py_type_err, logical};

#[derive(Clone)]
pub struct CreateCatalogSchemaPlanNode {
pub schema: DFSchemaRef,
Expand Down
9 changes: 6 additions & 3 deletions dask_planner/src/sql/logical/create_memory_table.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use crate::sql::exceptions::py_type_err;
use crate::sql::logical::PyLogicalPlan;
use datafusion_expr::{logical_plan::CreateMemoryTable, logical_plan::CreateView, LogicalPlan};
use datafusion_expr::{
logical_plan::{CreateMemoryTable, CreateView},
LogicalPlan,
};
use pyo3::prelude::*;

use crate::sql::{exceptions::py_type_err, logical::PyLogicalPlan};

#[pyclass(name = "CreateMemoryTable", module = "dask_planner", subclass)]
#[derive(Clone)]
pub struct PyCreateMemoryTable {
Expand Down
15 changes: 5 additions & 10 deletions dask_planner/src/sql/logical/create_model.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
use crate::sql::exceptions::py_type_err;
use crate::sql::logical;
use crate::sql::parser_utils::DaskParserUtils;
use pyo3::prelude::*;
use std::{any::Any, collections::HashMap, fmt, sync::Arc};

use datafusion_expr::logical_plan::UserDefinedLogicalNode;
use datafusion_expr::{Expr, LogicalPlan};
use datafusion_common::DFSchemaRef;
use datafusion_expr::{logical_plan::UserDefinedLogicalNode, Expr, LogicalPlan};
use datafusion_sql::sqlparser::ast::Expr as SqlParserExpr;

use fmt::Debug;
use std::collections::HashMap;
use std::{any::Any, fmt, sync::Arc};
use pyo3::prelude::*;

use datafusion_common::DFSchemaRef;
use crate::sql::{exceptions::py_type_err, logical, parser_utils::DaskParserUtils};

#[derive(Clone)]
pub struct CreateModelPlanNode {
Expand Down
14 changes: 5 additions & 9 deletions dask_planner/src/sql/logical/create_table.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use crate::sql::exceptions::py_type_err;
use crate::sql::logical;
use pyo3::prelude::*;
use std::{any::Any, collections::HashMap, fmt, sync::Arc};

use datafusion_expr::logical_plan::UserDefinedLogicalNode;
use datafusion_expr::{Expr, LogicalPlan};
use datafusion_common::{DFSchema, DFSchemaRef};
use datafusion_expr::{logical_plan::UserDefinedLogicalNode, Expr, LogicalPlan};
use datafusion_sql::sqlparser::ast::{Expr as SqlParserExpr, Value};

use fmt::Debug;
use std::collections::HashMap;
use std::{any::Any, fmt, sync::Arc};
use pyo3::prelude::*;

use datafusion_common::{DFSchema, DFSchemaRef};
use crate::sql::{exceptions::py_type_err, logical};

#[derive(Clone)]
pub struct CreateTablePlanNode {
Expand Down
13 changes: 5 additions & 8 deletions dask_planner/src/sql/logical/create_view.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use crate::sql::exceptions::py_type_err;
use crate::sql::logical;
use pyo3::prelude::*;

use datafusion_expr::logical_plan::UserDefinedLogicalNode;
use datafusion_expr::{Expr, LogicalPlan};

use fmt::Debug;
use std::{any::Any, fmt, sync::Arc};

use datafusion_common::{DFSchema, DFSchemaRef};
use datafusion_expr::{logical_plan::UserDefinedLogicalNode, Expr, LogicalPlan};
use fmt::Debug;
use pyo3::prelude::*;

use crate::sql::{exceptions::py_type_err, logical};

#[derive(Clone)]
pub struct CreateViewPlanNode {
Expand Down
Loading