Example #1
0
 public static Task <GraphBulkImportResponse> AddEdgesAsync(GraphBulkImport graphImporter,
                                                            IEnumerable <Edge> edges)
 {
     return(graphImporter.BulkImportEdgesAsync(
                edges: edges,
                enableUpsert: true));
 }
Example #2
0
 public static Task <GraphBulkImportResponse> AddVerticesAsync(GraphBulkImport graphImporter,
                                                               IEnumerable <Vertex> vertices)
 {
     return(graphImporter.BulkImportVerticesAsync(
                vertices: vertices,
                enableUpsert: true));
 }
Example #3
0
        //

        public static async Task <GraphBulkImport> CreateAndInitGraphImporterAsync(DocumentClient documentClient,
                                                                                   string databaseId, DocumentCollection collection)
        {
            var graphBulkImport = new GraphBulkImport(documentClient, collection, useFlatProperty: false);
            await graphBulkImport.InitializeAsync();

            return(graphBulkImport);
        }
        public static async Task TestBulkInSertAsync()
        {
            DocumentClient client = new DocumentClient(
                new Uri(ConfigurationManager.AppSettings["DocumentServerEndPoint"]),
                ConfigurationManager.AppSettings["PrimaryKey"],
                new ConnectionPolicy {
                ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp
            });

            string databaseId   = ConfigurationManager.AppSettings["Database"];
            string collectionId = ConfigurationManager.AppSettings["Collection"];

            Database database =
                client.CreateDatabaseQuery()
                .Where(db => db.Id == databaseId)
                .AsEnumerable()
                .FirstOrDefault();

            DocumentCollection collection = null;

            try
            {
                collection = await client.ReadDocumentCollectionAsync(
                    UriFactory.CreateDocumentCollectionUri(databaseId, collectionId)).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());

                string partitionKey       = ConfigurationManager.AppSettings["PartitionKeyName"];
                int    throughput         = int.Parse(ConfigurationManager.AppSettings["Throughput"]);
                bool   isPartitionedGraph = bool.Parse(ConfigurationManager.AppSettings["IsPartitionedGraph"]);

                Console.WriteLine(string.Format("No graph found. Creating a graph collection: {0} with throughput = {1}", collectionId, throughput));
                if (isPartitionedGraph)
                {
                    Console.WriteLine(string.Format("The collection is a partitioned collection with partition Key: /{0}", partitionKey));
                }
                else
                {
                    Console.WriteLine($"The collection is a fixed collection with no partition Key");
                }
                Console.WriteLine("Press any key to continue ...");
                Console.ReadKey();

                DocumentCollection myCollection = new DocumentCollection
                {
                    Id = collectionId
                };

                if (isPartitionedGraph)
                {
                    if (string.IsNullOrWhiteSpace(partitionKey))
                    {
                        throw new ArgumentNullException("PartionKey can't be null for a partitioned collection");
                    }

                    myCollection.PartitionKey.Paths.Add("/" + partitionKey);
                }

                collection = await client.CreateDocumentCollectionAsync(
                    database.SelfLink,
                    myCollection,
                    new RequestOptions { OfferThroughput = throughput });
            }


            GraphBulkImport graphBulkImporter = new GraphBulkImport(client, collection, useFlatProperty: false);

            await graphBulkImporter.InitializeAsync();

            int count     = int.Parse(ConfigurationManager.AppSettings["NumVertices"]);
            int batchSize = int.Parse(ConfigurationManager.AppSettings["BatchSize"]);

            GraphBulkImportResponse vResponse =
                await graphBulkImporter.BulkImportVerticesAsync(
                    GenerateVertices(count),
                    enableUpsert : true,
                    batchSize : batchSize).ConfigureAwait(false);

            Console.WriteLine("\n\nAdding edges\n\n");

            GraphBulkImportResponse eResponse =
                await graphBulkImporter.BulkImportEdgesAsync(
                    GenerateEdges(0),
                    enableUpsert : true,
                    batchSize : batchSize).ConfigureAwait(false);

            Console.WriteLine("\nSummary for batch");
            Console.WriteLine("--------------------------------------------------------------------- ");
            Console.WriteLine(
                "Inserted {0} vertices @ {1} edges @ {2} writes/s, {3} RU/s in {4} sec)",
                vResponse.NumberOfVerticesImported,
                eResponse.NumberOfEdgesImported,
                Math.Round(
                    (vResponse.NumberOfVerticesImported + eResponse.NumberOfEdgesImported) /
                    (vResponse.TotalTimeTaken.TotalSeconds + eResponse.TotalTimeTaken.TotalSeconds)),
                Math.Round(
                    (vResponse.TotalRequestUnitsConsumed + eResponse.TotalRequestUnitsConsumed) /
                    (vResponse.TotalTimeTaken.TotalSeconds + eResponse.TotalTimeTaken.TotalSeconds)),
                vResponse.TotalTimeTaken.TotalSeconds + eResponse.TotalTimeTaken.TotalSeconds);
            Console.WriteLine(
                "Average RU consumption per document: {0}",
                (vResponse.TotalRequestUnitsConsumed + eResponse.TotalRequestUnitsConsumed) /
                (vResponse.NumberOfVerticesImported + eResponse.NumberOfVerticesImported));
            Console.WriteLine("---------------------------------------------------------------------\n ");

            // Using the gremlin server (Supports gremlin queries)
            try
            {
                GremlinServer server = new GremlinServer(
                    ConfigurationManager.AppSettings["GremlinServerEndPoint"],
                    int.Parse(ConfigurationManager.AppSettings["GremlinServerPort"]),
                    true,
                    "/dbs/" + ConfigurationManager.AppSettings["Database"] + "/colls/" + ConfigurationManager.AppSettings["Collection"],
                    ConfigurationManager.AppSettings["PrimaryKey"]);

                using (GremlinClient gClient = new GremlinClient(server))
                {
                    foreach (string query in Program.gremlinQueries)
                    {
                        ExecuteGremlinServerQuery(gClient, query);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.WriteLine("---------------------------------------------------------------------\n ");


            // Using the document server (Supports DocumentDB SQL queries)
            try
            {
                foreach (string query in Program.documentQueries)
                {
                    await ExecuteDocumentServerQueryAsync(client, collection, query);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.WriteLine("---------------------------------------------------------------------\n ");

            Console.ReadLine();
        }