forked from opensearch-project/opensearch-spark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalcitePlanContext.java
40 lines (31 loc) · 1.2 KB
/
CalcitePlanContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
package org.opensearch.sql.calcite;
import lombok.Getter;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.tools.FrameworkConfig;
import org.apache.calcite.tools.RelBuilder;
import org.opensearch.sql.ast.expression.UnresolvedExpression;
import java.util.function.BiFunction;
public class CalcitePlanContext {
public final RelBuilder relBuilder;
public final ExtendedRexBuilder rexBuilder;
@Getter private boolean isResolvingJoinCondition = false;
public CalcitePlanContext(RelBuilder relBuilder) {
this.relBuilder = relBuilder;
this.rexBuilder = new ExtendedRexBuilder(relBuilder.getRexBuilder());
}
public RexNode resolveJoinCondition(
UnresolvedExpression expr,
BiFunction<UnresolvedExpression, CalcitePlanContext, RexNode> transformFunction) {
isResolvingJoinCondition = true;
RexNode result = transformFunction.apply(expr, this);
isResolvingJoinCondition = false;
return result;
}
public static CalcitePlanContext create(FrameworkConfig config) {
return new CalcitePlanContext(RelBuilder.create(config));
}
}