Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Speedup new_with_metadata by removing sort #8855

Merged
merged 1 commit into from
Jan 15, 2024
Merged
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
16 changes: 5 additions & 11 deletions datafusion/common/src/dfschema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! DFSchema is an extended schema struct that DataFusion uses to provide support for
//! fields with optional relation names.

use std::collections::{HashMap, HashSet};
use std::collections::{BTreeSet, HashMap};
use std::convert::TryFrom;
use std::fmt::{Display, Formatter};
use std::hash::Hash;
Expand Down Expand Up @@ -135,8 +135,8 @@ impl DFSchema {
fields: Vec<DFField>,
metadata: HashMap<String, String>,
) -> Result<Self> {
let mut qualified_names = HashSet::new();
let mut unqualified_names = HashSet::new();
let mut qualified_names = BTreeSet::new();
let mut unqualified_names = BTreeSet::new();

for field in &fields {
if let Some(qualifier) = field.qualifier() {
Expand All @@ -148,14 +148,8 @@ impl DFSchema {
}
}

// check for mix of qualified and unqualified field with same unqualified name
// note that we need to sort the contents of the HashSet first so that errors are
// deterministic
let mut qualified_names = qualified_names
.iter()
.map(|(l, r)| (l.to_owned(), r.to_owned()))
.collect::<Vec<(&OwnedTableReference, &String)>>();
qualified_names.sort();
// Check for mix of qualified and unqualified fields with same unqualified name.
// The BTreeSet storage makes sure that errors are reported in deterministic order.
for (qualifier, name) in &qualified_names {
if unqualified_names.contains(name) {
return _schema_err!(SchemaError::AmbiguousReference {
Expand Down