You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@auron.apache.org by "lyne7-sc (via GitHub)" <gi...@apache.org> on 2026/06/26 09:44:51 UTC
[PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
lyne7-sc opened a new pull request, #2367:
URL: https://github.com/apache/auron/pull/2367
# Which issue does this PR close?
Closes #2366
# Rationale for this change
Paimon metadata columns are produced by the Paimon scan layer rather than stored as physical columns in data files. The Paimon V2 native scan was passing these columns to the native Parquet/ORC reader as file columns, which can return incorrect values.
For example:
```sql
create table paimon.db.t_metadata (id int, v string) using paimon;
insert into paimon.db.t_metadata values (1, 'a');
select id, __paimon_file_path from paimon.db.t_metadata;
```
The native path returned null for `__paimon_file_path`, while Spark/Paimon's scan path returns the actual file path.
# What changes are included in this PR?
- Recognize Paimon metadata columns using PaimonMetadataColumn.
- Materialize supported file-level metadata columns (__paimon_file_path, __paimon_bucket) as per-file constants.
- Keep unsupported Paimon metadata columns on Spark/Paimon's scan path instead of reading them from Parquet/ORC files.
- Cover metadata columns both with and without table partition columns.
# Are there any user-facing changes?
No API changes. This is a correctness fix for Paimon V2 native scan.
# How was this patch tested?
Adds Paimon V2 integration 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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on code in PR #2367:
URL: https://github.com/apache/auron/pull/2367#discussion_r3488038233
##########
thirdparty/auron-paimon/src/test/scala/org/apache/auron/paimon/AuronPaimonV2IntegrationSuite.scala:
##########
@@ -209,13 +209,62 @@ class AuronPaimonV2IntegrationSuite
}
}
+ test("paimon v2 native scan supports file-level metadata columns") {
+ withTable("paimon.db.t_metadata") {
+ sql("create table paimon.db.t_metadata (id int, v string) using paimon")
+ sql("insert into paimon.db.t_metadata values (1, 'a')")
+
+ checkSparkAnswerAndNativePaimonScan(
+ "select id, __paimon_file_path, __paimon_bucket from paimon.db.t_metadata")
+ }
+ }
+
+ test("paimon v2 native scan supports metadata columns with table partitions") {
+ withTable("paimon.db.t_metadata_part") {
+ sql("""
+ |create table paimon.db.t_metadata_part (id int, v string, p string)
+ |using paimon
+ |partitioned by (p)
+ |""".stripMargin)
+ sql("insert into paimon.db.t_metadata_part values (1, 'a', 'p1'), (2, 'b', 'p2')")
+
+ checkSparkAnswerAndNativePaimonScan(
+ "select p, __paimon_file_path, id, __paimon_bucket from paimon.db.t_metadata_part")
+ }
+ }
+
+ test("paimon v2 native scan falls back for unsupported metadata columns") {
+ withTable("paimon.db.t_metadata_unsupported") {
+ sql("create table paimon.db.t_metadata_unsupported (id int, v string) using paimon")
+ sql("insert into paimon.db.t_metadata_unsupported values (1, 'a')")
+
+ val df = sql("select id, __paimon_row_index from paimon.db.t_metadata_unsupported")
+ val plan = df.queryExecution.executedPlan.toString()
+
+ assert(!plan.contains("NativePaimonV2TableScan"))
+ assert(df.collect().length === 1)
+ }
+ }
+
private def assertNativePaimonScanApplied(df: DataFrame): Unit = {
val plan = df.queryExecution.executedPlan.toString()
assert(
plan.contains("NativePaimonV2TableScan"),
s"plan should use native paimon scan:\n$plan")
}
+ private def checkSparkAnswerAndNativePaimonScan(sqlText: String): DataFrame = {
Review Comment:
Updated the helper to return `Unit`.
But I kept the existing `var expected` pattern because `val expected = withSQLConf { ... }` does not compile on Spark 3.x: `withSQLConf` returns `Unit` there.
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "SteNicholas (via GitHub)" <gi...@apache.org>.
SteNicholas commented on code in PR #2367:
URL: https://github.com/apache/auron/pull/2367#discussion_r3489758949
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -107,10 +115,25 @@ object PaimonScanSupport extends Logging {
logDebug("Skip native Paimon scan: unsupported column data type in read schema.")
return None
}
+ val physicalColumnSet = table.schema().fieldNames().asScala.toSet
+ def isPhysicalColumn(name: String): Boolean = containsName(physicalColumnSet, name)
+ val unsupportedMetadataColumns = readSchema.fields.filter { f =>
+ !isPhysicalColumn(f.name) && isPaimonMetadataColumn(f.name) && !isSupportedMetadataColumn(
+ f.name)
+ }
+ if (unsupportedMetadataColumns.nonEmpty) {
+ logDebug(
+ s"Skip native Paimon scan: unsupported metadata columns " +
+ s"${unsupportedMetadataColumns.map(_.name).mkString(", ")}.")
+ return None
+ }
- val partitionKeys = table.schema().partitionKeys().asScala.toSet
- val partitionFields = readSchema.fields.filter(f => containsName(partitionKeys, f.name))
- val fileFields = readSchema.fields.filterNot(f => containsName(partitionKeys, f.name))
+ val partitionKeySet = table.schema().partitionKeys().asScala.toSet
+ def isPartitionValueField(name: String): Boolean =
+ containsName(partitionKeySet, name) ||
+ (!isPhysicalColumn(name) && isSupportedMetadataColumn(name))
+ val partitionFields = readSchema.fields.filter(f => isPartitionValueField(f.name))
+ val fileFields = readSchema.fields.filterNot(f => isPartitionValueField(f.name))
val partitionSchema = StructType(partitionFields)
val fileSchema = StructType(fileFields)
Review Comment:
Metadata-only projections (e.g. `SELECT __paimon_file_path`) make `fileFields` empty, so `fileSchema` is empty and all output columns come from `partitionSchema`. The file is still treated as splittable downstream, so correctness then relies on the native parquet/orc scan producing the correct row count with **zero projected file columns** + byte ranges. `t_metadata_only` writes only 2 rows (a single, unsplit file), so the empty-schema + multi-range path is unverified — worth a test with a file large enough to be split.
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -149,19 +172,29 @@ object PaimonScanSupport extends Logging {
val partitionRowType = table.schema().logicalPartitionType()
val partitionConverter = new RowDataToObjectArrayConverter(partitionRowType)
+ val partitionKeys = table.schema().partitionKeys().asScala.toSeq
+ val filePathMetadataIndex = partitionSchema.fields.indexWhere { field =>
+ isFilePathMetadataColumn(field.name)
+ }
val files = splits.flatMap { split =>
- val partitionValues = if (partitionSchema.isEmpty) {
- InternalRow.empty
+ val partitionValueTemplate = if (partitionSchema.isEmpty) {
+ Array.empty[Any]
} else {
- toPartitionRow(
+ toPartitionValueTemplate(
partitionConverter.convert(split.partition()),
partitionRowType,
partitionSchema,
- table.schema().partitionKeys().asScala.toSeq)
+ partitionKeys,
+ split.bucket())
}
split.dataFiles().asScala.map { dataFile =>
val filePath = s"${split.bucketPath()}/${dataFile.fileName()}"
Review Comment:
`__paimon_file_path` value format diverges from Paimon. The value here is `split.bucketPath()/fileName`, i.e. `org.apache.paimon.fs.Path.toString()`, which uses `uri.getPath()` (URI-**decoded**). But Paimon's own metadata column (`PaimonRecordReaderIterator.updateMetadataRow`) emits `filePath().toUri().toString()` (percent-**encoded**) — verified by decompiling paimon-spark 1.2.0. The two diverge whenever the path contains characters Paimon escapes into a directory name, e.g. a partition value `50%` → dir `p=50%25` → Spark returns `…%2525…` while the native scan returns `…%25…`; non-ASCII partition values diverge similarly. The new tests only use clean ASCII paths, so this isn't caught. Suggest: `new Path(split.bucketPath(), dataFile.fileName()).toUri.toString`.
Related: this also ignores `dataFile.externalPath()`. Paimon's raw-file path is `externalPath().orElse(bucketPath/fileName)`, so for tables using `data-file.external-paths` both the `__paimon_file_path` value and the location opened here would be wrong.
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -174,30 +207,64 @@ object PaimonScanSupport extends Logging {
names.exists(n => resolver(n, target))
}
- // Build a Spark InternalRow for partition values matching partitionSchema's data types.
- // Partition values from Paimon are returned in the table's partition-key order; we reorder
- // them to match partitionSchema and convert each value into the Spark catalyst representation
- // expected for the field's type via Paimon's own DataConverter. This handles dates (epoch
- // days), timestamps (micros), decimals and binary correctly, rather than the lossy
- // String round-trip a Cast(Literal(value.toString), dataType) would perform.
- private def toPartitionRow(
+ private def isFilePathMetadataColumn(name: String): Boolean = {
+ SQLConf.get.resolver(name, PaimonFilePathColumn)
+ }
+
+ private def isBucketMetadataColumn(name: String): Boolean = {
+ SQLConf.get.resolver(name, PaimonBucketColumn)
+ }
+
+ private def isSupportedMetadataColumn(name: String): Boolean = {
+ isFilePathMetadataColumn(name) || isBucketMetadataColumn(name)
+ }
+
+ private def isPaimonMetadataColumn(name: String): Boolean = {
+ containsName(PaimonMetadataColumns, name) ||
+ name.toLowerCase(Locale.ROOT).startsWith(PaimonMetadataColumnPrefix)
+ }
+
+ // Build split-invariant constants for partition columns and supported metadata columns in
+ // partitionSchema order. Paimon's DataConverter preserves Catalyst representations for typed
+ // partition values such as dates, timestamps, decimals and binary.
+ private def toPartitionValueTemplate(
paimonValues: Array[AnyRef],
partitionRowType: RowType,
partitionSchema: StructType,
- partitionKeys: Seq[String]): InternalRow = {
+ partitionKeys: Seq[String],
+ bucket: Int): Array[Any] = {
val resolver = SQLConf.get.resolver
val indexByName = partitionKeys.zipWithIndex.toMap
- InternalRow.fromSeq(partitionSchema.fields.map { field =>
- val idx = indexByName
- .find { case (k, _) => resolver(k, field.name) }
- .map(_._2)
- .getOrElse(-1)
- if (idx >= 0 && idx < paimonValues.length && paimonValues(idx) != null) {
- DataConverter.fromPaimon(paimonValues(idx), partitionRowType.getTypeAt(idx))
- } else {
+ partitionSchema.fields.map { field =>
+ if (isFilePathMetadataColumn(field.name)) {
null
+ } else if (isBucketMetadataColumn(field.name)) {
Review Comment:
Partition-key vs metadata name collision. Classification (`unsupportedMetadataColumns`, `isPartitionValueField`) correctly guards with `!isPhysicalColumn`, but the value-filling here matches purely on name: a **partition column** literally named `__paimon_bucket` reaches this branch and gets `split.bucket()` instead of its real partition value. The same applies to `filePathMetadataIndex` (line 176) + `toPartitionRow` (line 265) for a partition column named `__paimon_file_path`. The PR's own collision test proves Paimon allows physical columns with these names, so e.g.
```sql
CREATE TABLE t(`__paimon_bucket` int, id int) USING paimon PARTITIONED BY (`__paimon_bucket`);
INSERT INTO t VALUES (10,1),(20,2);
SELECT `__paimon_bucket`, id FROM t; -- returns 0,_ instead of 10/20
```
returns the bucket value (0) instead of the stored partition values — silent data corruption. Suggest adding the `!isPhysicalColumn(field.name)` guard to these metadata branches and to `filePathMetadataIndex`.
##########
thirdparty/auron-paimon/src/test/scala/org/apache/auron/paimon/AuronPaimonV2IntegrationSuite.scala:
##########
@@ -209,13 +209,85 @@ class AuronPaimonV2IntegrationSuite
}
}
+ test("paimon v2 native scan supports file-level metadata columns") {
+ withTable("paimon.db.t_metadata") {
+ sql("create table paimon.db.t_metadata (id int, v string) using paimon")
+ sql("insert into paimon.db.t_metadata values (1, 'a')")
+
+ checkSparkAnswerAndNativePaimonScan(
+ "select id, __paimon_file_path, __paimon_bucket from paimon.db.t_metadata")
Review Comment:
Two coverage gaps in the new metadata tests:
- `__paimon_bucket` is `0` in every test that reads it (append-only unaware-bucket tables); the only bucketed tables never project it. A regression returning a constant bucket (or the partition-name-collision bug noted on `PaimonScanSupport`) would pass. Consider a bucketed table whose `__paimon_bucket` is non-zero.
- All tests use a single `INSERT` → one data file per split, so the per-file `partitionValueTemplate.clone()` + path-overwrite path is never exercised with >1 file in a single split. A multi-file split test would cover that.
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on code in PR #2367:
URL: https://github.com/apache/auron/pull/2367#discussion_r3492582472
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -174,30 +207,64 @@ object PaimonScanSupport extends Logging {
names.exists(n => resolver(n, target))
}
- // Build a Spark InternalRow for partition values matching partitionSchema's data types.
- // Partition values from Paimon are returned in the table's partition-key order; we reorder
- // them to match partitionSchema and convert each value into the Spark catalyst representation
- // expected for the field's type via Paimon's own DataConverter. This handles dates (epoch
- // days), timestamps (micros), decimals and binary correctly, rather than the lossy
- // String round-trip a Cast(Literal(value.toString), dataType) would perform.
- private def toPartitionRow(
+ private def isFilePathMetadataColumn(name: String): Boolean = {
+ SQLConf.get.resolver(name, PaimonFilePathColumn)
+ }
+
+ private def isBucketMetadataColumn(name: String): Boolean = {
+ SQLConf.get.resolver(name, PaimonBucketColumn)
+ }
+
+ private def isSupportedMetadataColumn(name: String): Boolean = {
+ isFilePathMetadataColumn(name) || isBucketMetadataColumn(name)
+ }
+
+ private def isPaimonMetadataColumn(name: String): Boolean = {
+ containsName(PaimonMetadataColumns, name) ||
+ name.toLowerCase(Locale.ROOT).startsWith(PaimonMetadataColumnPrefix)
+ }
+
+ // Build split-invariant constants for partition columns and supported metadata columns in
+ // partitionSchema order. Paimon's DataConverter preserves Catalyst representations for typed
+ // partition values such as dates, timestamps, decimals and binary.
+ private def toPartitionValueTemplate(
paimonValues: Array[AnyRef],
partitionRowType: RowType,
partitionSchema: StructType,
- partitionKeys: Seq[String]): InternalRow = {
+ partitionKeys: Seq[String],
+ bucket: Int): Array[Any] = {
val resolver = SQLConf.get.resolver
val indexByName = partitionKeys.zipWithIndex.toMap
- InternalRow.fromSeq(partitionSchema.fields.map { field =>
- val idx = indexByName
- .find { case (k, _) => resolver(k, field.name) }
- .map(_._2)
- .getOrElse(-1)
- if (idx >= 0 && idx < paimonValues.length && paimonValues(idx) != null) {
- DataConverter.fromPaimon(paimonValues(idx), partitionRowType.getTypeAt(idx))
- } else {
+ partitionSchema.fields.map { field =>
+ if (isFilePathMetadataColumn(field.name)) {
null
+ } else if (isBucketMetadataColumn(field.name)) {
Review Comment:
Fixed. Real physical/partition columns are now handled before metadata columns, so a partition column named `__paimon_bucket` or `__paimon_file_path` keeps its stored partition value.
I added regression coverage for both conflicting partition names.
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on code in PR #2367:
URL: https://github.com/apache/auron/pull/2367#discussion_r3488035831
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -107,10 +115,21 @@ object PaimonScanSupport extends Logging {
logDebug("Skip native Paimon scan: unsupported column data type in read schema.")
return None
}
+ val unsupportedMetadataColumns = readSchema.fields.filter { f =>
+ isPaimonMetadataColumn(f.name) && !isSupportedMetadataColumn(f.name)
+ }
+ if (unsupportedMetadataColumns.nonEmpty) {
+ logDebug(
+ s"Skip native Paimon scan: unsupported metadata columns " +
+ s"${unsupportedMetadataColumns.map(_.name).mkString(", ")}.")
+ return None
+ }
val partitionKeys = table.schema().partitionKeys().asScala.toSet
- val partitionFields = readSchema.fields.filter(f => containsName(partitionKeys, f.name))
- val fileFields = readSchema.fields.filterNot(f => containsName(partitionKeys, f.name))
+ def isPartitionValueField(name: String): Boolean =
+ containsName(partitionKeys, name) || isSupportedMetadataColumn(name)
Review Comment:
Fixed by making physical table columns take precedence over metadata name matching. A real column named
`__paimon_bucket` now stays in `fileSchema` and is read from the data file. Added a regression test for this case.
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "SteNicholas (via GitHub)" <gi...@apache.org>.
SteNicholas commented on PR #2367:
URL: https://github.com/apache/auron/pull/2367#issuecomment-4829391582
@lyne7-sc, could you provide your wechat which I could discuss with you?
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on code in PR #2367:
URL: https://github.com/apache/auron/pull/2367#discussion_r3488053660
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -174,28 +195,50 @@ object PaimonScanSupport extends Logging {
names.exists(n => resolver(n, target))
}
- // Build a Spark InternalRow for partition values matching partitionSchema's data types.
- // Partition values from Paimon are returned in the table's partition-key order; we reorder
- // them to match partitionSchema and convert each value into the Spark catalyst representation
- // expected for the field's type via Paimon's own DataConverter. This handles dates (epoch
- // days), timestamps (micros), decimals and binary correctly, rather than the lossy
- // String round-trip a Cast(Literal(value.toString), dataType) would perform.
+ private def isFilePathMetadataColumn(name: String): Boolean = {
+ SQLConf.get.resolver(name, PaimonFilePathColumn)
+ }
+
+ private def isBucketMetadataColumn(name: String): Boolean = {
+ SQLConf.get.resolver(name, PaimonBucketColumn)
+ }
+
+ private def isSupportedMetadataColumn(name: String): Boolean = {
+ isFilePathMetadataColumn(name) || isBucketMetadataColumn(name)
+ }
+
+ private def isPaimonMetadataColumn(name: String): Boolean = {
+ containsName(PaimonMetadataColumns, name) ||
+ name.toLowerCase(Locale.ROOT).startsWith(PaimonMetadataColumnPrefix)
Review Comment:
Thanks for pointing this out. Fixed by running Spotless.
##########
thirdparty/auron-paimon/src/test/scala/org/apache/auron/paimon/AuronPaimonV2IntegrationSuite.scala:
##########
@@ -209,13 +209,62 @@ class AuronPaimonV2IntegrationSuite
}
}
+ test("paimon v2 native scan supports file-level metadata columns") {
+ withTable("paimon.db.t_metadata") {
+ sql("create table paimon.db.t_metadata (id int, v string) using paimon")
+ sql("insert into paimon.db.t_metadata values (1, 'a')")
+
+ checkSparkAnswerAndNativePaimonScan(
+ "select id, __paimon_file_path, __paimon_bucket from paimon.db.t_metadata")
+ }
+ }
+
+ test("paimon v2 native scan supports metadata columns with table partitions") {
+ withTable("paimon.db.t_metadata_part") {
+ sql("""
+ |create table paimon.db.t_metadata_part (id int, v string, p string)
+ |using paimon
+ |partitioned by (p)
+ |""".stripMargin)
+ sql("insert into paimon.db.t_metadata_part values (1, 'a', 'p1'), (2, 'b', 'p2')")
+
+ checkSparkAnswerAndNativePaimonScan(
+ "select p, __paimon_file_path, id, __paimon_bucket from paimon.db.t_metadata_part")
+ }
+ }
+
+ test("paimon v2 native scan falls back for unsupported metadata columns") {
+ withTable("paimon.db.t_metadata_unsupported") {
+ sql("create table paimon.db.t_metadata_unsupported (id int, v string) using paimon")
+ sql("insert into paimon.db.t_metadata_unsupported values (1, 'a')")
+
+ val df = sql("select id, __paimon_row_index from paimon.db.t_metadata_unsupported")
+ val plan = df.queryExecution.executedPlan.toString()
+
+ assert(!plan.contains("NativePaimonV2TableScan"))
+ assert(df.collect().length === 1)
+ }
+ }
+
Review Comment:
Removed the trailing whitespace, and the ci is green now.
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "SteNicholas (via GitHub)" <gi...@apache.org>.
SteNicholas merged PR #2367:
URL: https://github.com/apache/auron/pull/2367
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on code in PR #2367:
URL: https://github.com/apache/auron/pull/2367#discussion_r3488032170
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -151,17 +170,19 @@ object PaimonScanSupport extends Logging {
val partitionConverter = new RowDataToObjectArrayConverter(partitionRowType)
val files = splits.flatMap { split =>
- val partitionValues = if (partitionSchema.isEmpty) {
- InternalRow.empty
- } else {
- toPartitionRow(
- partitionConverter.convert(split.partition()),
- partitionRowType,
- partitionSchema,
- table.schema().partitionKeys().asScala.toSeq)
- }
split.dataFiles().asScala.map { dataFile =>
val filePath = s"${split.bucketPath()}/${dataFile.fileName()}"
+ val partitionValues = if (partitionSchema.isEmpty) {
Review Comment:
Makes sense. Addressed by computing the split-invariant partition/metadata values once per split, and only filling the per-file `__paimon_file_path` inside the data-file loop.
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on code in PR #2367:
URL: https://github.com/apache/auron/pull/2367#discussion_r3492585683
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -107,10 +115,25 @@ object PaimonScanSupport extends Logging {
logDebug("Skip native Paimon scan: unsupported column data type in read schema.")
return None
}
+ val physicalColumnSet = table.schema().fieldNames().asScala.toSet
+ def isPhysicalColumn(name: String): Boolean = containsName(physicalColumnSet, name)
+ val unsupportedMetadataColumns = readSchema.fields.filter { f =>
+ !isPhysicalColumn(f.name) && isPaimonMetadataColumn(f.name) && !isSupportedMetadataColumn(
+ f.name)
+ }
+ if (unsupportedMetadataColumns.nonEmpty) {
+ logDebug(
+ s"Skip native Paimon scan: unsupported metadata columns " +
+ s"${unsupportedMetadataColumns.map(_.name).mkString(", ")}.")
+ return None
+ }
- val partitionKeys = table.schema().partitionKeys().asScala.toSet
- val partitionFields = readSchema.fields.filter(f => containsName(partitionKeys, f.name))
- val fileFields = readSchema.fields.filterNot(f => containsName(partitionKeys, f.name))
+ val partitionKeySet = table.schema().partitionKeys().asScala.toSet
+ def isPartitionValueField(name: String): Boolean =
+ containsName(partitionKeySet, name) ||
+ (!isPhysicalColumn(name) && isSupportedMetadataColumn(name))
+ val partitionFields = readSchema.fields.filter(f => isPartitionValueField(f.name))
+ val fileFields = readSchema.fields.filterNot(f => isPartitionValueField(f.name))
val partitionSchema = StructType(partitionFields)
val fileSchema = StructType(fileFields)
Review Comment:
Added a metadata-only projection test for `select __paimon_file_path`. This covers the empty `fileSchema` path and verifies the native result against Spark fallback.
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on PR #2367:
URL: https://github.com/apache/auron/pull/2367#issuecomment-4826458525
@SteNicholas Thanks for the careful review! Addressed the comments in the latest update, and the relevant ci is green now.
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on code in PR #2367:
URL: https://github.com/apache/auron/pull/2367#discussion_r3488035373
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -107,10 +115,21 @@ object PaimonScanSupport extends Logging {
logDebug("Skip native Paimon scan: unsupported column data type in read schema.")
return None
}
+ val unsupportedMetadataColumns = readSchema.fields.filter { f =>
+ isPaimonMetadataColumn(f.name) && !isSupportedMetadataColumn(f.name)
+ }
+ if (unsupportedMetadataColumns.nonEmpty) {
+ logDebug(
+ s"Skip native Paimon scan: unsupported metadata columns " +
+ s"${unsupportedMetadataColumns.map(_.name).mkString(", ")}.")
+ return None
+ }
val partitionKeys = table.schema().partitionKeys().asScala.toSet
- val partitionFields = readSchema.fields.filter(f => containsName(partitionKeys, f.name))
- val fileFields = readSchema.fields.filterNot(f => containsName(partitionKeys, f.name))
+ def isPartitionValueField(name: String): Boolean =
+ containsName(partitionKeys, name) || isSupportedMetadataColumn(name)
+ val partitionFields = readSchema.fields.filter(f => isPartitionValueField(f.name))
+ val fileFields = readSchema.fields.filterNot(f => isPartitionValueField(f.name))
Review Comment:
Good point. Added a regression test for metadata-only projection on a multi-row non-partitioned table.
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on PR #2367:
URL: https://github.com/apache/auron/pull/2367#issuecomment-4833942288
Thanks @SteNicholas for the reviews. I addressed the remaining comments in the latest commits, and verified the Paimon integration suites.
> @lyne7-sc, could you provide your wechat which I could discuss with you?
Sure, my wechat: lin545463364
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on code in PR #2367:
URL: https://github.com/apache/auron/pull/2367#discussion_r3492576397
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -149,19 +172,29 @@ object PaimonScanSupport extends Logging {
val partitionRowType = table.schema().logicalPartitionType()
val partitionConverter = new RowDataToObjectArrayConverter(partitionRowType)
+ val partitionKeys = table.schema().partitionKeys().asScala.toSeq
+ val filePathMetadataIndex = partitionSchema.fields.indexWhere { field =>
+ isFilePathMetadataColumn(field.name)
+ }
val files = splits.flatMap { split =>
- val partitionValues = if (partitionSchema.isEmpty) {
- InternalRow.empty
+ val partitionValueTemplate = if (partitionSchema.isEmpty) {
+ Array.empty[Any]
} else {
- toPartitionRow(
+ toPartitionValueTemplate(
partitionConverter.convert(split.partition()),
partitionRowType,
partitionSchema,
- table.schema().partitionKeys().asScala.toSeq)
+ partitionKeys,
+ split.bucket())
}
split.dataFiles().asScala.map { dataFile =>
val filePath = s"${split.bucketPath()}/${dataFile.fileName()}"
Review Comment:
Fixed. `__paimon_file_path` now uses the URI-style value via `Path(...).toUri.toString`, while the native reader still uses the raw path for file access. I also added coverage with an encoded partition value to catch this difference.
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "lyne7-sc (via GitHub)" <gi...@apache.org>.
lyne7-sc commented on code in PR #2367:
URL: https://github.com/apache/auron/pull/2367#discussion_r3492587323
##########
thirdparty/auron-paimon/src/test/scala/org/apache/auron/paimon/AuronPaimonV2IntegrationSuite.scala:
##########
@@ -209,13 +209,85 @@ class AuronPaimonV2IntegrationSuite
}
}
+ test("paimon v2 native scan supports file-level metadata columns") {
+ withTable("paimon.db.t_metadata") {
+ sql("create table paimon.db.t_metadata (id int, v string) using paimon")
+ sql("insert into paimon.db.t_metadata values (1, 'a')")
+
+ checkSparkAnswerAndNativePaimonScan(
+ "select id, __paimon_file_path, __paimon_bucket from paimon.db.t_metadata")
Review Comment:
Added both coverages.
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [AURON #2366] fix: Handle Paimon metadata columns in V2 native scan [auron]
Posted by "SteNicholas (via GitHub)" <gi...@apache.org>.
SteNicholas commented on code in PR #2367:
URL: https://github.com/apache/auron/pull/2367#discussion_r3487595562
##########
thirdparty/auron-paimon/src/test/scala/org/apache/auron/paimon/AuronPaimonV2IntegrationSuite.scala:
##########
@@ -209,13 +209,62 @@ class AuronPaimonV2IntegrationSuite
}
}
+ test("paimon v2 native scan supports file-level metadata columns") {
+ withTable("paimon.db.t_metadata") {
+ sql("create table paimon.db.t_metadata (id int, v string) using paimon")
+ sql("insert into paimon.db.t_metadata values (1, 'a')")
+
+ checkSparkAnswerAndNativePaimonScan(
+ "select id, __paimon_file_path, __paimon_bucket from paimon.db.t_metadata")
+ }
+ }
+
+ test("paimon v2 native scan supports metadata columns with table partitions") {
+ withTable("paimon.db.t_metadata_part") {
+ sql("""
+ |create table paimon.db.t_metadata_part (id int, v string, p string)
+ |using paimon
+ |partitioned by (p)
+ |""".stripMargin)
+ sql("insert into paimon.db.t_metadata_part values (1, 'a', 'p1'), (2, 'b', 'p2')")
+
+ checkSparkAnswerAndNativePaimonScan(
+ "select p, __paimon_file_path, id, __paimon_bucket from paimon.db.t_metadata_part")
+ }
+ }
+
+ test("paimon v2 native scan falls back for unsupported metadata columns") {
+ withTable("paimon.db.t_metadata_unsupported") {
+ sql("create table paimon.db.t_metadata_unsupported (id int, v string) using paimon")
+ sql("insert into paimon.db.t_metadata_unsupported values (1, 'a')")
+
+ val df = sql("select id, __paimon_row_index from paimon.db.t_metadata_unsupported")
+ val plan = df.queryExecution.executedPlan.toString()
+
+ assert(!plan.contains("NativePaimonV2TableScan"))
+ assert(df.collect().length === 1)
+ }
+ }
+
Review Comment:
**Style / CI blocker.** This blank line has trailing whitespace (8 spaces), which spotless rejects (`-········` → `+`). It is the second cause of the failing Style job. `mvn spotless:apply` removes it.
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -107,10 +115,21 @@ object PaimonScanSupport extends Logging {
logDebug("Skip native Paimon scan: unsupported column data type in read schema.")
return None
}
+ val unsupportedMetadataColumns = readSchema.fields.filter { f =>
+ isPaimonMetadataColumn(f.name) && !isSupportedMetadataColumn(f.name)
+ }
+ if (unsupportedMetadataColumns.nonEmpty) {
+ logDebug(
+ s"Skip native Paimon scan: unsupported metadata columns " +
+ s"${unsupportedMetadataColumns.map(_.name).mkString(", ")}.")
+ return None
+ }
val partitionKeys = table.schema().partitionKeys().asScala.toSet
- val partitionFields = readSchema.fields.filter(f => containsName(partitionKeys, f.name))
- val fileFields = readSchema.fields.filterNot(f => containsName(partitionKeys, f.name))
+ def isPartitionValueField(name: String): Boolean =
+ containsName(partitionKeys, name) || isSupportedMetadataColumn(name)
+ val partitionFields = readSchema.fields.filter(f => isPartitionValueField(f.name))
+ val fileFields = readSchema.fields.filterNot(f => isPartitionValueField(f.name))
Review Comment:
Coverage gap worth a test: when only metadata columns are projected from a **non-partitioned** table (e.g. `select __paimon_file_path from t`), every field is classified as a partition/metadata constant, so `fileFields` is empty and `fileSchema` is empty. The native Parquet/ORC scan is then asked to read zero data columns but must still emit one row per record so the constant columns get the right cardinality. All three new tests also select `id`, so the empty-`fileSchema` path is never exercised (and there's no existing partition-only/`count(*)` test either). Please add a metadata-only projection test on a multi-row non-partitioned table to confirm the row count is correct on this path.
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -174,28 +195,50 @@ object PaimonScanSupport extends Logging {
names.exists(n => resolver(n, target))
}
- // Build a Spark InternalRow for partition values matching partitionSchema's data types.
- // Partition values from Paimon are returned in the table's partition-key order; we reorder
- // them to match partitionSchema and convert each value into the Spark catalyst representation
- // expected for the field's type via Paimon's own DataConverter. This handles dates (epoch
- // days), timestamps (micros), decimals and binary correctly, rather than the lossy
- // String round-trip a Cast(Literal(value.toString), dataType) would perform.
+ private def isFilePathMetadataColumn(name: String): Boolean = {
+ SQLConf.get.resolver(name, PaimonFilePathColumn)
+ }
+
+ private def isBucketMetadataColumn(name: String): Boolean = {
+ SQLConf.get.resolver(name, PaimonBucketColumn)
+ }
+
+ private def isSupportedMetadataColumn(name: String): Boolean = {
+ isFilePathMetadataColumn(name) || isBucketMetadataColumn(name)
+ }
+
+ private def isPaimonMetadataColumn(name: String): Boolean = {
+ containsName(PaimonMetadataColumns, name) ||
+ name.toLowerCase(Locale.ROOT).startsWith(PaimonMetadataColumnPrefix)
Review Comment:
**Style / CI blocker.** spotless `scalafmt` rejects this line — the `||` continuation should be indented 4 spaces, not 6. This is one of the two violations turning the Style job red (`-······name.toLowerCase` → `+····name.toLowerCase`). `mvn spotless:apply` fixes it:
```scala
private def isPaimonMetadataColumn(name: String): Boolean = {
containsName(PaimonMetadataColumns, name) ||
name.toLowerCase(Locale.ROOT).startsWith(PaimonMetadataColumnPrefix)
}
```
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -151,17 +170,19 @@ object PaimonScanSupport extends Logging {
val partitionConverter = new RowDataToObjectArrayConverter(partitionRowType)
val files = splits.flatMap { split =>
- val partitionValues = if (partitionSchema.isEmpty) {
- InternalRow.empty
- } else {
- toPartitionRow(
- partitionConverter.convert(split.partition()),
- partitionRowType,
- partitionSchema,
- table.schema().partitionKeys().asScala.toSeq)
- }
split.dataFiles().asScala.map { dataFile =>
val filePath = s"${split.bucketPath()}/${dataFile.fileName()}"
+ val partitionValues = if (partitionSchema.isEmpty) {
Review Comment:
Efficiency: `partitionValues` is now computed inside `split.dataFiles().map`, so `partitionConverter.convert(split.partition())`, `indexByName`, and the per-field `DataConverter.fromPaimon` conversions all run once per data file — even though everything except `__paimon_file_path` is constant across the files of a split (`split.partition()` and `split.bucket()` are split-level). For a split with N data files this rebuilds the whole partition row N times. Consider computing the split-invariant portion once per split and only filling the per-file `file_path` slot inside the loop.
##########
thirdparty/auron-paimon/src/main/scala/org/apache/spark/sql/auron/paimon/PaimonScanSupport.scala:
##########
@@ -107,10 +115,21 @@ object PaimonScanSupport extends Logging {
logDebug("Skip native Paimon scan: unsupported column data type in read schema.")
return None
}
+ val unsupportedMetadataColumns = readSchema.fields.filter { f =>
+ isPaimonMetadataColumn(f.name) && !isSupportedMetadataColumn(f.name)
+ }
+ if (unsupportedMetadataColumns.nonEmpty) {
+ logDebug(
+ s"Skip native Paimon scan: unsupported metadata columns " +
+ s"${unsupportedMetadataColumns.map(_.name).mkString(", ")}.")
+ return None
+ }
val partitionKeys = table.schema().partitionKeys().asScala.toSet
- val partitionFields = readSchema.fields.filter(f => containsName(partitionKeys, f.name))
- val fileFields = readSchema.fields.filterNot(f => containsName(partitionKeys, f.name))
+ def isPartitionValueField(name: String): Boolean =
+ containsName(partitionKeys, name) || isSupportedMetadataColumn(name)
Review Comment:
Minor / edge case: classification here is purely by name (resolver against `__paimon_file_path`/`__paimon_bucket`). Paimon's schema validation reserves only the `_KEY_` prefix and the core system field names — not the `__paimon_` prefix — so a user could in principle define a real physical column named `__paimon_bucket`. It would then be treated as a per-file constant and return `split.bucket()` instead of the stored value (a silent wrong result rather than a fallback). Very unlikely in practice, but flagging it.
##########
thirdparty/auron-paimon/src/test/scala/org/apache/auron/paimon/AuronPaimonV2IntegrationSuite.scala:
##########
@@ -209,13 +209,62 @@ class AuronPaimonV2IntegrationSuite
}
}
+ test("paimon v2 native scan supports file-level metadata columns") {
+ withTable("paimon.db.t_metadata") {
+ sql("create table paimon.db.t_metadata (id int, v string) using paimon")
+ sql("insert into paimon.db.t_metadata values (1, 'a')")
+
+ checkSparkAnswerAndNativePaimonScan(
+ "select id, __paimon_file_path, __paimon_bucket from paimon.db.t_metadata")
+ }
+ }
+
+ test("paimon v2 native scan supports metadata columns with table partitions") {
+ withTable("paimon.db.t_metadata_part") {
+ sql("""
+ |create table paimon.db.t_metadata_part (id int, v string, p string)
+ |using paimon
+ |partitioned by (p)
+ |""".stripMargin)
+ sql("insert into paimon.db.t_metadata_part values (1, 'a', 'p1'), (2, 'b', 'p2')")
+
+ checkSparkAnswerAndNativePaimonScan(
+ "select p, __paimon_file_path, id, __paimon_bucket from paimon.db.t_metadata_part")
+ }
+ }
+
+ test("paimon v2 native scan falls back for unsupported metadata columns") {
+ withTable("paimon.db.t_metadata_unsupported") {
+ sql("create table paimon.db.t_metadata_unsupported (id int, v string) using paimon")
+ sql("insert into paimon.db.t_metadata_unsupported values (1, 'a')")
+
+ val df = sql("select id, __paimon_row_index from paimon.db.t_metadata_unsupported")
+ val plan = df.queryExecution.executedPlan.toString()
+
+ assert(!plan.contains("NativePaimonV2TableScan"))
+ assert(df.collect().length === 1)
+ }
+ }
+
private def assertNativePaimonScanApplied(df: DataFrame): Unit = {
val plan = df.queryExecution.executedPlan.toString()
assert(
plan.contains("NativePaimonV2TableScan"),
s"plan should use native paimon scan:\n$plan")
}
+ private def checkSparkAnswerAndNativePaimonScan(sqlText: String): DataFrame = {
Review Comment:
Minor test cleanup: the `DataFrame` return value is ignored by both callers (and the third metadata test doesn't use this helper), so `Unit` would be clearer. Also `var expected: Seq[Row] = Nil` reassigned inside `withSQLConf` can be a `val`, since `withSQLConf` returns its block value:
```scala
val expected = withSQLConf("spark.auron.enable.paimon.scan" -> "false") {
sql(sqlText).collect().toSeq
}
```
--
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: commits-unsubscribe@auron.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org