-
Notifications
You must be signed in to change notification settings - Fork 27
feat(export): Add client for /export endpoint #574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+829
−8
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a2f0079
feat(export): add client for /export endpoint
bevzzz 2f014c3
chore(export): fix Javadoc in Export.java
bevzzz 6e901ca
chore(config): deprecate async-replication parameters that aren't acc…
bevzzz 5061a1c
chore: replace 'backup' -> 'export' in docs
bevzzz 076f54c
feat(export): make fileFormat a required parameter
bevzzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package io.weaviate.integration; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.TimeoutException; | ||
|
|
||
| import org.assertj.core.api.Assertions; | ||
| import org.assertj.core.api.InstanceOfAssertFactories; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| import io.weaviate.ConcurrentTest; | ||
| import io.weaviate.client6.v1.api.WeaviateClient; | ||
| import io.weaviate.client6.v1.api.export.Export; | ||
| import io.weaviate.client6.v1.api.export.ExportStatus; | ||
| import io.weaviate.client6.v1.api.export.FileFormat; | ||
| import io.weaviate.client6.v1.api.export.ShardExportProgress; | ||
| import io.weaviate.containers.Weaviate; | ||
|
|
||
| public class ExportITest extends ConcurrentTest { | ||
| private static final WeaviateClient client = Weaviate.custom() | ||
| .withExportPath("/tmp/export").build() | ||
| .getClient(); | ||
|
|
||
| @BeforeClass | ||
| public static void __() { | ||
| Weaviate.Version.V137.orSkip(); | ||
| } | ||
|
|
||
| @Test | ||
| public void test_lifecycle() throws IOException, TimeoutException { | ||
| // Arrange | ||
| String nsA = ns("A"), nsB = ns("B"), nsC = ns("C"); | ||
| String exportId = ns("export_1").toLowerCase(); | ||
| String backend = "filesystem"; | ||
|
|
||
| var collectionA = client.collections.create(nsA); | ||
| var collectionB = client.collections.create(nsB); | ||
| var collectionC = client.collections.create(nsC); | ||
|
|
||
| // Insert some data | ||
| for (var c : List.of(collectionA, collectionB, collectionC)) { | ||
| var resp = c.data.insertMany(Map.of(), Map.of(), Map.of()); | ||
| Assertions.assertThat(resp.errors()).isEmpty(); | ||
| } | ||
|
|
||
| // Act: start export | ||
| var started = client.export.create(exportId, backend, FileFormat.PARQUET, | ||
| export -> export | ||
| .includeCollections(nsA, nsB)); | ||
|
|
||
| // Assert | ||
| Assertions.assertThat(started) | ||
| .as("created export operation") | ||
| .returns(exportId, Export::id) | ||
| .returns(backend, Export::backend) | ||
| .returns(ExportStatus.STARTED, Export::status) | ||
| .returns(null, Export::error) | ||
| .extracting(Export::includesCollections, InstanceOfAssertFactories.list(String.class)) | ||
| .containsOnly(nsA, nsB); | ||
|
|
||
| // Act: await export competion | ||
| var completed = started.waitForCompletion(client); | ||
|
|
||
| // Assert | ||
| Assertions.assertThat(completed) | ||
| .as("await export completion") | ||
| .returns(exportId, Export::id) | ||
| .returns(backend, Export::backend) | ||
| .returns(ExportStatus.SUCCESS, Export::status) | ||
| .returns(null, Export::error) | ||
| .extracting(Export::includesCollections, InstanceOfAssertFactories.list(String.class)) | ||
| .containsOnly(nsA, nsB); | ||
|
|
||
| Assertions.assertThat(completed) | ||
| .extracting(Export::shardStatus, InstanceOfAssertFactories.map(String.class, | ||
| Object.class)) | ||
| .allSatisfy((__, shards) -> { | ||
| Assertions.assertThat(shards) | ||
| .asInstanceOf(InstanceOfAssertFactories.map(String.class, ShardExportProgress.class)) | ||
| .isNotEmpty(); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/io/weaviate/client6/v1/api/export/CancelExportRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package io.weaviate.client6.v1.api.export; | ||
|
|
||
| import java.util.Collections; | ||
|
|
||
| import io.weaviate.client6.v1.internal.rest.Endpoint; | ||
| import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; | ||
|
|
||
| public record CancelExportRequest(String exportId, String backend) { | ||
|
|
||
| public static Endpoint<CancelExportRequest, Void> _ENDPOINT = SimpleEndpoint.sideEffect( | ||
| __ -> "DELETE", | ||
| request -> { | ||
| var cancel = (CancelExportRequest) request; | ||
| return "/export/" + cancel.backend + "/" + cancel.exportId; | ||
| }, | ||
| request -> Collections.emptyMap()) | ||
| .allowStatus(409); | ||
| } | ||
88 changes: 88 additions & 0 deletions
88
src/main/java/io/weaviate/client6/v1/api/export/CreateExportRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package io.weaviate.client6.v1.api.export; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.function.Function; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
|
|
||
| import io.weaviate.client6.v1.internal.ObjectBuilder; | ||
| import io.weaviate.client6.v1.internal.json.JSON; | ||
| import io.weaviate.client6.v1.internal.rest.Endpoint; | ||
| import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; | ||
|
|
||
| public record CreateExportRequest(ExportCreate config, String backend) { | ||
|
|
||
| public static Endpoint<CreateExportRequest, Export> _ENDPOINT = new SimpleEndpoint<>( | ||
| request -> "POST", | ||
| request -> "/export/" + request.backend, | ||
| request -> Collections.emptyMap(), | ||
| request -> JSON.serialize(request.config), | ||
| (statusCode, response) -> JSON.deserialize(response, Export.class)); | ||
|
|
||
| public static record ExportCreate( | ||
| @SerializedName("id") String id, | ||
| @SerializedName("file_format") FileFormat fileFormat, | ||
| @SerializedName("include") List<String> includeCollections, | ||
| @SerializedName("exclude") List<String> excludeCollections) { | ||
|
|
||
| public static ExportCreate of(String exportId, FileFormat fileFormat) { | ||
| return of(exportId, fileFormat, ObjectBuilder.identity()); | ||
| } | ||
|
|
||
| public static ExportCreate of(String exportId, FileFormat fileFormat, | ||
| Function<Builder, ObjectBuilder<ExportCreate>> fn) { | ||
| return fn.apply(new Builder(exportId, fileFormat)).build(); | ||
| } | ||
|
|
||
| public ExportCreate(Builder builder) { | ||
| this( | ||
| builder.exportId, | ||
| builder.fileFormat, | ||
| builder.includeCollections, | ||
| builder.excludeCollections); | ||
| } | ||
|
|
||
| public static class Builder implements ObjectBuilder<ExportCreate> { | ||
| private final String exportId; | ||
| private FileFormat fileFormat; | ||
|
|
||
| private final List<String> includeCollections = new ArrayList<>(); | ||
| private final List<String> excludeCollections = new ArrayList<>(); | ||
|
|
||
| public Builder(String exportId, FileFormat fileFormat) { | ||
| this.exportId = exportId; | ||
| this.fileFormat = fileFormat; | ||
| } | ||
|
|
||
| /** Collection that should be included in the export. */ | ||
| public Builder includeCollections(String... includeCollections) { | ||
| return includeCollections(Arrays.asList(includeCollections)); | ||
| } | ||
|
|
||
| /** Collection that should be included in the export. */ | ||
| public Builder includeCollections(List<String> includeCollections) { | ||
| this.includeCollections.addAll(includeCollections); | ||
| return this; | ||
| } | ||
|
|
||
| /** Collection that should be excluded from the export. */ | ||
| public Builder excludeCollections(String... excludeCollections) { | ||
| return excludeCollections(Arrays.asList(excludeCollections)); | ||
| } | ||
|
|
||
| /** Collection that should be excluded from the export. */ | ||
| public Builder excludeCollections(List<String> excludeCollections) { | ||
| this.excludeCollections.addAll(excludeCollections); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public ExportCreate build() { | ||
| return new ExportCreate(this); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.