|
18 | 18 | import java.util.List; |
19 | 19 | import java.util.Map; |
20 | 20 | import java.util.concurrent.atomic.AtomicReference; |
21 | | -import lombok.RequiredArgsConstructor; |
22 | 21 | import org.apache.calcite.plan.RelOptUtil; |
23 | 22 | import org.apache.calcite.rel.RelNode; |
24 | 23 | import org.apache.calcite.rel.RelRoot; |
|
38 | 37 | import org.opensearch.sql.executor.ExecutionEngine.Schema.Column; |
39 | 38 | import org.opensearch.sql.executor.Explain; |
40 | 39 | import org.opensearch.sql.executor.pagination.PlanSerializer; |
| 40 | +import org.opensearch.sql.expression.function.BuiltinFunctionName; |
| 41 | +import org.opensearch.sql.expression.function.PPLFuncImpTable; |
41 | 42 | import org.opensearch.sql.opensearch.client.OpenSearchClient; |
42 | 43 | import org.opensearch.sql.opensearch.executor.protector.ExecutionProtector; |
| 44 | +import org.opensearch.sql.opensearch.functions.GeoIpFunction; |
43 | 45 | import org.opensearch.sql.opensearch.util.JdbcOpenSearchDataTypeConvertor; |
44 | 46 | import org.opensearch.sql.planner.physical.PhysicalPlan; |
45 | 47 | import org.opensearch.sql.storage.TableScanOperator; |
46 | 48 |
|
47 | 49 | /** OpenSearch execution engine implementation. */ |
48 | | -@RequiredArgsConstructor |
49 | 50 | public class OpenSearchExecutionEngine implements ExecutionEngine { |
50 | 51 |
|
51 | 52 | private final OpenSearchClient client; |
52 | 53 |
|
53 | 54 | private final ExecutionProtector executionProtector; |
54 | 55 | private final PlanSerializer planSerializer; |
55 | 56 |
|
| 57 | + public OpenSearchExecutionEngine( |
| 58 | + OpenSearchClient client, |
| 59 | + ExecutionProtector executionProtector, |
| 60 | + PlanSerializer planSerializer) { |
| 61 | + this.client = client; |
| 62 | + this.executionProtector = executionProtector; |
| 63 | + this.planSerializer = planSerializer; |
| 64 | + registerOpenSearchFunctions(); |
| 65 | + } |
| 66 | + |
56 | 67 | @Override |
57 | 68 | public void execute(PhysicalPlan physicalPlan, ResponseListener<QueryResponse> listener) { |
58 | 69 | execute(physicalPlan, ExecutionContext.emptyExecutionContext(), listener); |
@@ -224,4 +235,12 @@ private void buildResultSet( |
224 | 235 | QueryResponse response = new QueryResponse(schema, values, null); |
225 | 236 | listener.onResponse(response); |
226 | 237 | } |
| 238 | + |
| 239 | + /** Registers opensearch-dependent functions */ |
| 240 | + private void registerOpenSearchFunctions() { |
| 241 | + PPLFuncImpTable.FunctionImp geoIpImpl = |
| 242 | + (builder, args) -> |
| 243 | + builder.makeCall(new GeoIpFunction(client.getNodeClient()).toUDF("GEOIP"), args); |
| 244 | + PPLFuncImpTable.INSTANCE.registerExternalFunction(BuiltinFunctionName.GEOIP, geoIpImpl); |
| 245 | + } |
227 | 246 | } |
0 commit comments