Skip to content

Commit 27899fb

Browse files
committed
more tests
1 parent c4a23c4 commit 27899fb

File tree

2 files changed

+84
-8
lines changed

2 files changed

+84
-8
lines changed

server/core/src/main/java/io/whitefox/core/types/predicates/NonLeafOp.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
@JsonSubTypes.Type(value = LessThanOp.class, name = "lessThan"),
1818
@JsonSubTypes.Type(value = LessThanOrEqualOp.class, name = "lessThanOrEqual"),
1919
@JsonSubTypes.Type(value = GreaterThanOp.class, name = "greaterThan"),
20-
@JsonSubTypes.Type(value = GreaterThanOrEqualOp.class, name = "greaterThanOrEqual")
20+
@JsonSubTypes.Type(value = GreaterThanOrEqualOp.class, name = "greaterThanOrEqual"),
21+
@JsonSubTypes.Type(value = DifferentThanOp.class, name = "differentThan")
2122
})
2223
public abstract class NonLeafOp implements BaseOp {
2324

@@ -37,8 +38,8 @@ public static NonLeafOp createPartitionFilter(List<LeafOp> children, String oper
3738
return new GreaterThanOp(children);
3839
case ">=":
3940
return new GreaterThanOrEqualOp(children);
40-
// case "<>":
41-
// return new DifferentThanOp(children);
41+
case "<>":
42+
return new DifferentThanOp(children);
4243
case "isnull":
4344
return new IsNullOp(children);
4445
default:
@@ -104,6 +105,33 @@ public Object eval(EvalContext ctx) throws PredicateException {
104105
}
105106
}
106107

108+
// not used in JsonPredicates, only for SQL
109+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "differentThan")
110+
class DifferentThanOp extends NonLeafOp implements BinaryOp {
111+
@JsonProperty("children")
112+
List<LeafOp> children;
113+
114+
public DifferentThanOp() {
115+
super();
116+
}
117+
118+
public DifferentThanOp(List<LeafOp> children) {
119+
this.children = children;
120+
}
121+
122+
@Override
123+
public void validate() throws PredicateException {
124+
validateChildren(
125+
List.copyOf(children).stream().map(c -> (BaseOp) c).collect(Collectors.toList()));
126+
}
127+
128+
@Override
129+
public Object eval(EvalContext ctx) throws PredicateException {
130+
this.validate();
131+
return EvalHelper.equal(children, ctx);
132+
}
133+
}
134+
107135
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "lessThan")
108136
class LessThanOp extends NonLeafOp implements BinaryOp {
109137
@JsonProperty("children")

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

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.whitefox.DeltaTestUtils;
44
import io.whitefox.core.*;
5+
import io.whitefox.core.services.exceptions.TableNotFound;
56
import io.whitefox.persistence.StorageManager;
67
import io.whitefox.persistence.memory.InMemoryStorageManager;
78
import java.util.Collections;
@@ -38,7 +39,7 @@ public void listShares() throws ExecutionException, InterruptedException {
3839
}
3940

4041
@Test
41-
public void listSharesWithToken() throws ExecutionException, InterruptedException {
42+
public void listSharesWithToken() {
4243
var shares = List.of(createShare("name", "key", Collections.emptyMap()));
4344
StorageManager storageManager = new InMemoryStorageManager(shares);
4445
DeltaSharesService deltaSharesService =
@@ -49,7 +50,7 @@ public void listSharesWithToken() throws ExecutionException, InterruptedExceptio
4950
}
5051

5152
@Test
52-
public void listSchemasOfEmptyShare() throws ExecutionException, InterruptedException {
53+
public void listSchemasOfEmptyShare() {
5354
var shares = List.of(createShare("name", "key", Collections.emptyMap()));
5455
StorageManager storageManager = new InMemoryStorageManager(shares);
5556
DeltaSharesService deltaSharesService =
@@ -61,7 +62,7 @@ public void listSchemasOfEmptyShare() throws ExecutionException, InterruptedExce
6162
}
6263

6364
@Test
64-
public void listSchemas() throws ExecutionException, InterruptedException {
65+
public void listSchemas() {
6566
var shares = List.of(createShare(
6667
"name", "key", Map.of("default", new Schema("default", Collections.emptyList(), "name"))));
6768
StorageManager storageManager = new InMemoryStorageManager(shares);
@@ -89,7 +90,7 @@ public void listSchemasOfUnknownShare() throws ExecutionException, InterruptedEx
8990
}
9091

9192
@Test
92-
public void listTables() throws ExecutionException, InterruptedException {
93+
public void listTables() {
9394
var shares = List.of(createShare(
9495
"name",
9596
"key",
@@ -114,7 +115,7 @@ public void listTables() throws ExecutionException, InterruptedException {
114115
}
115116

116117
@Test
117-
public void listAllTables() throws ExecutionException, InterruptedException {
118+
public void listAllTables() {
118119
var shares = List.of(createShare(
119120
"name",
120121
"key",
@@ -224,4 +225,51 @@ public void tableMetadataNotFound() {
224225
var resultTable = deltaSharesService.getTableMetadata("name", "default", "tableNotFound", null);
225226
Assertions.assertTrue(resultTable.isEmpty());
226227
}
228+
229+
@Test
230+
public void queryExistingTable() {
231+
var shares = List.of(createShare(
232+
"name",
233+
"key",
234+
Map.of(
235+
"default",
236+
new Schema(
237+
"default",
238+
List.of(new SharedTable(
239+
"partitioned-delta-table",
240+
"default",
241+
"name",
242+
DeltaTestUtils.deltaTable("partitioned-delta-table"))),
243+
"name"))));
244+
StorageManager storageManager = new InMemoryStorageManager(shares);
245+
DeltaSharesService deltaSharesService =
246+
new DeltaSharesServiceImpl(storageManager, 100, loader, fileSignerFactory);
247+
var resultTable = deltaSharesService.queryTable(
248+
"name",
249+
"default",
250+
"partitioned-delta-table",
251+
new ReadTableRequest.ReadTableCurrentVersion(
252+
Optional.empty(), Optional.empty(), Optional.empty()));
253+
Assertions.assertEquals(9, resultTable.files().size());
254+
}
255+
256+
@Test
257+
public void queryNonExistingTable() {
258+
var shares = List.of(createShare(
259+
"name",
260+
"key",
261+
Map.of(
262+
"default",
263+
new Schema(
264+
"default",
265+
List.of(new SharedTable(
266+
"table1", "default", "name", DeltaTestUtils.deltaTable("location1"))),
267+
"name"))));
268+
StorageManager storageManager = new InMemoryStorageManager(shares);
269+
DeltaSharesService deltaSharesService =
270+
new DeltaSharesServiceImpl(storageManager, 100, loader, fileSignerFactory);
271+
Assertions.assertThrows(
272+
TableNotFound.class,
273+
() -> deltaSharesService.queryTable("name", "default", "tableNotFound", null));
274+
}
227275
}

0 commit comments

Comments
 (0)