Skip to content
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",
Copy link
Member

@vamsimanohar vamsimanohar Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the query is
"source = t | stats count(a) by `t.b` "

it would treat t.b as column name.

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