Skip to content
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

[Feature] OAS-10537 Allow for Bulk Adding of Vertices to VertexCollection and Edges to EdgeCollection #657

Merged
4 changes: 2 additions & 2 deletions collection.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2017-2021 ArangoDB GmbH, Cologne, Germany
// Copyright 2017-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -183,7 +183,7 @@ type CollectionProperties struct {

IsSmartChild bool `json:"isSmartChild,omitempty"`

InternalValidatorType *int `json:"internalValidatorType, omitempty"`
InternalValidatorType *int `json:"internalValidatorType,omitempty"`

// Set to create a smart edge or vertex collection.
// This requires ArangoDB Enterprise Edition.
Expand Down
4 changes: 3 additions & 1 deletion v2/arangodb/graph_edge_definitions_edges.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -27,6 +27,8 @@ import (
)

type Edge interface {
Collection

// Name returns the name of the Edge collection
Name() string

Expand Down
5 changes: 4 additions & 1 deletion v2/arangodb/graph_edge_definitions_edges_impl.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,12 +32,15 @@ func newEdgeCollection(edge *graph, edgeColName string) *edgeCollection {
return &edgeCollection{
graph: edge,
edgeColName: edgeColName,
collection: *newCollection(edge.db, edgeColName, edge.modifiers...),
}
}

var _ Edge = &edgeCollection{}

type edgeCollection struct {
collection

edgeColName string

modifiers []connection.RequestModifier
Expand Down
4 changes: 3 additions & 1 deletion v2/arangodb/graph_vertex_collections_vertices.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -27,6 +27,8 @@ import (
)

type VertexCollection interface {
Collection

// Name returns the name of the vertex collection
Name() string

Expand Down
5 changes: 4 additions & 1 deletion v2/arangodb/graph_vertex_collections_vertices_impl.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,12 +32,15 @@ func newVertexCollection(vertex *graph, vertexColName string) *vertexCollection
return &vertexCollection{
graph: vertex,
vertexColName: vertexColName,
collection: *newCollection(vertex.db, vertexColName, vertex.modifiers...),
}
}

var _ VertexCollection = &vertexCollection{}

type vertexCollection struct {
collection

vertexColName string

modifiers []connection.RequestModifier
Expand Down
187 changes: 186 additions & 1 deletion v2/tests/graph_vertex_collections_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@ package tests

import (
"context"
"fmt"
"testing"

"github.com/arangodb/go-driver/v2/utils"
Expand Down Expand Up @@ -79,6 +80,190 @@ func Test_GraphVertexCollections(t *testing.T) {
})
}

func Test_AddBulkVerticesToCollection(t *testing.T) {
Wrap(t, func(t *testing.T, client arangodb.Client) {
requireClusterMode(t)
WithDatabase(t, client, nil, func(db arangodb.Database) {
WithGraph(t, db, sampleSmartGraph(), nil, func(graph arangodb.Graph) {
withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) {
// skipNoEnterprise(client, ctx, t)
enikon marked this conversation as resolved.
Show resolved Hide resolved

type DocVertex struct {
Key string `json:"_key,omitempty"`
Value string `json:"value"`
Lat float32 `json:"latitude"`
Lon float32 `json:"longitude"`
}

docs := []DocVertex{
{
Key: "111",
Value: "Value1",
Lat: 1,
Lon: 0,
},
{
Key: "222",
Value: "Value2",
Lat: 50,
Lon: 0,
},
{
Key: "333",
Value: "Value3",
Lat: 10,
Lon: 0,
},
}

colName := "test_vertex_collection_add_many"
createResp, err := graph.CreateVertexCollection(ctx, colName, nil)
require.NoError(t, err)
require.Contains(t, createResp.GraphDefinition.OrphanCollections, colName)

idxOpts := arangodb.CreateGeoIndexOptions{GeoJSON: utils.NewType(false)}
col := createResp.VertexCollection
col.EnsureGeoIndex(ctx, []string{"latitude", "longitude"}, &idxOpts)
_, err = col.CreateDocuments(ctx, docs)
require.NoError(t, err)

QUERY := fmt.Sprintf("FOR x IN %v FILTER DISTANCE(0, 0, x.latitude, x.longitude) <= 1120000 RETURN x", colName)
cursor, err := db.Query(ctx, QUERY, nil)
require.NoError(t, err)

var vertRead1, vertRead2 DocVertex
_, err = cursor.ReadDocument(ctx, &vertRead1)
require.NoError(t, err)
_, err = cursor.ReadDocument(ctx, &vertRead2)
require.NoError(t, err)
require.ElementsMatch(t, []string{"Value1", "Value3"}, []string{vertRead1.Value, vertRead2.Value})
cursor.Close()

err = col.GetVertex(ctx, "111", &vertRead1, nil)
require.NoError(t, err)
require.Equal(t, "Value1", vertRead1.Value)

})
})
})

WithDatabase(t, client, nil, func(db arangodb.Database) {
WithGraph(t, db, sampleSmartGraph(), nil, func(graph arangodb.Graph) {
withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) {
// skipNoEnterprise(client, ctx, t)

type DocVertex struct {
Key string `json:"_key,omitempty"`
Value string `json:"value"`
}

docs := []DocVertex{
{
Key: "111",
Value: "Value1",
},
{
Key: "222",
Value: "Value2",
},
{
Key: "333",
Value: "Value3",
},
{
Key: "444",
Value: "Value4",
},
}
vColName := "test_vertex_collection_add_many"
createVertResp, err := graph.CreateVertexCollection(ctx, vColName, nil)
require.NoError(t, err)
vCol := createVertResp.VertexCollection
_, err = vCol.CreateDocuments(ctx, docs)
require.NoError(t, err)
require.Contains(t, createVertResp.GraphDefinition.OrphanCollections, vColName)

type DocEdge struct {
From string `json:"_from"`
To string `json:"_to"`
}

px := vColName + "/"
edges := []DocEdge{
{
From: px + "111",
To: px + "222",
},
{
From: px + "222",
To: px + "333",
},
{
From: px + "333",
To: px + "444",
},
{
From: px + "444",
To: px + "111",
},
{
From: px + "222",
To: px + "111",
},
{
From: px + "333",
To: px + "222",
},
{
From: px + "444",
To: px + "333",
},
}

eColName := "test_edge_collection_add_many"
createEdgeResp, err := graph.CreateEdgeDefinition(ctx, eColName, []string{vColName}, []string{vColName}, nil)
require.NoError(t, err)
require.NotContains(t, createEdgeResp.GraphDefinition.OrphanCollections, vColName)
eCol := createEdgeResp.Edge
_, err = eCol.CreateDocuments(ctx, edges)
require.NoError(t, err)

var meta arangodb.DocumentMeta
_ = vCol.GetVertex(ctx, "111", &meta, nil)
QUERY := fmt.Sprintf(
"FOR v, e, p IN 1..1 OUTBOUND \"%v\" GRAPH \"%v\" RETURN CONCAT_SEPARATOR(\"--\", p.vertices[*].value)",
meta.ID,
graph.Name(),
)
cursor, err := db.Query(ctx, QUERY, nil)
require.NoError(t, err)

var pathRead string
_, err = cursor.ReadDocument(ctx, &pathRead)
require.NoError(t, err)
require.Equal(t, "Value1--Value2", pathRead)

_ = vCol.GetVertex(ctx, "444", &meta, nil)
QUERY = fmt.Sprintf(
"FOR v, e, p IN 1..1 OUTBOUND \"%v\" GRAPH \"%v\" RETURN CONCAT_SEPARATOR(\"--\", p.vertices[*].value)",
meta.ID,
graph.Name(),
)
cursor, err = db.Query(ctx, QUERY, nil)
require.NoError(t, err)

var pathRead2 string
_, err = cursor.ReadDocument(ctx, &pathRead)
require.NoError(t, err)
_, err = cursor.ReadDocument(ctx, &pathRead2)
require.NoError(t, err)
require.ElementsMatch(t, []string{"Value4--Value1", "Value4--Value3"}, []string{pathRead, pathRead2})
})
})
})
})
}

func TestCreateSatelliteVertexCollection(t *testing.T) {
Wrap(t, func(t *testing.T, client arangodb.Client) {
requireClusterMode(t)
Expand Down