Skip to content

Update 2.0 Branch #46

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
merged 72 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
242fa57
Update dependent job name
msmygit Nov 21, 2024
040d39f
Merge pull request #30 from datastax/2.0-beta
clun Nov 30, 2024
086aa17
Merge pull request #31 from datastax/2.0-beta
clun Nov 30, 2024
f0c9d0a
reducing to 1838474 warnings
clun Nov 30, 2024
de15941
less warnings
clun Nov 30, 2024
edda748
Add a getTable sample + options
clun Dec 2, 2024
521379a
javadoc
clun Dec 2, 2024
8889da7
Fixing Build
clun Dec 2, 2024
4da67b0
add sample
clun Dec 2, 2024
3ed6293
sample
clun Dec 2, 2024
43931f9
update list tables
clun Dec 3, 2024
4fbb79b
update list tables
clun Dec 3, 2024
163f010
Add Sample + simple syntax for creste index
clun Dec 3, 2024
395f50f
list indexes
clun Dec 3, 2024
b6206e6
Allow operations from the on other keyspace
clun Dec 3, 2024
b0a0eca
update examples
clun Dec 3, 2024
6bc862b
Fix #32: remove accidental debug System.out.println()
tatu-at-datastax Dec 3, 2024
ab80aec
update examples
clun Dec 4, 2024
3f8361e
Merge pull request #34 from tatu-at-datastax/main
clun Dec 4, 2024
98e9de3
update examples
clun Dec 4, 2024
e789bfa
update examples
clun Dec 4, 2024
e39a405
update examples
clun Dec 4, 2024
7e1039b
add samples
clun Dec 4, 2024
38d60ba
Mapping Row=> Bean and deserialization
clun Dec 5, 2024
2386880
Mapping Row=> Bean and deserialization
clun Dec 5, 2024
de5bf9a
double typing cursor and specialization
clun Dec 5, 2024
91ba89c
double typing cursor and specialization
clun Dec 5, 2024
0fa781c
double typing cursor and specialization
clun Dec 5, 2024
acaf500
double typing cursor and specialization
clun Dec 5, 2024
241b110
samples for updateOne
clun Dec 5, 2024
ce35c3c
samples for updateOne
clun Dec 5, 2024
143a3a4
update
clun Dec 6, 2024
6a1eef6
Samples for DataAPIVector
clun Dec 6, 2024
49557db
javadocs, javadoc, javadoc
clun Dec 7, 2024
b366490
javadocs, javadoc, javadoc
clun Dec 7, 2024
c08267d
javadocs, javadoc, javadoc...46 to go
clun Dec 7, 2024
05af2bc
javadocs, javadoc, javadoc...28 to go
clun Dec 8, 2024
97c8ce0
Fix all warnings, javadocs and compiling issue
clun Dec 9, 2024
a5dfb11
fixes
clun Dec 9, 2024
b6db3d5
[maven-release-plugin] prepare release 2.0.0-PREVIEW
clun Dec 9, 2024
9e4539c
[maven-release-plugin] prepare for next development iteration
clun Dec 9, 2024
eac62bc
[maven-release-plugin] rollback the release of 2.0.0-PREVIEW
clun Dec 9, 2024
8a52aca
removing samples and tools from the build
clun Dec 9, 2024
e0d900e
[maven-release-plugin] prepare release 2.0.0-PREVIEW
clun Dec 9, 2024
b433672
[maven-release-plugin] prepare for next development iteration
clun Dec 9, 2024
e2f3482
Split the controls to avoid NPE
clun Dec 9, 2024
02716eb
fixing #35 and aligning version
clun Dec 9, 2024
ecd471f
Remove Sort from deleteOne
clun Dec 10, 2024
15c5e86
Adding controls on serializations
clun Dec 10, 2024
78c7aea
update samples
clun Dec 10, 2024
5233a1c
Adjust the Java dist version to 17 by default
msmygit Jan 6, 2025
0cd195a
test
clun Jan 28, 2025
76fcffd
tmp update cursor and document dot notation
clun Jan 29, 2025
fb1791a
Changing collection to cursor, iprove distinct, fix getSortVector, ad…
clun Jan 30, 2025
762fb0c
remove secret
clun Jan 30, 2025
4dd9849
fix error on update
clun Jan 30, 2025
f606652
fix error on update
clun Jan 30, 2025
fda3b58
ok
clun Feb 11, 2025
52c3cef
update
clun Feb 11, 2025
6dd92a4
[maven-release-plugin] prepare release 2.0.0-PREVIEW1
clun Feb 11, 2025
46a7129
[maven-release-plugin] prepare for next development iteration
clun Feb 11, 2025
266b0a5
push the json loader to the repo
clun Mar 5, 2025
856867a
removing CRTP
clun Mar 7, 2025
d91d707
FindAndRerank
clun Mar 11, 2025
9548ffc
FindAndRerank
clun Mar 11, 2025
1daf15c
FindAndRerank
clun Mar 11, 2025
e32fb25
FindAndRerank
clun Mar 14, 2025
49d5c2e
FindAndRerank
clun Mar 14, 2025
cd00bbb
FindAndRerank
clun Mar 14, 2025
e2f2668
Update find and Rerank, start reworking the tests
clun Mar 27, 2025
c575a1f
test for BYOV
clun Mar 28, 2025
f6c8288
more test
clun Mar 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
double typing cursor and specialization
  • Loading branch information
