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

Task/remove deprecated projection #1

Merged
merged 2 commits into from
Aug 5, 2024

Conversation

2lambda123
Copy link
Owner

@2lambda123 2lambda123 commented Aug 5, 2024

Description

Related Issue

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the Code of Conduct
  • I have updated the documentation accordingly.
  • All commits are GPG signed

Summary by Sourcery

Remove deprecated projection methods and constructors, and update test cases to use the new API.

Enhancements:

  • Remove deprecated methods and constructors from DocumentProjection, Projection, KeyProjection, and EventDataQueryFieldFilter classes.
  • Update test cases to use the new constructors and methods for DocumentProjection and Projection classes.

Copy link

cr-gpt bot commented Aug 5, 2024

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables/Secrets for this repo. you could follow readme for more information

Copy link

git-greetings bot commented Aug 5, 2024

Thanks @2lambda123 for opening this PR!

For COLLABORATOR only :

  • To add labels, comment on the issue
    /label add label1,label2,label3

  • To remove labels, comment on the issue
    /label remove label1,label2,label3

Copy link

Unable to locate .performanceTestingBot config file

Copy link

@gitginie gitginie bot left a comment

Choose a reason for hiding this comment

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

@2lambda123
Thank you for your contribution to this repository! We appreciate your effort in opening pull request.
Happy coding!

Copy link

Processing PR updates...

Copy link

git-greetings bot commented Aug 5, 2024

First PR by @2lambda123

PR Details of @2lambda123 in NationalSecurityAgency-datawave :

OPEN CLOSED TOTAL
1 0 1

Copy link

quine-bot bot commented Aug 5, 2024

👋 Figuring out if a PR is useful is hard, hopefully this will help.

  • @2lambda123 has been on GitHub since 2019 and in that time has had 2458 public PRs merged
  • They haven't contributed to this repo before
  • Here's a good example of their work: HeyGenClone
  • From looking at their profile, they seem to be good with Python and Shell.

Their most recently public accepted PR is: 2lambda123/Accenture-sfmc-devtools#108

Copy link

sourcery-ai bot commented Aug 5, 2024

Reviewer's Guide by Sourcery

This pull request removes deprecated projection methods and updates the code to use new constructors with parameters. Deprecated annotations and methods such as setIncludes, setExcludes, and default constructors have been removed from various classes and test files.

File-Level Changes

Files Changes
warehouse/query-core/src/test/java/datawave/query/function/DocumentProjectionTest.java
warehouse/query-core/src/test/java/datawave/query/predicate/ProjectionTest.java
warehouse/query-core/src/test/java/datawave/query/predicate/KeyProjectionTest.java
Removed @deprecated annotations from test methods and updated instantiation to use new constructors with parameters.
warehouse/query-core/src/main/java/datawave/query/predicate/Projection.java
warehouse/query-core/src/main/java/datawave/query/predicate/KeyProjection.java
warehouse/query-core/src/main/java/datawave/query/predicate/EventDataQueryFieldFilter.java
warehouse/query-core/src/main/java/datawave/query/function/DocumentProjection.java
Removed deprecated methods setIncludes, setExcludes, and default constructors.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

codeautopilot bot commented Aug 5, 2024

PR summary

This Pull Request removes deprecated methods and constructors related to projections in the codebase. The changes involve refactoring out deprecated projection calls and updating unit tests to use the new methods. The purpose is to clean up the code by eliminating outdated methods and ensuring that the codebase uses the latest implementations. The impact is a more maintainable and cleaner codebase, reducing the risk of using deprecated methods that may be removed in future versions.

Suggestion

Consider adding more detailed documentation or comments in the code to explain the new methods and their usage, especially if they replace deprecated ones. This will help future developers understand the changes more easily.

Disclaimer: This comment was entirely generated using AI. Be aware that the information provided may be incorrect.

Current plan usage: 12.49%

Have feedback or need help?
Discord
Documentation
support@codeautopilot.com

@2lambda123 2lambda123 merged commit 2881534 into integration Aug 5, 2024
10 of 26 checks passed
@labels-and-badges labels-and-badges bot added NO JIRA This PR does not have a Jira Ticket PR:size/L Denotes a Pull Request that changes 100-499 lines. labels Aug 5, 2024
Copy link

@gitginie gitginie bot left a comment

Choose a reason for hiding this comment

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

@2lambda123
Thank you for your contribution to this repository! We appreciate your effort in closing pull request.
Happy coding!

