cloud-fan commented on code in PR #53158: URL: https://github.com/apache/spark/pull/53158#discussion_r2610019395
########## sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveMetricView.scala: ########## @@ -0,0 +1,347 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.catalyst.analysis + +import scala.collection.mutable + +import org.apache.spark.SparkException +import org.apache.spark.sql.SparkSession +import org.apache.spark.sql.catalyst.expressions._ +import org.apache.spark.sql.catalyst.expressions.aggregate.{AggregateExpression, Measure} +import org.apache.spark.sql.catalyst.parser.ParserInterface +import org.apache.spark.sql.catalyst.plans.logical._ +import org.apache.spark.sql.catalyst.rules.Rule +import org.apache.spark.sql.catalyst.trees.TreePattern.METRIC_VIEW_PLACEHOLDER +import org.apache.spark.sql.metricview.logical.{MetricViewPlaceholder, ResolvedMetricView} +import org.apache.spark.sql.metricview.serde.{Column => CanonicalColumn, Constants => MetricViewConstants, DimensionExpression, JsonUtils, MeasureExpression, MetricView => CanonicalMetricView} +import org.apache.spark.sql.types.{DataType, Metadata, MetadataBuilder} + +/** + * Analysis rule for resolving metric view operations (CREATE and SELECT). + * + * == Background == + * A metric view is a special type of view that defines a semantic layer over raw data by + * declaring dimensions (grouping columns) and measures (pre-aggregated metrics). Users can + * query metric views using the MEASURE() function to access pre-defined aggregations without + * needing to know the underlying aggregation logic. + * + * == Metric View Definition (YAML) == + * A metric view is defined using YAML syntax that specifies: + * - source: The underlying table or SQL query + * - where: Optional filter condition applied to the source + * - select: List of columns, each being either a dimension or measure + * - Dimensions: Expressions used for grouping (e.g., "region", "upper(region)") + * - Measures: Aggregate expressions (e.g., "sum(count)", "avg(price)") + * + * Example YAML definition: + * {{{ + * version: "0.1" + * source: + * asset: "sales_table" + * where: "product = 'product_1'" + * select: + * - name: region Review Comment: so all dimension and measure columns are named, why do we need to allow user-specified columns in CREATE VIEW? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
