Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17015#discussion_r103383279
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala
 ---
    @@ -349,36 +350,41 @@ object CatalogTypes {
     
     
     /**
    - * An interface that is implemented by logical plans to return the 
underlying catalog table.
    - * If we can in the future consolidate SimpleCatalogRelation and 
MetastoreRelation, we should
    - * probably remove this interface.
    + * A [[LogicalPlan]] that represents a table.
      */
    -trait CatalogRelation {
    -  def catalogTable: CatalogTable
    -  def output: Seq[Attribute]
    -}
    +case class CatalogRelation(
    +    tableMeta: CatalogTable,
    +    dataCols: Seq[Attribute],
    +    partitionCols: Seq[Attribute]) extends LeafNode with 
MultiInstanceRelation {
    +  assert(tableMeta.identifier.database.isDefined)
    +  assert(tableMeta.partitionSchema.sameType(partitionCols.toStructType))
    +  assert(tableMeta.dataSchema.sameType(dataCols.toStructType))
    +
    +  // The partition column should always appear after data columns.
    +  override def output: Seq[Attribute] = dataCols ++ partitionCols
    +
    +  def isPartitioned: Boolean = partitionCols.nonEmpty
    +
    +  override def equals(relation: Any): Boolean = relation match {
    +    case other: CatalogRelation => tableMeta == other.tableMeta && output 
== other.output
    +    case _ => false
    +  }
     
    +  override def hashCode(): Int = {
    +    Objects.hashCode(tableMeta.identifier, output)
    +  }
     
    -/**
    - * A [[LogicalPlan]] that wraps [[CatalogTable]].
    - *
    - * Note that in the future we should consolidate this and 
HiveCatalogRelation.
    - */
    -case class SimpleCatalogRelation(
    -    metadata: CatalogTable)
    -  extends LeafNode with CatalogRelation {
    -
    -  override def catalogTable: CatalogTable = metadata
    -
    -  override lazy val resolved: Boolean = false
    -
    -  override val output: Seq[Attribute] = {
    -    val (partCols, dataCols) = metadata.schema.toAttributes
    -      // Since data can be dumped in randomly with no validation, 
everything is nullable.
    -      
.map(_.withNullability(true).withQualifier(Some(metadata.identifier.table)))
    -      .partition { a =>
    -        metadata.partitionColumnNames.contains(a.name)
    -      }
    -    dataCols ++ partCols
    +  /** Only compare table identifier. */
    +  override lazy val cleanArgs: Seq[Any] = Seq(tableMeta.identifier)
    +
    +  override def computeStats(conf: CatalystConf): Statistics = {
    +    // For data source tables, we will create a `LogicalRelation` and 
won't call this method, for
    +    // hive serde tables, we will always generate a statistics.
    +    // TODO: unify the table stats generation.
    +    tableMeta.stats.map(_.toPlanStats(output)).get
    --- End diff --
    
    Yeah, the value should be always filled by `DetermineTableStats`, but maybe 
we still can issue an exception when it is `None`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to