Skip to content

Commit eb493cf

Browse files
committed
Update helper function naming
Signed-off-by: Yuanchun Shen <[email protected]>
1 parent 3903d36 commit eb493cf

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,8 +1925,11 @@ public RelNode visitFlatten(Flatten node, CalcitePlanContext context) {
19251925
return relBuilder.peek();
19261926
}
19271927

1928-
/** Helper method to get the function name for proper column naming */
1929-
private String getAggFieldAlias(UnresolvedExpression aggregateFunction) {
1928+
/**
1929+
* Helper method to get the metric alias for proper column naming. E.g. It returns {@code cnt} for
1930+
* {@code count(balance) as cnt}, and returns {@code avg(cpu_usage)} for {@code avg(cpu_usage)}
1931+
*/
1932+
private String getMetricAlias(UnresolvedExpression aggregateFunction) {
19301933
if (aggregateFunction instanceof Alias) {
19311934
return ((Alias) aggregateFunction).getName();
19321935
}
@@ -1976,7 +1979,7 @@ public RelNode visitTimechart(
19761979

19771980
// Handle no by field case
19781981
if (node.getByField() == null) {
1979-
String aggFieldAlias = getAggFieldAlias(node.getAggregateFunction());
1982+
String aggFieldAlias = getMetricAlias(node.getAggregateFunction());
19801983

19811984
// Create group expression list with just the timestamp span but use a different alias
19821985
// to avoid @timestamp naming conflict
@@ -2010,7 +2013,7 @@ public RelNode visitTimechart(
20102013
// Extract parameters for byField case
20112014
UnresolvedExpression byField = node.getByField();
20122015
String byFieldName = ((Field) byField).getField().toString();
2013-
String aggFieldAlias = getAggFieldAlias(node.getAggregateFunction());
2016+
String aggFieldAlias = getMetricAlias(node.getAggregateFunction());
20142017

20152018
int limit = Optional.ofNullable(node.getLimit()).orElse(10);
20162019
boolean useOther = Optional.ofNullable(node.getUseOther()).orElse(true);

0 commit comments

Comments
 (0)