1111import static org .opensearch .sql .ast .tree .Sort .SortOrder .ASC ;
1212import static org .opensearch .sql .ast .tree .Sort .SortOrder .DESC ;
1313import static org .opensearch .sql .data .type .ExprCoreType .STRUCT ;
14- import static org .opensearch .sql .utils .MLCommonsConstants .ACTION ;
15- import static org .opensearch .sql .utils .MLCommonsConstants .MODELID ;
16- import static org .opensearch .sql .utils .MLCommonsConstants .PREDICT ;
1714import static org .opensearch .sql .utils .MLCommonsConstants .RCF_ANOMALOUS ;
1815import static org .opensearch .sql .utils .MLCommonsConstants .RCF_ANOMALY_GRADE ;
1916import static org .opensearch .sql .utils .MLCommonsConstants .RCF_SCORE ;
20- import static org .opensearch .sql .utils .MLCommonsConstants .RCF_TIMESTAMP ;
21- import static org .opensearch .sql .utils .MLCommonsConstants .STATUS ;
22- import static org .opensearch .sql .utils .MLCommonsConstants .TASKID ;
2317import static org .opensearch .sql .utils .MLCommonsConstants .TIME_FIELD ;
24- import static org .opensearch .sql .utils .MLCommonsConstants .TRAIN ;
25- import static org .opensearch .sql .utils .MLCommonsConstants .TRAINANDPREDICT ;
26- import static org .opensearch .sql .utils .SystemIndexUtils .CATALOGS_TABLE_NAME ;
18+ import static org .opensearch .sql .utils .SystemIndexUtils .DATASOURCES_TABLE_NAME ;
2719
2820import com .google .common .collect .ImmutableList ;
2921import com .google .common .collect .ImmutableList .Builder ;
3729import java .util .stream .Collectors ;
3830import org .apache .commons .lang3 .tuple .ImmutablePair ;
3931import org .apache .commons .lang3 .tuple .Pair ;
40- import org .opensearch .sql .CatalogSchemaName ;
32+ import org .opensearch .sql .DataSourceSchemaName ;
4133import org .opensearch .sql .analysis .symbol .Namespace ;
4234import org .opensearch .sql .analysis .symbol .Symbol ;
4335import org .opensearch .sql .ast .AbstractNodeVisitor ;
6961import org .opensearch .sql .ast .tree .TableFunction ;
7062import org .opensearch .sql .ast .tree .UnresolvedPlan ;
7163import org .opensearch .sql .ast .tree .Values ;
72- import org .opensearch .sql .catalog .CatalogService ;
73- import org .opensearch .sql .catalog .model .Catalog ;
7464import org .opensearch .sql .data .model .ExprMissingValue ;
7565import org .opensearch .sql .data .type .ExprCoreType ;
66+ import org .opensearch .sql .datasource .DataSourceService ;
67+ import org .opensearch .sql .datasource .model .DataSource ;
7668import org .opensearch .sql .exception .SemanticCheckException ;
7769import org .opensearch .sql .expression .DSL ;
7870import org .opensearch .sql .expression .Expression ;
10193import org .opensearch .sql .planner .logical .LogicalRename ;
10294import org .opensearch .sql .planner .logical .LogicalSort ;
10395import org .opensearch .sql .planner .logical .LogicalValues ;
104- import org .opensearch .sql .planner .physical .catalog . CatalogTable ;
96+ import org .opensearch .sql .planner .physical .datasource . DataSourceTable ;
10597import org .opensearch .sql .storage .Table ;
10698import org .opensearch .sql .utils .ParseUtils ;
10799
@@ -117,7 +109,7 @@ public class Analyzer extends AbstractNodeVisitor<LogicalPlan, AnalysisContext>
117109
118110 private final NamedExpressionAnalyzer namedExpressionAnalyzer ;
119111
120- private final CatalogService catalogService ;
112+ private final DataSourceService dataSourceService ;
121113
122114 private final BuiltinFunctionRepository repository ;
123115
@@ -126,10 +118,10 @@ public class Analyzer extends AbstractNodeVisitor<LogicalPlan, AnalysisContext>
126118 */
127119 public Analyzer (
128120 ExpressionAnalyzer expressionAnalyzer ,
129- CatalogService catalogService ,
121+ DataSourceService dataSourceService ,
130122 BuiltinFunctionRepository repository ) {
131123 this .expressionAnalyzer = expressionAnalyzer ;
132- this .catalogService = catalogService ;
124+ this .dataSourceService = dataSourceService ;
133125 this .selectExpressionAnalyzer = new SelectExpressionAnalyzer (expressionAnalyzer );
134126 this .namedExpressionAnalyzer = new NamedExpressionAnalyzer (expressionAnalyzer );
135127 this .repository = repository ;
@@ -142,25 +134,27 @@ public LogicalPlan analyze(UnresolvedPlan unresolved, AnalysisContext context) {
142134 @ Override
143135 public LogicalPlan visitRelation (Relation node , AnalysisContext context ) {
144136 QualifiedName qualifiedName = node .getTableQualifiedName ();
145- Set <String > allowedCatalogNames = catalogService . getCatalogs ()
137+ Set <String > allowedDataSourceNames = dataSourceService . getDataSources ()
146138 .stream ()
147- .map (Catalog ::getName )
139+ .map (DataSource ::getName )
148140 .collect (Collectors .toSet ());
149- CatalogSchemaIdentifierNameResolver catalogSchemaIdentifierNameResolver
150- = new CatalogSchemaIdentifierNameResolver (qualifiedName .getParts (), allowedCatalogNames );
151- String tableName = catalogSchemaIdentifierNameResolver .getIdentifierName ();
141+ DataSourceSchemaIdentifierNameResolver dataSourceSchemaIdentifierNameResolver
142+ = new DataSourceSchemaIdentifierNameResolver (qualifiedName .getParts (),
143+ allowedDataSourceNames );
144+ String tableName = dataSourceSchemaIdentifierNameResolver .getIdentifierName ();
152145 context .push ();
153146 TypeEnvironment curEnv = context .peek ();
154147 Table table ;
155- if (CATALOGS_TABLE_NAME .equals (tableName )) {
156- table = new CatalogTable ( catalogService );
148+ if (DATASOURCES_TABLE_NAME .equals (tableName )) {
149+ table = new DataSourceTable ( dataSourceService );
157150 } else {
158- table = catalogService
159- .getCatalog ( catalogSchemaIdentifierNameResolver . getCatalogName ())
151+ table = dataSourceService
152+ .getDataSource ( dataSourceSchemaIdentifierNameResolver . getDataSourceName ())
160153 .getStorageEngine ()
161- .getTable (new CatalogSchemaName (catalogSchemaIdentifierNameResolver .getCatalogName (),
162- catalogSchemaIdentifierNameResolver .getSchemaName ()),
163- catalogSchemaIdentifierNameResolver .getIdentifierName ());
154+ .getTable (new DataSourceSchemaName (
155+ dataSourceSchemaIdentifierNameResolver .getDataSourceName (),
156+ dataSourceSchemaIdentifierNameResolver .getSchemaName ()),
157+ dataSourceSchemaIdentifierNameResolver .getIdentifierName ());
164158 }
165159 table .getFieldTypes ().forEach ((k , v ) -> curEnv .define (new Symbol (Namespace .FIELD_NAME , k ), v ));
166160
@@ -188,28 +182,29 @@ public LogicalPlan visitRelationSubquery(RelationSubquery node, AnalysisContext
188182 @ Override
189183 public LogicalPlan visitTableFunction (TableFunction node , AnalysisContext context ) {
190184 QualifiedName qualifiedName = node .getFunctionName ();
191- Set <String > allowedCatalogNames = catalogService . getCatalogs ()
185+ Set <String > allowedDataSourceNames = dataSourceService . getDataSources ()
192186 .stream ()
193- .map (Catalog ::getName )
187+ .map (DataSource ::getName )
194188 .collect (Collectors .toSet ());
195- CatalogSchemaIdentifierNameResolver catalogSchemaIdentifierNameResolver
196- = new CatalogSchemaIdentifierNameResolver (qualifiedName .getParts (), allowedCatalogNames );
189+ DataSourceSchemaIdentifierNameResolver dataSourceSchemaIdentifierNameResolver
190+ = new DataSourceSchemaIdentifierNameResolver (qualifiedName .getParts (),
191+ allowedDataSourceNames );
197192
198193 FunctionName functionName
199- = FunctionName .of (catalogSchemaIdentifierNameResolver .getIdentifierName ());
194+ = FunctionName .of (dataSourceSchemaIdentifierNameResolver .getIdentifierName ());
200195 List <Expression > arguments = node .getArguments ().stream ()
201196 .map (unresolvedExpression -> this .expressionAnalyzer .analyze (unresolvedExpression , context ))
202197 .collect (Collectors .toList ());
203198 TableFunctionImplementation tableFunctionImplementation
204199 = (TableFunctionImplementation ) repository .compile (
205- catalogSchemaIdentifierNameResolver . getCatalogName (), functionName , arguments );
200+ dataSourceSchemaIdentifierNameResolver . getDataSourceName (), functionName , arguments );
206201 context .push ();
207202 TypeEnvironment curEnv = context .peek ();
208203 Table table = tableFunctionImplementation .applyArguments ();
209204 table .getFieldTypes ().forEach ((k , v ) -> curEnv .define (new Symbol (Namespace .FIELD_NAME , k ), v ));
210205 curEnv .define (new Symbol (Namespace .INDEX_NAME ,
211- catalogSchemaIdentifierNameResolver .getIdentifierName ()), STRUCT );
212- return new LogicalRelation (catalogSchemaIdentifierNameResolver .getIdentifierName (),
206+ dataSourceSchemaIdentifierNameResolver .getIdentifierName ()), STRUCT );
207+ return new LogicalRelation (dataSourceSchemaIdentifierNameResolver .getIdentifierName (),
213208 tableFunctionImplementation .applyArguments ());
214209 }
215210
0 commit comments