Skip to content

Commit 065171d

Browse files
author
Marco Scalzo
committed
rebased
1 parent 3f84ab7 commit 065171d

23 files changed

+614
-41
lines changed

client-spark/build.gradle.kts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
plugins {
2+
java
3+
id("com.diffplug.spotless")
4+
id("whitefox.java-conventions")
5+
}
6+
7+
group = "io.whitefox"
8+
version = "spark-connector"
9+
10+
repositories {
11+
mavenCentral()
12+
}
13+
14+
val hadoopVersion = "3.3.6"
15+
dependencies {
16+
// DELTA
17+
testImplementation(String.format("org.apache.hadoop:hadoop-common:%s", hadoopVersion))
18+
testImplementation("io.delta:delta-sharing-spark_2.12:1.0.2")
19+
20+
//SPARK
21+
testImplementation("org.apache.spark:spark-core_2.12:3.3.2")
22+
testImplementation("org.apache.spark:spark-sql_2.12:3.3.2")
23+
testImplementation("com.github.mrpowers:spark-fast-tests_2.12:1.3.0")
24+
25+
//JUNIT
26+
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
27+
28+
}
29+
30+
// region code formatting
31+
spotless {
32+
java {}
33+
}
34+
// endregion
35+
36+
tasks.getByName<Test>("test") {
37+
useJUnitPlatform()
38+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package client;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import com.fasterxml.jackson.core.JsonProcessingException;
6+
import com.github.mrpowers.spark.fast.tests.DatasetComparer;
7+
import java.net.URISyntaxException;
8+
import java.util.List;
9+
import models.*;
10+
import org.apache.spark.sql.SparkSession;
11+
import org.apache.spark.sql.types.DataType;
12+
import org.apache.spark.sql.types.Metadata;
13+
import org.apache.spark.sql.types.StructField;
14+
import org.apache.spark.sql.types.StructType;
15+
import org.junit.jupiter.api.BeforeAll;
16+
import org.junit.jupiter.api.Test;
17+
import scala.collection.GenMap;
18+
import utils.StorageManagerInitializer;
19+
20+
public class ITDeltaSharingClient implements DatasetComparer {
21+
22+
private final String tablePath = String.format(
23+
"%s#%s.%s.%s",
24+
getClass().getClassLoader().getResource("MrFoxProfile.json"),
25+
"s3share",
26+
"s3schema",
27+
"s3Table1");
28+
29+
private final SparkSession spark = SparkSession.builder()
30+
.appName("delta sharing client test")
31+
.master("local[1, 4]")
32+
.getOrCreate();
33+
34+
@BeforeAll
35+
static void initStorageManager() throws URISyntaxException, JsonProcessingException {
36+
new StorageManagerInitializer().initStorageManager();
37+
}
38+
39+
@Test
40+
void showS3Table1withQueryTableApi() {
41+
var ds = spark.read().format("deltaSharing").load(tablePath);
42+
var expectedSchema = new StructType(new StructField[] {
43+
new StructField("id", DataType.fromDDL("long"), true, new Metadata(GenMap.empty()))
44+
});
45+
var expectedData = spark
46+
.createDataFrame(
47+
List.of(
48+
new MrFoxDeltaTableSchema(0),
49+
new MrFoxDeltaTableSchema(3),
50+
new MrFoxDeltaTableSchema(2),
51+
new MrFoxDeltaTableSchema(1),
52+
new MrFoxDeltaTableSchema(4)),
53+
MrFoxDeltaTableSchema.class)
54+
.toDF();
55+
56+
assertEquals(expectedSchema.json(), ds.schema().json());
57+
assertEquals(5, ds.count());
58+
assertSmallDatasetEquality(ds, expectedData, true, false, false, 500);
59+
}
60+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package models;
2+
3+
public class AddTableToSchemaInput {
4+
private final String name;
5+
private final TableReference reference;
6+
7+
public AddTableToSchemaInput(String name, TableReference reference) {
8+
this.name = name;
9+
this.reference = reference;
10+
}
11+
12+
public String getName() {
13+
return name;
14+
}
15+
16+
public TableReference getReference() {
17+
return reference;
18+
}
19+
20+
public static class TableReference {
21+
22+
private final String providerName;
23+
private final String name;
24+
25+
public TableReference(String providerName, String name) {
26+
this.providerName = providerName;
27+
this.name = name;
28+
}
29+
30+
public String getProviderName() {
31+
return providerName;
32+
}
33+
34+
public String getName() {
35+
return name;
36+
}
37+
}
38+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package models;
2+
3+
import java.util.List;
4+
5+
public class CreateShareInput {
6+
7+
private final String name;
8+
private final String comment;
9+
private final List<String> recipients;
10+
private final List<String> schemas;
11+
12+
public CreateShareInput(
13+
String name, String comment, List<String> recipients, List<String> schemas) {
14+
this.name = name;
15+
this.comment = comment;
16+
this.recipients = recipients;
17+
this.schemas = schemas;
18+
}
19+
20+
public String getName() {
21+
return name;
22+
}
23+
24+
public String getComment() {
25+
return comment;
26+
}
27+
28+
public List<String> getRecipients() {
29+
return recipients;
30+
}
31+
32+
public List<String> getSchemas() {
33+
return schemas;
34+
}
35+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package models;
2+
3+
public class CreateStorage {
4+
5+
private final String name;
6+
private final String comment;
7+
private final String type;
8+
private final S3Properties properties;
9+
private final boolean skipValidation;
10+
11+
public CreateStorage(
12+
String name, String comment, String type, S3Properties properties, boolean skipValidation) {
13+
this.name = name;
14+
this.comment = comment;
15+
this.type = type;
16+
this.properties = properties;
17+
this.skipValidation = skipValidation;
18+
}
19+
20+
public String getName() {
21+
return name;
22+
}
23+
24+
public String getComment() {
25+
return comment;
26+
}
27+
28+
public String getType() {
29+
return type;
30+
}
31+
32+
public S3Properties getProperties() {
33+
return properties;
34+
}
35+
36+
public boolean isSkipValidation() {
37+
return skipValidation;
38+
}
39+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package models;
2+
3+
public class CreateTableInput {
4+
private final String name;
5+
private final String comment;
6+
private final boolean skipValidation;
7+
private final DeltaTableProperties properties;
8+
9+
public CreateTableInput(
10+
String name, String comment, boolean skipValidation, DeltaTableProperties properties) {
11+
this.name = name;
12+
this.comment = comment;
13+
this.skipValidation = skipValidation;
14+
this.properties = properties;
15+
}
16+
17+
public String getName() {
18+
return name;
19+
}
20+
21+
public String getComment() {
22+
return comment;
23+
}
24+
25+
public boolean isSkipValidation() {
26+
return skipValidation;
27+
}
28+
29+
public DeltaTableProperties getProperties() {
30+
return properties;
31+
}
32+
33+
public static class DeltaTableProperties {
34+
private final String type;
35+
private final String location;
36+
private final String additionalProperties;
37+
38+
public DeltaTableProperties(String type, String location, String additionalProperties) {
39+
this.type = type;
40+
this.location = location;
41+
this.additionalProperties = additionalProperties;
42+
}
43+
44+
public String getType() {
45+
return type;
46+
}
47+
48+
public String getLocation() {
49+
return location;
50+
}
51+
52+
public String getAdditionalProperties() {
53+
return additionalProperties;
54+
}
55+
}
56+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package models;
2+
3+
public class MrFoxDeltaTableSchema {
4+
private final long id;
5+
6+
public MrFoxDeltaTableSchema(long id) {
7+
this.id = id;
8+
}
9+
10+
public long getId() {
11+
return id;
12+
}
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package models;
2+
3+
public class ProviderInput {
4+
5+
private final String name;
6+
private final String storageName;
7+
private final String metastoreName;
8+
9+
public ProviderInput(String name, String storageName, String metastoreName) {
10+
this.name = name;
11+
this.storageName = storageName;
12+
this.metastoreName = metastoreName;
13+
}
14+
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public String getStorageName() {
20+
return storageName;
21+
}
22+
23+
public String getMetastoreName() {
24+
return metastoreName;
25+
}
26+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package models;
2+
3+
public class S3Properties {
4+
private final AwsCredentials credentials;
5+
6+
public S3Properties(AwsCredentials credentials) {
7+
this.credentials = credentials;
8+
}
9+
10+
public AwsCredentials getCredentials() {
11+
return credentials;
12+
}
13+
14+
public static class AwsCredentials {
15+
private final String awsAccessKeyId;
16+
private final String awsSecretAccessKey;
17+
private final String region;
18+
19+
public AwsCredentials(String awsAccessKeyId, String awsSecretAccessKey, String region) {
20+
this.awsAccessKeyId = awsAccessKeyId;
21+
this.awsSecretAccessKey = awsSecretAccessKey;
22+
this.region = region;
23+
}
24+
25+
public String getAwsAccessKeyId() {
26+
return awsAccessKeyId;
27+
}
28+
29+
public String getAwsSecretAccessKey() {
30+
return awsSecretAccessKey;
31+
}
32+
33+
public String getRegion() {
34+
return region;
35+
}
36+
}
37+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package models;
2+
3+
public class S3TestConfig {
4+
5+
private final String region;
6+
private final String accessKey;
7+
private final String secretKey;
8+
9+
public String getRegion() {
10+
return region;
11+
}
12+
13+
public String getAccessKey() {
14+
return accessKey;
15+
}
16+
17+
public String getSecretKey() {
18+
return secretKey;
19+
}
20+
21+
public S3TestConfig(String region, String accessKey, String secretKey) {
22+
this.region = region;
23+
this.accessKey = accessKey;
24+
this.secretKey = secretKey;
25+
}
26+
}

0 commit comments

Comments
 (0)