Skip to content

Commit

Permalink
Remove backticks on by field in stats (opensearch-project#1728)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 authored Jun 16, 2023
1 parent 94d5479 commit 7525bb1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public void testMetricAvgAggregationCommand() {
verifySchema(response,
schema("agg", "double"),
schema("span(@timestamp,15s)", "timestamp"),
schema("`handler`", "string"),
schema("`job`", "string"));
schema("handler", "string"),
schema("job", "string"));
Assertions.assertTrue(response.getInt("size") > 0);
Assertions.assertEquals(4, response.getJSONArray("datarows").getJSONArray(0).length());
JSONArray firstRow = response.getJSONArray("datarows").getJSONArray(0);
Expand All @@ -132,7 +132,7 @@ public void testMetricAvgAggregationCommandWithAlias() {
verifySchema(response,
schema("agg", "double"),
schema("span(@timestamp,15s)", "timestamp"),
schema("`handler`", "string"),
schema("handler", "string"),
schema("job", "string"));
Assertions.assertTrue(response.getInt("size") > 0);
Assertions.assertEquals(4, response.getJSONArray("datarows").getJSONArray(0).length());
Expand Down
11 changes: 6 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 @@ -201,7 +201,8 @@ public UnresolvedPlan visitStatsCommand(StatsCommandContext ctx) {
.map(OpenSearchPPLParser.StatsByClauseContext::fieldList)
.map(expr -> expr.fieldExpression().stream()
.map(groupCtx ->
(UnresolvedExpression) new Alias(getTextInQuery(groupCtx),
(UnresolvedExpression) new Alias(
StringUtils.unquoteIdentifier(getTextInQuery(groupCtx)),
internalVisitExpression(groupCtx)))
.collect(Collectors.toList()))
.orElse(Collections.emptyList());
Expand Down Expand Up @@ -429,10 +430,10 @@ public UnresolvedPlan visitAdCommand(AdCommandContext ctx) {
public UnresolvedPlan visitMlCommand(OpenSearchPPLParser.MlCommandContext ctx) {
ImmutableMap.Builder<String, Literal> builder = ImmutableMap.builder();
ctx.mlArg()
.forEach(x -> {
builder.put(x.argName.getText(),
(Literal) internalVisitExpression(x.argValue));
});
.forEach(x -> {
builder.put(x.argName.getText(),
(Literal) internalVisitExpression(x.argValue));
});
return new ML(builder.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,27 @@ public void testStatsCommandWithByClause() {
));
}

@Test
public void testStatsCommandWithByClauseInBackticks() {
assertEqual("source=t | stats count(a) by `b` DEDUP_SPLITVALUES=false",
agg(
relation("t"),
exprList(
alias(
"count(a)",
aggregate("count", field("a"))
)
),
emptyList(),
exprList(
alias(
"b",
field("b")
)),
defaultStatsArgs()
));
}

@Test
public void testStatsCommandWithAlias() {
assertEqual("source=t | stats count(a) as alias",
Expand Down

0 comments on commit 7525bb1

Please sign in to comment.