linhongliu-db commented on code in PR #53146: URL: https://github.com/apache/spark/pull/53146#discussion_r2590263508
########## sql/catalyst/src/main/scala/org/apache/spark/sql/metricview/serde/MetricViewCanonical.scala: ########## @@ -0,0 +1,212 @@ +/* + * 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 scala.util.{Failure, Success, Try} + +import com.fasterxml.jackson.annotation.{JsonIgnoreProperties, JsonInclude, JsonProperty} +import com.fasterxml.jackson.annotation.JsonInclude.Include + +import org.apache.spark.sql.catalyst.parser.CatalystSqlParser +import org.apache.spark.sql.metricview.serde.ColumnType.ColumnType +import org.apache.spark.sql.metricview.serde.SourceType.SourceType + +// Trait representing the capability to validate an object +trait Validatable { + def validate(): Try[Unit] +} + +sealed abstract class MetricViewSerdeException(message: String, cause: Option[Throwable] = None) + extends Exception(message, cause.orNull) + +case class MetricViewValidationException(message: String, cause: Option[Throwable] = None) + extends MetricViewSerdeException(message, cause) + +case class MetricViewFromProtoException(message: String, cause: Option[Throwable] = None) + extends MetricViewSerdeException(message, cause) + +case class MetricViewYAMLParsingException(message: String, cause: Option[Throwable] = None) + extends MetricViewSerdeException(message, cause) + +// Expression types in a Metric View +sealed trait Expression extends Validatable { + def expr: String + + // Validate that expression is not empty + def validate(): Try[Unit] = { + if (expr.isEmpty) { + Failure(MetricViewValidationException("expr cannot be empty")) + } else Success(()) + } +} + +// Dimension expression representing a scalar value +case class DimensionExpression(expr: String) extends Expression + +// Measure expression representing an aggregated value +case class MeasureExpression(expr: String) extends Expression + +object SourceType extends Enumeration { + type SourceType = Value + val ASSET, SQL = Value + + def fromString(sourceType: String): SourceType = { + values.find(_.toString.equalsIgnoreCase(sourceType)).getOrElse { + throw MetricViewFromProtoException( + s"Unsupported source type: $sourceType" + ) + } + } +} + +// Representation of a source in the Metric View +sealed trait Source extends Validatable { + def sourceType: SourceType + + def validate(): Try[Unit] +} + +// Asset source, representing a UC table, view, or Metric View, etc. Review Comment: ```suggestion // Asset source, representing a catalog table, view, or Metric View, etc. ``` -- 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]
