forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: vamsi-amazon <reddyvam@amazon.com>
- Loading branch information
Showing
22 changed files
with
481 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
core/src/main/java/org/opensearch/sql/catalog/model/Catalog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.opensearch.sql.catalog.model; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.sql.storage.StorageEngine; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
@EqualsAndHashCode | ||
public class Catalog { | ||
|
||
private final String name; | ||
|
||
private final ConnectorType connectorType; | ||
|
||
@EqualsAndHashCode.Exclude | ||
private final StorageEngine storageEngine; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.opensearch.sql.planner.physical.catalog; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import java.util.Map; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.sql.catalog.CatalogService; | ||
import org.opensearch.sql.data.type.ExprType; | ||
import org.opensearch.sql.planner.DefaultImplementor; | ||
import org.opensearch.sql.planner.logical.LogicalPlan; | ||
import org.opensearch.sql.planner.logical.LogicalRelation; | ||
import org.opensearch.sql.planner.physical.PhysicalPlan; | ||
import org.opensearch.sql.storage.Table; | ||
|
||
|
||
/** | ||
* Table implementation to handle show catalogs command. | ||
* Since catalog information is not tied to any storage engine, this info | ||
* is handled via Catalog Table. | ||
* | ||
*/ | ||
@RequiredArgsConstructor | ||
@EqualsAndHashCode | ||
public class CatalogTable implements Table { | ||
|
||
private final CatalogService catalogService; | ||
|
||
@Override | ||
public Map<String, ExprType> getFieldTypes() { | ||
return CatalogTableSchema.CATALOG_TABLE_SCHEMA.getMapping(); | ||
} | ||
|
||
@Override | ||
public PhysicalPlan implement(LogicalPlan plan) { | ||
return plan.accept(new CatalogTableDefaultImplementor(catalogService), null); | ||
} | ||
|
||
@VisibleForTesting | ||
@RequiredArgsConstructor | ||
public static class CatalogTableDefaultImplementor | ||
extends DefaultImplementor<Object> { | ||
|
||
private final CatalogService catalogService; | ||
|
||
@Override | ||
public PhysicalPlan visitRelation(LogicalRelation node, Object context) { | ||
return new CatalogTableScan(catalogService); | ||
} | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTableScan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.opensearch.sql.planner.physical.catalog; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Set; | ||
import org.opensearch.sql.catalog.CatalogService; | ||
import org.opensearch.sql.catalog.model.Catalog; | ||
import org.opensearch.sql.data.model.ExprTupleValue; | ||
import org.opensearch.sql.data.model.ExprValue; | ||
import org.opensearch.sql.data.model.ExprValueUtils; | ||
import org.opensearch.sql.storage.TableScanOperator; | ||
|
||
/** | ||
* This class handles table scan of catalog table. | ||
* Right now these are derived from catalogService thorough static fields. | ||
* In future this might scan data from underlying datastore if we start | ||
* persisting catalog info somewhere. | ||
* | ||
*/ | ||
public class CatalogTableScan extends TableScanOperator { | ||
|
||
private final CatalogService catalogService; | ||
|
||
private Iterator<ExprValue> iterator; | ||
|
||
public CatalogTableScan(CatalogService catalogService) { | ||
this.catalogService = catalogService; | ||
this.iterator = Collections.emptyIterator(); | ||
} | ||
|
||
@Override | ||
public String explain() { | ||
return "GetCatalogRequestRequest{}"; | ||
} | ||
|
||
@Override | ||
public void open() { | ||
List<ExprValue> exprValues = new ArrayList<>(); | ||
Set<Catalog> catalogs = catalogService.getCatalogs(); | ||
for (Catalog catalog : catalogs) { | ||
exprValues.add( | ||
new ExprTupleValue(new LinkedHashMap<>(ImmutableMap.of( | ||
"CATALOG_NAME", ExprValueUtils.stringValue(catalog.getName()), | ||
"CONNECTOR_TYPE", ExprValueUtils.stringValue(catalog.getConnectorType().name()))))); | ||
} | ||
iterator = exprValues.iterator(); | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return iterator.hasNext(); | ||
} | ||
|
||
@Override | ||
public ExprValue next() { | ||
return iterator.next(); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
core/src/main/java/org/opensearch/sql/planner/physical/catalog/CatalogTableSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.planner.physical.catalog; | ||
|
||
import static org.opensearch.sql.data.type.ExprCoreType.STRING; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.sql.data.type.ExprType; | ||
|
||
/** | ||
* Definition of the system table schema. | ||
*/ | ||
@Getter | ||
@RequiredArgsConstructor | ||
public enum CatalogTableSchema { | ||
|
||
CATALOG_TABLE_SCHEMA(new LinkedHashMap<>() { | ||
{ | ||
put("CATALOG_NAME", STRING); | ||
put("CONNECTOR_TYPE", STRING); | ||
} | ||
} | ||
); | ||
private final Map<String, ExprType> mapping; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.