-
Notifications
You must be signed in to change notification settings - Fork 0
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 on now
function implementation
#113
Changes from 7 commits
c88a5ce
7534d46
0fa818d
eec2e19
2ea3a09
2c3047a
b9542d8
ce2e8bf
4008c75
6ef778d
64ccf47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
import org.opensearch.sql.ast.expression.EqualTo; | ||
import org.opensearch.sql.ast.expression.Field; | ||
import org.opensearch.sql.ast.expression.Function; | ||
import org.opensearch.sql.ast.expression.FunctionLikeConstant; | ||
import org.opensearch.sql.ast.expression.HighlightFunction; | ||
import org.opensearch.sql.ast.expression.In; | ||
import org.opensearch.sql.ast.expression.Interval; | ||
|
@@ -58,6 +59,7 @@ | |
import org.opensearch.sql.expression.aggregation.Aggregator; | ||
import org.opensearch.sql.expression.conditional.cases.CaseClause; | ||
import org.opensearch.sql.expression.conditional.cases.WhenClause; | ||
import org.opensearch.sql.expression.datetime.DateTimeFunction; | ||
import org.opensearch.sql.expression.function.BuiltinFunctionName; | ||
import org.opensearch.sql.expression.function.BuiltinFunctionRepository; | ||
import org.opensearch.sql.expression.function.FunctionName; | ||
|
@@ -169,6 +171,19 @@ public Expression visitRelevanceFieldList(RelevanceFieldList node, AnalysisConte | |
ImmutableMap.copyOf(node.getFieldList()))); | ||
} | ||
|
||
@Override | ||
public Expression visitFunctionLikeConstant(FunctionLikeConstant node, AnalysisContext context) { | ||
var valueName = node.toString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's sufficient to use
In the case of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, fixed in 4008c75. |
||
if (context.getFunctionLikeConstantValues().containsKey(valueName)) { | ||
return context.getFunctionLikeConstantValues().get(valueName); | ||
} | ||
|
||
var value = visitFunction(node, context); | ||
value = DSL.literal(value.valueOf(null)); | ||
context.getFunctionLikeConstantValues().put(valueName, value); | ||
return value; | ||
} | ||
|
||
@Override | ||
public Expression visitFunction(Function node, AnalysisContext context) { | ||
FunctionName functionName = FunctionName.of(node.getFuncName()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
|
||
package org.opensearch.sql.ast.expression; | ||
|
||
import java.util.List; | ||
import lombok.EqualsAndHashCode; | ||
import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
|
||
/** | ||
* Expression node that holds a function which should be replaced by its constant[1] value. | ||
* [1] Constant at execution time. | ||
*/ | ||
@EqualsAndHashCode(callSuper = false) | ||
public class FunctionLikeConstant extends Function { | ||
|
||
public FunctionLikeConstant(String funcName, List<UnresolvedExpression> funcArgs) { | ||
super(funcName, funcArgs); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(AbstractNodeVisitor<R, C> nodeVisitor, C context) { | ||
return nodeVisitor.visitFunctionLikeConstant(this, context); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Constant" suggests that the return value is hard-coded.
I would re-word this as a cache for function return values.
Maybe something like
functionToExpressionCache
.Note: It would be more useful if we could include arguments in the key, then we could use this cache to calculate and cache function calls with different arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to rename it.
Regarding arguments - they are already included, but
now
function (and all synonyms) doesn't accept argument anymore. Otherwise there is bug, whennow()
andnow(6)
have different values, because were calculated twice, because they can't cross-use cached value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. No arguments on
now
is fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming done in ce2e8bf.