@@ -25,8 +25,11 @@ import org.scalactic.source.Position
2525import org .scalatest .Tag
2626
2727import org .apache .hadoop .conf .Configuration
28- import org .apache .iceberg .hadoop .{HadoopConfigurable , HadoopFileIO }
29- import org .apache .iceberg .io .{FileIO , InputFile , OutputFile , ResolvingFileIO }
28+ import org .apache .iceberg .{PartitionSpec , StructLike , TableMetadata , TableOperations }
29+ import org .apache .iceberg .catalog .TableIdentifier
30+ import org .apache .iceberg .encryption .EncryptionManager
31+ import org .apache .iceberg .hadoop .{HadoopCatalog , HadoopConfigurable , HadoopFileIO }
32+ import org .apache .iceberg .io .{FileIO , InputFile , LocationProvider , OutputFile , ResolvingFileIO }
3033import org .apache .iceberg .util .SerializableSupplier
3134import org .apache .spark .SparkConf
3235import org .apache .spark .rdd .RDD
@@ -126,6 +129,12 @@ class CometIcebergWriteDetectionSuite extends CometTestBase with CometIcebergTes
126129 " writeProperties" )
127130 assert(IcebergReflection .getMetadataLocation(table).isDefined, " metadataLocation" )
128131 assert(IcebergReflection .getDataLocation(table).isDefined, " dataLocation" )
132+ val provider = IcebergReflection
133+ .getLocationProvider(table)
134+ .getOrElse(fail(" locationProvider" ))
135+ assert(
136+ provider.getClass.getName == IcebergReflection .ClassNames .DEFAULT_LOCATION_PROVIDER ,
137+ provider.getClass.getName)
129138 assert(IcebergReflection .getTableProperties(table).isDefined, " tableProperties" )
130139 }
131140 }
@@ -185,6 +194,32 @@ class CometIcebergWriteDetectionSuite extends CometTestBase with CometIcebergTes
185194 }
186195 }
187196
197+ test(" fall-back: custom TableOperations LocationProvider that no property reveals" ) {
198+ withTempIcebergDir { warehouseDir =>
199+ val locationCat = " location_provider_probe_cat"
200+ withSQLConf(
201+ s " spark.sql.catalog. $locationCat" -> " org.apache.iceberg.spark.SparkCatalog" ,
202+ s " spark.sql.catalog. $locationCat.catalog-impl " ->
203+ classOf [DetectionCustomLocationHadoopCatalog ].getName,
204+ s " spark.sql.catalog. $locationCat.warehouse " -> warehouseDir.getAbsolutePath) {
205+ spark.sql(s """
206+ CREATE TABLE $locationCat. $ns.custom_location_provider (
207+ id INT,
208+ region STRING,
209+ amount DOUBLE
210+ ) USING iceberg
211+ """ )
212+ val writeExec =
213+ planInsertWriteExec(s " $locationCat. $ns.custom_location_provider " )
214+ assertUnsupportedContains(
215+ writeExec,
216+ " custom_location_provider" ,
217+ " table.locationProvider()" ,
218+ classOf [DetectionDelegatingLocationProvider ].getName)
219+ }
220+ }
221+ }
222+
188223 test(" fall-back: format-version=3" ) {
189224 assume(isSpark35Plus, " V3 tables require Iceberg 1.8.1+ (Spark 3.5 profile)" )
190225 withDetectionCatalog { dir =>
@@ -1150,3 +1185,39 @@ class DetectionDelegatingFileIO extends FileIO with HadoopConfigurable {
11501185 SerializableSupplier [Configuration ]]): Unit =
11511186 delegate.serializeConfWith(confSerializer)
11521187}
1188+
1189+ /**
1190+ * A catalog whose TableOperations supplies a custom LocationProvider directly, without setting
1191+ * `write.location-provider.impl`. This is the path the native write gate must inspect explicitly.
1192+ */
1193+ class DetectionCustomLocationHadoopCatalog extends HadoopCatalog {
1194+ override protected def newTableOps (identifier : TableIdentifier ): TableOperations =
1195+ new DetectionLocationProviderTableOperations (super .newTableOps(identifier))
1196+ }
1197+
1198+ class DetectionLocationProviderTableOperations (delegate : TableOperations )
1199+ extends TableOperations {
1200+ override def current (): TableMetadata = delegate.current()
1201+ override def refresh (): TableMetadata = delegate.refresh()
1202+ override def commit (base : TableMetadata , metadata : TableMetadata ): Unit =
1203+ delegate.commit(base, metadata)
1204+ override def io (): FileIO = delegate.io()
1205+ override def encryption (): EncryptionManager = delegate.encryption()
1206+ override def metadataFileLocation (fileName : String ): String =
1207+ delegate.metadataFileLocation(fileName)
1208+ override def locationProvider (): LocationProvider =
1209+ new DetectionDelegatingLocationProvider (delegate.locationProvider())
1210+ override def temp (uncommittedMetadata : TableMetadata ): TableOperations =
1211+ new DetectionLocationProviderTableOperations (delegate.temp(uncommittedMetadata))
1212+ override def newSnapshotId (): Long = delegate.newSnapshotId()
1213+ override def requireStrictCleanup (): Boolean = delegate.requireStrictCleanup()
1214+ }
1215+
1216+ class DetectionDelegatingLocationProvider (delegate : LocationProvider ) extends LocationProvider {
1217+ override def newDataLocation (filename : String ): String = delegate.newDataLocation(filename)
1218+ override def newDataLocation (
1219+ spec : PartitionSpec ,
1220+ partitionData : StructLike ,
1221+ filename : String ): String =
1222+ delegate.newDataLocation(spec, partitionData, filename)
1223+ }
0 commit comments