Skip to content

[minor]: Introduce IndexSet and IndexMap aliases. - #13611

Merged
alamb merged 1 commit into
apache:mainfrom
akurmustafa:feature/index_map_common
Dec 4, 2024
Merged

[minor]: Introduce IndexSet and IndexMap aliases.#13611
alamb merged 1 commit into
apache:mainfrom
akurmustafa:feature/index_map_common

Conversation

@akurmustafa

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

This Pr is similar to PR. It replaces all usages of indexmap::IndexSet and indexmap::IndexMap with datafusion_common::IndexSet and datafusion_common::IndexMap to enforce consistency across DataFusion.

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actionsgithub-actionsBot added sql SQL Planner logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates optimizer Optimizer rules common Related to common crate labels Nov 30, 2024

@jayzhan211jayzhan211 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍🏻

@findepi

Copy link
Copy Markdown
Member

It replaces all usages of indexmap::IndexSet and indexmap::IndexMap with datafusion_common::IndexSet and datafusion_common::IndexMap to enforce consistency across DataFusion.

if some new code uses indexmap::IndexSet directly, will it cause compile-time or CI failure?

@akurmustafa

Copy link
Copy Markdown
ContributorAuthor

It replaces all usages of indexmap::IndexSet and indexmap::IndexMap with datafusion_common::IndexSet and datafusion_common::IndexMap to enforce consistency across DataFusion.

if some new code uses indexmap::IndexSet directly, will it cause compile-time or CI failure?

Actually, neither as far as I know. This is just a name alias.

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like an improvement to me, though as @findepi notes it would be even better with more docs / automatic checking / guidance for developers

@findepi

Copy link
Copy Markdown
Member

Can Clippy's disallowed types or methods be used to enforce consistency?

Otherwise, I would prefer to ensure consistency going into opposite direction.
If datafusion-common doesn't re-export IndexSet, then the code should consistently use indexmap::IndexSet as the only(?) available option.

use datafusion_common::{IndexSet, Result};
use datafusion_expr::logical_plan::LogicalPlan;
use datafusion_expr::{Aggregate, Expr, Sort, SortExpr};
use indexmap::IndexSet;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is indexmap also removed from datafusion/optimizer/Cargo.toml?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it cannot be removed because of indexmap::Equivalent.

implEquivalent<(Expr,Expr)>forExprPair<'_>{
fnequivalent(&self,other:&(Expr,Expr)) -> bool{
self.0 == &other.0 && self.1 == &other.1
}
}

@alamb

alamb commented Dec 4, 2024

Copy link
Copy Markdown
Contributor

Let's keep improving on main

@alamb
alamb merged commit 1aadce0 into apache:mainDec 4, 2024
@jonahgaojonahgao mentioned this pull request Dec 4, 2024
@jonahgao

Copy link
Copy Markdown
Member

Can Clippy's disallowed types or methods be used to enforce consistency?

We can add them to clippy disallowed-types.

But I am a bit doubtful whether this PR is necessary because, unlike HashMap, indexmap does not have two implementations in DataFusion that need to be unified. I think indexmap = { workspace = true } already provides consistency.

In addition, this type alias has added a permanent dependency for datafusion-common and can propagate to other packages. Even if one day, common/cse.rs no longer needs IndexMap.

We also need to create a type alias for indexmap::Equivalent to ensure consistency.

pub type HashMap<K, V, S = DefaultHashBuilder> = hashbrown::HashMap<K, V, S>;
pub type HashSet<T, S = DefaultHashBuilder> = hashbrown::HashSet<T, S>;

pub type IndexMap<T, S = DefaultHashBuilder> = indexmap::IndexMap<T, S>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should be

pubtypeIndexMap<K,V,S = RandomState> = indexmap::IndexMap<K,V,S>;

@findepi

Copy link
Copy Markdown
Member

I think indexmap = { workspace = true } already provides consistency.

I agree with that and also suggested in #13611 (comment)

In addition, this type alias has added a permanent dependency for datafusion-common

good point.
common is pretty common to depend on, but also is too fat already (eg pulls sqlparser dependency).
avoiding dependencies is a good thing.

@akurmustafa

Copy link
Copy Markdown
ContributorAuthor

I aggree with @findepi and @jonahgao that this might indeed be unnecessary. At first, this occurred to me as a natural continuation of the previous HashMap and HashSet work. However, it seems that, we have a single option anyway also without enforcing consistency, this is not helpful. Should I retract these changes?

@jonahgao

Copy link
Copy Markdown
Member

I aggree with @findepi and @jonahgao that this might indeed be unnecessary. At first, this occurred to me as a natural continuation of the previous HashMap and HashSet work. However, it seems that, we have a single option anyway also without enforcing consistency, this is not helpful. Should I retract these changes?

Thanks @akurmustafa. I think retracting these changes will make things simpler.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commonRelated to common cratelogical-exprLogical plan and expressionsoptimizerOptimizer rulesphysical-exprChanges to the physical-expr cratessqlSQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@akurmustafa@findepi@alamb@jonahgao@jayzhan211@Weijun-H