You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "AlbericByte (via GitHub)" <gi...@apache.org> on 2023/12/16 00:33:20 UTC
[PR] Support to pass dynamic values to timestamp Extract function (druid)
AlbericByte opened a new pull request, #15586:
URL: https://github.com/apache/druid/pull/15586
<!-- Thanks for trying to help us make Apache Druid be the best it can be! Please fill out as much of the following information as is possible (where relevant, and remove it when irrelevant) to help make the intention and scope of this PR clear in order to ease review. -->
<!-- Please read the doc for contribution (https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making this PR. Also, once you open a PR, please _avoid using force pushes and rebasing_ since these make it difficult for reviewers to see what you've changed in response to their reviews. See [the 'If your pull request shows conflicts with master' section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master) for more details. -->
Fixes #15072
<!-- Replace XXXX with the id of the issue fixed in this PR. Remove this section if there is no corresponding issue. Don't reference the issue in the title of this pull-request. -->
<!-- If you are a committer, follow the PR action item checklist for committers:
https://github.com/apache/druid/blob/master/dev/committer-instructions.md#pr-and-issue-action-item-checklist-for-committers. -->
### Description
<!-- Describe the goal of this PR, what problem are you fixing. If there is a corresponding issue (referenced above), it's not necessary to repeat the description here, however, you may choose to keep one summary sentence. -->
Before this modification , the third parameter (timezone) require to be a Literal, it will throw a error when this parameter is column Identifier.
<!-- Describe your patch: what did you change in code? How did you fix the problem? -->
<!-- If there are several relatively logically separate changes in this PR, create a mini-section for each of them. For example: -->
<!--
In each section, please describe design decisions made, including:
- Choice of algorithms
- Behavioral aspects. What configuration values are acceptable? How are corner cases and error conditions handled, such as when there are insufficient resources?
- Class organization and design (how the logic is split between classes, inheritance, composition, design patterns)
- Method organization and design (how the logic is split between methods, parameters and return types)
- Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
-->
<!-- It's good to describe an alternative design (or mention an alternative name) for every design (or naming) decision point and compare the alternatives with the designs that you've implemented (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
<!-- If there was a discussion of the design of the feature implemented in this PR elsewhere (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), link to that discussion from this PR description and explain what have changed in your final design compared to your original proposal or the consensus version in the end of the discussion. If something hasn't changed since the original discussion, you can omit a detailed discussion of those aspects of the design here, perhaps apart from brief mentioning for the sake of readability of this PR description. -->
<!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
#### Release note
<!-- Give your best effort to summarize your changes in a couple of sentences aimed toward Druid users.
If your change doesn't have end user impact, you can skip this section.
For tips about how to write a good release note, see [Release notes](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#release-notes).
-->
<hr>
##### Key changed/added classes in this PR
* Updated the validation
* Updated TimestampExtractExprMacro class
* Added a unit test in TimestampExtractExprMacroTest
<hr>
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
This PR has:
- [ *] been self-reviewed.
- [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [*] added integration tests.
- [*] been tested in a test Druid cluster.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "AlbericByte (via GitHub)" <gi...@apache.org>.
AlbericByte commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1433103108
##########
processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java:
##########
@@ -73,38 +74,39 @@ public Expr apply(final List<Expr> args)
throw validationFailed("unit arg must be literal");
}
- if (args.size() > 2) {
- validationHelperCheckArgIsLiteral(args.get(2), "timezone");
+ ISOChronology chronology = null;
+ if (args.size() > 2 && args.get(2).isLiteral()) {
+ DateTimeZone timeZone = ExprUtils.toTimeZone(args.get(2));
+ chronology = ISOChronology.getInstance(timeZone);
}
- final Expr arg = args.get(0);
final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) args.get(1).getLiteralValue()));
- final DateTimeZone timeZone;
- if (args.size() > 2) {
- timeZone = ExprUtils.toTimeZone(args.get(2));
- } else {
- timeZone = DateTimeZone.UTC;
- }
-
- final ISOChronology chronology = ISOChronology.getInstance(timeZone);
-
- class TimestampExtractExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr
+ class TimestampExtractExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr
Review Comment:
good catch and suggestion @clintropolis followed the example and fixed in the latest commit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "AlbericByte (via GitHub)" <gi...@apache.org>.
AlbericByte commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1431999152
##########
processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java:
##########
@@ -73,38 +75,39 @@ public Expr apply(final List<Expr> args)
throw validationFailed("unit arg must be literal");
}
- if (args.size() > 2) {
- validationHelperCheckArgIsLiteral(args.get(2), "timezone");
+ Optional<DateTimeZone> timeZone = Optional.empty();
+ if (args.size() > 2 && args.get(2).isLiteral()) {
+ timeZone = Optional.of(ExprUtils.toTimeZone(args.get(2)));
}
- final Expr arg = args.get(0);
Review Comment:
no reference for this arg, so I removed it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1430920807
##########
sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionsTest.java:
##########
@@ -1844,6 +1843,17 @@
makeExpression(ColumnType.LONG, "timestamp_extract(\"t\",'DAY','America/Los_Angeles')"),
2L
);
+
+ testHelper.testExpressionString(
+ new TimeExtractOperatorConversion().calciteOperator(),
+ ImmutableList.of(
+ testHelper.makeInputRef("t"),
+ testHelper.makeLiteral("DAY"),
+ testHelper.makeInputRef("timezone")
+ ),
+ makeExpression(ColumnType.LONG, "timestamp_extract(\"t\",'DAY',\"timezone\")"),
Review Comment:
## Deprecated method or constructor invocation
Invoking [CalciteTestBase.makeExpression](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/6384)
##########
sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionsTest.java:
##########
@@ -1844,6 +1843,17 @@
makeExpression(ColumnType.LONG, "timestamp_extract(\"t\",'DAY','America/Los_Angeles')"),
2L
);
+
+ testHelper.testExpressionString(
+ new TimeExtractOperatorConversion().calciteOperator(),
+ ImmutableList.of(
+ testHelper.makeInputRef("t"),
+ testHelper.makeLiteral("DAY"),
+ testHelper.makeInputRef("timezone")
+ ),
+ makeExpression(ColumnType.LONG, "timestamp_extract(\"t\",'DAY',\"timezone\")"),
+ 2L
+ );
Review Comment:
## Deprecated method or constructor invocation
Invoking [ExpressionTestHelper.testExpressionString](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/6383)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "abhishekagarwal87 (via GitHub)" <gi...@apache.org>.
abhishekagarwal87 commented on PR #15586:
URL: https://github.com/apache/druid/pull/15586#issuecomment-1865603852
thank you for your contribution @AlbericByte
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "AlbericByte (via GitHub)" <gi...@apache.org>.
AlbericByte commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1431999423
##########
processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java:
##########
@@ -73,38 +75,39 @@ public Expr apply(final List<Expr> args)
throw validationFailed("unit arg must be literal");
}
- if (args.size() > 2) {
- validationHelperCheckArgIsLiteral(args.get(2), "timezone");
+ Optional<DateTimeZone> timeZone = Optional.empty();
+ if (args.size() > 2 && args.get(2).isLiteral()) {
+ timeZone = Optional.of(ExprUtils.toTimeZone(args.get(2)));
}
- final Expr arg = args.get(0);
final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) args.get(1).getLiteralValue()));
- final DateTimeZone timeZone;
- if (args.size() > 2) {
- timeZone = ExprUtils.toTimeZone(args.get(2));
- } else {
- timeZone = DateTimeZone.UTC;
- }
-
- final ISOChronology chronology = ISOChronology.getInstance(timeZone);
+ final Optional<ISOChronology> chronologyOptional = timeZone.map(value -> ISOChronology.getInstance(value));
- class TimestampExtractExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr
+ class TimestampExtractExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr
{
- private TimestampExtractExpr(Expr arg)
+ private TimestampExtractExpr(List<Expr> args)
{
- super(FN_NAME, arg);
+ super(FN_NAME, args);
}
@Nonnull
@Override
public ExprEval eval(final ObjectBinding bindings)
{
- Object val = arg.eval(bindings).value();
+ Object val = args.get(0).eval(bindings).value();
if (val == null) {
// Return null if the argument if null.
return ExprEval.of(null);
}
+ final ISOChronology chronology = chronologyOptional.orElseGet(() -> {
+ Optional<String> timeZoneOptional = args.size() > 2
Review Comment:
fixed in the latest commit. @abhishekagarwal87 Thanks for you suggestion and time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "abhishekagarwal87 (via GitHub)" <gi...@apache.org>.
abhishekagarwal87 commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1431251372
##########
processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java:
##########
@@ -73,38 +75,39 @@ public Expr apply(final List<Expr> args)
throw validationFailed("unit arg must be literal");
}
- if (args.size() > 2) {
- validationHelperCheckArgIsLiteral(args.get(2), "timezone");
+ Optional<DateTimeZone> timeZone = Optional.empty();
+ if (args.size() > 2 && args.get(2).isLiteral()) {
+ timeZone = Optional.of(ExprUtils.toTimeZone(args.get(2)));
}
- final Expr arg = args.get(0);
final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) args.get(1).getLiteralValue()));
- final DateTimeZone timeZone;
- if (args.size() > 2) {
- timeZone = ExprUtils.toTimeZone(args.get(2));
- } else {
- timeZone = DateTimeZone.UTC;
- }
-
- final ISOChronology chronology = ISOChronology.getInstance(timeZone);
+ final Optional<ISOChronology> chronologyOptional = timeZone.map(value -> ISOChronology.getInstance(value));
- class TimestampExtractExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr
+ class TimestampExtractExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr
{
- private TimestampExtractExpr(Expr arg)
+ private TimestampExtractExpr(List<Expr> args)
{
- super(FN_NAME, arg);
+ super(FN_NAME, args);
}
@Nonnull
@Override
public ExprEval eval(final ObjectBinding bindings)
{
- Object val = arg.eval(bindings).value();
+ Object val = args.get(0).eval(bindings).value();
if (val == null) {
// Return null if the argument if null.
return ExprEval.of(null);
}
+ final ISOChronology chronology = chronologyOptional.orElseGet(() -> {
+ Optional<String> timeZoneOptional = args.size() > 2
Review Comment:
I also think the usage of Optional is unnecessary here given that the usage is contained within this class. So you could also do good-ol if-null-then-x-else-y style of code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "AlbericByte (via GitHub)" <gi...@apache.org>.
AlbericByte commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1433207345
##########
processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java:
##########
@@ -73,38 +74,39 @@ public Expr apply(final List<Expr> args)
throw validationFailed("unit arg must be literal");
}
- if (args.size() > 2) {
- validationHelperCheckArgIsLiteral(args.get(2), "timezone");
+ ISOChronology chronology = null;
+ if (args.size() > 2 && args.get(2).isLiteral()) {
+ DateTimeZone timeZone = ExprUtils.toTimeZone(args.get(2));
+ chronology = ISOChronology.getInstance(timeZone);
}
- final Expr arg = args.get(0);
final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) args.get(1).getLiteralValue()));
- final DateTimeZone timeZone;
- if (args.size() > 2) {
- timeZone = ExprUtils.toTimeZone(args.get(2));
- } else {
- timeZone = DateTimeZone.UTC;
- }
-
- final ISOChronology chronology = ISOChronology.getInstance(timeZone);
-
- class TimestampExtractExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr
+ class TimestampExtractExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr
Review Comment:
@clintropolis and @abhishekagarwal87 the unit test cases("Remote driver error: Unauthorized" and "leadership changed") failed which should be not relative to my modification.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "abhishekagarwal87 (via GitHub)" <gi...@apache.org>.
abhishekagarwal87 commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1431245009
##########
processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java:
##########
@@ -73,38 +75,39 @@ public Expr apply(final List<Expr> args)
throw validationFailed("unit arg must be literal");
}
- if (args.size() > 2) {
- validationHelperCheckArgIsLiteral(args.get(2), "timezone");
+ Optional<DateTimeZone> timeZone = Optional.empty();
+ if (args.size() > 2 && args.get(2).isLiteral()) {
+ timeZone = Optional.of(ExprUtils.toTimeZone(args.get(2)));
}
- final Expr arg = args.get(0);
Review Comment:
you could still keep it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "abhishekagarwal87 (via GitHub)" <gi...@apache.org>.
abhishekagarwal87 commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1431248175
##########
processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java:
##########
@@ -73,38 +75,39 @@ public Expr apply(final List<Expr> args)
throw validationFailed("unit arg must be literal");
}
- if (args.size() > 2) {
- validationHelperCheckArgIsLiteral(args.get(2), "timezone");
+ Optional<DateTimeZone> timeZone = Optional.empty();
+ if (args.size() > 2 && args.get(2).isLiteral()) {
+ timeZone = Optional.of(ExprUtils.toTimeZone(args.get(2)));
}
- final Expr arg = args.get(0);
final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) args.get(1).getLiteralValue()));
- final DateTimeZone timeZone;
- if (args.size() > 2) {
- timeZone = ExprUtils.toTimeZone(args.get(2));
- } else {
- timeZone = DateTimeZone.UTC;
- }
-
- final ISOChronology chronology = ISOChronology.getInstance(timeZone);
+ final Optional<ISOChronology> chronologyOptional = timeZone.map(value -> ISOChronology.getInstance(value));
- class TimestampExtractExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr
+ class TimestampExtractExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr
{
- private TimestampExtractExpr(Expr arg)
+ private TimestampExtractExpr(List<Expr> args)
{
- super(FN_NAME, arg);
+ super(FN_NAME, args);
}
@Nonnull
@Override
public ExprEval eval(final ObjectBinding bindings)
{
- Object val = arg.eval(bindings).value();
+ Object val = args.get(0).eval(bindings).value();
if (val == null) {
// Return null if the argument if null.
return ExprEval.of(null);
}
+ final ISOChronology chronology = chronologyOptional.orElseGet(() -> {
+ Optional<String> timeZoneOptional = args.size() > 2
Review Comment:
We could avoid this check in eval and set zone to UTC outside eval itself is args size is less than or equal to 2
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "abhishekagarwal87 (via GitHub)" <gi...@apache.org>.
abhishekagarwal87 merged PR #15586:
URL: https://github.com/apache/druid/pull/15586
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "AlbericByte (via GitHub)" <gi...@apache.org>.
AlbericByte commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1432057331
##########
processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java:
##########
@@ -73,38 +75,39 @@ public Expr apply(final List<Expr> args)
throw validationFailed("unit arg must be literal");
}
- if (args.size() > 2) {
- validationHelperCheckArgIsLiteral(args.get(2), "timezone");
+ Optional<DateTimeZone> timeZone = Optional.empty();
+ if (args.size() > 2 && args.get(2).isLiteral()) {
+ timeZone = Optional.of(ExprUtils.toTimeZone(args.get(2)));
}
- final Expr arg = args.get(0);
final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) args.get(1).getLiteralValue()));
- final DateTimeZone timeZone;
- if (args.size() > 2) {
- timeZone = ExprUtils.toTimeZone(args.get(2));
- } else {
- timeZone = DateTimeZone.UTC;
- }
-
- final ISOChronology chronology = ISOChronology.getInstance(timeZone);
+ final Optional<ISOChronology> chronologyOptional = timeZone.map(value -> ISOChronology.getInstance(value));
- class TimestampExtractExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr
+ class TimestampExtractExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr
{
- private TimestampExtractExpr(Expr arg)
+ private TimestampExtractExpr(List<Expr> args)
{
- super(FN_NAME, arg);
+ super(FN_NAME, args);
}
@Nonnull
@Override
public ExprEval eval(final ObjectBinding bindings)
{
- Object val = arg.eval(bindings).value();
+ Object val = args.get(0).eval(bindings).value();
if (val == null) {
// Return null if the argument if null.
return ExprEval.of(null);
}
+ final ISOChronology chronology = chronologyOptional.orElseGet(() -> {
+ Optional<String> timeZoneOptional = args.size() > 2
Review Comment:
the test error "Error while executing SQL "SELECT * FROM INFORMATION_SCHEMA.COLUMNS": Remote driver error: Unauthorized" should be irrelevant to my modification.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1432176937
##########
processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java:
##########
@@ -73,38 +74,39 @@ public Expr apply(final List<Expr> args)
throw validationFailed("unit arg must be literal");
}
- if (args.size() > 2) {
- validationHelperCheckArgIsLiteral(args.get(2), "timezone");
+ ISOChronology chronology = null;
+ if (args.size() > 2 && args.get(2).isLiteral()) {
+ DateTimeZone timeZone = ExprUtils.toTimeZone(args.get(2));
+ chronology = ISOChronology.getInstance(timeZone);
}
- final Expr arg = args.get(0);
final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) args.get(1).getLiteralValue()));
- final DateTimeZone timeZone;
- if (args.size() > 2) {
- timeZone = ExprUtils.toTimeZone(args.get(2));
- } else {
- timeZone = DateTimeZone.UTC;
- }
-
- final ISOChronology chronology = ISOChronology.getInstance(timeZone);
-
- class TimestampExtractExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr
+ class TimestampExtractExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr
Review Comment:
drive by comment: because `eval` is called every row, we often will split up implementations of `Expr` when one form has a dynamic argument that needs evaluated every row, see [`TimestampFloorExprMacro`](https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/query/expression/TimestampFloorExprMacro.java#L52) for example. This allows cases where the argument is a constant to skip some work.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Support to pass dynamic values to timestamp Extract function (druid)
Posted by "AlbericByte (via GitHub)" <gi...@apache.org>.
AlbericByte commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1431999423
##########
processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java:
##########
@@ -73,38 +75,39 @@ public Expr apply(final List<Expr> args)
throw validationFailed("unit arg must be literal");
}
- if (args.size() > 2) {
- validationHelperCheckArgIsLiteral(args.get(2), "timezone");
+ Optional<DateTimeZone> timeZone = Optional.empty();
+ if (args.size() > 2 && args.get(2).isLiteral()) {
+ timeZone = Optional.of(ExprUtils.toTimeZone(args.get(2)));
}
- final Expr arg = args.get(0);
final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) args.get(1).getLiteralValue()));
- final DateTimeZone timeZone;
- if (args.size() > 2) {
- timeZone = ExprUtils.toTimeZone(args.get(2));
- } else {
- timeZone = DateTimeZone.UTC;
- }
-
- final ISOChronology chronology = ISOChronology.getInstance(timeZone);
+ final Optional<ISOChronology> chronologyOptional = timeZone.map(value -> ISOChronology.getInstance(value));
- class TimestampExtractExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr
+ class TimestampExtractExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr
{
- private TimestampExtractExpr(Expr arg)
+ private TimestampExtractExpr(List<Expr> args)
{
- super(FN_NAME, arg);
+ super(FN_NAME, args);
}
@Nonnull
@Override
public ExprEval eval(final ObjectBinding bindings)
{
- Object val = arg.eval(bindings).value();
+ Object val = args.get(0).eval(bindings).value();
if (val == null) {
// Return null if the argument if null.
return ExprEval.of(null);
}
+ final ISOChronology chronology = chronologyOptional.orElseGet(() -> {
+ Optional<String> timeZoneOptional = args.size() > 2
Review Comment:
fixed in the latest commit. Thanks for you suggestion and time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org