You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "Stefanietry (via GitHub)" <gi...@apache.org> on 2026/09/04 03:53:01 UTC

[PR] [spark] Support source table fileio for blob descriptors on spark [paimon]

Stefanietry opened a new pull request, #9598:
URL: https://github.com/apache/paimon/pull/9598

   ### Purpose
   Purpose: blob-descriptor-field stores blob values as serialized BlobDescriptor bytes inline in data files. In Spark, reading such fields as normal binary data should return the actual blob bytes, while blob-as-descriptor=true should return descriptor bytes.
   Currently, spark may fail to resolve the actual blob data because the read path does not always attach the required descriptor reader to the reconstructed blob value.
   
   Linked issue: https://github.com/apache/paimon/issues/9582
   
   ### Tests
   1. org.apache.paimon.spark.SparkInternalRowTest#testBlobDescriptorResolvingRowReattachesReader
   2. org.apache.spark.sql.test.SQLTestUtils#test("Blob: read blob descriptor field data")
   
   


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Support source table fileio for blob descriptors on spark [paimon]

Posted by "Stefanietry (via GitHub)" <gi...@apache.org>.
Stefanietry commented on code in PR #9598:
URL: https://github.com/apache/paimon/pull/9598#discussion_r3946962731


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/PaimonPartitionReaderFactory.scala:
##########
@@ -29,13 +30,19 @@ import java.util.Objects
 case class PaimonPartitionReaderFactory(
     readBuilder: ReadBuilder,
     metadataColumns: Seq[PaimonMetadataColumn] = Seq.empty,
-    blobAsDescriptor: Boolean)
+    blobAsDescriptor: Boolean,
+    uriReaderFactory: UriReaderFactory = null)

Review Comment:
   Thanks for catching this. I've updated the code accordingly.



