Skip to content

Why does my Cloudwatch Opensearch SQL query visualization show both the alias and the statement

0

My query:

SELECT  window.start, min(rows) - lag(min(rows)) OVER (ORDER BY window(`@timestamp`, '5 minutes')) AS new_rows
FROM CGAP
WHERE table = 'std.a133_general'
GROUP BY window(`@timestamp`, '5 minutes')

Produces logs with three columns:

  • start
  • (min(rows) - lag(min(rows)OVER@timestamp)
  • new_rows

The second column is blank. The corresponding visualization has a lengend with the first series being labeled min(rows) - lag(min(rows)OVER@timestamp).

visualization issue

I'm expecting the alias to only show not the statement that the alias aliases. I tried making this entire query a subquery to select only the two relevant columns but I couldn't get it working (the necessary GROUP BY for the window to make the visualization) was necessary and the visualization wouldn't display no matter how I modified the query.

asked 2 years ago632 views

1 Answer
0
Accepted Answer

The issue you're experiencing with your CloudWatch OpenSearch SQL query visualization is likely due to how OpenSearch SQL handles aliases in certain complex queries, especially those involving window functions.

When using window functions or other complex operations in OpenSearch SQL, the query engine sometimes retains both the original expression and the alias in the result set. This can lead to the situation you're seeing, where both the full expression and the alias appear in the visualization legend.

To address this, you could try a few approaches:

  1. Simplify the query if possible, breaking it down into simpler parts or using a subquery.

  2. Use a more descriptive alias that clearly represents what the calculation is doing. This way, even if both the expression and alias appear, the alias will be more meaningful.

  3. If the visualization tool allows, you might be able to manually edit the legend labels after the query runs.

  4. Consider using the Piped Processing Language (PPL) instead of SQL for this type of query, as it might handle the aliasing more cleanly in some cases.

As for the blank second column, this could be because the lag function is not finding a previous value for the first row, resulting in a null value. You might want to use a COALESCE function or similar to handle this case.

Regarding your attempt to use a subquery, it's worth noting that OpenSearch SQL has some limitations with nested queries and complex operations. Only one level of nested subqueries is supported, which might explain why you had difficulty getting it to work.

If you continue to face issues, you might want to consider breaking down the query into simpler parts or using materialized views if available in your setup to precompute some of the complex calculations.
Sources
OpenSearch SQL language - Amazon CloudWatch Logs
Amazon CloudWatch and Amazon OpenSearch Service launch an integrated analytics experience - AWS

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Thanks for your help. This seems like a bug. Can I submit it as a bug somewere?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.