cloud-fan commented on a change in pull request #31368: URL: https://github.com/apache/spark/pull/31368#discussion_r565879026
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala ########## @@ -845,17 +845,33 @@ class SessionCatalog( } private def fromCatalogTable(metadata: CatalogTable, isTempView: Boolean): View = { - val viewText = metadata.viewText.getOrElse(sys.error("Invalid view without text.")) + val viewText = metadata.viewText.getOrElse { + throw new IllegalStateException("Invalid view without text.") + } val viewConfigs = metadata.viewSQLConfigs - val viewPlan = + val parsedPlan = SQLConf.withExistingConf(View.effectiveSQLConf(viewConfigs, isTempView = isTempView)) { parser.parsePlan(viewText) } - View( - desc = metadata, - isTempView = isTempView, - output = metadata.schema.toAttributes, - child = viewPlan) + val viewColumnNames = metadata.viewQueryColumnNames + val viewPlan = if (viewColumnNames.nonEmpty) { + assert(viewColumnNames.length == metadata.schema.length) + // For view queries like `SELECT * FROM t`, the schema of the referenced table/view may + // change after the view has been created. We need to add an extra SELECT to pick the columns Review comment: It's from https://github.com/apache/spark/pull/31368/files#diff-782f0d0b0d5fa6cf642285962eb0c831d9807e3f9ec2810f964292da89547e1aL38 I changed it a little bit to match the current context. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org