chenwang-databricks commented on code in PR #55487:
URL: https://github.com/apache/spark/pull/55487#discussion_r3148494201
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/command/metricViewCommands.scala:
##########
@@ -65,6 +83,65 @@ case class CreateMetricViewCommand(
ignoreIfExists = allowExisting)
Seq.empty
}
+
+ private def createMetricViewInV2Catalog(
+ sparkSession: SparkSession,
+ resolved: ResolvedIdentifier): Seq[Row] = {
+ // Metric views are persisted through the same `ViewCatalog` interface as
plain views; the
+ // only differences are `PROP_TABLE_TYPE = METRIC_VIEW` (so
`V1Table.toCatalogTable` maps the
+ // round-tripped row back to `CatalogTableType.METRIC_VIEW`), the
`metric_view.*` descriptor
+ // properties produced by `MetricView.getProperties`, and the typed
`viewDependencies` field.
+ val viewCatalog = resolved.catalog match {
+ case vc: ViewCatalog => vc
+ case other =>
+ throw QueryCompilationErrors.missingCatalogViewsAbilityError(other)
+ }
+ val ident = resolved.identifier
+ val name = ident.asTableIdentifier
+
+ val analyzed = MetricViewHelper.analyzeMetricViewText(sparkSession, name,
originalText)
+ validateUserColumns(name, analyzed)
+
+ val aliasedSchema = ViewHelper.aliasPlan(sparkSession, analyzed,
userSpecifiedColumns).schema
+
+ // Describe this metric view's source and filter as user-visible
properties so catalogs and
+ // tooling can inspect them without re-parsing the YAML body.
+ val metricView = MetricViewFactory.fromYAML(originalText)
+ val viewProperties = new java.util.HashMap[String, String]()
+ properties.foreach { case (k, v) => viewProperties.put(k, v) }
+ metricView.getProperties.foreach { case (k, v) => viewProperties.put(k, v)
}
+
+ val sourceTableNames = MetricViewHelper.collectTableDependencies(analyzed)
+ val deps = if (sourceTableNames.nonEmpty) {
+ DependencyList.of(sourceTableNames.map(Dependency.table): _*)
+ } else {
+ null
+ }
+
+ val manager = sparkSession.sessionState.catalogManager
+ val builder = new ViewInfo.Builder()
+ .withSchema(aliasedSchema)
+ .withProperties(viewProperties)
+ .withQueryText(originalText)
+ .withCurrentCatalog(manager.currentCatalog.name)
+ .withCurrentNamespace(manager.currentNamespace)
+ .withSqlConfigs(
+ ViewHelper.sqlConfigsToProps(sparkSession.sessionState.conf,
"").asJava)
+ .withSchemaMode(SchemaUnsupported.toString)
+ .withQueryColumnNames(analyzed.output.map(_.name).toArray)
+ .withViewDependencies(deps)
+ comment.foreach(builder.withComment)
+ val viewInfo = builder.build()
+ // `ViewInfo`'s constructor unconditionally stamps `PROP_TABLE_TYPE =
VIEW`. Refine that to
Review Comment:
Can you change ViewInfo's constructor to say that if you know we are setting
the table type as metric view, then keep it as metric view so that you don't
have to reset the prop table type to metric view again?
--
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]