Skip to content

Commit 1db8839

Browse files
committed
Alter node client passing: OpenSearchPluginModule -> QueryService -> CalcitePlanContext
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent cee8a16 commit 1db8839

10 files changed

Lines changed: 26 additions & 45 deletions

File tree

core/src/main/java/org/opensearch/sql/calcite/CalcitePlanContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ public static CalcitePlanContext create(
9191
FrameworkConfig config, QueryType queryType, NodeClient client) {
9292
return new CalcitePlanContext(config, queryType, client);
9393
}
94+
95+
public static CalcitePlanContext create(FrameworkConfig config, QueryType queryType) {
96+
return new CalcitePlanContext(config, queryType, null);
97+
}
9498
}

core/src/main/java/org/opensearch/sql/datasource/DataSourceService.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.Set;
1010
import org.opensearch.sql.datasource.model.DataSource;
1111
import org.opensearch.sql.datasource.model.DataSourceMetadata;
12-
import org.opensearch.transport.client.node.NodeClient;
1312

1413
/** DataSource Service manage {@link DataSource}. */
1514
public interface DataSourceService {
@@ -88,13 +87,4 @@ public interface DataSourceService {
8887
*/
8988
DataSourceMetadata verifyDataSourceAccessAndGetRawMetadata(
9089
String dataSourceName, RequestContext context);
91-
92-
/**
93-
* Returns a NodeClient instance for executing requests against the OpenSearch cluster.
94-
*
95-
* @return NodeClient instance or throw an exception if not implemented.
96-
*/
97-
default NodeClient getNodeClient() {
98-
throw new UnsupportedOperationException("Not implemented");
99-
}
10090
}

core/src/main/java/org/opensearch/sql/executor/QueryService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.opensearch.sql.planner.Planner;
4545
import org.opensearch.sql.planner.logical.LogicalPlan;
4646
import org.opensearch.sql.planner.physical.PhysicalPlan;
47+
import org.opensearch.transport.client.node.NodeClient;
4748

4849
/** The low level interface of core engine. */
4950
@RequiredArgsConstructor
@@ -59,6 +60,7 @@ public class QueryService {
5960

6061
private DataSourceService dataSourceService;
6162
private Settings settings;
63+
private NodeClient nodeClient;
6264

6365
/** Execute the {@link UnresolvedPlan}, using {@link ResponseListener} to get response.<br> */
6466
public void execute(
@@ -94,8 +96,7 @@ public void executeWithCalcite(
9496
(PrivilegedAction<Void>)
9597
() -> {
9698
CalcitePlanContext context =
97-
CalcitePlanContext.create(
98-
buildFrameworkConfig(), queryType, dataSourceService.getNodeClient());
99+
CalcitePlanContext.create(buildFrameworkConfig(), queryType, nodeClient);
99100
RelNode relNode = analyze(plan, context);
100101
RelNode optimized = optimize(relNode);
101102
RelNode calcitePlan = convertToCalcitePlan(optimized);
@@ -127,8 +128,7 @@ public void explainWithCalcite(
127128
(PrivilegedAction<Void>)
128129
() -> {
129130
CalcitePlanContext context =
130-
CalcitePlanContext.create(
131-
buildFrameworkConfig(), queryType, dataSourceService.getNodeClient());
131+
CalcitePlanContext.create(buildFrameworkConfig(), queryType, nodeClient);
132132
RelNode relNode = analyze(plan, context);
133133
RelNode optimized = optimize(relNode);
134134
RelNode calcitePlan = convertToCalcitePlan(optimized);

datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceServiceImpl.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,14 @@ public class DataSourceServiceImpl implements DataSourceService {
4343

4444
private final DataSourceUserAuthorizationHelper dataSourceUserAuthorizationHelper;
4545

46-
/** Certain functions (e.g., GEOIP) depend on NodeClient for performing RPC calls. **/
47-
@Getter
48-
private final NodeClient nodeClient;
49-
5046
/** Construct from the set of {@link DataSourceFactory} at bootstrap time. */
51-
public DataSourceServiceImpl(
52-
Set<DataSourceFactory> dataSourceFactories,
53-
DataSourceMetadataStorage dataSourceMetadataStorage,
54-
DataSourceUserAuthorizationHelper dataSourceUserAuthorizationHelper) {
55-
this(
56-
dataSourceFactories,
57-
dataSourceMetadataStorage,
58-
dataSourceUserAuthorizationHelper,
59-
null);
60-
}
61-
6247
public DataSourceServiceImpl(
6348
Set<DataSourceFactory> dataSourceFactories,
6449
DataSourceMetadataStorage dataSourceMetadataStorage,
65-
DataSourceUserAuthorizationHelper dataSourceUserAuthorizationHelper,
66-
NodeClient nodeClient) {
50+
DataSourceUserAuthorizationHelper dataSourceUserAuthorizationHelper) {
6751
this.dataSourceMetadataStorage = dataSourceMetadataStorage;
6852
this.dataSourceUserAuthorizationHelper = dataSourceUserAuthorizationHelper;
6953
this.dataSourceLoaderCache = new DataSourceLoaderCacheImpl(dataSourceFactories);
70-
this.nodeClient = nodeClient;
7154
}
7255

7356
@Override

integ-test/src/test/java/org/opensearch/sql/calcite/standalone/CalcitePPLIntegTestCase.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ public void init() throws IOException {
8787
.add(new OpenSearchDataSourceFactory(client, getSettings()))
8888
.build(),
8989
getDataSourceMetadataStorage(),
90-
getDataSourceUserRoleHelper(),
91-
// Node client is not accessible and used in standalone tests, so we pass null
92-
null);
90+
getDataSourceUserRoleHelper());
9391
dataSourceService.createDataSource(defaultOpenSearchDataSourceMetadata());
9492

9593
ModulesBuilder modules = new ModulesBuilder();
@@ -372,8 +370,9 @@ public QueryPlanFactory queryPlanFactory(ExecutionEngine executionEngine) {
372370
new Analyzer(
373371
new ExpressionAnalyzer(functionRepository), dataSourceService, functionRepository);
374372
Planner planner = new Planner(LogicalPlanOptimizer.create());
373+
// NodeClient is not used in integration test, so we pass null
375374
QueryService queryService =
376-
new QueryService(analyzer, executionEngine, planner, dataSourceService, settings);
375+
new QueryService(analyzer, executionEngine, planner, dataSourceService, settings, null);
377376
return new QueryPlanFactory(queryService);
378377
}
379378
}

integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ public void init() throws Exception {
8484
.add(new OpenSearchDataSourceFactory(client, defaultSettings()))
8585
.build(),
8686
getDataSourceMetadataStorage(),
87-
getDataSourceUserRoleHelper(),
88-
// Node client is not accessible and used in standalone tests, so we pass null
89-
null);
87+
getDataSourceUserRoleHelper());
9088
dataSourceService.createDataSource(defaultOpenSearchDataSourceMetadata());
9189

9290
ModulesBuilder modules = new ModulesBuilder();

plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ private DataSourceServiceImpl createDataSourceService() {
326326
.add(new SecurityLakeDataSourceFactory(pluginSettings))
327327
.build(),
328328
dataSourceMetadataStorage,
329-
dataSourceUserAuthorizationHelper,
330-
client);
329+
dataSourceUserAuthorizationHelper);
331330
}
332331

333332
@Override

plugin/src/main/java/org/opensearch/sql/plugin/config/OpenSearchPluginModule.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,22 @@ public SQLService sqlService(QueryManager queryManager, QueryPlanFactory queryPl
9898
/** {@link QueryPlanFactory}. */
9999
@Provides
100100
public QueryPlanFactory queryPlanFactory(
101-
DataSourceService dataSourceService, ExecutionEngine executionEngine, Settings settings) {
101+
DataSourceService dataSourceService,
102+
ExecutionEngine executionEngine,
103+
Settings settings,
104+
OpenSearchClient client) {
102105
Analyzer analyzer =
103106
new Analyzer(
104107
new ExpressionAnalyzer(functionRepository), dataSourceService, functionRepository);
105108
Planner planner = new Planner(LogicalPlanOptimizer.create());
106109
QueryService queryService =
107-
new QueryService(analyzer, executionEngine, planner, dataSourceService, settings);
110+
new QueryService(
111+
analyzer,
112+
executionEngine,
113+
planner,
114+
dataSourceService,
115+
settings,
116+
client.getNodeClient());
108117
return new QueryPlanFactory(queryService);
109118
}
110119
}

ppl/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ dependencies {
5454
api project(':common')
5555
api project(':core')
5656
api project(':protocol')
57-
implementation group: 'org.opensearch.client', name: 'opensearch-rest-high-level-client', version: "${opensearch_version}"
5857

5958
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
6059
testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: "${hamcrest_version}"

ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLAbstractTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected CalcitePlanContext createBuilderContext() {
7474
private CalcitePlanContext createBuilderContext(UnaryOperator<RelBuilder.Config> transform) {
7575
config.context(Contexts.of(transform.apply(RelBuilder.Config.DEFAULT)));
7676
// NodeClient is not used in this test, so we pass null
77-
return CalcitePlanContext.create(config.build(), PPL, null);
77+
return CalcitePlanContext.create(config.build(), PPL);
7878
}
7979

8080
/** Get the root RelNode of the given PPL query */

0 commit comments

Comments
 (0)