Comment on lines 74 to 77
final JsonParser parser = new JsonParser();
try (final Reader rdr = new FileReader(fName)) {
@SuppressWarnings("deprecation")
final JsonElement json = parser.parse(rdr);

Choose a reason for hiding this comment

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

Using the deprecated JsonParser class from the com.google.gson package is not recommended as it may be removed in future versions, leading to potential maintenance issues.

Recommended Solution: Replace the deprecated JsonParser with the non-deprecated alternatives provided by the Gson library, such as JsonParser.parseReader(Reader).

Comment on lines 75 to 79
try (final Reader rdr = new FileReader(fName)) {
@SuppressWarnings("deprecation")
final JsonElement json = parser.parse(rdr);
final IngestConfig val = gson.fromJson(json.toString(), IngestConfig.class);
cfg.set(val);

Choose a reason for hiding this comment

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

The code does not handle potential JsonSyntaxException or JsonIOException that could be thrown by gson.fromJson(). This could lead to unhandled exceptions and application crashes.

Recommended Solution: Add specific exception handling for JsonSyntaxException and JsonIOException to ensure that the application can handle these errors gracefully.

Comment on lines 40 to 41
public DocumentProjection(boolean includeGroupingContext, boolean reducedResponse, boolean trackSizes, Set<String> projections,
Projection.ProjectionType projectionType) {

Choose a reason for hiding this comment

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

The constructor of the DocumentProjection class has too many parameters, which can make it difficult to understand and maintain. Consider using a builder pattern or a configuration object to encapsulate these parameters. This will improve readability and maintainability.

Comment on lines 22 to 24
private boolean initialized;

@Deprecated
public void setIncludes(Set<String> includes) {
if (this.initialized) {
throw new RuntimeException("This Projection instance was already initialized");
}

// do not make a copy of the incoming include fields. It could be a UniversalSet
this.projections = includes;
this.initialized = true;
type = ProjectionType.INCLUDES;
}

@Deprecated
public void setExcludes(Set<String> excludes) {
if (this.initialized) {
throw new RuntimeException("This Projection instance was already initialized");
}

this.projections = Sets.newHashSet(excludes);
this.initialized = true;
type = ProjectionType.EXCLUDES;
}

@Deprecated
public Set<String> getIncludes() {
return Collections.unmodifiableSet(this.projections);
}

@Deprecated
public Set<String> getExcludes() {
return Collections.unmodifiableSet(this.projections);
}

/* Explicit constructor needed now that the new constructor was added */
@Deprecated
public Projection() {
this.initialized = false;
}

private Set<String> projections;
private ProjectionType type;

Choose a reason for hiding this comment

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

The fields initialized, projections, and type are not marked as volatile and there are no synchronization mechanisms in place. If this class is intended to be used in a multi-threaded environment, this could lead to data races and inconsistent state.

Recommended Solution: Ensure proper synchronization or use volatile for these fields if they are accessed by multiple threads.

@@ -56,26 +47,6 @@ public void testNoConfiguration() {
assertTrue(projection.apply(iter.next()));
}

Choose a reason for hiding this comment

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

The test testNoConfiguration is expected to throw a RuntimeException, but it does not verify the exception message or type beyond the base RuntimeException. This can lead to false positives if a different RuntimeException is thrown for an unexpected reason.

Recommendation: Use ExpectedException rule or assertThrows to verify the exception message and type more precisely. This will ensure that the test fails for the correct reason.

Comment on lines 12 to 16
@Test(expected = RuntimeException.class)
public void testNoConfiguration() {
Projection projection = new Projection(null, Projection.ProjectionType.INCLUDES);
assertTrue(projection.apply("FIELD_A"));
}

Choose a reason for hiding this comment

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

The test testNoConfiguration is expected to throw a RuntimeException, but it does not verify the exception message or type beyond RuntimeException. This can lead to false positives if any RuntimeException is thrown for reasons other than the intended one.

Recommendation: Use ExpectedException rule or assertThrows to verify the exception type and message to ensure the test is validating the correct behavior.

Comment on lines 19 to 23
public void testIncludesDepricated() {
Projection projection = new Projection();
projection.setIncludes(Sets.newHashSet("FIELD_A", "FIELD_B"));

Projection projection = new Projection(Sets.newHashSet("FIELD_A", "FIELD_B"), Projection.ProjectionType.INCLUDES);
assertTrue(projection.isUseIncludes());
assertFalse(projection.isUseExcludes());

Choose a reason for hiding this comment

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

The method name testIncludesDepricated contains a typo. The correct spelling is Deprecated. This can cause confusion and reduce code readability.

Recommendation: Rename the method to testIncludesDeprecated to correct the spelling.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @2lambda123 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding migration instructions or documentation for users transitioning from the deprecated API to the new one.
  • The SuppressWarnings annotations in IngestConfig.java suggest there might be more deprecated code to address. Consider updating these as well if possible.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Copy link

There was an issue running the performance test

4 similar comments
Copy link

There was an issue running the performance test

Copy link

There was an issue running the performance test

Copy link

There was an issue running the performance test

Copy link

There was an issue running the performance test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NO JIRA This PR does not have a Jira Ticket PR:size/L Denotes a Pull Request that changes 100-499 lines. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant