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

Use query execution start time as the value of now-like functions. #149

Merged
merged 18 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/org/opensearch/sql/expression/DSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static NamedArgumentExpression namedArgument(String argName, Expression v
return new NamedArgumentExpression(argName, value);
}

public NamedArgumentExpression namedArgument(String name, String value) {
public static NamedArgumentExpression namedArgument(String name, String value) {
return namedArgument(name, literal(value));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static DefaultFunctionResolver avg() {
functionName,
new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>()
.put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
arguments -> new AvgAggregator(arguments, DOUBLE))
(functionProperties, arguments) -> new AvgAggregator(arguments, DOUBLE))
.build()
);
}
Expand All @@ -78,7 +78,7 @@ private static DefaultFunctionResolver count() {
DefaultFunctionResolver functionResolver = new DefaultFunctionResolver(functionName,
ExprCoreType.coreTypes().stream().collect(Collectors.toMap(
type -> new FunctionSignature(functionName, Collections.singletonList(type)),
type -> arguments -> new CountAggregator(arguments, INTEGER))));
type -> (functionProperties, arguments) -> new CountAggregator(arguments, INTEGER))));
return functionResolver;
}

Expand All @@ -88,13 +88,13 @@ private static DefaultFunctionResolver sum() {
functionName,
new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>()
.put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)),
arguments -> new SumAggregator(arguments, INTEGER))
(functionProperties, arguments) -> new SumAggregator(arguments, INTEGER))
.put(new FunctionSignature(functionName, Collections.singletonList(LONG)),
arguments -> new SumAggregator(arguments, LONG))
(functionProperties, arguments) -> new SumAggregator(arguments, LONG))
.put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)),
arguments -> new SumAggregator(arguments, FLOAT))
(functionProperties, arguments) -> new SumAggregator(arguments, FLOAT))
.put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
arguments -> new SumAggregator(arguments, DOUBLE))
(functionProperties, arguments) -> new SumAggregator(arguments, DOUBLE))
.build()
);
}
Expand All @@ -105,23 +105,23 @@ private static DefaultFunctionResolver min() {
functionName,
new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>()
.put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)),
arguments -> new MinAggregator(arguments, INTEGER))
(functionProperties, arguments) -> new MinAggregator(arguments, INTEGER))
.put(new FunctionSignature(functionName, Collections.singletonList(LONG)),
arguments -> new MinAggregator(arguments, LONG))
(functionProperties, arguments) -> new MinAggregator(arguments, LONG))
.put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)),
arguments -> new MinAggregator(arguments, FLOAT))
(functionProperties, arguments) -> new MinAggregator(arguments, FLOAT))
.put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
arguments -> new MinAggregator(arguments, DOUBLE))
(functionProperties, arguments) -> new MinAggregator(arguments, DOUBLE))
.put(new FunctionSignature(functionName, Collections.singletonList(STRING)),
arguments -> new MinAggregator(arguments, STRING))
(functionProperties, arguments) -> new MinAggregator(arguments, STRING))
.put(new FunctionSignature(functionName, Collections.singletonList(DATE)),
arguments -> new MinAggregator(arguments, DATE))
(functionProperties, arguments) -> new MinAggregator(arguments, DATE))
.put(new FunctionSignature(functionName, Collections.singletonList(DATETIME)),
arguments -> new MinAggregator(arguments, DATETIME))
(functionProperties, arguments) -> new MinAggregator(arguments, DATETIME))
.put(new FunctionSignature(functionName, Collections.singletonList(TIME)),
arguments -> new MinAggregator(arguments, TIME))
(functionProperties, arguments) -> new MinAggregator(arguments, TIME))
.put(new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)),
arguments -> new MinAggregator(arguments, TIMESTAMP))
(functionProperties, arguments) -> new MinAggregator(arguments, TIMESTAMP))
.build());
}

