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

    https://github.com/apache/spark/pull/14241#discussion_r73261265
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/ExistingRDD.scala ---
    @@ -275,62 +272,161 @@ private[sql] case class RowDataSourceScanExec(
            |}
          """.stripMargin
       }
    +
    +  // Ignore rdd when checking results
    +  override def sameResult(plan: SparkPlan): Boolean = plan match {
    +    case other: RowDataSourceScanExec => relation == other.relation && 
metadata == other.metadata
    +    case _ => false
    +  }
     }
     
    -/** Physical plan node for scanning data from a batched relation. */
    -private[sql] case class BatchedDataSourceScanExec(
    +/**
    + * Physical plan node for scanning data from HadoopFsRelations.
    + *
    + * @param relation The file-based relation to scan.
    + * @param output Output attributes of the scan.
    + * @param outputSchema Output schema of the scan.
    + * @param partitionFilters Predicates to use for partition pruning.
    + * @param dataFilters Data source filters to use for filtering data within 
partitions.
    + * @param metastoreTableIdentifier
    + */
    +private[sql] case class FileSourceScanExec(
    +    @transient relation: HadoopFsRelation,
         output: Seq[Attribute],
    -    rdd: RDD[InternalRow],
    -    @transient relation: BaseRelation,
    -    override val outputPartitioning: Partitioning,
    -    override val metadata: Map[String, String],
    +    outputSchema: StructType,
    +    partitionFilters: Seq[Expression],
    +    dataFilters: Seq[Filter],
         override val metastoreTableIdentifier: Option[TableIdentifier])
    -  extends DataSourceScanExec with CodegenSupport {
    +  extends DataSourceScanExec {
    +
    +  val supportsBatch = relation.fileFormat.supportBatch(
    +    relation.sparkSession, StructType.fromAttributes(output))
    +
    +  val needsUnsafeRowConversion = if 
(relation.fileFormat.isInstanceOf[ParquetSource]) {
    +    
SparkSession.getActiveSession.get.sessionState.conf.parquetVectorizedReaderEnabled
    +  } else {
    +    false
    +  }
    +
    +  override val outputPartitioning: Partitioning = {
    +    val bucketSpec = if 
(relation.sparkSession.sessionState.conf.bucketingEnabled) {
    +      relation.bucketSpec
    +    } else {
    +      None
    +    }
    +    bucketSpec.map { spec =>
    +      val numBuckets = spec.numBuckets
    +      val bucketColumns = spec.bucketColumnNames.flatMap { n =>
    +        output.find(_.name == n)
    +      }
    +      if (bucketColumns.size == spec.bucketColumnNames.size) {
    +        HashPartitioning(bucketColumns, numBuckets)
    +      } else {
    +        UnknownPartitioning(0)
    +      }
    +    }.getOrElse {
    +      UnknownPartitioning(0)
    +    }
    +  }
    +
    +  override val metadata: Map[String, String] = Map(
    +    "Format" -> relation.fileFormat.toString,
    +    "ReadSchema" -> outputSchema.catalogString,
    +    DataSourceScanExec.PUSHED_FILTERS -> dataFilters.mkString("[", ", ", 
"]"),
    +    DataSourceScanExec.INPUT_PATHS -> relation.location.paths.mkString(", 
"))
    +
    +  private def buildScan(): RDD[InternalRow] = {
    +    val selectedPartitions = relation.location.listFiles(partitionFilters)
    +
    +    val readFile: (PartitionedFile) => Iterator[InternalRow] =
    +      relation.fileFormat.buildReaderWithPartitionValues(
    +        sparkSession = relation.sparkSession,
    +        dataSchema = relation.dataSchema,
    +        partitionSchema = relation.partitionSchema,
    +        requiredSchema = outputSchema,
    +        filters = dataFilters,
    +        options = relation.options,
    +        hadoopConf = 
relation.sparkSession.sessionState.newHadoopConfWithOptions(relation.options))
    +
    +    relation.bucketSpec match {
    +      case Some(bucketing) if 
relation.sparkSession.sessionState.conf.bucketingEnabled =>
    +        createBucketedReadRDD(bucketing, readFile, selectedPartitions, 
relation)
    +      case _ =>
    +        createNonBucketedReadRDD(readFile, selectedPartitions, relation)
    +    }
    +  }
    +
    +  override def inputRDDs(): Seq[RDD[InternalRow]] = {
    +    buildScan() :: Nil
    +  }
     
       private[sql] override lazy val metrics =
         Map("numOutputRows" -> SQLMetrics.createMetric(sparkContext, "number 
of output rows"),
           "scanTime" -> SQLMetrics.createTimingMetric(sparkContext, "scan 
time"))
     
       protected override def doExecute(): RDD[InternalRow] = {
    -    // in the case of fallback, this batched scan should never fail 
because of:
    -    // 1) only primitive types are supported
    -    // 2) the number of columns should be smaller than 
spark.sql.codegen.maxFields
    -    WholeStageCodegenExec(this).execute()
    +    if (supportsBatch) {
    +      // in the case of fallback, this batched scan should never fail 
because of:
    +      // 1) only primitive types are supported
    +      // 2) the number of columns should be smaller than 
spark.sql.codegen.maxFields
    +      WholeStageCodegenExec(this).execute()
    +    } else {
    +      val unsafeRows = {
    +        val scan = buildScan()
    +        if (needsUnsafeRowConversion) {
    +          scan.mapPartitionsInternal { iter =>
    +            val proj = UnsafeProjection.create(schema)
    +            iter.map(proj)
    +          }
    +        } else {
    +          scan
    +        }
    +      }
    +      val numOutputRows = longMetric("numOutputRows")
    +      unsafeRows.map { r =>
    +        numOutputRows += 1
    +        r
    +      }
    +    }
       }
     
       override def simpleString: String = {
         val metadataEntries = for ((key, value) <- metadata.toSeq.sorted) 
yield {
           key + ": " + StringUtils.abbreviate(value, 100)
         }
         val metadataStr = Utils.truncatedString(metadataEntries, " ", ", ", "")
    -    s"Batched$nodeName${Utils.truncatedString(output, "[", ",", 
"]")}$metadataStr"
    +    s"File$nodeName${Utils.truncatedString(output, "[", ",", 
"]")}$metadataStr"
    --- End diff --
    
    I added Batch to metadata.


---
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