MCPcopy
hub / github.com/dgraph-io/dgraph / TestBulkLoadMixedPredicates

Function TestBulkLoadMixedPredicates

systest/vector/load_test.go:355–515  ·  view source on GitHub ↗

TestBulkLoadMixedPredicates tests bulk loading vector data alongside other predicate types (string with index, int with index, uid edges) to ensure vector indexing doesn't break existing functionality.

(t *testing.T)

Source from the content-addressed store, hash-verified

353// predicate types (string with index, int with index, uid edges) to ensure
354// vector indexing doesn't break existing functionality.
355func TestBulkLoadMixedPredicates(t *testing.T) {
356 // Schema with vectors AND other indexed predicates
357 mixedSchema := `
358 project_description_v: float32vector @index(hnsw(exponent: "5", metric: "euclidean")) .
359 name: string @index(term, fulltext) .
360 age: int @index(int) .
361 score: float .
362 friend: [uid] @reverse .
363 dgraph.type: [string] @index(exact) .
364 `
365
366 numVectors := 500
367 vectorDim := 10
368
369 // Step 1: Create source cluster and load mixed data
370 sourceConf := dgraphtest.NewClusterConfig().
371 WithNumAlphas(1).
372 WithNumZeros(1).
373 WithReplicas(1).
374 WithACL(time.Hour)
375 sourceCluster, err := dgraphtest.NewLocalCluster(sourceConf)
376 require.NoError(t, err)
377 defer func() { sourceCluster.Cleanup(t.Failed()) }()
378 require.NoError(t, sourceCluster.Start())
379
380 gc, cleanup, err := sourceCluster.Client()
381 require.NoError(t, err)
382 defer cleanup()
383 require.NoError(t, gc.LoginIntoNamespace(context.Background(),
384 dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.RootNamespace))
385
386 hc, err := sourceCluster.HTTPClient()
387 require.NoError(t, err)
388 require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
389 dgraphapi.DefaultPassword, x.RootNamespace))
390
391 require.NoError(t, gc.SetupSchema(mixedSchema))
392
393 // Generate mixed RDF data: vectors + strings + ints + edges
394 var rdfBuilder strings.Builder
395 vectors := make([][]float32, numVectors)
396
397 for i := 0; i < numVectors; i++ {
398 uid := i + 10
399 // Generate random vector
400 vec := dgraphapi.GenerateRandomVector(vectorDim)
401 vectors[i] = vec
402 vecStr := fmt.Sprintf(`"[%s]"`, strings.Trim(strings.Join(strings.Fields(fmt.Sprint(vec)), ", "), "[]"))
403
404 // Add vector predicate
405 rdfBuilder.WriteString(fmt.Sprintf("<0x%x> <project_description_v> %s .\n", uid, vecStr))
406 // Add string predicate
407 rdfBuilder.WriteString(fmt.Sprintf("<0x%x> <name> \"Person %d\" .\n", uid, i))
408 // Add int predicate
409 rdfBuilder.WriteString(fmt.Sprintf("<0x%x> <age> \"%d\"^^<xs:int> .\n", uid, 20+i%50))
410 // Add float predicate
411 rdfBuilder.WriteString(fmt.Sprintf("<0x%x> <score> \"%f\"^^<xs:float> .\n", uid, float64(i)*1.5))
412 // Add dgraph.type

Callers

nothing calls this directly

Calls 15

CleanupMethod · 0.95
StartMethod · 0.95
ClientMethod · 0.95
HTTPClientMethod · 0.95
StartZeroMethod · 0.95
HealthCheckMethod · 0.95
CopyExportToHostMethod · 0.95
BulkLoadMethod · 0.95
NewClusterConfigFunction · 0.92
NewLocalClusterFunction · 0.92
GenerateRandomVectorFunction · 0.92
cleanupFunction · 0.85

Tested by

no test coverage detected