Skip to content

Commit 69b48bc

Browse files
committed
make clippy happy
1 parent c566109 commit 69b48bc

File tree

1 file changed

+45
-33
lines changed

1 file changed

+45
-33
lines changed

datafusion-postgres/src/handlers.rs

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ impl DfSessionService {
7878
async fn handle_set(&self, variable: &ObjectName, value: &[Expr]) -> PgWireResult<()> {
7979
let var_name = variable
8080
.0
81-
.get(0)
81+
.first()
8282
.map(|ident| ident.to_string().to_lowercase())
8383
.unwrap_or_default();
8484

85-
let value_str = match value.get(0) {
85+
let value_str = match value.first() {
8686
Some(Expr::Value(v)) => match &v.value {
8787
sqlparser::ast::Value::SingleQuotedString(s)
8888
| sqlparser::ast::Value::DoubleQuotedString(s) => s.clone(),
@@ -91,11 +91,13 @@ impl DfSessionService {
9191
},
9292
Some(expr) => expr.to_string(),
9393
None => {
94-
return Err(PgWireError::UserError(Box::new(pgwire::error::ErrorInfo::new(
95-
"ERROR".to_string(),
96-
"22023".to_string(),
97-
"SET requires a value".to_string(),
98-
))));
94+
return Err(PgWireError::UserError(Box::new(
95+
pgwire::error::ErrorInfo::new(
96+
"ERROR".to_string(),
97+
"22023".to_string(),
98+
"SET requires a value".to_string(),
99+
),
100+
)));
99101
}
100102
};
101103

@@ -124,7 +126,7 @@ impl DfSessionService {
124126
*sc_guard = new_context;
125127
Ok(())
126128
}
127-
| "client_encoding"
129+
"client_encoding"
128130
| "search_path"
129131
| "application_name"
130132
| "datestyle"
@@ -138,17 +140,19 @@ impl DfSessionService {
138140
vars.insert(var_name, value_str);
139141
Ok(())
140142
}
141-
_ => Err(PgWireError::UserError(Box::new(pgwire::error::ErrorInfo::new(
142-
"ERROR".to_string(),
143-
"42704".to_string(),
144-
format!("Unrecognized configuration parameter '{}'", var_name),
145-
)))),
143+
_ => Err(PgWireError::UserError(Box::new(
144+
pgwire::error::ErrorInfo::new(
145+
"ERROR".to_string(),
146+
"42704".to_string(),
147+
format!("Unrecognized configuration parameter '{}'", var_name),
148+
),
149+
))),
146150
}
147151
}
148152

149153
async fn handle_show<'a>(&self, variable: &[Ident]) -> PgWireResult<QueryResponse<'a>> {
150154
let var_name = variable
151-
.get(0)
155+
.first()
152156
.map(|ident| ident.to_string().to_lowercase())
153157
.unwrap_or_default();
154158

@@ -305,15 +309,21 @@ impl DfSessionService {
305309
}
306310

307311
_ => {
308-
return Err(PgWireError::UserError(Box::new(pgwire::error::ErrorInfo::new(
309-
"ERROR".to_string(),
310-
"42704".to_string(),
311-
format!("Unrecognized configuration parameter '{}'", var_name),
312-
))));
312+
return Err(PgWireError::UserError(Box::new(
313+
pgwire::error::ErrorInfo::new(
314+
"ERROR".to_string(),
315+
"42704".to_string(),
316+
format!("Unrecognized configuration parameter '{}'", var_name),
317+
),
318+
)));
313319
}
314320
};
315321

316-
let schema = Arc::new(Schema::new(vec![Field::new(&var_name, DataType::Utf8, false)]));
322+
let schema = Arc::new(Schema::new(vec![Field::new(
323+
&var_name,
324+
DataType::Utf8,
325+
false,
326+
)]));
317327
let batch = RecordBatch::try_new(schema, vec![Arc::new(StringArray::from(vec![value]))])
318328
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
319329
let df = sc_guard
@@ -367,15 +377,17 @@ impl SimpleQueryHandler for DfSessionService {
367377
continue;
368378
}
369379
match statement {
370-
Statement::SetVariable { variables, value, .. } => {
380+
Statement::SetVariable {
381+
variables, value, ..
382+
} => {
371383
let var = match variables {
372384
sqlparser::ast::OneOrManyWithParens::One(ref name) => name,
373-
sqlparser::ast::OneOrManyWithParens::Many(ref names) => names.first().unwrap(),
385+
sqlparser::ast::OneOrManyWithParens::Many(ref names) => {
386+
names.first().unwrap()
387+
}
374388
};
375389
self.handle_set(var, &value).await?;
376-
responses.push(Response::Execution(
377-
pgwire::api::results::Tag::new("SET").into(),
378-
));
390+
responses.push(Response::Execution(pgwire::api::results::Tag::new("SET")));
379391
}
380392
Statement::ShowVariable { variable } => {
381393
let resp = self.handle_show(&variable).await?;
@@ -415,8 +427,7 @@ impl ExtendedQueryHandler for DfSessionService {
415427
{
416428
let plan = &target.statement;
417429
let schema = plan.schema();
418-
let fields =
419-
datatypes::df_schema_to_pg_fields(schema.as_ref(), &Format::UnifiedBinary)?;
430+
let fields = datatypes::df_schema_to_pg_fields(schema.as_ref(), &Format::UnifiedBinary)?;
420431
let params = plan
421432
.get_parameter_types()
422433
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
@@ -465,13 +476,16 @@ impl ExtendedQueryHandler for DfSessionService {
465476
let dialect = GenericDialect {};
466477
let stmts = SqlParser::parse_sql(&dialect, &stmt_string)
467478
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
468-
if let Statement::SetVariable { variables, value, .. } = &stmts[0] {
479+
if let Statement::SetVariable {
480+
variables, value, ..
481+
} = &stmts[0]
482+
{
469483
let var = match variables {
470484
sqlparser::ast::OneOrManyWithParens::One(ref name) => name,
471485
sqlparser::ast::OneOrManyWithParens::Many(ref names) => names.first().unwrap(),
472486
};
473-
self.handle_set(var, &value).await?;
474-
return Ok(Response::Execution(pgwire::api::results::Tag::new("SET").into()));
487+
self.handle_set(var, value).await?;
488+
return Ok(Response::Execution(pgwire::api::results::Tag::new("SET")));
475489
}
476490
} else if stmt_upper.starts_with("SHOW ") {
477491
let dialect = GenericDialect {};
@@ -506,9 +520,7 @@ impl ExtendedQueryHandler for DfSessionService {
506520
}
507521
}
508522

509-
fn ordered_param_types(
510-
types: &HashMap<String, Option<DataType>>,
511-
) -> Vec<Option<&DataType>> {
523+
fn ordered_param_types(types: &HashMap<String, Option<DataType>>) -> Vec<Option<&DataType>> {
512524
// Datafusion stores the parameters as a map. In our case, the keys will be
513525
// `$1`, `$2` etc. The values will be the parameter types.
514526
let mut types_vec = types.iter().collect::<Vec<_>>();

0 commit comments

Comments
 (0)