##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/read/BaseScan.scala:
##########
@@ -144,7 +144,16 @@ trait BaseScan extends Scan with SupportsReportStatistics with Logging {
   override def toBatch: Batch = {
     val metadataColumns = metadataFields.map(
       field => PaimonMetadataColumn.get(field.name, SparkTypeUtils.toSparkPartitionType(table)))
-    PaimonBatch(inputPartitions, readBuilder, coreOptions.blobAsDescriptor(), metadataColumns)
+    val uriReaderFactory = table match {
+      case fileStoreTable: FileStoreTable => BlobDescriptorReaderFactory.create(fileStoreTable)

Review Comment:
   Thanks for catching this. I've updated the code accordingly.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Support source table fileio for blob descriptors on spark [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #9598:
URL: https://github.com/apache/paimon/pull/9598#discussion_r3931981969


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/read/BaseScan.scala:
##########
@@ -144,7 +144,16 @@ trait BaseScan extends Scan with SupportsReportStatistics with Logging {
   override def toBatch: Batch = {
     val metadataColumns = metadataFields.map(
       field => PaimonMetadataColumn.get(field.name, SparkTypeUtils.toSparkPartitionType(table)))
-    PaimonBatch(inputPartitions, readBuilder, coreOptions.blobAsDescriptor(), metadataColumns)
+    val uriReaderFactory = table match {
+      case fileStoreTable: FileStoreTable => BlobDescriptorReaderFactory.create(fileStoreTable)

Review Comment:
   [P1] Do not resolve the source table when descriptor output is requested
   
   BlobDescriptorReaderFactory.create is called for every FileStoreTable before checking coreOptions.blobAsDescriptor(). With blob-as-descriptor=true the partition reader deliberately never uses this factory, but create may still open the configured catalog and load blob-descriptor-source-table. A descriptor-only query (or even a projection with no BLOB column) now fails if that source table is unavailable, although returning the serialized descriptor requires no source data access. Please gate factory creation on !blobAsDescriptor (and preferably on the projected read type containing a BLOB) so unused source-table resolution cannot break scans.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Support source table fileio for blob descriptors on spark [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #9598:
URL: https://github.com/apache/paimon/pull/9598


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Support source table fileio for blob descriptors on spark [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #9598:
URL: https://github.com/apache/paimon/pull/9598#discussion_r3976673460


##########
paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sources/PaimonMicroBatchStreamTest.scala:
##########
@@ -87,6 +91,39 @@ class PaimonMicroBatchStreamTest extends AnyFunSuite {
     verify(scan, times(2)).notifyCheckpointComplete(6L)
   }
 
+  test("skip blob descriptor source table loading when descriptor output is requested") {
+    val table = mock(classOf[FileStoreTable])
+    val readBuilder = mock(classOf[ReadBuilder])
+    val options = new HashMap[String, String]
+    options.put(CoreOptions.BLOB_AS_DESCRIPTOR.key(), "true")
+    options.put(CoreOptions.BLOB_DESCRIPTOR_SOURCE_TABLE.key(), "db.missing_source")
+    when(table.options()).thenReturn(options)
+    when(readBuilder.readType()).thenReturn(blobRowType)
+
+    val stream = new PaimonMicroBatchStream(table, readBuilder, "unused")
+    val readerFactory = stream.createReaderFactory().asInstanceOf[PaimonPartitionReaderFactory]
+
+    assert(readerFactory.uriReaderFactory == null)
+    verify(table, never()).catalogEnvironment()
+  }
+
+  test("propagate blob descriptor reader to streaming reader factory") {
+    val table = mock(classOf[FileStoreTable])
+    val readBuilder = mock(classOf[ReadBuilder])
+    val catalogEnvironment = mock(classOf[CatalogEnvironment])
+    val options = Collections.emptyMap[String, String]()

Review Comment:
   [P2] Declare a descriptor field in the streaming reader test
   
   This fixture still uses an empty options map. With the new field scoping, `coreOptions().blobDescriptorField()` is empty, so no projected descriptor indices are selected and `createUriReaderFactory` correctly returns `null`. Consequently, the non-null assertion at line 124 fails instead of testing reader propagation. The focused Spark 3 run reproduced `null equaled null` here, with 5 tests passing and 1 failing in `PaimonMicroBatchStreamTest`.
   
   Please configure `blob-descriptor-field=picture` in this fixture, for example with `Collections.singletonMap(CoreOptions.BLOB_DESCRIPTOR_FIELD.key(), "picture")`, and assert that `readerFactory.blobDescriptorFieldIndices` contains exactly index `1` in addition to checking the non-null factory. This will exercise the intended descriptor read path and restore the test suite.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Support source table fileio for blob descriptors on spark [paimon]

Posted by "Stefanietry (via GitHub)" <gi...@apache.org>.
Stefanietry commented on code in PR #9598:
URL: https://github.com/apache/paimon/pull/9598#discussion_r3978720362


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/PaimonPartitionReader.scala:
##########
@@ -136,3 +149,24 @@ case class PaimonPartitionReader(
     }
   }
 }
+
+private[spark] object BlobDescriptorUtils {
+
+  def createUriReaderFactory(
+      table: Table,
+      readType: RowType,
+      blobAsDescriptor: Boolean): UriReaderFactory = {
+    if (blobAsDescriptor || !hasBlobFileFields(readType)) {
+      null
+    } else {
+      table match {
+        case fileStoreTable: FileStoreTable => BlobDescriptorReaderFactory.create(fileStoreTable)

Review Comment:
   Thanks for catching this. I've updated the code accordingly.



##########
paimon-spark/paimon-spark-ut/src/test/scala/org/apache/paimon/spark/sources/PaimonMicroBatchStreamTest.scala:
##########
@@ -87,6 +91,39 @@ class PaimonMicroBatchStreamTest extends AnyFunSuite {
     verify(scan, times(2)).notifyCheckpointComplete(6L)
   }
 
+  test("skip blob descriptor source table loading when descriptor output is requested") {
+    val table = mock(classOf[FileStoreTable])
+    val readBuilder = mock(classOf[ReadBuilder])
+    val options = new HashMap[String, String]
+    options.put(CoreOptions.BLOB_AS_DESCRIPTOR.key(), "true")
+    options.put(CoreOptions.BLOB_DESCRIPTOR_SOURCE_TABLE.key(), "db.missing_source")
+    when(table.options()).thenReturn(options)
+    when(readBuilder.readType()).thenReturn(blobRowType)
+
+    val stream = new PaimonMicroBatchStream(table, readBuilder, "unused")
+    val readerFactory = stream.createReaderFactory().asInstanceOf[PaimonPartitionReaderFactory]
+
+    assert(readerFactory.uriReaderFactory == null)
+    verify(table, never()).catalogEnvironment()
+  }
+
+  test("propagate blob descriptor reader to streaming reader factory") {
+    val table = mock(classOf[FileStoreTable])
+    val readBuilder = mock(classOf[ReadBuilder])
+    val catalogEnvironment = mock(classOf[CatalogEnvironment])
+    val options = Collections.emptyMap[String, String]()

Review Comment:
   Thanks for catching this. I've updated the code accordingly.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Support source table fileio for blob descriptors on spark [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #9598:
URL: https://github.com/apache/paimon/pull/9598#discussion_r3931980818


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/PaimonPartitionReaderFactory.scala:
##########
@@ -29,13 +30,19 @@ import java.util.Objects
 case class PaimonPartitionReaderFactory(
     readBuilder: ReadBuilder,
     metadataColumns: Seq[PaimonMetadataColumn] = Seq.empty,
-    blobAsDescriptor: Boolean)
+    blobAsDescriptor: Boolean,
+    uriReaderFactory: UriReaderFactory = null)

Review Comment:
   [P1] Propagate the descriptor reader through every Spark read path
   
   This new dependency defaults to null, and PaimonMicroBatchStream#createReaderFactory still constructs PaimonPartitionReaderFactory with only readBuilder/blobAsDescriptor. Every Structured Streaming read therefore takes the uriReaderFactory == null branch and keeps the BlobRef reader built from the target table FileIO, so descriptors that require blob-descriptor-source-table still fail on toData(). The postpone.merge-on-read path has the same gap: SortedBucketMergeIterator converts currentReader.next() directly and MergePlan carries only blobAsDescriptor. Please build/pass the source UriReaderFactory through both paths (and add streaming/postponed-read regressions) instead of silently falling back to null.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Support source table fileio for blob descriptors on spark [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #9598:
URL: https://github.com/apache/paimon/pull/9598#discussion_r3969534923


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/PaimonPartitionReader.scala:
##########
@@ -136,3 +149,24 @@ case class PaimonPartitionReader(
     }
   }
 }
+
+private[spark] object BlobDescriptorUtils {
+
+  def createUriReaderFactory(
+      table: Table,
+      readType: RowType,
+      blobAsDescriptor: Boolean): UriReaderFactory = {
+    if (blobAsDescriptor || !hasBlobFileFields(readType)) {
+      null
+    } else {
+      table match {
+        case fileStoreTable: FileStoreTable => BlobDescriptorReaderFactory.create(fileStoreTable)

Review Comment:
   [P1] Scope reader rebinding to descriptor fields and preserve managed BLOB FileIO
   
   `hasBlobFileFields` also matches ordinary managed `blob-field` columns, so this creates an external descriptor factory for them, and `BlobDescriptorResolvingRow` subsequently replaces every `BlobRef` reader. For a managed primary-key BLOB, `ColumnarRow.getBlob()` already supplies the target table's FileIO. Replacing it with a reader rebuilt from catalog options loses table-scoped credentials (e.g. `RESTTokenFileIO`), causing default payload reads to fail even when `blob-descriptor.source-table` is unset. I reproduced this with an isolated table-scoped FileIO: the original BlobRef reads successfully, while the wrapped row fails.
   
   The same scope problem introduces an unnecessary source-table dependency after materialization. In the existing `Blob: materialize descriptor with source table FileIO` test, dropping `blob_source` after the insert makes `SELECT picture FROM blob_target` fail with `Failed to load BLOB descriptor source table`, although the payload has already been copied into the target. Removing the target's `blob-descriptor.source-table` option restores the read.
   
   Please limit both factory initialization and reader replacement to the projected `blob-descriptor-field` columns, preserving the original readers for managed BLOBs. Gating factory creation alone is insufficient when a projection contains both descriptor and managed columns. Please cover table-scoped FileIO and reading a materialized copy after source removal in regression tests.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org