cloud-fan commented on code in PR #53146: URL: https://github.com/apache/spark/pull/53146#discussion_r2590284287
########## sql/catalyst/src/main/scala/org/apache/spark/sql/metricview/serde/MetricViewSerDeV01.scala: ########## @@ -0,0 +1,81 @@ +/* + * 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.metricview.serde + +import com.fasterxml.jackson.annotation.JsonProperty + +case class ColumnV01( + @JsonProperty(required = true) name: String, + @JsonProperty(required = true) expr: String +) extends ColumnBase + +object ColumnV01 { + def fromCanonical(canonical: Column[_ <: Expression]): ColumnV01 = { + val name = canonical.name + val expr = canonical.expression match { + case DimensionExpression(exprStr) => exprStr + case MeasureExpression(exprStr) => exprStr + case _ => + throw new IllegalArgumentException( + s"Unsupported expression type: ${canonical.expression.getClass.getName}") + } + ColumnV01(name = name, expr = expr) + } +} + +case class MetricViewV01( + @JsonProperty(required = true) version: String, + @JsonProperty(required = true) source: String, + filter: Option[String] = None, + dimensions: Seq[ColumnV01] = Seq.empty, + measures: Seq[ColumnV01] = Seq.empty) extends MetricViewBase + +object MetricViewV01 { + def fromCanonical(canonical: MetricView): MetricViewV01 = { + val source = canonical.from.toString + val filter = canonical.where + // Separate dimensions and measures based on expression type + val dimensions = canonical.select.collect { + case column if column.expression.isInstanceOf[DimensionExpression] => + ColumnV01.fromCanonical(column) + } + val measures = canonical.select.collect { + case column if column.expression.isInstanceOf[MeasureExpression] => + ColumnV01.fromCanonical(column) + } + MetricViewV01( + version = canonical.version, + source = source, + filter = filter, + dimensions = dimensions, + measures = measures + ) + } +} + +object YamlMapperProvider extends YamlMapperProviderBase Review Comment: do we need to add `V01` postfix? -- 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]
