Skip to content

Conversation

@linhongliu-db
Copy link
Contributor

What changes were proposed in this pull request?

This PR implements the command to create metric views and the analysis rule to resolve a metric view query:

  • CREATE Metric view
    • Add SQL grammar to support WITH METRIC when creating a view
    • Add dollar-quoted string support for YAML definitions
    • Implement CreateMetricViewCommand to analyze the view body
    • Use a table property to indicate that the View is a metric view since HIVE has no dedicated table type
  • SELECT Metric view
    • Update SessionCatalog to parse metric view definitions on read
    • Add MetricViewPlanner utility to parse the YAML definition and construct an unresolved plan
    • Add ResolveMetricView rule to substitute the dimensions and measures reference to actual expressions

NOTE: This PR depends on #53146

Why are the changes needed?

SPIP: Metrics & semantic modeling in Spark

Does this PR introduce any user-facing change?

No

How was this patch tested?

build/sbt "hive/testOnly  org.apache.spark.sql.execution.SimpleMetricViewSuite"
build/sbt "hive/testOnly  org.apache.spark.sql.hive.execution.HiveMetricViewSuite"

Was this patch authored or co-authored using generative AI tooling?

No

  - Add METRICS keyword to lexer
  - Add dollar-quoted string support for YAML definitions
  - Add createMetricView production rule
- Add METRIC_VIEW catalog table type
- Implement CreateMetricViewCommand:
  - Parse YAML definition
  - Build MetricViewPlaceholder logical node
  - Validate and analyze metric view
- Add MetricViewPlaceholder logical node with tree patterns
- Update ViewHelper to support metric view creation
- Add basic test suite for metric views

- Add MetricViewPlanner utility:
  - planRead() to parse metric view for SELECT queries
  - planWrite() refactored from metricViewCommands
  - parseYAML() shared parsing logic
- Add ResolveMetricView analyzer rule:
  - Transform MetricViewPlaceholder into aggregation queries
  - Parse dimensions and measures from schema metadata
  - Build Project with dimensions and Aggregate with measures
  - Handle measure references in aggregates
- Update SessionCatalog to parse metric view definitions on read
- Update EliminateView to handle ResolvedMetricView nodes
- Refactor CreateMetricViewCommand to use MetricViewPlanner
- Update ViewHelper to set METRIC_VIEW table type correctly
- Add ResolveMetricView to analyzer rule chain
- Update test suite with query tests

update

test

test
@github-actions github-actions bot added the SQL label Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant