Skip to content

Commit 3b398de

Browse files
committed
update with HDC
1 parent e92113d commit 3b398de

30 files changed

+2168
-399
lines changed

README.MD

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ This client library provides a simplified way to interact with Data API for Astr
2424
This library is under development and is available in Maven Central.
2525
You can build it locally and install it in your local repository.
2626

27+
## 📋 Table Of Content
28+
29+
1. Installation
30+
1. Prerequisites
31+
2. Packaging
32+
2. QuickStart with Astra DB
33+
1. Sign up for Astra DB
34+
2. Create a Database
35+
3. Get your credentials
36+
4. Create a new project and add the dependency
37+
3. QuickStart with DSE
38+
1. Start Data Api.
39+
2. Connection to DSE
40+
3. Create a namespace
41+
4. Create a collection
42+
4. QuickStart with HCD
43+
1. Start Data Api.
44+
2. Connection to HCD
45+
3. Create a namespace
46+
4. Create a collection
47+
2748
## 1. Installation
2849

2950
### 1.1 Prerequisites

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090

9191
import static com.datastax.astra.client.exception.DataApiException.ERROR_CODE_INTERRUPTED;
9292
import static com.datastax.astra.client.exception.DataApiException.ERROR_CODE_TIMEOUT;
93+
import static com.datastax.astra.client.model.DataAPIKeywords.SORT_VECTOR;
9394
import static com.datastax.astra.internal.utils.AnsiUtils.cyan;
9495
import static com.datastax.astra.internal.utils.AnsiUtils.green;
9596
import static com.datastax.astra.internal.utils.AnsiUtils.magenta;
@@ -174,6 +175,8 @@ public class Collection<T> extends AbstractCommandRunner {
174175
/** json inputs */
175176
public static final String INPUT_INCLUDE_SIMILARITY = "includeSimilarity";
176177
/** json inputs */
178+
public static final String INPUT_INCLUDE_SORT_VECTOR = "includeSortVector";
179+
/** json inputs */
177180
private static final String INPUT_UPSERT = "upsert";
178181
/** json inputs */
179182
private static final String INPUT_RETURN_DOCUMENT = "returnDocument";
@@ -1216,7 +1219,10 @@ public Optional<T> findOne(Filter filter, FindOneOptions findOneOptions) {
12161219
.withFilter(filter)
12171220
.withSort(findOneOptions.getSort())
12181221
.withProjection(findOneOptions.getProjection())
1219-
.withOptions(new Document().appendIfNotNull(INPUT_INCLUDE_SIMILARITY, findOneOptions.getIncludeSimilarity()));
1222+
.withOptions(new Document()
1223+
.appendIfNotNull(INPUT_INCLUDE_SIMILARITY, findOneOptions.getIncludeSimilarity())
1224+
.appendIfNotNull(INPUT_INCLUDE_SORT_VECTOR, findOneOptions.getIncludeSortVector())
1225+
);
12201226

12211227
return Optional.ofNullable(
12221228
runCommand(findOne, findOneOptions)
@@ -1452,14 +1458,24 @@ public Page<T> findPage(Filter filter, FindOptions options) {
14521458
.appendIfNotNull("skip", options.getSkip())
14531459
.appendIfNotNull("limit", options.getLimit())
14541460
.appendIfNotNull(INPUT_PAGE_STATE, options.getPageState())
1461+
.appendIfNotNull(INPUT_INCLUDE_SORT_VECTOR, options.getIncludeSortVector())
14551462
.appendIfNotNull(INPUT_INCLUDE_SIMILARITY, options.getIncludeSimilarity()));
14561463
ApiResponse apiResponse = runCommand(findCommand, options);
1464+
1465+
// load sortVector if available
1466+
float[] sortVector = null;
1467+
if (options.getIncludeSortVector() &&
1468+
apiResponse.getStatus() != null &&
1469+
apiResponse.getStatus().get(SORT_VECTOR.getKeyword()) != null) {
1470+
sortVector = apiResponse.getStatus().get(SORT_VECTOR.getKeyword(), float[].class);
1471+
}
1472+
14571473
return new Page<>(
14581474
apiResponse.getData().getNextPageState(),
14591475
apiResponse.getData().getDocuments()
14601476
.stream()
14611477
.map(d -> d.map(getDocumentClass()))
1462-
.collect(Collectors.toList()));
1478+
.collect(Collectors.toList()), sortVector);
14631479
}
14641480

14651481
/**
@@ -1703,7 +1719,6 @@ public DeleteResult deleteOne(Filter filter, DeleteOneOptions deleteOneOptions)
17031719
* the result of the remove many operation
17041720
*/
17051721
public DeleteResult deleteMany(Filter filter, DeleteManyOptions options) {
1706-
Assert.notNull(filter, ARG_FILTER);
17071722
AtomicInteger totalCount = new AtomicInteger(0);
17081723
boolean moreData = false;
17091724
do {
@@ -2153,6 +2168,7 @@ public Optional<T> findOneAndDelete(Filter filter, FindOneAndDeleteOptions optio
21532168
* @return
21542169
* the result of the bulk write
21552170
*/
2171+
@Deprecated(since = "1.3.0", forRemoval = true)
21562172
public BulkWriteResult bulkWrite(List<Command> commands) {
21572173
return bulkWrite(commands, new BulkWriteOptions());
21582174
}
@@ -2167,6 +2183,7 @@ public BulkWriteResult bulkWrite(List<Command> commands) {
21672183
* @return
21682184
* the result of the bulk write
21692185
*/
2186+
@Deprecated(since = "1.3.0", forRemoval = true)
21702187
public BulkWriteResult bulkWrite(List<Command> commands, BulkWriteOptions options) {
21712188
notNull(commands, ARG_COMMANDS);
21722189
notNull(options, ARG_OPTIONS);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222

2323
import com.datastax.astra.client.admin.DataAPIDatabaseAdmin;
24-
import com.datastax.astra.internal.auth.TokenProviderStargateV2;
24+
import com.datastax.astra.internal.auth.UsernamePasswordTokenProvider;
2525
import com.datastax.astra.internal.command.LoggingCommandObserver;
2626

2727
import static com.datastax.astra.client.admin.AstraDBAdmin.DEFAULT_NAMESPACE;
@@ -75,7 +75,7 @@ private DataAPIClients() {}
7575
*/
7676
public static DataAPIClient createForLocal() {
7777
return new DataAPIClient(
78-
new TokenProviderStargateV2().getToken(),
78+
new UsernamePasswordTokenProvider().getToken(),
7979
DataAPIOptions.builder()
8080
.withDestination(DataAPIOptions.DataAPIDestination.CASSANDRA)
8181
.withObserver(new LoggingCommandObserver(DataAPIClient.class))

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ public enum DataAPIDestination {
155155
*/
156156
DSE,
157157

158+
/**
159+
* Hyper Converged Database
160+
*/
161+
HCD,
162+
158163
/**
159164
* Local installation of Apache Cassandra
160165
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public interface DatabaseAdmin {
9696
* }
9797
* </pre>
9898
* @return
99+
* list of available providers
99100
*/
100101
Map<String, EmbeddingProvider> listEmbeddingProviders();
101102

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public enum DataAPIKeywords {
9494
*/
9595
VECTOR("$vector"),
9696

97+
/**
98+
* SORT VECTOR.
99+
*/
100+
SORT_VECTOR("sortVector"),
101+
97102
/**
98103
* VECTORIZE.
99104
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.util.ArrayList;
2929
import java.util.List;
30+
import java.util.Optional;
3031

3132
/**
3233
* Represents the result of a 'find' command executed on a collection, providing an iterable interface to navigate
@@ -89,11 +90,10 @@ public FindIterator<T> iterator() {
8990
* all values of the iterable
9091
*/
9192
public List<T> all() {
92-
if (exhausted) throw new IllegalStateException("Iterable is already exhauted.");
93+
if (exhausted) throw new IllegalStateException("Iterable is already exhausted.");
9394
if (active) throw new IllegalStateException("Iterable has already been started");
9495
List<T> results = new ArrayList<>();
9596
for (T t : this) results.add(t);
9697
return results;
9798
}
98-
9999
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ public T next() {
104104
* @since 4.4
105105
*/
106106
public int available() {
107-
return 0;
107+
return availableWithoutFetch;
108108
}
109109
}

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

Lines changed: 43 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public FindOneAndDeleteOptions() {
5050
// left blank as sort is populated in static way
5151
}
5252

53+
// ----------------
54+
// ---- Sort ------
55+
// ----------------
56+
5357
/**
5458
* Syntax sugar as delete option is only a sort
5559
*
@@ -59,24 +63,51 @@ public FindOneAndDeleteOptions() {
5963
* current command.
6064
*/
6165
public FindOneAndDeleteOptions sort(Sort... sort) {
62-
setSort(OptionsUtils.sort(sort));
66+
return sort(OptionsUtils.sort(sort));
67+
}
68+
69+
/**
70+
* Syntax sugar as delete option is only a sort
71+
* Could be like Map.of("$vectorize", "command, "field1", 1, "field2", -1);
72+
*
73+
* @param rawSort
74+
* raw sort clause
75+
* @return
76+
* current command.
77+
*/
78+
public FindOneAndDeleteOptions sort(Map<String, Object> rawSort) {
79+
Document doc = new Document();
80+
doc.putAll(rawSort);
81+
return sort(doc);
82+
}
83+
84+
/**
85+
* Syntax sugar as delete option is only a sort
86+
* Could be like Map.of("$vectorize", "command, "field1", 1, "field2", -1);
87+
*
88+
* @param sorClause
89+
* sort clause as a document
90+
* @return
91+
* current command.
92+
*/
93+
public FindOneAndDeleteOptions sort(Document sorClause) {
94+
setSort(sorClause);
6395
return this;
6496
}
6597

6698
/**
6799
* Add a criteria with $vectorize in the sort clause.
68-
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
69100
*
70101
* @param vectorize an expression to look for vectorization
71102
* @param sorts The sort criteria to be applied to the findOne operation.
72103
* @return current command
73104
*/
74105
public FindOneAndDeleteOptions sort(String vectorize, Sort ... sorts) {
75-
setSort(Sorts.vectorize(vectorize));
106+
Document doc = Sorts.vectorize(vectorize);
76107
if (sorts != null) {
77-
getSort().putAll(OptionsUtils.sort(sorts));
108+
doc.putAll(OptionsUtils.sort(sorts));
78109
}
79-
return this;
110+
return sort(doc);
80111
}
81112

82113
/**
@@ -87,13 +118,17 @@ public FindOneAndDeleteOptions sort(String vectorize, Sort ... sorts) {
87118
* @return current command
88119
*/
89120
public FindOneAndDeleteOptions sort(float[] vector, Sort... sorts) {
90-
setSort(Sorts.vector(vector));
121+
Document doc = Sorts.vector(vector);
91122
if (sorts != null) {
92-
getSort().putAll(OptionsUtils.sort(sorts));
123+
doc.putAll(OptionsUtils.sort(sorts));
93124
}
94-
return this;
125+
return sort(doc);
95126
}
96127

128+
// ----------------------
129+
// ---- Projection ------
130+
// ----------------------
131+
97132
/**
98133
* Syntax sugar as delete option is only a sort
99134
*
@@ -107,59 +142,6 @@ public FindOneAndDeleteOptions projection(Projection... projection) {
107142
return this;
108143
}
109144

110-
/**
111-
* Builder for creating {@link FindOneAndDeleteOptions} instances with a fluent API.
112-
*/
113-
public static class Builder {
114-
115-
/**
116-
* Hide constructor.
117-
*/
118-
private Builder() {
119-
}
120-
121-
/**
122-
* Initializes the building process with sorting options.
123-
*
124-
* @param sort The sort criteria to be applied to the delete operation.
125-
* @return A new {@link FindOneAndDeleteOptions} instance configured with the provided sort criteria.
126-
*/
127-
public static FindOneAndDeleteOptions sort(Sort... sort) {
128-
return new FindOneAndDeleteOptions().sort(sort);
129-
}
130-
131-
/**
132-
* Initializes the building process with projection options.
133-
*
134-
* @param projection The projection criteria to be applied to the delete operation.
135-
* @return A new {@link FindOneAndDeleteOptions} instance configured with the provided projection criteria.
136-
*/
137-
public static FindOneAndDeleteOptions projection(Projection... projection) {
138-
return new FindOneAndDeleteOptions().projection(projection);
139-
}
140-
141-
/**
142-
* Initializes the building process with vectorize options.
143-
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
144-
*
145-
* @param vectorize The vectorize criteria to be applied to the findOne operation
146-
* @param sorts The sort criteria to be applied to the findOne operation.
147-
* @return A new {@link FindOneAndDeleteOptions} instance configured with the provided vectorize criteria.
148-
*/
149-
public static FindOneAndDeleteOptions sort(String vectorize, Sort... sorts) {
150-
return new FindOneAndDeleteOptions().sort(vectorize, sorts);
151-
}
152145

153-
/**
154-
* Initializes the building process with vector options.
155-
*
156-
* @param vector The vector criteria to be applied to the findOne operation
157-
* @param sorts The sort criteria to be applied to the findOne operation.
158-
* @return A new {@link FindOneAndDeleteOptions} instance configured with the provided vector criteria.
159-
*/
160-
public static FindOneAndDeleteOptions sort(float[] vector, Sort... sorts) {
161-
return new FindOneAndDeleteOptions().sort(vector, sorts);
162-
}
163-
}
164146

165147
}

0 commit comments

Comments
 (0)