Skip to content

Commit bc4e06c

Browse files
committed
The SPath fix
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
1 parent 2c8609f commit bc4e06c

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

core/src/main/java/org/opensearch/sql/ast/tree/SPath.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package org.opensearch.sql.ast.tree;
77

8+
import static org.opensearch.sql.common.utils.StringUtils.unquoteIdentifier;
9+
810
import com.google.common.collect.ImmutableList;
911
import java.util.List;
1012
import lombok.AllArgsConstructor;
@@ -48,15 +50,16 @@ public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) {
4850

4951
public Eval rewriteAsEval() {
5052
String outField = this.outField;
53+
String unquotedPath = unquoteIdentifier(this.path);
5154
if (outField == null) {
52-
outField = this.path;
55+
outField = unquotedPath;
5356
}
5457

5558
return AstDSL.eval(
5659
this.child,
5760
AstDSL.let(
5861
AstDSL.field(outField),
5962
AstDSL.function(
60-
"json_extract", AstDSL.field(inField), AstDSL.stringLiteral(this.path))));
63+
"json_extract", AstDSL.field(inField), AstDSL.stringLiteral(unquotedPath))));
6164
}
6265
}

ppl/src/test/java/org/opensearch/sql/ppl/utils/SPathRewriteTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,13 @@ public void testSpathMissingPathArgumentHandling() {
6464
public void testSpathArgumentDeshuffle() {
6565
assertEquals(plan("source = t | spath path=a input=a"), plan("source = t | spath input=a a"));
6666
}
67+
68+
@Test
69+
public void testSpathEscapedParse() {
70+
SPath sp =
71+
(SPath) plan("source = t | spath input=f output=o path=`attributes.['cluster.name']`");
72+
Eval ev = (Eval) plan("source = t | eval o=json_extract(f, \"attributes.['cluster.name']\")");
73+
74+
assertEquals(ev, sp.rewriteAsEval());
75+
}
6776
}

0 commit comments

Comments
 (0)