From 39d25a325fedf151ae64079fab241b974c0bb5f0 Mon Sep 17 00:00:00 2001 From: Dovie Shalev Date: Wed, 28 Oct 2026 16:22:58 -0400 Subject: [PATCH 1/4] Add deleteMaterializedAggregates to deleteFeatures Passes the new `delete_materialized_aggregates` flag of `DELETE /v1/features/rows` (DeleteFeaturesParams.Builder.withDeleteMaterializedAggregates): when set, the server also deletes every online bucket of the namespace's materialized windowed aggregations stored under the given primary keys. DeleteFeaturesResult exposes `materializedAggregateKeysDeleted`. The previous all-args constructors of DeleteFeaturesParams, its Builder and DeleteFeaturesResult are kept as overloads. Co-Authored-By: Claude Opus 5.5 --- .../java/ai/chalk/client/ChalkClientImpl.java | 3 +- .../FeatureObservationDeletionRequest.java | 3 +- .../ai/chalk/models/DeleteFeaturesParams.java | 48 ++++++++++++++++- .../ai/chalk/models/DeleteFeaturesResult.java | 11 ++++ .../ai/chalk/client/TestDeleteFeatures.java | 52 ++++++++++++++++++- 5 files changed, 113 insertions(+), 4 deletions(-) diff --git a/src/main/java/ai/chalk/client/ChalkClientImpl.java b/src/main/java/ai/chalk/client/ChalkClientImpl.java index bd4ed38..f3d6b90 100644 --- a/src/main/java/ai/chalk/client/ChalkClientImpl.java +++ b/src/main/java/ai/chalk/client/ChalkClientImpl.java @@ -284,7 +284,8 @@ public DeleteFeaturesResult deleteFeatures(DeleteFeaturesParams params) throws C params.getTags(), params.getPrimaryKeys(), params.isRetainOffline(), - params.isRetainOnline() + params.isRetainOnline(), + params.isDeleteMaterializedAggregates() )) .method("DELETE") .environmentOverride(params.getEnvironmentId()) diff --git a/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java b/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java index bc11df1..0c22fb0 100644 --- a/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java +++ b/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java @@ -8,6 +8,7 @@ public record FeatureObservationDeletionRequest( List tags, List primaryKeys, boolean retainOffline, - boolean retainOnline + boolean retainOnline, + boolean deleteMaterializedAggregates ) { } diff --git a/src/main/java/ai/chalk/models/DeleteFeaturesParams.java b/src/main/java/ai/chalk/models/DeleteFeaturesParams.java index 59bf1f2..fb112e6 100644 --- a/src/main/java/ai/chalk/models/DeleteFeaturesParams.java +++ b/src/main/java/ai/chalk/models/DeleteFeaturesParams.java @@ -54,6 +54,27 @@ public class DeleteFeaturesParams { * If true, the given observations will not be dropped from the online store. */ private final boolean retainOnline; + /** + * If true, also delete every online bucket of the namespace's materialized windowed + * aggregations stored under the given primary keys (restricted by {@code features} / + * {@code tags} if given). Ignored when {@code retainOnline} is true. Buckets are not rebuilt: + * later stream updates and backfills write them again as usual. + */ + private final boolean deleteMaterializedAggregates; + + /** Equivalent to the full constructor with {@code deleteMaterializedAggregates = false}. */ + public DeleteFeaturesParams( + String namespace, + @Nullable List features, + @Nullable List tags, + List primaryKeys, + @Nullable String environmentId, + @Nullable String branch, + boolean retainOffline, + boolean retainOnline + ) { + this(namespace, features, tags, primaryKeys, environmentId, branch, retainOffline, retainOnline, false); + } @AllArgsConstructor @NoArgsConstructor @@ -66,6 +87,21 @@ public static class Builder { protected String branch; protected boolean retainOffline = false; protected boolean retainOnline = false; + protected boolean deleteMaterializedAggregates = false; + + /** Equivalent to the full constructor with {@code deleteMaterializedAggregates = false}. */ + public Builder( + String namespace, + List features, + List tags, + List primaryKeys, + String environmentId, + String branch, + boolean retainOffline, + boolean retainOnline + ) { + this(namespace, features, tags, primaryKeys, environmentId, branch, retainOffline, retainOnline, false); + } public DeleteFeaturesParams build() { return new DeleteFeaturesParams( @@ -76,7 +112,8 @@ public DeleteFeaturesParams build() { this.environmentId, this.branch, this.retainOffline, - this.retainOnline); + this.retainOnline, + this.deleteMaterializedAggregates); } public Builder withNamespace(String namespace) { @@ -120,6 +157,15 @@ public Builder withRetainOnline(boolean retainOnline) { this.retainOnline = retainOnline; return this; } + + /** + * Also delete every online bucket of the namespace's materialized windowed aggregations + * stored under the given primary keys. Defaults to {@code false}. + */ + public Builder withDeleteMaterializedAggregates(boolean deleteMaterializedAggregates) { + this.deleteMaterializedAggregates = deleteMaterializedAggregates; + return this; + } } public static Builder builder() { diff --git a/src/main/java/ai/chalk/models/DeleteFeaturesResult.java b/src/main/java/ai/chalk/models/DeleteFeaturesResult.java index 26e1bea..a38c6fd 100644 --- a/src/main/java/ai/chalk/models/DeleteFeaturesResult.java +++ b/src/main/java/ai/chalk/models/DeleteFeaturesResult.java @@ -6,6 +6,7 @@ import lombok.Data; import lombok.NoArgsConstructor; +import javax.annotation.Nullable; import java.util.List; /** @@ -17,4 +18,14 @@ @AllArgsConstructor public class DeleteFeaturesResult { private List errors; + /** + * The number of online store entries removed by {@code deleteMaterializedAggregates}, + * or {@code null} if that was not requested. + */ + @Nullable + private Long materializedAggregateKeysDeleted; + + public DeleteFeaturesResult(List errors) { + this(errors, null); + } } diff --git a/src/test/java/ai/chalk/client/TestDeleteFeatures.java b/src/test/java/ai/chalk/client/TestDeleteFeatures.java index 3766060..b92a52c 100644 --- a/src/test/java/ai/chalk/client/TestDeleteFeatures.java +++ b/src/test/java/ai/chalk/client/TestDeleteFeatures.java @@ -15,6 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -66,13 +67,62 @@ public void testHttpDeleteFeatures() throws Exception { assertEquals("DELETE", method.get()); assertEquals( "{\"namespace\":\"user\",\"features\":[\"name\",\"email\"],\"tags\":null," - + "\"primary_keys\":[\"1\",\"2\"],\"retain_offline\":false,\"retain_online\":false}", + + "\"primary_keys\":[\"1\",\"2\"],\"retain_offline\":false,\"retain_online\":false," + + "\"delete_materialized_aggregates\":false}", body.get() ); assertEquals("Bearer test-token", authorization.get()); assertEquals(ENVIRONMENT_ID, environmentHeader.get()); assertEquals(1, result.getErrors().size()); assertEquals("partial failure", result.getErrors().get(0).getMessage()); + assertNull(result.getMaterializedAggregateKeysDeleted()); + } finally { + server.stop(0); + } + } + + @Test + public void testHttpDeleteFeaturesWithMaterializedAggregates() throws Exception { + AtomicReference body = new AtomicReference<>(); + HttpServer server = HttpServer.create(new InetSocketAddress("localhost", 0), 0); + server.createContext("/v1/oauth/token", exchange -> respondJson( + exchange, + """ + { + "access_token": "test-token", + "expires_in": 3600, + "primary_environment": "%s", + "engines": {} + } + """.formatted(ENVIRONMENT_ID) + )); + server.createContext("/v1/features/rows", exchange -> { + body.set(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8)); + respondJson(exchange, "{\"errors\": [], \"materialized_aggregate_keys_deleted\": 7}"); + }); + server.start(); + + String serverUrl = "http://localhost:" + server.getAddress().getPort(); + try (ChalkClient client = ChalkClient.builder() + .withApiServer(serverUrl) + .withClientId("test-client") + .withClientSecret("test-secret") + .withEnvironmentId(ENVIRONMENT_ID) + .build()) { + DeleteFeaturesResult result = client.deleteFeatures(DeleteFeaturesParams.builder() + .withNamespace("user") + .withPrimaryKeys(List.of("1")) + .withDeleteMaterializedAggregates(true) + .build()); + + assertEquals( + "{\"namespace\":\"user\",\"features\":null,\"tags\":null,\"primary_keys\":[\"1\"]," + + "\"retain_offline\":false,\"retain_online\":false," + + "\"delete_materialized_aggregates\":true}", + body.get() + ); + assertTrue(result.getErrors().isEmpty()); + assertEquals(7L, result.getMaterializedAggregateKeysDeleted()); } finally { server.stop(0); } From a71e1b194619c446c483dac6656e5ee79e70c192 Mon Sep 17 00:00:00 2001 From: Dovie Shalev Date: Thu, 29 Oct 2026 15:33:19 -0400 Subject: [PATCH 2/4] Reject features/tags with delete_materialized_aggregates The server deletes every materialized aggregation of the primary keys and rejects a `features` / `tags` selection combined with the flag; fail fast in the client with the same rule instead of sending the request. Co-Authored-By: Claude Opus 5.5 --- .../java/ai/chalk/client/ChalkClientImpl.java | 6 ++++ .../ai/chalk/models/DeleteFeaturesParams.java | 13 +++---- .../ai/chalk/client/TestDeleteFeatures.java | 35 +++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/main/java/ai/chalk/client/ChalkClientImpl.java b/src/main/java/ai/chalk/client/ChalkClientImpl.java index f3d6b90..c33f373 100644 --- a/src/main/java/ai/chalk/client/ChalkClientImpl.java +++ b/src/main/java/ai/chalk/client/ChalkClientImpl.java @@ -268,6 +268,12 @@ public UploadFeaturesResult uploadFeatures(UploadFeaturesParams params) throws C @Override public DeleteFeaturesResult deleteFeatures(DeleteFeaturesParams params) throws ChalkException { + if (params.isDeleteMaterializedAggregates() && (params.getFeatures() != null || params.getTags() != null)) { + throw new ClientException( + "deleteMaterializedAggregates deletes every materialized aggregation of the primary keys " + + "and cannot be combined with features or tags." + ); + } String branch = params.getBranch() != null ? params.getBranch() : this.branch; if (branch != null) { throw new ClientException( diff --git a/src/main/java/ai/chalk/models/DeleteFeaturesParams.java b/src/main/java/ai/chalk/models/DeleteFeaturesParams.java index fb112e6..56eba92 100644 --- a/src/main/java/ai/chalk/models/DeleteFeaturesParams.java +++ b/src/main/java/ai/chalk/models/DeleteFeaturesParams.java @@ -55,10 +55,10 @@ public class DeleteFeaturesParams { */ private final boolean retainOnline; /** - * If true, also delete every online bucket of the namespace's materialized windowed - * aggregations stored under the given primary keys (restricted by {@code features} / - * {@code tags} if given). Ignored when {@code retainOnline} is true. Buckets are not rebuilt: - * later stream updates and backfills write them again as usual. + * If true, also delete every online bucket of every materialized windowed aggregation of the + * namespace stored under the given primary keys. Cannot be combined with {@code features} or + * {@code tags}. Ignored when {@code retainOnline} is true. Buckets are not rebuilt: later stream + * updates and backfills write them again as usual. */ private final boolean deleteMaterializedAggregates; @@ -159,8 +159,9 @@ public Builder withRetainOnline(boolean retainOnline) { } /** - * Also delete every online bucket of the namespace's materialized windowed aggregations - * stored under the given primary keys. Defaults to {@code false}. + * Also delete every online bucket of every materialized windowed aggregation of the namespace + * stored under the given primary keys. Cannot be combined with features or tags. Defaults to + * {@code false}. */ public Builder withDeleteMaterializedAggregates(boolean deleteMaterializedAggregates) { this.deleteMaterializedAggregates = deleteMaterializedAggregates; diff --git a/src/test/java/ai/chalk/client/TestDeleteFeatures.java b/src/test/java/ai/chalk/client/TestDeleteFeatures.java index b92a52c..363eb89 100644 --- a/src/test/java/ai/chalk/client/TestDeleteFeatures.java +++ b/src/test/java/ai/chalk/client/TestDeleteFeatures.java @@ -128,6 +128,41 @@ public void testHttpDeleteFeaturesWithMaterializedAggregates() throws Exception } } + @Test + public void testDeleteMaterializedAggregatesRejectsFeatureSelection() throws Exception { + AtomicReference deleteCalled = new AtomicReference<>(false); + HttpServer server = HttpServer.create(new InetSocketAddress("localhost", 0), 0); + server.createContext("/v1/features/rows", exchange -> { + deleteCalled.set(true); + respondJson(exchange, "{\"errors\": []}"); + }); + server.start(); + + String serverUrl = "http://localhost:" + server.getAddress().getPort(); + try (ChalkClient client = ChalkClient.builder() + .withApiServer(serverUrl) + .withClientId("test-client") + .withClientSecret("test-secret") + .withEnvironmentId(ENVIRONMENT_ID) + .build()) { + for (DeleteFeaturesParams.Builder builder : List.of( + DeleteFeaturesParams.builder().withFeatures(List.of("name")), + DeleteFeaturesParams.builder().withTags(List.of("pii")) + )) { + ClientException e = assertThrows(ClientException.class, () -> client.deleteFeatures( + builder.withNamespace("user") + .withPrimaryKeys(List.of("1")) + .withDeleteMaterializedAggregates(true) + .build() + )); + assertTrue(e.getMessage().contains("cannot be combined")); + } + assertFalse(deleteCalled.get()); + } finally { + server.stop(0); + } + } + @Test public void testHttpDeleteFeaturesRejectsBranch() throws Exception { AtomicReference deleteCalled = new AtomicReference<>(false); From e1256ebc120559d546cd3c304c8140d05c1dd891 Mon Sep 17 00:00:00 2001 From: Dovie Shalev Date: Fri, 30 Oct 2026 15:48:28 -0400 Subject: [PATCH 3/4] Replace delete_materialized_aggregates with retain_materialized_aggregates The flag is now `retain_materialized_aggregates`, defaulting to true; passing false deletes the keys' materialized aggregation buckets and is rejected together with `features` / `tags`. Co-Authored-By: Claude Opus 5.5 --- .../java/ai/chalk/client/ChalkClientImpl.java | 6 ++-- .../FeatureObservationDeletionRequest.java | 2 +- .../ai/chalk/models/DeleteFeaturesParams.java | 31 +++++++------------ .../ai/chalk/models/DeleteFeaturesResult.java | 5 +-- .../ai/chalk/client/TestDeleteFeatures.java | 12 +++---- 5 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/main/java/ai/chalk/client/ChalkClientImpl.java b/src/main/java/ai/chalk/client/ChalkClientImpl.java index c33f373..29b3435 100644 --- a/src/main/java/ai/chalk/client/ChalkClientImpl.java +++ b/src/main/java/ai/chalk/client/ChalkClientImpl.java @@ -268,9 +268,9 @@ public UploadFeaturesResult uploadFeatures(UploadFeaturesParams params) throws C @Override public DeleteFeaturesResult deleteFeatures(DeleteFeaturesParams params) throws ChalkException { - if (params.isDeleteMaterializedAggregates() && (params.getFeatures() != null || params.getTags() != null)) { + if (!params.isRetainMaterializedAggregates() && (params.getFeatures() != null || params.getTags() != null)) { throw new ClientException( - "deleteMaterializedAggregates deletes every materialized aggregation of the primary keys " + "retainMaterializedAggregates=false deletes every materialized aggregation of the primary keys " + "and cannot be combined with features or tags." ); } @@ -291,7 +291,7 @@ public DeleteFeaturesResult deleteFeatures(DeleteFeaturesParams params) throws C params.getPrimaryKeys(), params.isRetainOffline(), params.isRetainOnline(), - params.isDeleteMaterializedAggregates() + params.isRetainMaterializedAggregates() )) .method("DELETE") .environmentOverride(params.getEnvironmentId()) diff --git a/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java b/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java index 0c22fb0..e4385de 100644 --- a/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java +++ b/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java @@ -9,6 +9,6 @@ public record FeatureObservationDeletionRequest( List primaryKeys, boolean retainOffline, boolean retainOnline, - boolean deleteMaterializedAggregates + boolean retainMaterializedAggregates ) { } diff --git a/src/main/java/ai/chalk/models/DeleteFeaturesParams.java b/src/main/java/ai/chalk/models/DeleteFeaturesParams.java index 56eba92..b75ae5e 100644 --- a/src/main/java/ai/chalk/models/DeleteFeaturesParams.java +++ b/src/main/java/ai/chalk/models/DeleteFeaturesParams.java @@ -54,15 +54,10 @@ public class DeleteFeaturesParams { * If true, the given observations will not be dropped from the online store. */ private final boolean retainOnline; - /** - * If true, also delete every online bucket of every materialized windowed aggregation of the - * namespace stored under the given primary keys. Cannot be combined with {@code features} or - * {@code tags}. Ignored when {@code retainOnline} is true. Buckets are not rebuilt: later stream - * updates and backfills write them again as usual. - */ - private final boolean deleteMaterializedAggregates; + /** If false, also delete the keys' materialized aggregation buckets (not with features or tags). */ + private final boolean retainMaterializedAggregates; - /** Equivalent to the full constructor with {@code deleteMaterializedAggregates = false}. */ + /** Equivalent to the full constructor with {@code retainMaterializedAggregates = true}. */ public DeleteFeaturesParams( String namespace, @Nullable List features, @@ -73,7 +68,7 @@ public DeleteFeaturesParams( boolean retainOffline, boolean retainOnline ) { - this(namespace, features, tags, primaryKeys, environmentId, branch, retainOffline, retainOnline, false); + this(namespace, features, tags, primaryKeys, environmentId, branch, retainOffline, retainOnline, true); } @AllArgsConstructor @@ -87,9 +82,9 @@ public static class Builder { protected String branch; protected boolean retainOffline = false; protected boolean retainOnline = false; - protected boolean deleteMaterializedAggregates = false; + protected boolean retainMaterializedAggregates = true; - /** Equivalent to the full constructor with {@code deleteMaterializedAggregates = false}. */ + /** Equivalent to the full constructor with {@code retainMaterializedAggregates = true}. */ public Builder( String namespace, List features, @@ -100,7 +95,7 @@ public Builder( boolean retainOffline, boolean retainOnline ) { - this(namespace, features, tags, primaryKeys, environmentId, branch, retainOffline, retainOnline, false); + this(namespace, features, tags, primaryKeys, environmentId, branch, retainOffline, retainOnline, true); } public DeleteFeaturesParams build() { @@ -113,7 +108,7 @@ public DeleteFeaturesParams build() { this.branch, this.retainOffline, this.retainOnline, - this.deleteMaterializedAggregates); + this.retainMaterializedAggregates); } public Builder withNamespace(String namespace) { @@ -158,13 +153,9 @@ public Builder withRetainOnline(boolean retainOnline) { return this; } - /** - * Also delete every online bucket of every materialized windowed aggregation of the namespace - * stored under the given primary keys. Cannot be combined with features or tags. Defaults to - * {@code false}. - */ - public Builder withDeleteMaterializedAggregates(boolean deleteMaterializedAggregates) { - this.deleteMaterializedAggregates = deleteMaterializedAggregates; + /** Pass false to also delete the keys' materialized aggregation buckets. Defaults to {@code true}. */ + public Builder withRetainMaterializedAggregates(boolean retainMaterializedAggregates) { + this.retainMaterializedAggregates = retainMaterializedAggregates; return this; } } diff --git a/src/main/java/ai/chalk/models/DeleteFeaturesResult.java b/src/main/java/ai/chalk/models/DeleteFeaturesResult.java index a38c6fd..5bf2bbd 100644 --- a/src/main/java/ai/chalk/models/DeleteFeaturesResult.java +++ b/src/main/java/ai/chalk/models/DeleteFeaturesResult.java @@ -18,10 +18,7 @@ @AllArgsConstructor public class DeleteFeaturesResult { private List errors; - /** - * The number of online store entries removed by {@code deleteMaterializedAggregates}, - * or {@code null} if that was not requested. - */ + /** Online store entries removed when {@code retainMaterializedAggregates} is false, else null. */ @Nullable private Long materializedAggregateKeysDeleted; diff --git a/src/test/java/ai/chalk/client/TestDeleteFeatures.java b/src/test/java/ai/chalk/client/TestDeleteFeatures.java index 363eb89..5bcd0d1 100644 --- a/src/test/java/ai/chalk/client/TestDeleteFeatures.java +++ b/src/test/java/ai/chalk/client/TestDeleteFeatures.java @@ -68,7 +68,7 @@ public void testHttpDeleteFeatures() throws Exception { assertEquals( "{\"namespace\":\"user\",\"features\":[\"name\",\"email\"],\"tags\":null," + "\"primary_keys\":[\"1\",\"2\"],\"retain_offline\":false,\"retain_online\":false," - + "\"delete_materialized_aggregates\":false}", + + "\"retain_materialized_aggregates\":true}", body.get() ); assertEquals("Bearer test-token", authorization.get()); @@ -82,7 +82,7 @@ public void testHttpDeleteFeatures() throws Exception { } @Test - public void testHttpDeleteFeaturesWithMaterializedAggregates() throws Exception { + public void testHttpDeleteFeaturesDeletingMaterializedAggregates() throws Exception { AtomicReference body = new AtomicReference<>(); HttpServer server = HttpServer.create(new InetSocketAddress("localhost", 0), 0); server.createContext("/v1/oauth/token", exchange -> respondJson( @@ -112,13 +112,13 @@ public void testHttpDeleteFeaturesWithMaterializedAggregates() throws Exception DeleteFeaturesResult result = client.deleteFeatures(DeleteFeaturesParams.builder() .withNamespace("user") .withPrimaryKeys(List.of("1")) - .withDeleteMaterializedAggregates(true) + .withRetainMaterializedAggregates(false) .build()); assertEquals( "{\"namespace\":\"user\",\"features\":null,\"tags\":null,\"primary_keys\":[\"1\"]," + "\"retain_offline\":false,\"retain_online\":false," - + "\"delete_materialized_aggregates\":true}", + + "\"retain_materialized_aggregates\":false}", body.get() ); assertTrue(result.getErrors().isEmpty()); @@ -129,7 +129,7 @@ public void testHttpDeleteFeaturesWithMaterializedAggregates() throws Exception } @Test - public void testDeleteMaterializedAggregatesRejectsFeatureSelection() throws Exception { + public void testNotRetainingMaterializedAggregatesRejectsFeatureSelection() throws Exception { AtomicReference deleteCalled = new AtomicReference<>(false); HttpServer server = HttpServer.create(new InetSocketAddress("localhost", 0), 0); server.createContext("/v1/features/rows", exchange -> { @@ -152,7 +152,7 @@ public void testDeleteMaterializedAggregatesRejectsFeatureSelection() throws Exc ClientException e = assertThrows(ClientException.class, () -> client.deleteFeatures( builder.withNamespace("user") .withPrimaryKeys(List.of("1")) - .withDeleteMaterializedAggregates(true) + .withRetainMaterializedAggregates(false) .build() )); assertTrue(e.getMessage().contains("cannot be combined")); From 77c00d45798ea3a4ecb3ada484f1f4f381d6b44d Mon Sep 17 00:00:00 2001 From: Dovie Shalev Date: Tue, 3 Nov 2026 12:28:25 -0500 Subject: [PATCH 4/4] Leave retainMaterializedAggregates unset by default retainMaterializedAggregates is now a nullable Boolean that defaults to null, so the API server applies its default (true). Only an explicit false is rejected with features or tags. Co-Authored-By: Claude Opus 5.5 --- .../java/ai/chalk/client/ChalkClientImpl.java | 5 +++-- .../FeatureObservationDeletionRequest.java | 2 +- .../ai/chalk/models/DeleteFeaturesParams.java | 18 +++++++++++------- .../ai/chalk/client/TestDeleteFeatures.java | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/ai/chalk/client/ChalkClientImpl.java b/src/main/java/ai/chalk/client/ChalkClientImpl.java index 29b3435..5a977e3 100644 --- a/src/main/java/ai/chalk/client/ChalkClientImpl.java +++ b/src/main/java/ai/chalk/client/ChalkClientImpl.java @@ -268,7 +268,8 @@ public UploadFeaturesResult uploadFeatures(UploadFeaturesParams params) throws C @Override public DeleteFeaturesResult deleteFeatures(DeleteFeaturesParams params) throws ChalkException { - if (!params.isRetainMaterializedAggregates() && (params.getFeatures() != null || params.getTags() != null)) { + if (Boolean.FALSE.equals(params.getRetainMaterializedAggregates()) + && (params.getFeatures() != null || params.getTags() != null)) { throw new ClientException( "retainMaterializedAggregates=false deletes every materialized aggregation of the primary keys " + "and cannot be combined with features or tags." @@ -291,7 +292,7 @@ public DeleteFeaturesResult deleteFeatures(DeleteFeaturesParams params) throws C params.getPrimaryKeys(), params.isRetainOffline(), params.isRetainOnline(), - params.isRetainMaterializedAggregates() + params.getRetainMaterializedAggregates() )) .method("DELETE") .environmentOverride(params.getEnvironmentId()) diff --git a/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java b/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java index e4385de..a0c649b 100644 --- a/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java +++ b/src/main/java/ai/chalk/internal/request/models/FeatureObservationDeletionRequest.java @@ -9,6 +9,6 @@ public record FeatureObservationDeletionRequest( List primaryKeys, boolean retainOffline, boolean retainOnline, - boolean retainMaterializedAggregates + Boolean retainMaterializedAggregates ) { } diff --git a/src/main/java/ai/chalk/models/DeleteFeaturesParams.java b/src/main/java/ai/chalk/models/DeleteFeaturesParams.java index b75ae5e..a7d26a5 100644 --- a/src/main/java/ai/chalk/models/DeleteFeaturesParams.java +++ b/src/main/java/ai/chalk/models/DeleteFeaturesParams.java @@ -54,10 +54,14 @@ public class DeleteFeaturesParams { * If true, the given observations will not be dropped from the online store. */ private final boolean retainOnline; - /** If false, also delete the keys' materialized aggregation buckets (not with features or tags). */ - private final boolean retainMaterializedAggregates; + /** + * If false, also delete the keys' materialized aggregation buckets (not with features or tags). + * Null leaves the default to the API server, which keeps the buckets. + */ + @Nullable + private final Boolean retainMaterializedAggregates; - /** Equivalent to the full constructor with {@code retainMaterializedAggregates = true}. */ + /** Equivalent to the full constructor with {@code retainMaterializedAggregates = null}. */ public DeleteFeaturesParams( String namespace, @Nullable List features, @@ -68,7 +72,7 @@ public DeleteFeaturesParams( boolean retainOffline, boolean retainOnline ) { - this(namespace, features, tags, primaryKeys, environmentId, branch, retainOffline, retainOnline, true); + this(namespace, features, tags, primaryKeys, environmentId, branch, retainOffline, retainOnline, null); } @AllArgsConstructor @@ -82,9 +86,9 @@ public static class Builder { protected String branch; protected boolean retainOffline = false; protected boolean retainOnline = false; - protected boolean retainMaterializedAggregates = true; + protected Boolean retainMaterializedAggregates = null; - /** Equivalent to the full constructor with {@code retainMaterializedAggregates = true}. */ + /** Equivalent to the full constructor with {@code retainMaterializedAggregates = null}. */ public Builder( String namespace, List features, @@ -95,7 +99,7 @@ public Builder( boolean retainOffline, boolean retainOnline ) { - this(namespace, features, tags, primaryKeys, environmentId, branch, retainOffline, retainOnline, true); + this(namespace, features, tags, primaryKeys, environmentId, branch, retainOffline, retainOnline, null); } public DeleteFeaturesParams build() { diff --git a/src/test/java/ai/chalk/client/TestDeleteFeatures.java b/src/test/java/ai/chalk/client/TestDeleteFeatures.java index 5bcd0d1..be277ca 100644 --- a/src/test/java/ai/chalk/client/TestDeleteFeatures.java +++ b/src/test/java/ai/chalk/client/TestDeleteFeatures.java @@ -68,7 +68,7 @@ public void testHttpDeleteFeatures() throws Exception { assertEquals( "{\"namespace\":\"user\",\"features\":[\"name\",\"email\"],\"tags\":null," + "\"primary_keys\":[\"1\",\"2\"],\"retain_offline\":false,\"retain_online\":false," - + "\"retain_materialized_aggregates\":true}", + + "\"retain_materialized_aggregates\":null}", body.get() ); assertEquals("Bearer test-token", authorization.get());