Skip to content

Commit 79c1eab

Browse files
Return read version in ReadTableResult (#198)
Add lombok because pojo refactor was too painful
1 parent 9c58f42 commit 79c1eab

File tree

10 files changed

+60
-141
lines changed

10 files changed

+60
-141
lines changed

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ dependencies {
1010
implementation("org.openapi.generator:org.openapi.generator.gradle.plugin:6.6.0")
1111
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.25.0")
1212
implementation("com.palantir.gradle.gitversion:gradle-git-version:3.0.0")
13+
implementation("io.freefair.lombok:io.freefair.lombok.gradle.plugin:8.4")
1314
}

buildSrc/src/main/kotlin/whitefox.java-conventions.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
id("com.palantir.git-version")
88
id("org.openapi.generator")
99
id("com.diffplug.spotless")
10+
id("io.freefair.lombok")
1011
}
1112
// Projects should use Maven Central for external dependencies
1213
repositories {

lombok.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lombok.accessors.fluent=true
2+
lombok.addLombokGeneratedAnnotation = true

protocol/delta-sharing-protocol-api.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,6 @@ paths:
413413
description: 'Named table'
414414
schema:
415415
type: string
416-
- in: query
417-
name: startingTimestamp
418-
required: false
419-
description: 'Starting Timestamp ISO8601 format, in the UTC timezone'
420-
schema:
421-
type: string
422416
- in: header
423417
name: delta-sharing-capabilities
424418
required: false

server/app/src/main/java/io/whitefox/api/deltasharing/server/DeltaSharesApiImpl.java

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -164,49 +164,35 @@ share, schema, parseToken(pageToken), Optional.ofNullable(maxResults)),
164164
exceptionToResponse);
165165
}
166166

167-
/***
168-
* Example:
169-
* TableQueryResponse:
170-
* type: string
171-
* example: |
172-
* {"protocol":{"minReaderVersion":1}}
173-
* {"metaData":{"id":"f8d5c169-3d01-4ca3-ad9e-7dc3355aedb2","format":{"provider":"parquet"},"schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"eventTime\",\"type\":\"timestamp\",\"nullable\":true,\"metadata\":{}},{\"name\":\"date\",\"type\":\"date\",\"nullable\":true,\"metadata\":{}}]}","partitionColumns":["date"]}}
174-
* {"file":{"url":"https://<s3-bucket-name>.s3.us-west-2.amazonaws.com/delta-exchange-test/table2/date%3D2021-04-28/part-00000-8b0086f2-7b27-4935-ac5a-8ed6215a6640.c000.snappy.parquet?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210501T010516Z&X-Amz-SignedHeaders=host&X-Amz-Expires=900&X-Amz-Credential=AKIAISZRDL4Q4Q7AIONA%2F20210501%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Signature=97b6762cfd8e4d7e94b9d707eff3faf266974f6e7030095c1d4a66350cfd892e","id":"8b0086f2-7b27-4935-ac5a-8ed6215a6640","partitionValues":{"date":"2021-04-28"},"size":573,"stats":"{\"numRecords\":1,\"minValues\":{\"eventTime\":\"2021-04-28T23:33:57.955Z\"},\"maxValues\":{\"eventTime\":\"2021-04-28T23:33:57.955Z\"},\"nullCount\":{\"eventTime\":0}}"}}
175-
* {"file":{"url":"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?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210501T010516Z&X-Amz-SignedHeaders=host&X-Amz-Expires=899&X-Amz-Credential=AKIAISZRDL4Q4Q7AIONA%2F20210501%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Signature=0f7acecba5df7652457164533a58004936586186c56425d9d53c52db574f6b62","id":"591723a8-6a27-4240-a90e-57426f4736d2","partitionValues":{"date":"2021-04-28"},"size":573,"stats":"{\"numRecords\":1,\"minValues\":{\"eventTime\":\"2021-04-28T23:33:48.719Z\"},\"maxValues\":{\"eventTime\":\"2021-04-28T23:33:48.719Z\"},\"nullCount\":{\"eventTime\":0}}"}}
176-
*
177-
*
178-
* @param share
179-
* @param schema
180-
* @param table
181-
* @param queryRequest
182-
* @param startingTimestamp
183-
* @return
167+
/**
168+
* <pre>
169+
* {"protocol":{"minReaderVersion":1}}
170+
* {"metaData":{"id":"f8d5c169-3d01-4ca3-ad9e-7dc3355aedb2","format":{"provider":"parquet"},"schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"eventTime\",\"type\":\"timestamp\",\"nullable\":true,\"metadata\":{}},{\"name\":\"date\",\"type\":\"date\",\"nullable\":true,\"metadata\":{}}]}","partitionColumns":["date"]}}
171+
* {"file":{"url":"https://<s3-bucket-name>.s3.us-west-2.amazonaws.com/delta-exchange-test/table2/date%3D2021-04-28/part-00000-8b0086f2-7b27-4935-ac5a-8ed6215a6640.c000.snappy.parquet?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210501T010516Z&X-Amz-SignedHeaders=host&X-Amz-Expires=900&X-Amz-Credential=AKIAISZRDL4Q4Q7AIONA%2F20210501%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Signature=97b6762cfd8e4d7e94b9d707eff3faf266974f6e7030095c1d4a66350cfd892e","id":"8b0086f2-7b27-4935-ac5a-8ed6215a6640","partitionValues":{"date":"2021-04-28"},"size":573,"stats":"{\"numRecords\":1,\"minValues\":{\"eventTime\":\"2021-04-28T23:33:57.955Z\"},\"maxValues\":{\"eventTime\":\"2021-04-28T23:33:57.955Z\"},\"nullCount\":{\"eventTime\":0}}"}}
172+
* {"file":{"url":"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?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210501T010516Z&X-Amz-SignedHeaders=host&X-Amz-Expires=899&X-Amz-Credential=AKIAISZRDL4Q4Q7AIONA%2F20210501%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Signature=0f7acecba5df7652457164533a58004936586186c56425d9d53c52db574f6b62","id":"591723a8-6a27-4240-a90e-57426f4736d2","partitionValues":{"date":"2021-04-28"},"size":573,"stats":"{\"numRecords\":1,\"minValues\":{\"eventTime\":\"2021-04-28T23:33:48.719Z\"},\"maxValues\":{\"eventTime\":\"2021-04-28T23:33:48.719Z\"},\"nullCount\":{\"eventTime\":0}}"}}
173+
* </pre>
184174
*/
185175
@Override
186176
public Response queryTable(
187177
String share,
188178
String schema,
189179
String table,
190180
QueryRequest queryRequest,
191-
String startingTimestamp,
192181
String deltaSharingCapabilities) {
193182
return wrapExceptions(
194-
() -> optionalToNotFound(
195-
deltaSharesService.getTableVersion(share, schema, table, startingTimestamp),
196-
version -> Response.ok(
197-
tableQueryResponseSerializer.serialize(
198-
DeltaMappers.readTableResult2api(deltaSharesService.queryTable(
199-
share,
200-
schema,
201-
table,
202-
DeltaMappers.api2ReadTableRequest(queryRequest)))),
203-
ndjsonMediaType)
204-
.header(DELTA_TABLE_VERSION_HEADER, version)
205-
.header(
206-
DELTA_SHARE_CAPABILITIES_HEADER,
207-
getResponseFormatHeader(
208-
DeltaMappers.toHeaderCapabilitiesMap(deltaSharingCapabilities)))
209-
.build()),
183+
() -> {
184+
var readResult = deltaSharesService.queryTable(
185+
share, schema, table, DeltaMappers.api2ReadTableRequest(queryRequest));
186+
var serializedReadResult =
187+
tableQueryResponseSerializer.serialize(DeltaMappers.readTableResult2api(readResult));
188+
return Response.ok(serializedReadResult, ndjsonMediaType)
189+
.header(DELTA_TABLE_VERSION_HEADER, readResult.version())
190+
.header(
191+
DELTA_SHARE_CAPABILITIES_HEADER,
192+
getResponseFormatHeader(
193+
DeltaMappers.toHeaderCapabilitiesMap(deltaSharingCapabilities)))
194+
.build();
195+
},
210196
exceptionToResponse);
211197
}
212198

server/app/src/test/java/io/whitefox/api/deltasharing/server/DeltaSharesApiImplTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,23 @@ public void getTableVersionBadTimestamp() {
352352
.statusCode(502);
353353
}
354354

355+
@DisabledOnOs(OS.WINDOWS)
356+
@Test
357+
public void queryNotExistingTable() throws IOException {
358+
given()
359+
.when()
360+
.filter(deltaFilter)
361+
.body("{}")
362+
.header(new Header("Content-Type", "application/json"))
363+
.post(
364+
"delta-api/v1/shares/{share}/schemas/{schema}/tables/{table}/query",
365+
"name",
366+
"default",
367+
"tableThatDoesNotExist")
368+
.then()
369+
.statusCode(404);
370+
}
371+
355372
@DisabledOnOs(OS.WINDOWS)
356373
@Test
357374
public void queryTableCurrentVersion() throws IOException {
@@ -367,6 +384,7 @@ public void queryTableCurrentVersion() throws IOException {
367384
"table1")
368385
.then()
369386
.statusCode(200)
387+
.header("Delta-Table-Version", "0")
370388
.extract()
371389
.body()
372390
.asString()
@@ -410,6 +428,7 @@ public void queryTableByVersion() throws IOException {
410428
"table1")
411429
.then()
412430
.statusCode(200)
431+
.header("Delta-Table-Version", "0")
413432
.extract()
414433
.body()
415434
.asString()
@@ -453,6 +472,7 @@ public void queryTableByTs() throws IOException {
453472
"table-with-history")
454473
.then()
455474
.statusCode(200)
475+
.header("Delta-Table-Version", "0")
456476
.extract()
457477
.body()
458478
.asString()
Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,12 @@
11
package io.whitefox.core;
22

3-
import io.whitefox.annotations.SkipCoverageGenerated;
43
import java.util.List;
5-
import java.util.Objects;
4+
import lombok.Value;
65

6+
@Value
77
public class ReadTableResult {
8-
private final Protocol protocol;
9-
private final Metadata metadata;
10-
private final List<TableFile> files;
11-
12-
public ReadTableResult(Protocol protocol, Metadata metadata, List<TableFile> files) {
13-
this.protocol = protocol;
14-
this.metadata = metadata;
15-
this.files = files;
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-
ReadTableResult that = (ReadTableResult) o;
24-
return Objects.equals(protocol, that.protocol)
25-
&& Objects.equals(metadata, that.metadata)
26-
&& Objects.equals(files, that.files);
27-
}
28-
29-
@Override
30-
@SkipCoverageGenerated
31-
public int hashCode() {
32-
return Objects.hash(protocol, metadata, files);
33-
}
34-
35-
@Override
36-
@SkipCoverageGenerated
37-
public String toString() {
38-
return "QueryTableResult{" + "protocol="
39-
+ protocol + ", metadata="
40-
+ metadata + ", files="
41-
+ files + '}';
42-
}
43-
44-
public Protocol protocol() {
45-
return protocol;
46-
}
47-
48-
public Metadata metadata() {
49-
return metadata;
50-
}
51-
52-
public List<TableFile> files() {
53-
return files;
54-
}
8+
Protocol protocol;
9+
Metadata metadata;
10+
List<TableFile> files;
11+
long version;
5512
}
Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,12 @@
11
package io.whitefox.core;
22

3-
import io.whitefox.annotations.SkipCoverageGenerated;
43
import java.util.List;
5-
import java.util.Objects;
4+
import lombok.Value;
65

6+
@Value
77
public class ReadTableResultToBeSigned {
8-
private final Protocol protocol;
9-
private final Metadata metadata;
10-
private final List<TableFileToBeSigned> other;
11-
12-
public ReadTableResultToBeSigned(
13-
Protocol protocol, Metadata metadata, List<TableFileToBeSigned> other) {
14-
this.protocol = protocol;
15-
this.metadata = metadata;
16-
this.other = other;
17-
}
18-
19-
@Override
20-
@SkipCoverageGenerated
21-
public boolean equals(Object o) {
22-
if (this == o) return true;
23-
if (o == null || getClass() != o.getClass()) return false;
24-
ReadTableResultToBeSigned that = (ReadTableResultToBeSigned) o;
25-
return Objects.equals(protocol, that.protocol)
26-
&& Objects.equals(metadata, that.metadata)
27-
&& Objects.equals(other, that.other);
28-
}
29-
30-
@Override
31-
@SkipCoverageGenerated
32-
public int hashCode() {
33-
return Objects.hash(protocol, metadata, other);
34-
}
35-
36-
@Override
37-
@SkipCoverageGenerated
38-
public String toString() {
39-
return "QueryTableResult{" + "protocol="
40-
+ protocol + ", metadata="
41-
+ metadata + ", other="
42-
+ other + '}';
43-
}
44-
45-
public Protocol protocol() {
46-
return protocol;
47-
}
48-
49-
public Metadata metadata() {
50-
return metadata;
51-
}
52-
53-
public List<TableFileToBeSigned> other() {
54-
return other;
55-
}
8+
Protocol protocol;
9+
Metadata metadata;
10+
List<TableFileToBeSigned> other;
11+
long version;
5612
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public ReadTableResultToBeSigned queryTable(ReadTableRequest readTableRequest) {
102102
snapshot.getMetadata().getCreatedTime(),
103103
f.getStats(),
104104
f.getPartitionValues()))
105-
.collect(Collectors.toList()));
105+
.collect(Collectors.toList()),
106+
snapshot.getVersion());
106107
}
107108

108109
private Optional<Snapshot> getSnapshot(Optional<String> startingTimestamp) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public ReadTableResult queryTable(
140140
readTableResultToBeSigned.metadata(),
141141
readTableResultToBeSigned.other().stream()
142142
.map(fileSigner::sign)
143-
.collect(Collectors.toList()));
143+
.collect(Collectors.toList()),
144+
readTableResultToBeSigned.version());
144145
}
145146
}

0 commit comments

Comments
 (0)