Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Properly set ARN in namespace for Iceberg Glue symlinks #2943

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 152,7 @@ private static Optional<URI> getMetastoreUri(SparkContext context) {
}

@SneakyThrows
private static Optional<String> getGlueArn(SparkConf sparkConf, Configuration hadoopConf) {
public static Optional<String> getGlueArn(SparkConf sparkConf, Configuration hadoopConf) {
Optional<String> clientFactory =
SparkConfUtils.findHadoopConfigKey(hadoopConf, "hive.metastore.client.factory.class");
// Fetch from spark config if set.
Expand Down
3 changes: 3 additions & 0 deletions integration/spark/spark3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 64,7 @@ dependencies {
testFixturesApi("org.assertj:assertj-core:${assertjVersion}")
testFixturesApi("org.junit.jupiter:junit-jupiter-api:${junit5Version}")
testFixturesApi("org.junit.jupiter:junit-jupiter:${junit5Version}")
testFixturesApi("org.junit-pioneer:junit-pioneer:1.9.1")
testFixturesApi("org.mockito:mockito-core:${mockitoVersion}")
testFixturesApi("org.mockito:mockito-inline:${mockitoVersion}")

Expand Down Expand Up @@ -95,6 96,7 @@ dependencies {
testScala212Implementation("org.assertj:assertj-core:${assertjVersion}")
testScala212Implementation("org.junit.jupiter:junit-jupiter-api:${junit5Version}")
testScala212Implementation("org.junit.jupiter:junit-jupiter:${junit5Version}")
testScala212Implementation("org.junit-pioneer:junit-pioneer:1.9.1")
testScala212Implementation("org.mockito:mockito-core:${mockitoVersion}")
testScala212Implementation("org.mockito:mockito-inline:${mockitoVersion}")

Expand Down Expand Up @@ -126,6 128,7 @@ dependencies {
testScala213Implementation("org.assertj:assertj-core:${assertjVersion}")
testScala213Implementation("org.junit.jupiter:junit-jupiter-api:${junit5Version}")
testScala213Implementation("org.junit.jupiter:junit-jupiter:${junit5Version}")
testScala213Implementation("org.junit-pioneer:junit-pioneer:1.9.1")
testScala213Implementation("org.mockito:mockito-core:${mockitoVersion}")
testScala213Implementation("org.mockito:mockito-inline:${mockitoVersion}")
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 27,7 @@
import org.apache.iceberg.spark.SparkCatalog;
import org.apache.iceberg.spark.SparkSessionCatalog;
import org.apache.iceberg.spark.source.SparkTable;
import org.apache.spark.SparkContext;
import org.apache.spark.sql.SparkSession;
import org.apache.spark.sql.catalyst.analysis.NoSuchTableException;
import org.apache.spark.sql.connector.catalog.Identifier;
Expand Down Expand Up @@ -91,6 92,8 @@ public DatasetIdentifier getDatasetIdentifier(
symlink = getRestIdentifier(catalogConf.get(CatalogProperties.URI), tableName);
} else if ("nessie".equals(catalogType)) {
symlink = getNessieIdentifier(catalogConf.get(CatalogProperties.URI), tableName);
} else if ("glue".equals(catalogType)) {
symlink = getGlueIdentifier(tableName, session);
} else {
symlink = FilesystemDatasetUtils.fromLocationAndName(warehouseLocation.toUri(), tableName);
}
Expand Down Expand Up @@ -135,6 138,14 @@ private DatasetIdentifier getNessieIdentifier(@Nullable String confUri, String t
return new DatasetIdentifier(table, uri);
}

@SneakyThrows
private DatasetIdentifier getGlueIdentifier(String table, SparkSession sparkSession) {
SparkContext sparkContext = sparkSession.sparkContext();
String arn =
PathUtils.getGlueArn(sparkContext.getConf(), sparkContext.hadoopConfiguration()).get();
return new DatasetIdentifier(table, arn);
}

@SneakyThrows
private DatasetIdentifier getRestIdentifier(@Nullable String confUri, String table) {
String uri = new URI(confUri).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 19,11 @@
import java.util.Optional;
import java.util.stream.Stream;
import lombok.SneakyThrows;
import org.apache.hadoop.conf.Configuration;
import org.apache.iceberg.spark.SparkCatalog;
import org.apache.iceberg.spark.source.SparkTable;
import org.apache.spark.SparkConf;
import org.apache.spark.SparkContext;
import org.apache.spark.sql.RuntimeConfig;
import org.apache.spark.sql.SparkSession;
import org.apache.spark.sql.catalyst.analysis.NoSuchTableException;
Expand All @@ -30,6 33,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junitpioneer.jupiter.SetEnvironmentVariable;
import scala.collection.immutable.Map;

@SuppressWarnings("PMD.AvoidDuplicateLiterals")
Expand All @@ -38,6 42,9 @@ class IcebergHandlerTest {
private OpenLineageContext context = mock(OpenLineageContext.class);
private IcebergHandler icebergHandler = new IcebergHandler(context);
private SparkSession sparkSession = mock(SparkSession.class);
private SparkContext sparkContext = mock(SparkContext.class);
private SparkConf sparkConf = new SparkConf();
private Configuration hadoopConf = new Configuration();
private RuntimeConfig runtimeConfig = mock(RuntimeConfig.class);

@ParameterizedTest
Expand Down Expand Up @@ -162,8 169,16 @@ void testGetDatasetIdentifierForRest() {

@Test
@SneakyThrows
@SetEnvironmentVariable(key = "AWS_DEFAULT_REGION", value = "us-west-2")
void testGetDatasetIdentifierForGlue() {
when(sparkSession.conf()).thenReturn(runtimeConfig);
sparkConf.set("spark.glue.accountId", "1122334455");
when(sparkContext.getConf()).thenReturn(sparkConf);
hadoopConf.set(
"hive.metastore.client.factory.class",
"com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory");
when(sparkContext.hadoopConfiguration()).thenReturn(hadoopConf);
when(sparkSession.sparkContext()).thenReturn(sparkContext);
when(runtimeConfig.getAll())
.thenReturn(
new Map.Map2<>(
Expand Down Expand Up @@ -193,7 208,7 @@ void testGetDatasetIdentifierForGlue() {

assertThat(datasetIdentifier.getSymlinks())
.singleElement()
.hasFieldOrPropertyWithValue("namespace", "file:/tmp/warehouse")
.hasFieldOrPropertyWithValue("namespace", "arn:aws:glue:us-west-2:1122334455")
.hasFieldOrPropertyWithValue("name", "database.table")
.hasFieldOrPropertyWithValue("type", DatasetIdentifier.SymlinkType.TABLE);
}
Expand Down