Skip to content

Commit 06202a2

Browse files
committed
Add a CSV loader
1 parent aaff8b6 commit 06202a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+962
-546
lines changed

astra-db-java/src/main/java/com/datastax/astra/client/Collection.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,10 +1240,8 @@ public Page<T> findPage(Filter filter, FindOptions options) {
12401240
.appendIfNotNull("limit", options.getLimit())
12411241
.appendIfNotNull(INPUT_PAGE_STATE, options.getPageState())
12421242
.appendIfNotNull(INPUT_INCLUDE_SIMILARITY, options.getIncludeSimilarity()));
1243-
12441243
ApiResponse apiResponse = runCommand(findCommand);
1245-
1246-
return new Page<>(DataAPIOptions.getMaxPageSize(),
1244+
return new Page<>(
12471245
apiResponse.getData().getNextPageState(),
12481246
apiResponse.getData().getDocuments()
12491247
.stream()
@@ -1806,6 +1804,18 @@ public Optional<T> findOneAndDelete(Filter filter) {
18061804
return findOneAndDelete(filter, new FindOneAndDeleteOptions());
18071805
}
18081806

1807+
/**
1808+
* Delete and return a document asynchronous.
1809+
*
1810+
* @param filter
1811+
* filter to delete
1812+
* @return
1813+
* the document that was removed. If no documents matched the query filter, then null will be returned
1814+
*/
1815+
public CompletableFuture<Optional<T>> findOneAndDeleteAsync(Filter filter) {
1816+
return CompletableFuture.supplyAsync(() -> findOneAndDelete(filter));
1817+
}
1818+
18091819
/**
18101820
* Atomically find a document and remove it.
18111821
*

astra-db-java/src/main/java/com/datastax/astra/client/DataAPIOptions.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
* limitations under the License.
2020
* #L%
2121
*/
22+
2223
import com.datastax.astra.internal.utils.Assert;
23-
import lombok.AllArgsConstructor;
24-
import lombok.Data;
2524
import lombok.Getter;
25+
import lombok.Setter;
2626

2727
import java.net.http.HttpClient;
2828

@@ -143,7 +143,7 @@ public enum DataAPIDestination {
143143
/**
144144
* Options to set up http Client.
145145
*/
146-
@Data
146+
@Getter @Setter
147147
public static class HttpClientOptions {
148148

149149
/** Default user agent. */
@@ -201,7 +201,7 @@ public HttpClientOptions() {
201201
/**
202202
* Subclass to represent an http proxy.
203203
*/
204-
@Data
204+
@Getter @Setter
205205
public static class HttpProxy {
206206

207207
/** hostname of the proxy. */
@@ -255,7 +255,7 @@ public static class DataAPIClientOptionsBuilder {
255255
private HttpProxy httpProxy;
256256

257257
/** Moving to HTTP/2. */
258-
private HttpClient.Version httpVersion = HttpClient.Version.HTTP_2;
258+
private HttpClient.Version httpVersion = HttpClient.Version.HTTP_1_1;
259259

260260
/** Redirect */
261261
private HttpClient.Redirect httpRedirect = HttpClient.Redirect.NORMAL;

astra-db-java/src/main/java/com/datastax/astra/client/admin/AstraDBAdmin.java

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* limitations under the License.
2020
* #L%
2121
*/
22+
2223
import com.datastax.astra.client.DataAPIOptions;
2324
import com.datastax.astra.client.model.DatabaseInfo;
2425
import com.datastax.astra.internal.api.AstraApiEndpoint;
@@ -30,17 +31,12 @@
3031
import com.dtsx.astra.sdk.db.domain.DatabaseCreationRequest;
3132
import com.dtsx.astra.sdk.db.domain.DatabaseStatusType;
3233
import com.dtsx.astra.sdk.db.exception.DatabaseNotFoundException;
33-
import com.dtsx.astra.sdk.utils.ApiLocator;
3434
import com.dtsx.astra.sdk.utils.AstraEnvironment;
3535
import com.dtsx.astra.sdk.utils.AstraRc;
3636
import lombok.NonNull;
3737
import lombok.extern.slf4j.Slf4j;
3838

39-
import java.net.URI;
4039
import java.net.http.HttpClient;
41-
import java.net.http.HttpRequest;
42-
import java.net.http.HttpResponse;
43-
import java.net.http.HttpResponse.BodyHandlers;
4440
import java.time.Duration;
4541
import java.util.List;
4642
import java.util.Optional;
@@ -226,20 +222,9 @@ public DatabaseAdmin createDatabase(String name, CloudProviderType cloud, String
226222
case INITIALIZING:
227223
case PENDING:
228224
case RESUMING:
229-
log.info("Database {} already exists and is in {} state, waiting for it to be ACTIVE", name, db.getStatus());
230-
if (waitForDb) {
231-
waitForDatabase(devopsDbClient.database(db.getId()));
232-
}
233-
return getDatabaseAdmin(UUID.fromString(db.getId()));
234225
case HIBERNATED:
235-
log.info("Database {} is in {} state, resuming...", name, db.getStatus());
236-
resumeDb(db);
237-
if (waitForDb) {
238-
waitForDatabase(devopsDbClient.database(db.getId()));
239-
}
240-
return getDatabaseAdmin(UUID.fromString(db.getId()));
241226
default:
242-
throw new IllegalStateException("Database already exist but cannot be activate");
227+
throw new IllegalStateException("Database already exists but is not in expected state.");
243228
}
244229
}
245230
// Database is not present, creating and waiting for it to be active.
@@ -410,33 +395,4 @@ private DatabaseStatusType getStatus(DbOpsClient dbc) {
410395
return dbc.find().orElseThrow(() -> new DatabaseNotFoundException(dbc.getDatabaseId())).getStatus();
411396
}
412397

413-
/**
414-
* Database name.
415-
*
416-
* @param db
417-
* database name
418-
*/
419-
private void resumeDb(Database db) {
420-
try {
421-
// Compute Endpoint for the Keyspace
422-
String endpoint = ApiLocator.getApiRestEndpoint(db.getId(), db.getInfo().getRegion()) + "/v2/schemas/keyspace";
423-
HttpRequest request = HttpRequest.newBuilder()
424-
.uri(URI.create(endpoint))
425-
.timeout(Duration.ofSeconds(20))
426-
.header("Content-Type", "application/json")
427-
.header(TOKEN_HEADER_PARAM, token)
428-
.GET()
429-
.build();
430-
HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());
431-
if (response.statusCode() == 500) {
432-
throw new IllegalStateException("Cannot resume database, please check your account");
433-
}
434-
} catch (InterruptedException e) {
435-
log.warn("Interrupted {}",e.getMessage());
436-
Thread.currentThread().interrupt();
437-
} catch (Exception e) {
438-
log.warn("Resuming request might have failed, please check {}}",e.getMessage());
439-
}
440-
}
441-
442398
}

astra-db-java/src/main/java/com/datastax/astra/client/admin/AstraDBDatabaseAdmin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public void createNamespace(String namespace) {
144144
/** {@inheritDoc} */
145145
@Override
146146
public void dropNamespace(String namespace) {
147-
devopsDbClient.database(databaseId.toString()).keyspaces().delete(namespace);
147+
try {
148+
devopsDbClient.database(databaseId.toString()).keyspaces().delete(namespace);
149+
} catch(NullPointerException e) {
150+
// Left blank to parse output from a delete
151+
}
148152
}
149153
}

astra-db-java/src/main/java/com/datastax/astra/client/model/BulkWriteOptions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
*/
2222

2323
import lombok.Getter;
24-
import lombok.Setter;
2524

2625
/**
2726
*
2827
* Options used in the `bulkWrite` command.
2928
*/
30-
@Getter @Setter
29+
@Getter
3130
public final class BulkWriteOptions {
3231

3332
/**

astra-db-java/src/main/java/com/datastax/astra/client/model/BulkWriteResult.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222

2323
import com.datastax.astra.internal.api.ApiResponse;
24-
import lombok.Data;
2524
import lombok.Getter;
2625
import lombok.Setter;
2726

astra-db-java/src/main/java/com/datastax/astra/client/model/CollectionOptions.java

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

2323
import com.fasterxml.jackson.annotation.JsonIgnore;
2424
import com.fasterxml.jackson.annotation.JsonProperty;
25-
import lombok.Data;
2625
import lombok.Getter;
2726
import lombok.NonNull;
2827
import lombok.Setter;
@@ -63,7 +62,7 @@ public CollectionOptions() {
6362
/**
6463
* Subclass representing the indexing options.
6564
*/
66-
@Data
65+
@Getter @Setter
6766
public static class DefaultIdOptions {
6867

6968
/** Type for the default id. */
@@ -90,7 +89,7 @@ public DefaultIdOptions(String type) {
9089
/**
9190
* Subclass representing the indexing options.
9291
*/
93-
@Data
92+
@Getter @Setter
9493
public static class IndexingOptions {
9594

9695
/**
@@ -114,7 +113,7 @@ public IndexingOptions() {
114113
/**
115114
* Subclass representing the vector options.
116115
*/
117-
@Data
116+
@Getter @Setter
118117
public static class VectorOptions {
119118

120119
/**
@@ -152,7 +151,7 @@ public SimilarityMetric getSimilarityMetric() {
152151
/**
153152
* Subclass representing the services options.
154153
*/
155-
@Data
154+
@Getter @Setter
156155
public static class Service {
157156

158157
/** LLM provider. */
@@ -177,7 +176,7 @@ public Service() {
177176
/**
178177
* Subclass representing the Authentication options.
179178
*/
180-
@Data
179+
@Getter @Setter
181180
public static class Authentication {
182181

183182
/** Type of authentication: Oauth, API Key, etc. */
@@ -195,7 +194,7 @@ public Authentication() {
195194
/**
196195
* Subclass representing a parameters for LLM Services
197196
*/
198-
@Data
197+
@Getter @Setter
199198
public static class Parameters {
200199

201200
/** Type for the parameters. */

astra-db-java/src/main/java/com/datastax/astra/client/model/Command.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public class Command implements Serializable {
4747
/** Command payload.*/
4848
protected Document payload = new Document();
4949

50+
/**
51+
* Default constructor.
52+
*/
53+
public Command() {
54+
// left blank and initialize with Jackson
55+
}
56+
5057
/**
5158
* Create an empty command from its name.
5259
*
@@ -59,11 +66,6 @@ public static Command create(String name) {
5966
return new Command(name);
6067
}
6168

62-
/**
63-
* Default constructor.
64-
*/
65-
public Command() {}
66-
6769
/**
6870
* Constructor with a name.
6971
*

astra-db-java/src/main/java/com/datastax/astra/client/model/DeleteResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
/**
2727
* Hold the result of delete commands (deleteOne, deleteMany).
2828
*/
29-
@Getter @Setter
29+
@Getter
3030
public class DeleteResult {
3131

3232
/**
3333
* NUmber of documents deleted.
3434
*/
35-
int deletedCount;
35+
private final int deletedCount;
3636

3737
/**
3838
* Default constructor.

0 commit comments

Comments
 (0)