LuciferYang commented on code in PR #14296:
URL: https://github.com/apache/gravitino/pull/14296#discussion_r4493016893
##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/extensions/IcebergExtendedDataSourceV2Strategy.java:
##########
@@ -269,14 +269,17 @@ static Option<IcebergCatalogAndIdentifier>
buildCatalogAndIdentifier(
return new Some<>(
IcebergCatalogAndIdentifier.of(
(TableCatalog) catalog, catalogAndIdentifier.identifier()));
- } else {
- // TODO: support SparkSessionCatalog
- throw new UnsupportedOperationException(
- "Unsupported catalog type: " + catalog.getClass().getName());
}
+ // Not a Gravitino catalog: the caller falls back to the parent Iceberg
strategy.
+ return Option.empty();
}
}
+ private Seq<SparkPlan> superFallback(LogicalPlan plan) {
+ // On Scala 2.12 Strategy.apply returns scala.collection.Seq; the parent
builds immutable Lists.
+ return (Seq<SparkPlan>) (Object) super.apply(plan);
Review Comment:
Done in 6c707b9fa: `superFallback` now calls `toIndexedSeq()` on the
parent's result and keeps the null check, and the `else` branch of `apply`
calls `superFallback`.
##########
spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/iceberg/extensions/TestIcebergExtendedDataSourceV2Strategy.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.spark.connector.iceberg.extensions;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.nio.file.Path;
+import java.util.List;
+import org.apache.iceberg.spark.SparkCatalog;
+import org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SparkSession;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Tests {@link IcebergExtendedDataSourceV2Strategy} on an Iceberg catalog
that Gravitino does not
+ * manage.
+ */
+public class TestIcebergExtendedDataSourceV2Strategy {
+
+ @TempDir static Path warehouse;
+
+ private static SparkSession spark;
+
+ @BeforeAll
+ static void startSpark() {
+ // Same extension order as GravitinoDriverPlugin: the Gravitino strategy
runs first.
+ spark =
+ SparkSession.builder()
+ .master("local[1]")
+ .appName("test-iceberg-extended-strategy")
+ .config("spark.ui.enabled", "false")
+ .config(
+ "spark.sql.extensions",
+ GravitinoIcebergSparkSessionExtensions.class.getName()
+ + ","
+ + IcebergSparkSessionExtensions.class.getName())
+ .config("spark.sql.catalog.local", SparkCatalog.class.getName())
+ .config("spark.sql.catalog.local.type", "hadoop")
+ .config("spark.sql.catalog.local.warehouse",
warehouse.toUri().toString())
+ .getOrCreate();
+ }
+
+ @AfterAll
+ static void stopSpark() {
+ if (spark != null) {
+ spark.stop();
+ }
+ }
+
+ @Test
+ void testIcebergDdlOnPlainIcebergCatalog() {
Review Comment:
Added in 6c707b9fa and 4bb04de16. The tests now run all ten statements on
the hadoop `SparkCatalog` (create and drop tag and branch, add, replace and
drop partition field, set and drop identifier fields, `WRITE ORDERED BY`) and
check the result in the table metadata.
`testGravitinoIcebergCatalogTakesGravitinoBranch` mocks
`Spark3Util.catalogAndIdentifier` to check that a `GravitinoIcebergCatalog`
resolves to the Gravitino branch and a `SparkCatalog` does not, and that
`apply` on `ADD PARTITION FIELD` returns an `AddPartitionFieldExec` on the
Gravitino catalog, which Iceberg's own strategy would not plan. Reverting
`getOrElse` to `get()` in a branch, or never matching
`GravitinoIcebergCatalog`, fails these 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]