Skip to content

Commit 0d1acc5

Browse files
Add DeltaFile
1 parent 5ca16d8 commit 0d1acc5

File tree

3 files changed

+117
-146
lines changed

3 files changed

+117
-146
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.whitefox.api.deltasharing.model.v1.delta;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.databind.JsonNode;
6+
import java.util.Optional;
7+
import lombok.Builder;
8+
import lombok.NonNull;
9+
import lombok.Value;
10+
import lombok.experimental.SuperBuilder;
11+
import lombok.extern.jackson.Jacksonized;
12+
13+
@Value
14+
@SuperBuilder
15+
@Jacksonized
16+
public class DeltaFile {
17+
18+
@JsonProperty
19+
@NonNull File file;
20+
21+
@Value
22+
@SuperBuilder
23+
@Jacksonized
24+
@JsonInclude(JsonInclude.Include.NON_ABSENT)
25+
public static class File {
26+
27+
/**
28+
* A unique string for the file in a table.
29+
* The same file is guaranteed to have the same id across multiple requests.
30+
* A client may cache the file content and use this id as a key to decide whether to use the cached file content.
31+
*/
32+
@JsonProperty
33+
@NonNull String id;
34+
35+
/**
36+
* A unique string for the deletion vector file in a table.
37+
* The same deletion vector file is guaranteed to have the same id across multiple requests.
38+
* A client may cache the file content and use this id as a key to decide whether to use the cached file content.
39+
*/
40+
@JsonProperty
41+
@Builder.Default
42+
Optional<String> deletionVectorFileId = Optional.empty();
43+
44+
/**
45+
* The table version of the file, returned when querying a table data with a version or timestamp parameter.
46+
*/
47+
@JsonProperty
48+
@Builder.Default
49+
Optional<Long> version = Optional.empty();
50+
51+
/**
52+
* The unix timestamp corresponding to the table version of the file, in milliseconds,
53+
* returned when querying a table data with a version or timestamp parameter.
54+
*/
55+
@JsonProperty
56+
@Builder.Default
57+
Optional<Long> timestamp = Optional.empty();
58+
59+
/**
60+
* The unix timestamp corresponding to the expiration of the url, in milliseconds,
61+
* returned when the server supports the feature.
62+
*/
63+
@JsonProperty
64+
@Builder.Default
65+
Optional<Long> expirationTimestamp = Optional.empty();
66+
67+
/**
68+
* Need to be parsed by a delta library as a delta single action, the path field is replaced by pr-signed url.
69+
*/
70+
@JsonProperty
71+
@NonNull JsonNode deltaSingleAction;
72+
}
73+
}

server/app/src/main/java/io/whitefox/api/deltasharing/model/v1/delta/DeltaFiles.yaml

Lines changed: 0 additions & 146 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.whitefox.api.deltasharing.model.v1.delta;
2+
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
6+
import java.io.IOException;
7+
import java.util.Optional;
8+
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.Test;
10+
11+
public class DeltaFileSerializationTest {
12+
String singleActionJson;
13+
String json;
14+
15+
DeltaFile object;
16+
ObjectMapper om;
17+
18+
public DeltaFileSerializationTest() throws JsonProcessingException {
19+
om = new ObjectMapper();
20+
om.registerModule(new Jdk8Module());
21+
singleActionJson =
22+
"{\"add\":{\"dataChange\":false,\"modificationTime\":0,\"partitionValues\":{\"date\":\"2021-04-28\"},\"path\":\"https://s3-bucket-name.s3.us-west-2.amazonaws.com/delta-exchange-test/table2/date%3D2021-04-28/part-00000-591723a8-6a27-4240-a90e-57426f4736d2.c000.snappy.parquet?...\",\"pathAsUri\":\"https://s3-bucket-name.s3.us-west-2.amazonaws.com/delta-exchange-test/table2/date%3D2021-04-28/part-00000-591723a8-6a27-4240-a90e-57426f4736d2.c000.snappy.parquet?...\",\"size\":0,\"stats\":\"{\\\"numRecords\\\":1,\\\"minValues\\\":{\\\"eventTime\\\":\\\"2021-04-28T23:33:48.719Z\\\"},\\\"maxValues\\\":{\\\"eventTime\\\":\\\"2021-04-28T23:33:48.719Z\\\"},\\\"nullCount\\\":{\\\"eventTime\\\":0}}\"}}";
23+
json =
24+
"{\"file\":{\"id\":\"591723a8-6a27-4240-a90e-57426f4736d2\",\"expirationTimestamp\":1652140800000,\"deltaSingleAction\":"
25+
+ singleActionJson + "}}";
26+
object = DeltaFile.builder()
27+
.file(DeltaFile.File.builder()
28+
.id("591723a8-6a27-4240-a90e-57426f4736d2")
29+
.expirationTimestamp(Optional.of(1652140800000L))
30+
.deltaSingleAction(om.readTree(singleActionJson))
31+
.build())
32+
.build();
33+
}
34+
35+
@Test
36+
void serialize() throws IOException {
37+
Assertions.assertEquals(json, om.writer().writeValueAsString(object));
38+
}
39+
40+
@Test
41+
void deserialize() throws IOException {
42+
Assertions.assertEquals(object, om.reader().readValue(json, DeltaFile.class));
43+
}
44+
}

0 commit comments

Comments
 (0)