subquery-patterns-and-union

Combine OPAL subqueries with labels, unions, and timeshift for period comparisons.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/rustomax/observe-community-mcp --skill subquery-patterns-and-union
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: subquery-patterns-and-union
Source: https://github.com/rustomax/observe-community-mcp/tree/main/skills/subquery-patterns-and-union
Command: npx skills add https://github.com/rustomax/observe-community-mcp --skill subquery-patterns-and-union

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a structured pattern library to build and combine multiple OPAL subqueries using labels, unions, and timeshift, enabling powerful period-over-period comparisons and multi-dataset analysis.

Core Features & Use Cases

  • Subquery syntax: define reusable blocks with @label <- @dataset to organize complex pipelines.
  • Union patterns: merge results from different periods or datasets while preserving comparable columns.
  • Timeshift and alignment: shift data to compare adjacent periods (e.g., current vs previous hour) and align buckets for accurate joins.
  • any_not_null() collapse: collapse sparse union results into a single per-group row.
  • Use Case: perform period-over-period metric comparisons, time-series analysis, and build intermediate results for multi-stage calculations.

Quick Start

Run a simple example: build a current subquery for a metric, a timeshifted previous subquery, union their results and apply aggregation to produce a per-group summary.

Frequently Asked Questions about subquery-patterns-and-union

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I perform period-over-period comparisons using OPAL queries?

Period-over-period comparisons in OPAL are performed by defining labeled subqueries for different time ranges, applying timeshift to align buckets, and unioning the results to compare metrics across adjacent periods. You then collapse the sparse union output to produce a single summary row per group.

What is the best way to merge multiple datasets in OPAL for time-series analysis?

Merging multiple datasets in OPAL for time-series analysis is best done using union patterns. You define separate subqueries with @label <- @dataset syntax, union their comparable columns to merge results, and apply aggregations to produce aligned time-series outputs.

How does the any_not_null function work when combining subquery results?

The any_not_null function collapses sparse union results into a single per-group row. When you union subqueries from different periods or datasets, it merges the non-null values, ensuring each group has one consolidated record for accurate period-over-period analysis.

Can I use timeshift to align data buckets for adjacent periods in OPAL?

Yes, you can use timeshift in OPAL to shift data and align buckets for accurate joins. It adjusts the time periods of your subqueries so that current and previous periods match, enabling accurate multi-dataset analysis and period-over-period comparisons.

When should I use labeled subqueries instead of direct queries for multi-dataset analysis?

You should use labeled subqueries with @label <- @dataset when building complex multi-stage calculations. They organize pipelines into reusable blocks, making it easier to apply timeshift, union different periods, and handle multi-dataset analysis without repeating query logic.

Why does my OPAL union return sparse rows for period-over-period metrics?

An OPAL union returns sparse rows because each subquery populates different columns based on its time period. To resolve this, apply the any_not_null collapse function to merge the sparse union results into a single per-group row for clean period-over-period comparisons.