Skip to content

Commit

Permalink
merge table source parsing for search and describe
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Kao <seankao@amazon.com>
  • Loading branch information
seankao-az committed Jun 24, 2022
1 parent 7f8e9d8 commit 7e228ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 7 additions & 3 deletions ppl/src/main/antlr/OpenSearchPPLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ searchCommand
;

describeCommand
: DESCRIBE tableSource (COMMA tableSource)*
: DESCRIBE tableSourceClause
;

whereCommand
Expand Down Expand Up @@ -128,8 +128,12 @@ adParameter

/** clauses */
fromClause
: SOURCE EQUAL tableSource (COMMA tableSource)*
| INDEX EQUAL tableSource (COMMA tableSource)*
: SOURCE EQUAL tableSourceClause
| INDEX EQUAL tableSourceClause
;

tableSourceClause
: tableSource (COMMA tableSource)*
;

renameClasue
Expand Down
12 changes: 7 additions & 5 deletions ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.SearchFromFilterContext;
import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.SortCommandContext;
import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.StatsCommandContext;
import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.TableSourceClauseContext;
import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.TopCommandContext;
import static org.opensearch.sql.ppl.antlr.parser.OpenSearchPPLParser.WhereCommandContext;
import static org.opensearch.sql.utils.SystemIndexUtils.mappingTable;
Expand All @@ -36,7 +37,6 @@
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.ParseTree;
import org.opensearch.sql.ast.expression.Alias;
import org.opensearch.sql.ast.expression.AllFields;
import org.opensearch.sql.ast.expression.Field;
import org.opensearch.sql.ast.expression.Let;
import org.opensearch.sql.ast.expression.Literal;
Expand Down Expand Up @@ -115,10 +115,7 @@ public UnresolvedPlan visitSearchFilterFrom(SearchFilterFromContext ctx) {
*/
@Override
public UnresolvedPlan visitDescribeCommand(DescribeCommandContext ctx) {
// Gets the mapping table (_ODFE_SYS_TABLE_MAPPINGS) of the indices by name
final Relation table = new Relation(ctx.tableSource()
.stream().map(this::internalVisitExpression)
.collect(Collectors.toList()));
final Relation table = (Relation) visitTableSourceClause(ctx.tableSourceClause());
return new Relation(qualifiedName(mappingTable(table.getTableName())));
}

Expand Down Expand Up @@ -302,6 +299,11 @@ public UnresolvedPlan visitTopCommand(TopCommandContext ctx) {
*/
@Override
public UnresolvedPlan visitFromClause(FromClauseContext ctx) {
return visitTableSourceClause(ctx.tableSourceClause());
}

@Override
public UnresolvedPlan visitTableSourceClause(TableSourceClauseContext ctx) {
return new Relation(ctx.tableSource()
.stream().map(this::internalVisitExpression)
.collect(Collectors.toList()));
Expand Down

0 comments on commit 7e228ac

Please sign in to comment.