Skip to content

Query the iceberg table through all delta tablev1 apis #196

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -23,18 +23,45 @@ public class ITDeltaSharingClient implements DatasetComparer, ScalaUtils {

private final StorageManagerInitializer storageManagerInitializer;
private final String deltaTablePath;
private final String icebergTablePath;

public ITDeltaSharingClient() {
this.storageManagerInitializer = new StorageManagerInitializer();
this.deltaTablePath =
TablePath.getDeltaTablePath(getClass().getClassLoader().getResource("MrFoxProfile.json"));
this.icebergTablePath =
TablePath.getIcebergTablePath(getClass().getClassLoader().getResource("MrFoxProfile.json"));
}

@BeforeAll
static void initStorageManager() {
new StorageManagerInitializer().initStorageManager();
}

@Test
void showS3IcebergTable1withQueryTableApi() {
var spark = TestSparkSession.newSparkSession();
storageManagerInitializer.createIcebergTableWithGlueMetastore();
var ds = spark.read().format("deltaSharing").load(icebergTablePath);
var expectedSchema = new StructType(new StructField[] {
new StructField("id", DataType.fromDDL("long"), false, new Metadata(emptyScalaMap()))
});
var expectedData = spark
.createDataFrame(
List.of(
new MrFoxDeltaTableSchema(0),
new MrFoxDeltaTableSchema(3),
new MrFoxDeltaTableSchema(2),
new MrFoxDeltaTableSchema(1),
new MrFoxDeltaTableSchema(4)),
MrFoxDeltaTableSchema.class)
.toDF();

assertEquals(expectedSchema, ds.schema());
assertEquals(5, ds.count());
assertSmallDatasetEquality(ds, expectedData, true, false, false, 500);
}

@Test
void showS3Table1withQueryTableApi() {
var spark = TestSparkSession.newSparkSession();
Expand All @@ -43,6 +70,8 @@ void showS3Table1withQueryTableApi() {
var expectedSchema = new StructType(new StructField[] {
new StructField("id", DataType.fromDDL("long"), true, new Metadata(emptyScalaMap()))
});

ds.show();
var expectedData = spark
.createDataFrame(
List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class S3TestConfig {
private final String region;
private final String accessKey;
private final String secretKey;
private final String glueCatalogId;

public String getRegion() {
return region;
Expand All @@ -17,16 +18,22 @@ public String getSecretKey() {
return secretKey;
}

public S3TestConfig(String region, String accessKey, String secretKey) {
public String getGlueCatalogId() {
return glueCatalogId;
}

public S3TestConfig(String region, String accessKey, String secretKey, String glueCatalogId) {
this.region = region;
this.accessKey = accessKey;
this.secretKey = secretKey;
this.glueCatalogId = glueCatalogId;
}

public static S3TestConfig loadFromEnv() {
return new S3TestConfig(
System.getenv().get("WHITEFOX_TEST_AWS_REGION"),
System.getenv().get("WHITEFOX_TEST_AWS_ACCESS_KEY_ID"),
System.getenv().get("WHITEFOX_TEST_AWS_SECRET_ACCESS_KEY"));
System.getenv().get("WHITEFOX_TEST_AWS_SECRET_ACCESS_KEY"),
System.getenv().get("WHITEFOX_TEST_GLUE_CATALOG_ID"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ public TableInfo createIcebergTableWithGlueMetastore() {
var provider = ApiUtils.recoverConflictLazy(
() -> providerV1Api.addProvider(providerRequest),
() -> providerV1Api.getProvider(providerRequest.getName()));
var schemaRequest = createSchemaRequest(TableFormat.iceberg);
var shareRequest = createShareRequest();
ignoreConflict(() -> schemaV1Api.createSchema(shareRequest.getName(), schemaRequest));
var createTableRequest = createIcebergTableRequest();
return ApiUtils.recoverConflictLazy(
ApiUtils.recoverConflictLazy(
() -> tableV1Api.createTableInProvider(provider.getName(), createTableRequest),
() -> tableV1Api.describeTableInProvider(provider.getName(), createTableRequest.getName()));
ignoreConflict(() -> schemaV1Api.addTableToSchema(
shareRequest.getName(),
schemaRequest,
addTableToSchemaRequest(providerRequest.getName(), createTableRequest.getName())));
return tableV1Api.describeTableInProvider(provider.getName(), createTableRequest.getName());
}

private String createSchemaRequest(TableFormat tableFormat) {
Expand Down Expand Up @@ -122,7 +130,7 @@ private CreateMetastore createMetastoreRequest(
.type(type)
.skipValidation(true)
.properties(new MetastoreProperties(new GlueProperties()
.catalogId("catalogId") // TODO
.catalogId(s3TestConfig.getGlueCatalogId())
.credentials(new SimpleAwsCredentials()
.region(s3TestConfig.getRegion())
.awsAccessKeyId(s3TestConfig.getAccessKey())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

public class TablePath {

public static String getIcebergTablePath(URL resource) {
return String.format("%s#%s.%s.%s", resource, "s3share", "s3schemaiceberg", "s3IcebergTable1");
}

public static String getDeltaTablePath(URL resource) {
return String.format("%s#%s.%s.%s", resource, "s3share", "s3schemadelta", "s3Table1");
}
Expand Down