Skip to content

Add profiling support to unified query API#5268

Draft
dai-chen wants to merge 3 commits intoopensearch-project:mainfrom
dai-chen:feature/unified-query-profiling
Draft

Add profiling support to unified query API#5268
dai-chen wants to merge 3 commits intoopensearch-project:mainfrom
dai-chen:feature/unified-query-profiling

Conversation

@dai-chen
Copy link
Collaborator

@dai-chen dai-chen commented Mar 25, 2026

Description

This PR enables profiling capability in the unified query API so external consumers (OpenSearch, Spark, CLI) can collect per-phase timing metrics without depending on the REST-specific QueryContext MDC layer.

Key design decisions:

  • Reuses existing profiling infrastructure: Profiling output follows the same format and semantics as the profile=true in REST API, but hide internal profiling abstraction behind UnifiedQueryContext.
  • Auto-profiling inside, measure() API outside: Each unified query component auto-profiles its phase and provide measure API for code outside unified query components, e.g., PreparedStatement.executeQuery(), response formatting.

Related Issues

Resolves #5248 (partially)

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@dai-chen dai-chen self-assigned this Mar 25, 2026
@dai-chen dai-chen added the enhancement New feature or request label Mar 25, 2026
@github-actions
Copy link
Contributor

Failed to generate code suggestions for PR

Add TRANSPILE metric for profiling query transpilation in the unified
query API, used when converting logical plans to target SQL dialects.

Signed-off-by: Chen Dai <daichen@amazon.com>
@dai-chen dai-chen force-pushed the feature/unified-query-profiling branch from c85370d to a4ea219 Compare March 25, 2026 23:05
@github-actions
Copy link
Contributor

Failed to generate code suggestions for PR

@dai-chen dai-chen force-pushed the feature/unified-query-profiling branch from a4ea219 to 6749914 Compare March 25, 2026 23:09
@github-actions
Copy link
Contributor

Failed to generate code suggestions for PR

@dai-chen dai-chen force-pushed the feature/unified-query-profiling branch from 6749914 to 2f645f3 Compare March 25, 2026 23:27
@github-actions
Copy link
Contributor

Failed to generate code suggestions for PR

Enable profiling in unified query components via UnifiedQueryContext:
- profiling(boolean) builder to activate/deactivate profiling
- measure(name, callable) API for user-profiled phases (execute, format)
- getProfile() to retrieve QueryProfile snapshot after execution
- Auto-profiling in UnifiedQueryPlanner (ANALYZE), UnifiedQueryCompiler
  (OPTIMIZE), and UnifiedQueryTranspiler (TRANSPILE)
- All components use context.measure() internally for consistency
- NoopProfileContext ensures zero overhead when profiling is disabled

Signed-off-by: Chen Dai <daichen@amazon.com>
Extract common test schema and utilities into UnifiedQueryTestBase to
reduce duplication across unified query test classes. Profiling tests
now extend this base and override buildContext() to enable profiling.

Change all timing assertions from > 0 to >= 0 to prevent flakiness.
Millisecond-resolution timers can return 0 for fast operations when
System.currentTimeMillis() samples the same tick before and after.
The >= 0 assertion still validates the metric was recorded (phase key
exists in the profile map) without depending on wall-clock granularity.

Signed-off-by: Chen Dai <daichen@amazon.com>
@dai-chen dai-chen force-pushed the feature/unified-query-profiling branch from 2f645f3 to 4a1cbef Compare March 26, 2026 02:08
@github-actions
Copy link
Contributor

Failed to generate code suggestions for PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] SQL query support for Analytics engine integration

1 participant