WweiL commented on code in PR #40189: URL: https://github.com/apache/spark/pull/40189#discussion_r1119678933
########## sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/VersionUnresolvedRelation.scala: ########## @@ -0,0 +1,58 @@ +/* + * 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.execution.datasources + +import org.apache.spark.sql.SparkSession +import org.apache.spark.sql.catalyst.analysis.MultiInstanceRelation +import org.apache.spark.sql.catalyst.expressions.Attribute +import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, LogicalPlan, Statistics} +import org.apache.spark.sql.types.StructType + +object VersionUnresolvedRelation { + def apply( + dataSource: DataSource, + isStreaming: Boolean)(session: SparkSession): VersionUnresolvedRelation = { + VersionUnresolvedRelation( + source = dataSource.className, + dataSource = Some(dataSource), + options = dataSource.options, + userSpecifiedSchema = dataSource.userSpecifiedSchema, + output = dataSource.sourceInfo.schema.toAttributes, + isStreaming = isStreaming)(session) + } +} + +case class VersionUnresolvedRelation ( + source: String, + dataSource: Option[DataSource], + options: Map[String, String] = Map.empty, + userSpecifiedSchema: Option[StructType] = None, + paths: Seq[String] = Seq.empty, + output: Seq[Attribute] = Seq.empty, Review Comment: Would it work if here we set `output` always to be `Seq.empty`? Given that this relation is always created with `DataSet.ofRows()`, which resolve the logical plan immediately. [source](https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala#L89) Existing [tests fail](https://github.com/WweiL/oss-spark/actions/runs/4280466678/jobs/7453140220) because when created with `rate` source, which is only supported in V2, is asking for output attrs from V1 source, which errored. To set this field correctly, we need to first resolve the data source version, then do either `dataSource.sourceInfo.schema.toAttributes` for v1 source, or `table.columns.asSchema.toAttributes` for V2 sources. But then this requires us to resolve the version before or when creating this `VersionUnresolvedRelation`. We definitely can't do it before creating this relation because that's what we do now. So I was thinking of doing it when creating the relation. But that also failed with issues of sparkSession. If we can ignore the output field and set it to be empty always, it won't be a problem then. Although it seems to be anti-pattern. -- 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]
