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

Rework ExprMacro base classes to simplify implementations. #15622

Merged
merged 4 commits into from
Feb 12, 2024

Conversation

gianm
Copy link
Contributor

@gianm gianm commented Jan 3, 2024

This patch removes BaseScalarUnivariateMacroFunctionExpr, adds BaseMacroFunctionExpr at the top of the hierarchy (a suitable base class for ExprMacros that take either arrays or scalars), and adds an implementation for "visit" to BaseMacroFunctionExpr.

The effect on implementations is generally cleaner code:

  • Exprs no longer need to implement "visit".
  • Exprs no longer need to implement "stringify", even if they don't use all of their args at runtime, because BaseMacroFunctionExpr has access to even unused args.
  • Exprs that accept arrays can extend BaseMacroFunctionExpr and inherit a bunch of useful methods. The only one they need to implement themselves that scalar exprs don't is "supplyAnalyzeInputs".

gianm added 3 commits January 19, 2024 09:08
This patch removes BaseScalarUnivariateMacroFunctionExpr, adds
BaseMacroFunctionExpr at the top of the hierarchy (a suitable base class
for ExprMacros that take either arrays or scalars), and adds an
implementation for "visit" to BaseMacroFunctionExpr.

The effect on implementations is generally cleaner code:

- Exprs no longer need to implement "visit".
- Exprs no longer need to implement "stringify", even if they don't
  use all of their args at runtime, because BaseMacroFunctionExpr has
  access to even unused args.
- Exprs that accept arrays can extend BaseMacroFunctionExpr and
  inherit a bunch of useful methods. The only one they need to
  implement themselves that scalar exprs don't is "supplyAnalyzeInputs".
@gianm gianm force-pushed the expr-macro-rework branch from 8a2291e to 8f2f319 Compare January 19, 2024 17:08
Copy link
Member

@asdf2014 asdf2014 left a comment

Choose a reason for hiding this comment

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

Overall LGTM, also left some suggestions 😄

}
return new LikeExtractExpr(arg);
return new LikeExtractExpr(args);
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

Copy link
Member

Choose a reason for hiding this comment

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

nit: there are two blank lines

Copy link
Member

Choose a reason for hiding this comment

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

It would be better to use @see instead of @link here, like this way:

 * @see ContainsExprMacro for the case-sensitive version.

Copy link
Member

Choose a reason for hiding this comment

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

Same as above, for example:

 * @see CaseInsensitiveContainsExprMacro for the case-insensitive version.

List<Expr> newArgs = args.stream().map(x -> x.visit(shuttle)).collect(Collectors.toList());
return shuttle.visit(new JsonKeysExpr(newArgs));
}

@Nullable
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@Nullable
@NotNull

Copy link
Member

Choose a reason for hiding this comment

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

It seems that the getOutputType method always returns ExpressionType.STRING, so we should use @NotNull instead of @Nullable here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the @Nullable and left it without any annotation.

I don't think we have an official project style on this, so different people do different things, but I personally prefer to leave nonnullable things without any annotation. Most methods are not nullable and I feel like omitting the @NotNull annotation keeps the code cleaner. If it's important for a certain package, we could use @EverythingIsNonnullByDefault in package-info.java.

Copy link
Member

Choose a reason for hiding this comment

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

SGTM 👍

@@ -101,6 +95,6 @@ public ExpressionType getOutputType(InputBindingInspector inspector)
return null;
Copy link
Member

Choose a reason for hiding this comment

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

We can mark this method with @Nullable annotation

@gianm
Copy link
Contributor Author

gianm commented Feb 11, 2024

@asdf2014 thank you for the review. I made most of the changes you suggested.

@gianm
Copy link
Contributor Author

gianm commented Feb 12, 2024

This test is failing: standard-its / (Compile=openjdk8, Run=openjdk8, Cluster Build On K8s) ITNestedQueryPushDownTest integration test

It doesn't seem related, and is failing on other PRs too. So I will merge this one. Thanks again for the review.

@gianm gianm merged commit 0f6a895 into apache:master Feb 12, 2024
82 of 83 checks passed
@gianm gianm deleted the expr-macro-rework branch February 12, 2024 23:50
sreemanamala pushed a commit to sreemanamala/druid that referenced this pull request Feb 20, 2024
)

* Rework ExprMacro base classes to simplify implementations.

This patch removes BaseScalarUnivariateMacroFunctionExpr, adds
BaseMacroFunctionExpr at the top of the hierarchy (a suitable base class
for ExprMacros that take either arrays or scalars), and adds an
implementation for "visit" to BaseMacroFunctionExpr.

The effect on implementations is generally cleaner code:

- Exprs no longer need to implement "visit".
- Exprs no longer need to implement "stringify", even if they don't
  use all of their args at runtime, because BaseMacroFunctionExpr has
  access to even unused args.
- Exprs that accept arrays can extend BaseMacroFunctionExpr and
  inherit a bunch of useful methods. The only one they need to
  implement themselves that scalar exprs don't is "supplyAnalyzeInputs".

* Make StringDecodeBase64UTFExpression a static class.

* Remove unused import.

* Formatting, annotation changes.
@adarshsanjeev adarshsanjeev added this to the 30.0.0 milestone May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants