Skip to content

Commit fb0b47f

Browse files
Decouple Deltasharesservice from DeltaLake classes (#86)
1 parent 84ea583 commit fb0b47f

File tree

10 files changed

+135
-12
lines changed

10 files changed

+135
-12
lines changed

server/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ tasks.jacocoTestCoverageVerification {
187187
violationRules {
188188
rule {
189189
limit {
190-
minimum = BigDecimal.valueOf(0.76)
190+
minimum = BigDecimal.valueOf(0.80)
191191
}
192192
}
193193
}

server/src/main/java/io/whitefox/api/deltasharing/Mappers.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,12 @@ public static TableResponseMetadata toTableResponseMetadata(
180180
.protocol(new ProtocolResponseProtocol().minReaderVersion(new BigDecimal(1))),
181181
new MetadataResponse()
182182
.metadata(new MetadataResponseMetadata()
183-
.id(deltaTableMetadata.getMetadata().getId())
183+
.id(deltaTableMetadata.getMetadata().id())
184184
.format(new MetadataResponseMetadataFormat()
185-
.provider(deltaTableMetadata.getMetadata().getFormat().getProvider()))
186-
.schemaString(deltaTableMetadata.getMetadata().getSchema().toJson())
187-
.partitionColumns(deltaTableMetadata.getMetadata().getPartitionColumns())));
185+
.provider(deltaTableMetadata.getMetadata().format().provider()))
186+
.schemaString(
187+
deltaTableMetadata.getMetadata().tableSchema().structType().toJson())
188+
.partitionColumns(deltaTableMetadata.getMetadata().partitionColumns())));
188189
}
189190

190191
/**

server/src/main/java/io/whitefox/api/deltasharing/model/DeltaTableMetadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.whitefox.api.deltasharing.model;
22

3-
import io.delta.standalone.actions.Metadata;
43
import io.whitefox.annotations.SkipCoverageGenerated;
4+
import io.whitefox.core.Metadata;
55
import java.util.Objects;
66

77
public class DeltaTableMetadata {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package io.whitefox.core;
2+
3+
import io.whitefox.annotations.SkipCoverageGenerated;
4+
import java.util.List;
5+
import java.util.Objects;
6+
7+
public class Metadata {
8+
private final String id;
9+
private final Format format;
10+
private final TableSchema tableSchema;
11+
private final List<String> partitionColumns;
12+
13+
public enum Format {
14+
PARQUET("parquet");
15+
16+
private final String provider;
17+
18+
private Format(final String provider) {
19+
this.provider = provider;
20+
}
21+
22+
public String provider() {
23+
return this.provider;
24+
}
25+
}
26+
27+
public Metadata(
28+
String id, Format format, TableSchema tableSchema, List<String> partitionColumns) {
29+
this.id = id;
30+
this.format = format;
31+
this.tableSchema = tableSchema;
32+
this.partitionColumns = partitionColumns;
33+
}
34+
35+
public String id() {
36+
return id;
37+
}
38+
39+
public Format format() {
40+
return format;
41+
}
42+
43+
public TableSchema tableSchema() {
44+
return tableSchema;
45+
}
46+
47+
public List<String> partitionColumns() {
48+
return partitionColumns;
49+
}
50+
51+
@Override
52+
@SkipCoverageGenerated
53+
public boolean equals(Object o) {
54+
if (this == o) return true;
55+
if (o == null || getClass() != o.getClass()) return false;
56+
Metadata metadata = (Metadata) o;
57+
return Objects.equals(id, metadata.id)
58+
&& format == metadata.format
59+
&& Objects.equals(tableSchema, metadata.tableSchema)
60+
&& Objects.equals(partitionColumns, metadata.partitionColumns);
61+
}
62+
63+
@Override
64+
@SkipCoverageGenerated
65+
public int hashCode() {
66+
return Objects.hash(id, format, tableSchema, partitionColumns);
67+
}
68+
69+
@Override
70+
@SkipCoverageGenerated
71+
public String toString() {
72+
return "Metadata{" + "id='"
73+
+ id + '\'' + ", format="
74+
+ format + ", tableSchema="
75+
+ tableSchema + ", partitionColumns="
76+
+ partitionColumns + '}';
77+
}
78+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.whitefox.core;
2+
3+
import io.delta.standalone.types.StructType;
4+
import io.whitefox.annotations.SkipCoverageGenerated;
5+
import java.util.Objects;
6+
7+
public class TableSchema {
8+
private final StructType structType;
9+
10+
public TableSchema(StructType structType) {
11+
this.structType = structType;
12+
}
13+
14+
public StructType structType() {
15+
return structType;
16+
}
17+
18+
@Override
19+
@SkipCoverageGenerated
20+
public boolean equals(Object o) {
21+
if (this == o) return true;
22+
if (o == null || getClass() != o.getClass()) return false;
23+
TableSchema that = (TableSchema) o;
24+
return Objects.equals(structType, that.structType);
25+
}
26+
27+
@Override
28+
@SkipCoverageGenerated
29+
public int hashCode() {
30+
return Objects.hash(structType);
31+
}
32+
33+
@Override
34+
@SkipCoverageGenerated
35+
public String toString() {
36+
return "TableSchema{" + "structType=" + structType + '}';
37+
}
38+
}

server/src/main/java/io/whitefox/core/services/DeltaSharedTable.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import io.delta.standalone.DeltaLog;
44
import io.delta.standalone.Snapshot;
5-
import io.delta.standalone.actions.Metadata;
5+
import io.whitefox.core.Metadata;
66
import io.whitefox.core.Table;
7+
import io.whitefox.core.TableSchema;
78
import java.nio.file.Paths;
89
import java.sql.Timestamp;
910
import java.time.OffsetDateTime;
@@ -33,7 +34,12 @@ public static DeltaSharedTable of(Table table) {
3334
}
3435

3536
public Optional<Metadata> getMetadata(Optional<String> startingTimestamp) {
36-
return getSnapshot(startingTimestamp).map(Snapshot::getMetadata);
37+
return getSnapshot(startingTimestamp)
38+
.map(snapshot -> new Metadata(
39+
snapshot.getMetadata().getId(),
40+
Metadata.Format.PARQUET,
41+
new TableSchema(snapshot.getMetadata().getSchema()),
42+
snapshot.getMetadata().getPartitionColumns()));
3743
}
3844

3945
public Optional<Long> getTableVersion(Optional<String> startingTimestamp) {

server/src/main/java/io/whitefox/core/services/DeltaSharesService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.whitefox.core.services;
22

3-
import io.delta.standalone.actions.Metadata;
3+
import io.whitefox.core.Metadata;
44
import io.whitefox.core.Schema;
55
import io.whitefox.core.Share;
66
import io.whitefox.core.Table;

server/src/main/java/io/whitefox/core/services/DeltaSharesServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.whitefox.core.services;
22

3-
import io.delta.standalone.actions.Metadata;
3+
import io.whitefox.core.Metadata;
44
import io.whitefox.core.Schema;
55
import io.whitefox.core.Share;
66
import io.whitefox.core.Table;

server/src/test/java/io/whitefox/api/deltasharing/DeltaSharedTableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void getTableMetadata() {
3131
var DTable = DeltaSharedTable.of(PTable);
3232
var metadata = DTable.getMetadata(Optional.empty());
3333
assertTrue(metadata.isPresent());
34-
assertEquals("56d48189-cdbc-44f2-9b0e-2bded4c79ed7", metadata.get().getId());
34+
assertEquals("56d48189-cdbc-44f2-9b0e-2bded4c79ed7", metadata.get().id());
3535
}
3636

3737
@Test

server/src/test/java/io/whitefox/services/DeltaShareServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void getTableMetadata() {
206206
DeltaSharesService deltaSharesService = new DeltaSharesServiceImpl(storageManager, 100, loader);
207207
var tableMetadata = deltaSharesService.getTableMetadata("name", "default", "table1", null);
208208
assertTrue(tableMetadata.isPresent());
209-
assertEquals("56d48189-cdbc-44f2-9b0e-2bded4c79ed7", tableMetadata.get().getId());
209+
assertEquals("56d48189-cdbc-44f2-9b0e-2bded4c79ed7", tableMetadata.get().id());
210210
}
211211

212212
@Test

0 commit comments

Comments
 (0)