Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Remove backticks on by field in stats #1751

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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