Conversation
…terBuilder and require their specific usage. datastax#75
…g higher than ms precision. Fixes datastax#63 and datastax#64. datastax#63 datastax#64
| /// <summary> | ||
| /// Attribute for defining the name to be given to a collection. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] |
There was a problem hiding this comment.
I'm adding this to the docs, but unlike GetTable which has an overload public Table<TRow> GetTable<TRow>() where TRow : class, new();, GetCollection always requires a collection name even if you pass it the document type with the CollectionName attribute.
There was a problem hiding this comment.
@skedwards88 Good call. I have added the additional overloads that allow GetCollection() or GetCollection<T,TId>()
There was a problem hiding this comment.
Can you double check this works? I get this when I try:
Unhandled exception. System.ArgumentNullException: collectionName (Parameter 'Value cannot be null or empty.')
at DataStax.AstraDB.DataApi.Utils.Guard.NotNullOrEmpty(String value, String paramName, String message) in /Users/sarah.edwards/repos/astra-db-csharp/src/DataStax.AstraDB.DataApi/Utils/Guard.cs:line 29
at DataStax.AstraDB.DataApi.Core.Database.GetCollection[T](String collectionName, DatabaseCollectionCommandOptions options) in /Users/sarah.edwards/repos/astra-db-csharp/src/DataStax.AstraDB.DataApi/Core/Database.cs:line 669
at DataStax.AstraDB.DataApi.Core.Database.GetCollection[T]() in /Users/sarah.edwards/repos/astra-db-csharp/src/DataStax.AstraDB.DataApi/Core/Database.cs:line 654
at Examples.Example.Main() in /Users/sarah.edwards/repos/astra-client-docs-tests/.docs_tests_temp/execution_environments/csharp/Example.cs:line 47
at Examples.Example.<Main>()
from running
using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Collections;
using DataStax.AstraDB.DataApi.Core;
using DataStax.AstraDB.DataApi.SerDes;
namespace Examples;
[CollectionName("**COLLECTION_NAME**")]
public class ExampleDocument
{
[DocumentId]
public Guid? Id { get; set; }
[DocumentMapping(DocumentMappingField.Vector)]
public float[]? VectorEmbeddings { get; set; }
[DocumentMapping(DocumentMappingField.Vectorize)]
public string? StringToVectorize { get; set; }
[DocumentMapping(DocumentMappingField.Lexical)]
[LexicalOptions(
TokenizerName = "standard",
Filters = new[] { "lowercase" }
)]
public string? StringForLexical { get; set; }
// [DocumentMapping(DocumentMappingField.Similarity)]
// public double Similarity { get; set; }
public string? Title { get; set; }
public int? NumberOfPages { get; set; }
public bool? IsCheckedOut { get; set; }
}
public class Program
{
static async Task Main()
{
// Get an existing collection
var client = new DataAPIClient();
var database = client.GetDatabase(
"**API_ENDPOINT**",
"**APPLICATION_TOKEN**"
);
var collection = database.GetCollection<ExampleDocument>();
// Insert documents
var insertionResult = await collection.InsertManyAsync(
[
new ExampleDocument()
{
VectorEmbeddings = [0.08f, -0.62f, 0.39f],
Title = "Ocean Depths",
NumberOfPages = 434,
IsCheckedOut = false,
},
new ExampleDocument()
{
StringToVectorize =
"A thrilling novel about the future of flight.",
Title = "Sky Limits",
NumberOfPages = 298,
},
new ExampleDocument()
{
Id = Guid.CreateVersion7(),
Title = "Open Plains",
IsCheckedOut = true,
},
]
);
// Find documents
var filterBuilder = Builders<ExampleDocument>.Filter;
var filter = filterBuilder.And(
filterBuilder.Eq(x => x.IsCheckedOut, false),
filterBuilder.Lt(x => x.NumberOfPages, 300)
);
var findResult = collection
.Find(filter)
.Project(
Builders<ExampleDocument>
.Projection.Include(x => x.Title)
.Include(x => x.IsCheckedOut)
);
await foreach (var document in findResult)
{
Console.WriteLine(
System.Text.Json.JsonSerializer.Serialize(document)
);
}
}
}There was a problem hiding this comment.
(but that error goes away if I call GetCollection with the collection name)
There was a problem hiding this comment.
@skedwards88 did you get that error running against this branch? Will make sure there's a working test for that overload.
There was a problem hiding this comment.
Yes, I verified just now that I am up to date and retested but get the same error
There was a problem hiding this comment.
@skedwards88 Found the missing piece and updated. Good catch!
| /// Create instances using <see cref="CollectionFilterBuilder{T}"/> via <c>Builders<T>.CollectionFilter</c>. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of the documents in the collection.</typeparam> | ||
| public class CollectionFilter<T> : Filter<T> |
There was a problem hiding this comment.
I don't know if this is intentional or not: I get a Argument 1: cannot convert from 'DataStax.AstraDB.DataApi.Core.Query.CollectionFilter<DataStax.AstraDB.DataApi.Tables.Row>' to 'DataStax.AstraDB.DataApi.Core.Query.TableFilter<DataStax.AstraDB.DataApi.Tables.Row>' error if I do Builders<Row>.Filter. Did you mean to make Filter fall back to CollectionFilter, or did you intend to force the user to specify CollectionFilter?
There was a problem hiding this comment.
@skedwards88 Fixed, Filter was intended to be removed.
| /// </code> | ||
| /// </example> | ||
| public IDatabaseAdmin CreateDatabase(DatabaseCreationOptions options, CommandOptions commandOptions, bool waitForDb = true) | ||
| public IDatabaseAdmin CreateDatabase(DatabaseCreationOptions options, CommandOptions commandOptions, bool waitForDb) |
There was a problem hiding this comment.
It looks like #90 also covers DropDatabase(Async), but I only see changes for CreateDatabase(Async)
There was a problem hiding this comment.
Fixed, and rearranged the params per #90.
There was a problem hiding this comment.
@a-random-steve it looks like you missed the overload for DropDatabaseAsync that doesn't require waitForDb (but you have it for DropDatabase)
There was a problem hiding this comment.
Updated...I think I have all the potentials covered now!
test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/ExamplesTests.cs
Outdated
Show resolved
Hide resolved
test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalTableTests.cs
Show resolved
Hide resolved
test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalTableTests.cs
Show resolved
Hide resolved
|
Wow, that's a lot of stuff indeed! I left some comments and suggestions on the code. A general point to address: when I run the IT locally (on HCD) I get two failures: Can you confirm? |
…terBuilder and require their specific usage. datastax#75
…g higher than ms precision. Fixes datastax#63 and datastax#64. datastax#63 datastax#64
774cd04 to
2d9c81a
Compare
…m/a-random-steve/astra-db-csharp into filter-builder-rework+minor-fixes # Conflicts: # src/DataStax.AstraDB.DataApi/Admin/AstraDatabasesAdmin.cs # src/DataStax.AstraDB.DataApi/Core/CommandOptions.cs # src/DataStax.AstraDB.DataApi/Core/Query/FilterBuilder.cs # src/DataStax.AstraDB.DataApi/SerDes/SimpleDictionaryConverter.cs # test/DataStax.AstraDB.DataApi.IntegrationTests/TestObjects.cs # test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalCollectionTests.cs # test/DataStax.AstraDB.DataApi.IntegrationTests/Tests/AdditionalTableTests.cs
…m/a-random-steve/astra-db-csharp into filter-builder-rework+minor-fixes
…add additional wait before dropkeyspace
… fix for timeuuid
(for perusal, will likely replace this PR once we merge in the others)
Fixes the following issues
[CollectionName]attribute? #76FilterModelStatusfor querying reranking/embedding providers? #77TableFilterBuilder,FilterBuilderandPrimaryKeyFilter? #75Nan,Infinityand-Infinitynot recognized when reading floats/doubles #65timeuuids should live in their own dedicatedTimeUuidclass #50