Skip to content

Commit 680dfac

Browse files
wwwwwip
1 parent 5770527 commit 680dfac

32 files changed

+554
-98
lines changed

docs/protocol/whitefox-protocol-api.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,9 @@ components:
14261426
type: object
14271427
additionalProperties:
14281428
type: string
1429+
required:
1430+
- name
1431+
- properties
14291432
example:
14301433
name: customer
14311434
properties:

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import io.whitefox.core.*;
66
import io.whitefox.core.Schema;
77
import io.whitefox.core.Share;
8-
import io.whitefox.core.Table;
8+
import io.whitefox.core.SharedTable;
99
import io.whitefox.core.actions.CreateMetastore;
1010
import io.whitefox.core.actions.CreateProvider;
11-
import io.whitefox.core.storage.CreateStorage;
12-
import io.whitefox.core.storage.Storage;
13-
import io.whitefox.core.storage.StorageProperties;
14-
import io.whitefox.core.storage.StorageType;
11+
import io.whitefox.core.actions.CreateStorage;
12+
import io.whitefox.core.Storage;
13+
import io.whitefox.core.StorageProperties;
14+
import io.whitefox.core.StorageType;
1515
import java.time.OffsetDateTime;
1616
import java.util.Arrays;
1717
import java.util.List;
@@ -34,11 +34,11 @@ public static io.whitefox.api.deltasharing.model.v1.generated.Schema schema2api(
3434
.share(schema.share());
3535
}
3636

