Skip to content

Clippy lints#6464

Merged
alamb merged 9 commits intoapache:mainfrom
LouisGariepy:clippy-lints
May 30, 2023
Merged

Clippy lints#6464
alamb merged 9 commits intoapache:mainfrom
LouisGariepy:clippy-lints

Conversation

@LouisGariepy
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #207.

Rationale for this change

This PR fixes most of the remaining clippy allows remaining in the code base.

Clippy allows sometimes silence actually useful lints. Even if the lint was not useful at some point, it's easy to forget about them even after the code has been fixed.

For these reasons it's good practice to clean them up once in a while.

What changes are included in this PR?

The bulk of the changes is simply removing allows the were not needed at all.

Some changes are slightly more involved, but should still be pretty localized and self-explanatory.

Are these changes tested?

This PR does not (and should not) introduce new features or modify existing features. Thus, existing test coverage should be sufficient.

I added one test to for the code I added for data pointer equality (related to the removal of vtable address comparison lints

Are there any user-facing changes?

No(*) (see the Notes section below)

Notes

All of the committed fixes are fairly straightforward and uncontroversial.

Some fixes would be breaking(*) or require maintainer input to get right. I documented these cases with TODO(clippy) and gave ample details and potential solutions. I would appreciate if the reviewer could pay special attention to these so we can decide which ones should be fixed as part of this PR, which ones should be fixed as part of a separate PR, and which ones should not be fixed at all.

The remaining allows are all too many arguments lints whose fixes are not straightforward and might require some more in-depth redesign. I'm proposing to leave them as is for now and fix them on a case-by-case basis as solutions become more evident. I did not mark these with TODO(clippy) as I can't suggest solutions for them without some more careful examination. I will try to get to them in due time, in one or more future PRs.

@github-actions github-actions Bot added core Core DataFusion crate logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates substrait Changes to the substrait crate labels May 27, 2023
@LouisGariepy
Copy link
Copy Markdown
Contributor Author

Oh one thing I was unsure about:

I put the DataPtr trait in datafusion_common::utils. I'm not sure that's the right place for this utility. Please let me know 😃 .

@LouisGariepy
Copy link
Copy Markdown
Contributor Author

LouisGariepy commented May 27, 2023

Also, bear in mind that the line count includes several added detailed comments. I'm fairly certain that overall this PR removes lines of code or is very close to neutral.

@alamb
Copy link
Copy Markdown
Contributor

alamb commented May 28, 2023

Thank you @LouisGariepy -- I plan to review this carefully tomorrow or Tuesday if no one beats me to it

This fixes the doc build error in CI and seems more appropriate.
Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you very much @LouisGariepy - I went through this PR carefully and I think it is a really nice cleanup and thus plan to merge it in.

I had some comments that might improve the code more, but I think this PR as it is is a great step forward and we can address the other items as follow on PRs.

Again, thank you for helping keep the codebase cleaner 🦾

// TODO(clippy): The clippy `allow` could be removed by renaming this method to `next_batch`.
// This would also make the intent of the method clearer.
//
// Another option could be to rework `AvroArrowArrayReader::next_batch` so it returns an
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.

I think this second option would be my preference


// "YES if the column is possibly nullable, NO if it is known not nullable. "
let nullable_str = if is_nullable { "YES" } else { "NO" };
let nullable_str = if field.is_nullable() { "YES" } else { "NO" };
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.

this is a nice cleanup

Comment thread datafusion/core/src/catalog/mod.rs Outdated
//! This module contains interfaces and default implementations
//! of table namespacing concepts, including catalogs and schemas.

// TODO(clippy): Having a `datasource::datasource` module path is unclear and ambiguous.
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.

👍

{
let left_changed = Arc::ptr_eq(left, &right_exec);
let right_changed = Arc::ptr_eq(right, &left_exec);
let left_changed = Arc::data_ptr_eq(left, &right_exec);
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.

I like the fact that you have moved the (potentially dubious) pointer comparisons into a trait that has much better documentation about rationale. 🙏 thank you

baseline_metrics,
context,
partition,
self, context, partition,
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.

this certainly looks much nicer 😍

};
use std::sync::Arc;

struct PrimitiveTypeField<'a> {
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.

👍

use std::sync::Arc;

struct PrimitiveTypeField<'a> {
name: &'a str,
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.

I don't think it is important but given that name seems to always be a constant string, you could do something like

Suggested change
name: &'a str,
name: &'static str,

And avoid having to have the named lifetime 'a on this struct

None,
)]);
let schema_descr = get_test_schema_descr(vec![PrimitiveTypeField {
name: "c1",
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.

I am a big fan of explicit field names as a way to better document what is going on here.

Comment on lines +359 to +366
PrimitiveTypeField {
name: "c1",
physical_ty: PhysicalType::INT32,
logical_ty: None,
precision: None,
scale: None,
byte_len: None,
},
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.

When I was reading this, I was thinking these tests might be even more readable if they had a builder style, something like

 PrimtiveTypeField::new("c1", PhysicalType::INT32)

And then for tests that need other optional fields set:

 PrimtiveTypeField::new("c1", PhysicalType::INT32)
  .with_logical_type(LogicalType::Decimal {
                scale: 0,
                precision: 9,
            });

// TODO(clippy): This should probably be renamed to use a `with_*` prefix. Something
// like `with_template`, or `with_exprs_and_inputs`.
//
// Also, I think `ExtensionPlanNode` has been renamed to `UserDefinedLogicalNode`
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.

👍

@LouisGariepy
Copy link
Copy Markdown
Contributor Author

LouisGariepy commented May 29, 2023

@alamb Thank you for the review 😃. I implemented your suggestions and fixed a typo that slipped in.

Just to be sure, regarding the TODO(clippy) comments, would you prefer those to be fixed in this PR, or in a separate one?

@alamb
Copy link
Copy Markdown
Contributor

alamb commented May 30, 2023

Just to be sure, regarding the TODO(clippy) comments, would you prefer those to be fixed in this PR, or in a separate one?

I think a separate one is better -- I don't see any reason to hold up the changes in this PR for technically unrelated other changes.

THanks again @LouisGariepy

physical_ty: PhysicalType::INT32,
logical_ty: Some(LogicalType::Decimal {

let field = PrimitiveTypeField::new("c1", PhysicalType::INT32)
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.

❤️

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

Labels

core Core DataFusion crate logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates substrait Changes to the substrait crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable all clippy lints

2 participants