0

I am trying to use BulkDelete function (for Cosmos DB graph database) that takes a string query and deletes all results, in my .NET C# application. Documentation: https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmosdb.bulkexecutor.graph.graphbulkexecutor.bulkdeleteasync?view=azure-dotnet

Since I don't know the Ids and partition keys of vertices and edges to be deleted in the graph, I can't use this BulkDelete API: https://github.com/Azure/azure-cosmosdb-bulkexecutor-dotnet-getting-started#bulk-delete-api

Using CosmosDB.BulkExecutor.Graph.GraphBulkExecutor.BulkDeleteAsync (that takes in query as as string) throws this exception:

System.NotImplementedException: The method or operation is not implemented. at Microsoft.Azure.CosmosDB.BulkExecutor.Graph.GraphBulkExecutor.BulkDeleteAsync(String query, Nullable`1 deleteBatchSize, CancellationToken cancellationToken) at ...

relevant code snippet:

        // Prepare for bulk delete
         var bulkExecutor = new GraphBulkExecutor(client, dataCollection);
        await bulkExecutor.InitializeAsync();
        var cancellationToken = new CancellationTokenSource().Token;


        string query = "g.V().hasLabel('user')";

        BulkDeleteResponse bulkDeleteResponse = null;

        try
        {
            bulkDeleteResponse = await bulkExecutor.BulkDeleteAsync(query, 1000, cancellationToken);
            PrintSummaryofBulkDelete(bulkDeleteResponse);
        }
        catch (DocumentClientException de)
        {
            LogUtility.Error("Document client exception: {0}", de);
        }
        catch (Exception e)
        {
            LogUtility.Error("Exception: {0}", e);
        }

Is is really not implemented or am I making a mistake in using it?

1 Answers1

1

It is really not implemented. For GraphBulkExecutor, the only available operation seems to be Import.

And the reason might be that GraphBulkExecutor just uses the Bulk Executor SQL API library, which only supports SQL type of queries (no graph queries). That could be the reason GraphBulkExecutor does not take any query input, because it wouldn't be able to run it.

Matias Quaranta
  • 13,907
  • 1
  • 22
  • 47
  • Thanks @Matias. In that case, what is the fastest way to delete graph elements based on query results in BULK? I can write the equivalent SQL query(ies) for the gremlin query (ies) that would output the vertices/edges (documents) to be deleted. – Apoorva Agrawal Mar 01 '21 at 21:17
  • If you have the ID + PK values, you could certainly leverage BulkDelete of the Bulk Executor SQL library (not GraphBulkExecutor) OR use the V3 SDK Bulk mode with DeleteItem operations, both will do – Matias Quaranta Mar 02 '21 at 00:31
  • Small clarification: I don't have the ID + PK values. Whether an item has to be deleted or not depend's on its dynamic properties. I need to extract it from the graph DB through a query. – Apoorva Agrawal Mar 02 '21 at 01:47
  • Right, you'd need a query to get the ID + PK in order to be able to use any Bulk Delete alternatives. – Matias Quaranta Mar 02 '21 at 19:35