Skip to content

Commit

Permalink
Decouple function repository and DSL from IoC container for use anywh…
Browse files Browse the repository at this point in the history
…ere (#1085)

* Make function repository singleton

Signed-off-by: Chen Dai <[email protected]>

* Make all DSL function static

Signed-off-by: Chen Dai <[email protected]>

* Clean up unused imports

Signed-off-by: Chen Dai <[email protected]>

* Update javadoc with more context

Signed-off-by: Chen Dai <[email protected]>

* Remove expression config

Signed-off-by: Chen Dai <[email protected]>

* Add TODO comment

Signed-off-by: Chen Dai <[email protected]>

* Fixed build failure

Signed-off-by: Chen Dai <[email protected]>

* Address PR comments

Signed-off-by: Chen Dai <[email protected]>

Signed-off-by: Chen Dai <[email protected]>
  • Loading branch information
dai-chen authored Nov 17, 2022
1 parent cdb30ee commit 81c9285
Show file tree
Hide file tree
Showing 84 changed files with 2,207 additions and 2,391 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.opensearch.sql.ast.expression.AggregateFunction;
import org.opensearch.sql.ast.expression.AllFields;
import org.opensearch.sql.ast.expression.And;
import org.opensearch.sql.ast.expression.Argument;
import org.opensearch.sql.ast.expression.Case;
import org.opensearch.sql.ast.expression.Cast;
import org.opensearch.sql.ast.expression.Compare;
Expand Down Expand Up @@ -74,7 +73,6 @@
public class ExpressionAnalyzer extends AbstractNodeVisitor<Expression, AnalysisContext> {
@Getter
private final BuiltinFunctionRepository repository;
private final DSL dsl;

@Override
public Expression visitCast(Cast node, AnalysisContext context) {
Expand All @@ -86,7 +84,6 @@ public Expression visitCast(Cast node, AnalysisContext context) {
public ExpressionAnalyzer(
BuiltinFunctionRepository repository) {
this.repository = repository;
this.dsl = new DSL(repository);
}

public Expression analyze(UnresolvedExpression unresolved, AnalysisContext context) {
Expand All @@ -103,7 +100,7 @@ public Expression visitEqualTo(EqualTo node, AnalysisContext context) {
Expression left = node.getLeft().accept(this, context);
Expression right = node.getRight().accept(this, context);

return dsl.equal(left, right);
return DSL.equal(left, right);
}

@Override
Expand All @@ -116,36 +113,36 @@ public Expression visitLiteral(Literal node, AnalysisContext context) {
public Expression visitInterval(Interval node, AnalysisContext context) {
Expression value = node.getValue().accept(this, context);
Expression unit = DSL.literal(node.getUnit().name());
return dsl.interval(value, unit);
return DSL.interval(value, unit);
}

@Override
public Expression visitAnd(And node, AnalysisContext context) {
Expression left = node.getLeft().accept(this, context);
Expression right = node.getRight().accept(this, context);

return dsl.and(left, right);
return DSL.and(left, right);
}

@Override
public Expression visitOr(Or node, AnalysisContext context) {
Expression left = node.getLeft().accept(this, context);
Expression right = node.getRight().accept(this, context);

return dsl.or(left, right);
return DSL.or(left, right);
}

@Override
public Expression visitXor(Xor node, AnalysisContext context) {
Expression left = node.getLeft().accept(this, context);
Expression right = node.getRight().accept(this, context);

return dsl.xor(left, right);
return DSL.xor(left, right);
}

@Override
public Expression visitNot(Not node, AnalysisContext context) {
return dsl.not(node.getExpression().accept(this, context));
return DSL.not(node.getExpression().accept(this, context));
}

@Override
Expand Down Expand Up @@ -226,7 +223,7 @@ private Expression visitIn(
if (valueList.size() == 1) {
return visitCompare(new Compare("=", field, valueList.get(0)), context);
} else if (valueList.size() > 1) {
return dsl.or(
return DSL.or(
visitCompare(new Compare("=", field, valueList.get(0)), context),
visitIn(field, valueList.subList(1, valueList.size()), context));
} else {
Expand Down
Loading

0 comments on commit 81c9285

Please sign in to comment.