HyukjinKwon commented on a change in pull request #24473: [SPARK-27534][SQL] Do not load `content` column in binary data source if it is not selected URL: https://github.com/apache/spark/pull/24473#discussion_r279179784
########## File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/binaryfile/BinaryFileFormatSuite.scala ########## @@ -286,4 +287,54 @@ class BinaryFileFormatSuite extends QueryTest with SharedSQLContext with SQLTest EqualTo(MODIFICATION_TIME, file1Status.getModificationTime) ), true) } + + test("column pruning") { + def getRequiredSchema(fieldNames: String*): StructType = { + StructType(fieldNames.map { + case f if schema.fieldNames.contains(f) => schema(f) + case other => StructField(other, NullType) + }) + } + def read(file: File, requiredSchema: StructType): Row = { + val format = new BinaryFileFormat + val reader = format.buildReaderWithPartitionValues( + sparkSession = spark, + dataSchema = schema, + partitionSchema = StructType(Nil), + requiredSchema = requiredSchema, + filters = Seq.empty, + options = Map.empty, + hadoopConf = spark.sessionState.newHadoopConf() + ) + val partitionedFile = mock(classOf[PartitionedFile]) + when(partitionedFile.filePath).thenReturn(file.getPath) + val encoder = RowEncoder(requiredSchema).resolveAndBind() + encoder.fromRow(reader(partitionedFile).next()) + } + val file = new File(Utils.createTempDir(), "data") + val content = "123".getBytes + Files.write(file.toPath, content, StandardOpenOption.CREATE, StandardOpenOption.WRITE) + + read(file, getRequiredSchema(MODIFICATION_TIME, CONTENT, LENGTH, PATH)) match { + case Row(t, c, l, p) => + assert(t === new Timestamp(file.lastModified)) + assert(c === content) + assert(l === content.length) + assert(p.asInstanceOf[String].endsWith(file.getAbsolutePath)) + } + file.setReadable(false) + withClue("cannot read content") { Review comment: We can still retain the group too, for instance, `column pruning - positive` and `column pruning - negative`. Not a big deal but I don't think it's difficult or too demanding to fix. ---------------------------------------------------------------- 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 With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org