From 6c8aae33ac773ec408058698c72cac39548b104e Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Wed, 31 May 2023 09:13:00 -0700 Subject: [PATCH] Allow backtick around fields in sort cmd (#1688) * Allow backtick around fields in sort cmd Signed-off-by: Joshua Li * Add test Signed-off-by: Joshua Li * Update test setup Signed-off-by: Joshua Li * revert ignoring sql-cli repo if exists Signed-off-by: Joshua Li --------- Signed-off-by: Joshua Li (cherry picked from commit 691012db9a250e8d40f436f078975820af601cc4) --- .gitignore | 4 +++- .../opensearch/sql/ppl/parser/AstExpressionBuilder.java | 2 +- .../sql/ppl/parser/AstExpressionBuilderTest.java | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2b1f9be522..1b892036dd 100644 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,6 @@ gen .java-version .worktrees -http-client.env.json \ No newline at end of file +http-client.env.json +/doctest/sql-cli/ +.factorypath diff --git a/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java b/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java index e56eae83a6..4ce9ce2789 100644 --- a/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java +++ b/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java @@ -182,7 +182,7 @@ public UnresolvedExpression visitWcFieldExpression(WcFieldExpressionContext ctx) @Override public UnresolvedExpression visitSortField(SortFieldContext ctx) { return new Field( - qualifiedName(ctx.sortFieldExpression().fieldExpression().getText()), + visit(ctx.sortFieldExpression().fieldExpression().qualifiedName()), ArgumentFactory.getArgumentList(ctx) ); } diff --git a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java index 16a6ff63b4..3f3c0e50ba 100644 --- a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java +++ b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java @@ -301,6 +301,15 @@ public void testSortFieldWithMinusKeyword() { )); } + @Test + public void testSortFieldWithBackticks() { + assertEqual("source=t | sort `f`", + sort( + relation("t"), + field("f", defaultSortFieldArgs()) + )); + } + @Test public void testSortFieldWithAutoKeyword() { assertEqual("source=t | sort auto(f)",