clun committed Dec 5, 2024
commit acaf500340acb4d58f1d19e54ac8fdc1447e6a1d
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import com.datastax.astra.internal.utils.Assert;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.hc.core5.http.NotImplementedException;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -557,8 +558,6 @@ private Callable<TableInsertManyResult> getInsertManyResultCallable(List<? exten
// --- findOne ----
// --------------------------



public <R> Optional<R> findOne(Filter filter, TableFindOneOptions findOneOptions, Class<R> newRowClass) {
Command findOne = Command.create("findOne").withFilter(filter);
if (findOneOptions != null) {
Expand Down Expand Up @@ -731,41 +730,18 @@ public Page<T> findPage(Filter filter, TableFindOptions options) {
// --- distinct ----
// -------------------------

/**
* Gets the distinct values of the specified field name.
* The iteration is performed at CLIENT-SIDE and will exhaust all the table elements.
*
* @param fieldName
* the field name
* @param resultClass
* the class to cast any distinct items into.
* @param <F>
* the target type of the iterable.
* @return
* an iterable of distinct values
/*

Cursor could take a boolean in the constructor to mark the distinct

public <F> CollectionDistinctIterable<T, F> distinct(String fieldName, Class<F> resultClass) {
return distinct(fieldName, null, resultClass);
public <R> TableCursor<T, R> distinct(String fieldName, TableFindOptions options, Class<R> resultClass) {
throw new UnsupportedOperationException("distinct is not implemented yet");
}

/**
* Gets the distinct values of the specified field name.
*
* @param fieldName
* the field name
* @param filter
* the query filter
* @param resultClass
* the class to cast any distinct items into.
* @param <F>
* the target type of the iterable.
* @return
* an iterable of distinct values
public TableCursor<T, T> distinct(String fieldName, TableFindOptions options) {
return distinct(fieldName, null, getRowClass());
}*/

public <F> CollectionDistinctIterable<T, F> distinct(String fieldName, Filter filter, Class<F> resultClass) {
return new CollectionDistinctIterable<>(this, fieldName, filter, resultClass);
}
*/
// -------------------------
// --- updateOne ----
// -------------------------
Expand All @@ -777,11 +753,9 @@ public <F> CollectionDistinctIterable<T, F> distinct(String fieldName, Filter fi
* a row describing the query filter, which may not be null.
* @param update
* a row describing the update, which may not be null. The update to apply must include at least one update operator.
* @return
* the result of the update one operation
*/
public TableUpdateResult updateOne(Filter filter, TableUpdateOperation update) {
return updateOne(filter, update, new TableUpdateOneOptions());
public void updateOne(Filter filter, TableUpdateOperation update) {
updateOne(filter, update, new TableUpdateOneOptions());
}

/**
Expand All @@ -793,46 +767,15 @@ public TableUpdateResult updateOne(Filter filter, TableUpdateOperation update) {
* a document describing the update, which may not be null. The update to apply must include at least one update operator.
* @param updateOptions
* the options to apply to the update operation
* @return
* the result of the update one operation
*/
public TableUpdateResult updateOne(Filter filter, TableUpdateOperation update, TableUpdateOneOptions updateOptions) {
public void updateOne(Filter filter, TableUpdateOperation update, TableUpdateOneOptions updateOptions) {
notNull(update, ARG_UPDATE);
notNull(updateOptions, ARG_OPTIONS);
Command cmd = Command
.create("updateOne")
.withFilter(filter)
.withUpdate(update)
.withSort(updateOptions.getSortArray())
.withOptions(new Document()
.appendIfNotNull(INPUT_UPSERT, updateOptions.upsert())
);
return getUpdateResult(runCommand(cmd, updateOptions));
}

/**
* Update all documents in the collection according to the specified arguments.
*
* @param apiResponse
* response for the API
* @return
* the result of the update many operation
*/
private static TableUpdateResult getUpdateResult(DataAPIResponse apiResponse) {
TableUpdateResult result = new TableUpdateResult();
DataAPIStatus status = apiResponse.getStatus();
if (status != null) {
if (status.containsKey(RESULT_MATCHED_COUNT)) {
result.setMatchedCount(status.getInteger(RESULT_MATCHED_COUNT));
}
if (status.containsKey(RESULT_MODIFIED_COUNT)) {
result.setModifiedCount(status.getInteger(RESULT_MODIFIED_COUNT));
}
if (status.containsKey(RESULT_UPSERTED_ID)) {
result.setMatchedCount(status.getInteger(RESULT_UPSERTED_ID));
}
}
return result;
.withUpdate(update);
runCommand(cmd, updateOptions);
}

// -------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,24 @@ public TableUpdateOperation(Map<String, Object> obj) {
this.columnMap.putAll(obj);
}

/**
* Allow to creat a new instance.
*
* @return
* a new instance
*/
public static TableUpdateOperation create() {
return new TableUpdateOperation();
}

/**
* Builder pattern
*
* @param fieldName
* field name
* @param fields
* fields name
* @return
* reference to self
*/
public TableUpdateOperation unset(String fieldName) {
return update("$unset", fieldName, "");
public TableUpdateOperation unset(String... fields) {
if (fields != null) {
for (String field : fields) {
update("$unset", field, "");
}
}
return this;
}
public TableUpdateOperation unset(String field, Object value) {
return update("$unset", field, value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,12 @@

*/
@Getter @Setter
@NoArgsConstructor
@Accessors(fluent = true, chain = true)
public class TableUpdateOneOptions extends BaseOptions<TableUpdateOneOptions> {

/**
* if upsert is selected
* Default constructor.
*/
private Boolean upsert;

/**
* Order by.
*/
private Sort[] sort;

/**
* Adding this on top of sort(Sort[] s) to allow for a more fluent API.
* @param s
* sort options
* @return
* current command
*/
public TableUpdateOneOptions sort(Sort... s) {
this.sort = s;
return this;
}

/**
* Get the sort options.
*
* @return
* sort options
*/
public Sort[] getSortArray() {
return sort;
public TableUpdateOneOptions() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ public void should_updateOne() {
assertThat(table.findOne(johnFilter)).isPresent();

// Update the document
TableUpdateResult birthday = table.updateOne(johnFilter, TableUpdateOperation.create()
TableUpdateResult birthday = table.updateOne(johnFilter, new TableUpdateOperation()
.set("age", 43));
//.updateMul(Map.of("price", 1.1d)));
Assertions.assertThat(birthday.getMatchedCount()).isEqualTo(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.datastax.astra.client.tables;

import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.collections.commands.Update;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Projection;
import com.datastax.astra.client.core.query.Sort;
import com.datastax.astra.client.core.vector.DataAPIVector;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.commands.TableUpdateOperation;
import com.datastax.astra.client.tables.commands.options.TableFindOneOptions;
import com.datastax.astra.client.tables.commands.options.TableUpdateOneOptions;
import com.datastax.astra.client.tables.commands.results.TableUpdateResult;
import com.datastax.astra.client.tables.definition.rows.Row;
import com.datastax.astra.client.tables.mapping.Column;
import lombok.Data;

import java.util.Optional;
import java.util.Set;

import static com.datastax.astra.client.core.query.Filters.and;
import static com.datastax.astra.client.core.query.Filters.eq;
import static com.datastax.astra.client.core.query.Filters.gt;

public class UpdateOne {
public static void main(String[] args) {
Database db = DataAPIClients.localDbWithDefaultKeyspace();
// Database astraDb = new DataAPIClient(token).getDatabase(endpoint);

Table<Row> tableRow = db.getTable("games");

// Update
Filter filter = and(
eq("match_id", "fight4"),
eq("round", 1));
new TableUpdateOneOptions()
.timeout(1000);
tableRow.updateOne(filter, new TableUpdateOperation()
.set("winner", "Winona"));

// Unset 2 columns
tableRow.updateOne(filter, new TableUpdateOperation()
.set("winner", "Winona"));

// Set a new value for a column
tableRow.updateOne(and(
eq("match_id", "fight4"),
eq("round", 1)),
new TableUpdateOperation().set("winner", "Winona"));

// Set a new value for a column while unsetting another colum
tableRow.updateOne(and(
eq("match_id", "fight4"),
eq("round", 1)),
new TableUpdateOperation()
.set("score", 24)
.unset("winner")
.unset("fighters", Set.of()));
}

}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy