MCPcopy Create free account
hub / github.com/apache/datafusion / fmt

Method fmt

datafusion/common/src/error.rs:202–279  ·  view source on GitHub ↗
(&self, f: &mut Formatter<'_>)

Source from the content-addressed store, hash-verified

200
201impl Display for SchemaError {
202 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
203 match self {
204 Self::FieldNotFound {
205 field,
206 valid_fields,
207 } => {
208 write!(f, "No field named {}", field.quoted_flat_name())?;
209 let lower_valid_fields = valid_fields
210 .iter()
211 .map(|column| column.flat_name().to_lowercase())
212 .collect::<Vec<String>>();
213
214 let valid_fields_names = valid_fields
215 .iter()
216 .map(|column| column.flat_name())
217 .collect::<Vec<String>>();
218 if lower_valid_fields.contains(&field.flat_name().to_lowercase()) {
219 write!(
220 f,
221 ". Column names are case sensitive. You can use double quotes to refer to the \"{}\" column \
222 or set the datafusion.sql_parser.enable_ident_normalization configuration",
223 field.quoted_flat_name()
224 )?;
225 }
226 let field_name = field.name();
227 if let Some(matched) = valid_fields_names
228 .iter()
229 .filter(|str| normalized_levenshtein(str, field_name) >= 0.5)
230 .collect::<Vec<&String>>()
231 .first()
232 {
233 write!(f, ". Did you mean '{matched}'?")?;
234 } else if !valid_fields.is_empty() {
235 write!(
236 f,
237 ". Valid fields are {}",
238 valid_fields
239 .iter()
240 .map(|field| field.quoted_flat_name())
241 .collect::<Vec<String>>()
242 .join(", ")
243 )?;
244 }
245 write!(f, ".")
246 }
247 Self::DuplicateQualifiedField { qualifier, name } => {
248 write!(
249 f,
250 "Schema contains duplicate qualified field name {}.{}",
251 qualifier.to_quoted_string(),
252 quote_identifier(name)
253 )
254 }
255 Self::DuplicateUnqualifiedField { name } => {
256 write!(
257 f,
258 "Schema contains duplicate unqualified field name {}",
259 quote_identifier(name)

Callers

nothing calls this directly

Calls 11

normalized_levenshteinFunction · 0.85
flat_nameMethod · 0.80
error_prefixMethod · 0.80
messageMethod · 0.80
mapMethod · 0.45
iterMethod · 0.45
containsMethod · 0.45
nameMethod · 0.45
firstMethod · 0.45
filterMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected