Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
jairad26 committed Nov 12, 2024
1 parent ac15c46 commit 90ef967
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
9 changes: 2 additions & 7 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ type Config struct {
limitNormalizeNode int
}

func NewDefaultConfig() Config {
return Config{limitNormalizeNode: 10000}
}

func (cc Config) WithDataDir(dir string) Config {
cc.dataDir = dir
return cc
func NewDefaultConfig(dir string) Config {
return Config{dataDir: dir, limitNormalizeNode: 10000}
}

func (cc Config) WithLimitNormalizeNode(n int) Config {
Expand Down
4 changes: 2 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ func (db *DB) DropData(ctx context.Context) error {
return nil
}

func (db *DB) AlterSchema(ctx context.Context, sch string) error {
func (db *DB) AlterSchema(ctx context.Context, sch string, ns uint64) error {
db.mutex.Lock()
defer db.mutex.Unlock()

if !db.isOpen {
return ErrDBClosed
}

sc, err := schema.ParseWithNamespace(sch, 0)
sc, err := schema.ParseWithNamespace(sch, ns)
if err != nil {
return fmt.Errorf("error parsing schema: %w", err)
}
Expand Down
14 changes: 7 additions & 7 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
func TestRestart(t *testing.T) {
dataDir := t.TempDir()

db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(dataDir))
db, err := modusdb.New(modusdb.NewDefaultConfig(dataDir))
require.NoError(t, err)
defer func() { db.Close() }()

require.NoError(t, db.DropAll(context.Background()))
require.NoError(t, db.AlterSchema(context.Background(), "name: string @index(term) ."))
require.NoError(t, db.AlterSchema(context.Background(), "name: string @index(term) .", 0))

_, err = db.Mutate(context.Background(), []*api.Mutation{
{
Expand All @@ -47,7 +47,7 @@ func TestRestart(t *testing.T) {
require.JSONEq(t, `{"me":[{"name":"A"}]}`, string(qresp.GetJson()))

db.Close()
db, err = modusdb.New(modusdb.NewDefaultConfig().WithDataDir(dataDir))
db, err = modusdb.New(modusdb.NewDefaultConfig(dataDir))
require.NoError(t, err)
qresp, err = db.Query(context.Background(), query)
require.NoError(t, err)
Expand All @@ -57,7 +57,7 @@ func TestRestart(t *testing.T) {
}

func TestSchemaQuery(t *testing.T) {
db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir()))
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
defer db.Close()

Expand All @@ -68,7 +68,7 @@ func TestSchemaQuery(t *testing.T) {
married: bool .
loc: geo .
dob: datetime .
`))
`, 0))

resp, err := db.Query(context.Background(), `schema(pred: [name, age]) {type}`)
require.NoError(t, err)
Expand All @@ -86,13 +86,13 @@ func TestBasicVector(t *testing.T) {
}
vectBytes := buf.Bytes()

db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir()))
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
defer db.Close()

require.NoError(t, db.DropAll(context.Background()))
require.NoError(t, db.AlterSchema(context.Background(),
`project_description_v: float32vector @index(hnsw(exponent: "5", metric: "euclidean")) .`))
`project_description_v: float32vector @index(hnsw(exponent: "5", metric: "euclidean")) .`, 0))

uids, err := db.Mutate(context.Background(), []*api.Mutation{{
Set: []*api.NQuad{{
Expand Down
2 changes: 1 addition & 1 deletion live.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (db *DB) Load(ctx context.Context, schemaPath, dataPath string) error {
if err != nil {
return fmt.Errorf("error reading schema file [%v]: %w", schemaPath, err)
}
if err := db.AlterSchema(ctx, string(schemaData)); err != nil {
if err := db.AlterSchema(ctx, string(schemaData), 0); err != nil {
return fmt.Errorf("error altering schema: %w", err)
}

Expand Down
4 changes: 2 additions & 2 deletions live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestLiveLoaderSmall(t *testing.T) {
`
)

db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir()))
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
defer func() { db.Close() }()

Expand Down Expand Up @@ -83,7 +83,7 @@ func TestLiveLoaderSmall(t *testing.T) {
}

func TestLiveLoader1Million(t *testing.T) {
db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir()))
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
defer func() { db.Close() }()

Expand Down
4 changes: 2 additions & 2 deletions vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const (
)

func TestVectorDelete(t *testing.T) {
db, err := modusdb.New(modusdb.NewDefaultConfig().WithDataDir(t.TempDir()))
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
defer func() { db.Close() }()

require.NoError(t, db.DropAll(context.Background()))
require.NoError(t, db.AlterSchema(context.Background(),
fmt.Sprintf(vectorSchemaWithIndex, "vtest", "4", "euclidean")))
fmt.Sprintf(vectorSchemaWithIndex, "vtest", "4", "euclidean"), 0))

// insert random vectorss
assignIDs, err := db.LeaseUIDs(numVectors + 1)
Expand Down

0 comments on commit 90ef967

Please sign in to comment.