37-
public static io.whitefox.api.deltasharing.model.v1.generated.Table table2api(Table table) {
37+
public static io.whitefox.api.deltasharing.model.v1.generated.Table table2api(SharedTable sharedTable) {
3838
return new io.whitefox.api.deltasharing.model.v1.generated.Table()
39-
.name(table.name())
40-
.share(table.share())
41-
.schema(table.schema());
39+
.name(sharedTable.name())
40+
.share(sharedTable.share())
41+
.schema(sharedTable.schema());
4242
}
4343

4444
public static io.whitefox.api.model.v1.generated.Storage storage2api(Storage storage) {
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package io.whitefox.core;
2+
3+
import io.whitefox.annotations.SkipCoverageGenerated;
4+
5+
import java.util.Objects;
6+
import java.util.Optional;
7+
8+
public class InternalTable {
9+
private final String name;
10+
private final Optional<String> comment;
11+
private final InternalTableProperties properties;
12+
private final Optional<Long> validatedAt;
13+
private final Long createdAt;
14+
private final Principal createdBy;
15+
private final Long updatedAt;
16+
private final Principal updatedBy;
17+
private final Provider provider;
18+
19+
public InternalTable(String name, Optional<String> comment, InternalTableProperties properties, Optional<Long> validatedAt, Long createdAt, Principal createdBy, Long updatedAt, Principal updatedBy, Provider provider) {
20+
this.name = name;
21+
this.comment = comment;
22+
this.properties = properties;
23+
this.validatedAt = validatedAt;
24+
this.createdAt = createdAt;
25+
this.createdBy = createdBy;
26+
this.updatedAt = updatedAt;
27+
this.updatedBy = updatedBy;
28+
this.provider = provider;
29+
}
30+
31+
public String name() {
32+
return name;
33+
}
34+
35+
public Optional<String> comment() {
36+
return comment;
37+
}
38+
39+
public InternalTableProperties properties() {
40+
return properties;
41+
}
42+
43+
public Optional<Long> validatedAt() {
44+
return validatedAt;
45+
}
46+
47+
public Long createdAt() {
48+
return createdAt;
49+
}
50+
51+
public Principal createdBy() {
52+
return createdBy;
53+
}
54+
55+
public Long updatedAt() {
56+
return updatedAt;
57+
}
58+
59+
public Principal updatedBy() {
60+
return updatedBy;
61+
}
62+
63+
public Provider provider() {
64+
return provider;
65+
}
66+
67+
@Override
68+
@SkipCoverageGenerated
69+
public String toString() {
70+
return "InternalTable{" +
71+
"name='" + name + '\'' +
72+
", comment=" + comment +
73+
", properties=" + properties +
74+
", validatedAt=" + validatedAt +
75+
", createdAt=" + createdAt +
76+
", createdBy=" + createdBy +
77+
", updatedAt=" + updatedAt +
78+
", updatedBy=" + updatedBy +
79+
", provider=" + provider +
80+
'}';
81+
}
82+
83+
@Override
84+
@SkipCoverageGenerated
85+
public boolean equals(Object o) {
86+
if (this == o) return true;
87+
if (o == null || getClass() != o.getClass()) return false;
88+
InternalTable that = (InternalTable) o;
89+
return Objects.equals(name, that.name) && Objects.equals(comment, that.comment) && Objects.equals(properties, that.properties) && Objects.equals(validatedAt, that.validatedAt) && Objects.equals(createdAt, that.createdAt) && Objects.equals(createdBy, that.createdBy) && Objects.equals(updatedAt, that.updatedAt) && Objects.equals(updatedBy, that.updatedBy) && Objects.equals(provider, that.provider);
90+
}
91+
92+
@Override
93+
@SkipCoverageGenerated
94+
public int hashCode() {
95+
return Objects.hash(name, comment, properties, validatedAt, createdAt, createdBy, updatedAt, updatedBy, provider);
96+
}
97+
98+
public interface InternalTableProperties {
99+
}
100+
101+
public static class IcebergTableProperties implements InternalTableProperties {
102+
103+
public static final String type = "iceberg";
104+
private final String databaseName;
105+
private final String tableName;
106+
107+
public IcebergTableProperties(String databaseName, String tableName) {
108+
this.databaseName = databaseName;
109+
this.tableName = tableName;
110+
}
111+
112+
@Override
113+
@SkipCoverageGenerated
114+
public boolean equals(Object o) {
115+
if (this == o) return true;
116+
if (o == null || getClass() != o.getClass()) return false;
117+
IcebergTableProperties that = (IcebergTableProperties) o;
118+
return Objects.equals(databaseName, that.databaseName) && Objects.equals(tableName, that.tableName);
119+
}
120+
121+
@Override
122+
@SkipCoverageGenerated
123+
public int hashCode() {
124+
return Objects.hash(databaseName, tableName);
125+
}
126+
127+
@Override
128+
@SkipCoverageGenerated
129+
public String toString() {
130+
return "IcebergTableProperties{" +
131+
"databaseName='" + databaseName + '\'' +
132+
", tableName='" + tableName + '\'' +
133+
'}';
134+
}
135+
136+
public String databaseName() {
137+
return databaseName;
138+
}
139+
140+
public String tableName() {
141+
return tableName;
142+
}
143+
}
144+
145+
public static class DeltaTableProperties implements InternalTableProperties {
146+
147+
public static final String type = "delta";
148+
private final String location;
149+
150+
public DeltaTableProperties(String location) {
151+
this.location = location;
152+
}
153+
154+
public String location() {
155+
return location;
156+
}
157+
158+
@Override
159+
@SkipCoverageGenerated
160+
public boolean equals(Object o) {
161+
if (this == o) return true;
162+
if (o == null || getClass() != o.getClass()) return false;
163+
DeltaTableProperties that = (DeltaTableProperties) o;
164+
return Objects.equals(location, that.location);
165+
}
166+
167+
@Override
168+
@SkipCoverageGenerated
169+
public int hashCode() {
170+
return Objects.hash(location);
171+
}
172+
173+
@Override
174+
@SkipCoverageGenerated
175+
public String toString() {
176+
return "DeltaTableProperties{" +
177+
"location='" + location + '\'' +
178+
'}';
179+
}
180+
}
181+
}

server/src/main/java/io/whitefox/core/Provider.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.whitefox.core;
22

33
import io.whitefox.annotations.SkipCoverageGenerated;
4-
import io.whitefox.core.storage.Storage;
4+
import io.whitefox.core.services.exceptions.TableAlreadyExists;
5+
6+
import java.util.Map;
57
import java.util.Objects;
68
import java.util.Optional;
79

@@ -14,6 +16,7 @@ public class Provider {
1416
private final Long updatedAt;
1517
private final Principal updatedBy;
1618
private final Principal owner;
19+
private final Map<String, InternalTable> tables;
1720

1821
public Provider(
1922
String name,
@@ -32,6 +35,46 @@ public Provider(
3235
this.updatedAt = updatedAt;
3336
this.updatedBy = updatedBy;
3437
this.owner = owner;
38+
this.tables = Map.of();
39+
}
40+
41+
public Provider(
42+
String name,
43+
Storage storage,
44+
Optional<Metastore> metastore,
45+
Long createdAt,
46+
Principal createdBy,
47+
Long updatedAt,
48+
Principal updatedBy,
49+
Principal owner,
50+
Map<String, InternalTable> tables) {
51+
this.name = name;
52+
this.storage = storage;
53+
this.metastore = metastore;
54+
this.createdAt = createdAt;
55+
this.createdBy = createdBy;
56+
this.updatedAt = updatedAt;
57+
this.updatedBy = updatedBy;
58+
this.owner = owner;
59+
this.tables = tables;
60+
}
61+
62+
public Provider addTable(InternalTable table) {
63+
if (tables.containsKey(table.name())) {
64+
throw new TableAlreadyExists("Table " + table.name() + " already exists");
65+
}
66+
var newMap = Map.copyOf(tables);
67+
newMap.put(table.name(), table);
68+
return new Provider(
69+
name,
70+
storage,
71+
metastore,
72+
createdAt,
73+
createdBy,
74+
updatedAt,
75+
updatedBy,
76+
owner,
77+
newMap);
3578
}
3679

3780
public String name() {

server/src/main/java/io/whitefox/core/Schema.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66

77
public final class Schema {
88
private final String name;
9-
private final List<Table> tables;
9+
private final List<SharedTable> sharedTables;
1010
private final String share;
1111

12-
public Schema(String name, List<Table> tables, String share) {
12+
public Schema(String name, List<SharedTable> sharedTables, String share) {
1313
this.name = name;
14-
this.tables = tables;
14+
this.sharedTables = sharedTables;
1515
this.share = share;
1616
}
1717

1818
public String name() {
1919
return name;
2020
}
2121

22-
public List<Table> tables() {
23-
return tables;
22+
public List<SharedTable> tables() {
23+
return sharedTables;
2424
}
2525

2626
public String share() {
@@ -34,19 +34,19 @@ public boolean equals(Object obj) {
3434
if (obj == null || obj.getClass() != this.getClass()) return false;
3535
var that = (Schema) obj;
3636
return Objects.equals(this.name, that.name)
37-
&& Objects.equals(this.tables, that.tables)
37+
&& Objects.equals(this.sharedTables, that.sharedTables)
3838
&& Objects.equals(this.share, that.share);
3939
}
4040

4141
@Override
4242
@SkipCoverageGenerated
4343
public int hashCode() {
44-
return Objects.hash(name, tables, share);
44+
return Objects.hash(name, sharedTables, share);
4545
}
4646

4747
@Override
4848
@SkipCoverageGenerated
4949
public String toString() {
50-
return "Schema[" + "name=" + name + ", " + "tables=" + tables + ", " + "share=" + share + ']';
50+
return "Schema[" + "name=" + name + ", " + "tables=" + sharedTables + ", " + "share=" + share + ']';
5151
}
5252
}

server/src/main/java/io/whitefox/core/Table.java renamed to server/src/main/java/io/whitefox/core/SharedTable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import io.whitefox.annotations.SkipCoverageGenerated;
44
import java.util.Objects;
55

6-
public final class Table {
6+
public final class SharedTable {
77
private final String name;
88
private final String location;
99
private final String schema;
1010
private final String share;
1111

12-
public Table(String name, String location, String schema, String share) {
12+
public SharedTable(String name, String location, String schema, String share) {
1313
this.name = name;
1414
this.location = location;
1515
this.schema = schema;
@@ -37,7 +37,7 @@ public String share() {
3737
public boolean equals(Object obj) {
3838
if (obj == this) return true;
3939
if (obj == null || obj.getClass() != this.getClass()) return false;
40-
var that = (Table) obj;
40+
var that = (SharedTable) obj;
4141
return Objects.equals(this.name, that.name)
4242
&& Objects.equals(this.location, that.location)
4343
&& Objects.equals(this.schema, that.schema)

server/src/main/java/io/whitefox/core/storage/Storage.java renamed to server/src/main/java/io/whitefox/core/Storage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package io.whitefox.core.storage;
1+
package io.whitefox.core;
22

33
import io.whitefox.annotations.SkipCoverageGenerated;
4-
import io.whitefox.core.Principal;
4+
55
import java.util.Objects;
66
import java.util.Optional;
77

server/src/main/java/io/whitefox/core/storage/StorageProperties.java renamed to server/src/main/java/io/whitefox/core/StorageProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package io.whitefox.core.storage;
1+
package io.whitefox.core;
22

33
import io.whitefox.annotations.SkipCoverageGenerated;
4-
import io.whitefox.core.AwsCredentials;
4+
55
import java.util.Objects;
66

77
public interface StorageProperties {

server/src/main/java/io/whitefox/core/storage/StorageType.java renamed to server/src/main/java/io/whitefox/core/StorageType.java

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

33
import java.util.Arrays;
44
import java.util.Optional;

0 commit comments

Comments
 (0)