Expand All @@ -131,23 +131,23 @@ private static DefaultFunctionResolver max() {
functionName,
new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>()
.put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)),
arguments -> new MaxAggregator(arguments, INTEGER))
(functionProperties, arguments) -> new MaxAggregator(arguments, INTEGER))
.put(new FunctionSignature(functionName, Collections.singletonList(LONG)),
arguments -> new MaxAggregator(arguments, LONG))
(functionProperties, arguments) -> new MaxAggregator(arguments, LONG))
.put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)),
arguments -> new MaxAggregator(arguments, FLOAT))
(functionProperties, arguments) -> new MaxAggregator(arguments, FLOAT))
.put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
arguments -> new MaxAggregator(arguments, DOUBLE))
(functionProperties, arguments) -> new MaxAggregator(arguments, DOUBLE))
.put(new FunctionSignature(functionName, Collections.singletonList(STRING)),
arguments -> new MaxAggregator(arguments, STRING))
(functionProperties, arguments) -> new MaxAggregator(arguments, STRING))
.put(new FunctionSignature(functionName, Collections.singletonList(DATE)),
arguments -> new MaxAggregator(arguments, DATE))
(functionProperties, arguments) -> new MaxAggregator(arguments, DATE))
.put(new FunctionSignature(functionName, Collections.singletonList(DATETIME)),
arguments -> new MaxAggregator(arguments, DATETIME))
(functionProperties, arguments) -> new MaxAggregator(arguments, DATETIME))
.put(new FunctionSignature(functionName, Collections.singletonList(TIME)),
arguments -> new MaxAggregator(arguments, TIME))
(functionProperties, arguments) -> new MaxAggregator(arguments, TIME))
.put(new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)),
arguments -> new MaxAggregator(arguments, TIMESTAMP))
(functionProperties, arguments) -> new MaxAggregator(arguments, TIMESTAMP))
.build()
);
}
Expand All @@ -158,7 +158,7 @@ private static DefaultFunctionResolver varSamp() {
functionName,
new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>()
.put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
arguments -> varianceSample(arguments, DOUBLE))
(functionProperties, arguments) -> varianceSample(arguments, DOUBLE))
.build()
);
}
Expand All @@ -169,7 +169,7 @@ private static DefaultFunctionResolver varPop() {
functionName,
new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>()
.put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
arguments -> variancePopulation(arguments, DOUBLE))
(functionProperties, arguments) -> variancePopulation(arguments, DOUBLE))
.build()
);
}
Expand All @@ -180,7 +180,7 @@ private static DefaultFunctionResolver stddevSamp() {
functionName,
new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>()
.put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
arguments -> stddevSample(arguments, DOUBLE))
(functionProperties, arguments) -> stddevSample(arguments, DOUBLE))
.build()
);
}
Expand All @@ -191,7 +191,7 @@ private static DefaultFunctionResolver stddevPop() {
functionName,
new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>()
.put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)),
arguments -> stddevPopulation(arguments, DOUBLE))
(functionProperties, arguments) -> stddevPopulation(arguments, DOUBLE))
.build()
);
}
Expand All @@ -201,7 +201,7 @@ private static DefaultFunctionResolver take() {
DefaultFunctionResolver functionResolver = new DefaultFunctionResolver(functionName,
new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>()
.put(new FunctionSignature(functionName, ImmutableList.of(STRING, INTEGER)),
arguments -> new TakeAggregator(arguments, ARRAY))
(functionProperties, arguments) -> new TakeAggregator(arguments, ARRAY))
.build());
return functionResolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

package org.opensearch.sql.expression.config;

import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
import java.util.HashMap;
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.aggregation.AggregatorFunction;
import org.opensearch.sql.expression.datetime.DateTimeFunction;
import org.opensearch.sql.expression.datetime.IntervalClause;
import org.opensearch.sql.expression.function.BuiltinFunctionRepository;
import org.opensearch.sql.expression.function.FunctionProperties;
import org.opensearch.sql.expression.function.OpenSearchFunctions;
import org.opensearch.sql.expression.operator.arthmetic.ArithmeticFunction;
import org.opensearch.sql.expression.operator.arthmetic.MathematicalFunction;
Expand All @@ -33,9 +37,10 @@ public class ExpressionConfig {
* BuiltinFunctionRepository constructor.
*/
@Bean
public BuiltinFunctionRepository functionRepository() {
public BuiltinFunctionRepository functionRepository(FunctionProperties functionContext) {

BuiltinFunctionRepository builtinFunctionRepository =
new BuiltinFunctionRepository(new HashMap<>());
new BuiltinFunctionRepository(new HashMap<>(), functionContext);
ArithmeticFunction.register(builtinFunctionRepository);
BinaryPredicateOperator.register(builtinFunctionRepository);
MathematicalFunction.register(builtinFunctionRepository);
Expand All @@ -51,8 +56,14 @@ public BuiltinFunctionRepository functionRepository() {
return builtinFunctionRepository;
}

@Bean
public FunctionProperties functionExecutionContext() {
return new FunctionProperties(Instant.now(), ZoneId.systemDefault());
}

@Bean
public DSL dsl(BuiltinFunctionRepository repository) {
return new DSL(repository);
}

}
Loading