Skip to content

Issue cleanup round #1#99

Open
a-random-steve wants to merge 41 commits intodatastax:mainfrom
a-random-steve:filter-builder-rework+minor-fixes
Open

Issue cleanup round #1#99
a-random-steve wants to merge 41 commits intodatastax:mainfrom
a-random-steve:filter-builder-rework+minor-fixes

Conversation

/// <summary>
/// Attribute for defining the name to be given to a collection.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skedwards88 Good call. I have added the additional overloads that allow GetCollection() or GetCollection<T,TId>()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
      );
    }
  }
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(but that error goes away if I call GetCollection with the collection name)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skedwards88 did you get that error running against this branch? Will make sure there's a working test for that overload.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I verified just now that I am up to date and retested but get the same error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skedwards88 Found the missing piece and updated. Good catch!

/// Create instances using <see cref="CollectionFilterBuilder{T}"/> via <c>Builders&lt;T&gt;.CollectionFilter</c>.
/// </summary>
/// <typeparam name="T">The type of the documents in the collection.</typeparam>
public class CollectionFilter<T> : Filter<T>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like #90 also covers DropDatabase(Async), but I only see changes for CreateDatabase(Async)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, and rearranged the params per #90.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a-random-steve it looks like you missed the overload for DropDatabaseAsync that doesn't require waitForDb (but you have it for DropDatabase)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated...I think I have all the potentials covered now!

@sl-at-ibm
Copy link
Collaborator

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:

[xUnit.net 00:00:13.40]     DataStax.AstraDB.DataApi.IntegrationTests.UserDefinedTypesTests.UserDefinedTypes_CreateFromClasses [FAIL]
  Error Message:
   System.Text.Json.JsonException : The JSON value could not be converted to System.TimeOnly. Path: $.Time | LineNumber: 0 | BytePositionInLine: 116.

[xUnit.net 00:18:39.51]     DataStax.AstraDB.DataApi.IntegrationTests.SerializationTests.TestSpecific [FAIL]
  Error Message:
   System.Text.Json.JsonException : Unexpected token String when reading date value.

Can you confirm?

@a-random-steve a-random-steve force-pushed the filter-builder-rework+minor-fixes branch from 774cd04 to 2d9c81a Compare March 25, 2026 19:40
stephenatsembit and others added 13 commits March 25, 2026 12:52
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment