diqiu50 commented on code in PR #12414: URL: https://github.com/apache/gravitino/pull/12414#discussion_r3810983642
########## spark-connector/v3.3/spark-runtime/build.gradle.kts: ########## @@ -1,70 +0,0 @@ -/* - * 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. - */ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar - Review Comment: Two suggestions on the build layout Keep spark-common as a Gradle module. No need to publish it or depend on it as a jar — the srcDirs composition can stay as is — but as a module the shared tree still compiles on its own, the way trino-connector:trino-connector does. It also gives Spotless and Javadoc a natural home instead of the special-casing in spark-connector/build.gradle.kts. Factor the common build config into a reusable plugin. srcDirs carries sources, not dependencies, so the module alone does not remove the duplication: the dependencies {} blocks in v3.5/spark and v4.0/spark are ~140 lines each and differ by about a dozen. The common part could move into a convention plugin both apply. ########## build.gradle.kts: ########## @@ -377,8 +377,18 @@ subprojects { ":flink-connector" ) + // Spark 4 requires JDK 17, so the Spark 4 connector modules opt out of the JDK 8 target even + // though the rest of :spark-connector (3.x) stays on Java 8. + val jdk17OnlyProjectPaths = setOf( + ":spark-connector:spark-4.0", + ":spark-connector:spark-runtime-4.0" + ) + Review Comment: I suggest configuring it in the specific module rather than at the top level. Please refer to the Trino implementation. ########## spark-connector/build.gradle.kts: ########## @@ -16,7 +16,66 @@ * specific language governing permissions and limitations * under the License. */ +import com.diffplug.gradle.spotless.SpotlessExtension +import java.net.URI +// This project builds nothing of its own; it groups the per-Spark-version modules and owns the +// pieces they share. `spark-common` is a source tree rather than a module, so the version modules +// compile it themselves and nothing here produces a jar. Two exceptions stay enabled: Spotless, +// which formats the shared tree below, and downloadGlueHiveJars, which the version modules' +// Glue ITs depend on. tasks.all { - enabled = false -} \ No newline at end of file + enabled = name.startsWith("spotless") || name == "downloadGlueHiveJars" +} + +// spark-common belongs to no project, so no module's Spotless picks it up. Format it from here, +// where it lives, and keep the version modules scoped to their own trees. +plugins.withId("com.diffplug.spotless") { + configure<SpotlessExtension> { + java { + target(project.fileTree("spark-common/src") { include("**/*.java") }) + } + } +} + +// Jars for Spark's IsolatedClientLoader: patched Hive 2.3.10 + Glue datacatalog client. +// aws-java-sdk-glue 1.12.31 requires PropertyNamingStrategy$PascalCaseStrategy which was +// removed in Jackson 2.12. Jackson included here so the isolated classloader uses a compatible +// version instead of the app-level Jackson bundled with Spark (2.14+). +// Only set when AWS_ACCESS_KEY_ID is present so version-specific modules can skip the download +// when Glue tests are not enabled. +val glueHiveJarsDir: String? = + if (System.getenv("AWS_ACCESS_KEY_ID") != null) "$buildDir/tmp/glue-hive-jars" else null +extra["glueHiveJarsDir"] = glueHiveJarsDir +val glueLibsApiUrl = + "https://api.github.com/repos/datastrato/spark-hive-glue-libs/contents/spark3/glue-3.4.0" + +val downloadGlueHiveJars by +tasks.registering { + glueHiveJarsDir?.let { outputs.dir(it) } + onlyIf { + val outputDir = file(glueHiveJarsDir ?: return@onlyIf false) + outputDir.listFiles()?.none { it.name.endsWith(".jar") } ?: true + } + doLast { + val outputDir = file(glueHiveJarsDir ?: return@doLast) + outputDir.mkdirs() + val response = URI(glueLibsApiUrl).toURL().readText() + + @Suppress("UNCHECKED_CAST") + val entries = groovy.json.JsonSlurper().parseText(response) as List<Map<String, Any>> + entries + .filter { (it["name"] as String).endsWith(".jar") } + .forEach { entry -> + val jarName = entry["name"] as String + val downloadUrl = entry["download_url"] as String + val dest = outputDir.resolve(jarName) + if (!dest.exists()) { + logger.lifecycle("Downloading $jarName ...") + URI(downloadUrl).toURL().openStream().use { input -> + dest.outputStream().use { output -> input.copyTo(output) } Review Comment: Move these to spark common is better ########## spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/plugin/GravitinoDriverPlugin.java: ########## @@ -176,6 +179,35 @@ private void registerCatalog(SparkConf sparkConf, String catalogName, String pro LOG.info("Register {} catalog to Spark catalog manager.", catalogName); } + /** + * Resolves the Spark catalog class a Gravitino catalog provider needs, from the table the + * connector jar on the classpath declares. Returns null when this connector has no catalog for + * the provider, which is also how an unbuilt catalog reports itself. + */ + @Nullable + private static String catalogClassName(String provider) { + SparkCatalogKind kind = SparkCatalogKind.fromProvider(provider); + return kind == null ? null : SparkCatalogs.classNames().get(kind); + } + + /** + * Queues the Paimon session extensions, unless this connector jar has no Paimon catalog. Paimon + * publishes no paimon-spark artifact for every Spark version and Scala version this connector + * supports, so some builds omit the Paimon classes; registering the extension there would fail + * SparkSession construction with a ClassNotFoundException. Skip it the way an unsupported catalog + * provider is skipped, so a config carried over from another build degrades to a warning. + */ + @VisibleForTesting + void registerPaimonExtensionsIfSupported() { + if (!SparkCatalogs.classNames().containsKey(SparkCatalogKind.LAKEHOUSE_PAIMON)) { + LOG.warn( + "Skip registering Paimon session extensions because {} is not supported yet.", + PAIMON_PROVIDER); Review Comment: Why don't we throw an exception here ########## spark-connector/spark-common/src/main/spark40/org/apache/gravitino/spark/connector/authorization/GravitinoAuthorizationSparkSessionExtensions.java: ########## @@ -0,0 +1,106 @@ +/* + * 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.authorization; + +import org.apache.spark.sql.SparkSessionExtensions; +import org.apache.spark.sql.catalyst.FunctionIdentifier; +import org.apache.spark.sql.catalyst.TableIdentifier; +import org.apache.spark.sql.catalyst.expressions.Expression; +import org.apache.spark.sql.catalyst.parser.ParseException; +import org.apache.spark.sql.catalyst.parser.ParserInterface; +import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan; +import org.apache.spark.sql.types.DataType; +import org.apache.spark.sql.types.StructType; +import scala.Function1; +import scala.collection.immutable.Seq; + +/** + * Registers Gravitino authorization checks with a Spark session. + * + * <p>This is the Spark 4 flavor. It matches the Spark 3.5 one under {@code src/main/spark35} except + * that Spark 4 added the abstract {@code parseRoutineParam} method to {@code ParserInterface}. + */ +public class GravitinoAuthorizationSparkSessionExtensions + implements Function1<SparkSessionExtensions, Void> { Review Comment: I suggest extracting the reusable parts into a base class and placing it in the shared module. -- 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]
