Skip to content

Commit

Permalink
Add AddTagTTL and AddEdgeTTL for Session Pool
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxins committed Feb 28, 2024
1 parent 5bfccb7 commit c242eaf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
2 changes: 2 additions & 0 deletions result_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ func (res ResultSet) Scan(v interface{}) error {
func (res ResultSet) scanRow(row *nebula.Row, colNames []string, t reflect.Type) (reflect.Value, error) {
rowVals := row.GetValues()

fmt.Println("DEBUG: rowVals: ", rowVals)

val := reflect.New(t).Elem()

for fIdx := 0; fIdx < t.NumField(); fIdx++ {
Expand Down
20 changes: 20 additions & 0 deletions session_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ func (pool *SessionPool) CreateTag(tag LabelSchema) (*ResultSet, error) {
return rs, nil
}

func (pool *SessionPool) AddTagTTL(tagName string, colName string, duration uint) (*ResultSet, error) {
q := fmt.Sprintf(`ALTER TAG %s TTL_DURATION = %d, TTL_COL = "%s";`, tagName, duration, colName)
rs, err := pool.ExecuteAndCheck(q)
if err != nil {
return nil, err
}

return rs, nil
}

func (pool *SessionPool) DescTag(tagName string) ([]Label, error) {
q := fmt.Sprintf("DESC TAG %s;", tagName)
rs, err := pool.ExecuteAndCheck(q)
Expand Down Expand Up @@ -353,6 +363,16 @@ func (pool *SessionPool) CreateEdge(edge LabelSchema) (*ResultSet, error) {
return rs, nil
}

func (pool *SessionPool) AddEdgeTTL(tagName string, colName string, duration uint) (*ResultSet, error) {
q := fmt.Sprintf(`ALTER EDGE %s TTL_DURATION = %d, TTL_COL = "%s";`, tagName, duration, colName)
rs, err := pool.ExecuteAndCheck(q)
if err != nil {
return nil, err
}

return rs, nil
}

func (pool *SessionPool) DescEdge(edgeName string) ([]Label, error) {
q := fmt.Sprintf("DESC EDGE %s;", edgeName)
rs, err := pool.ExecuteAndCheck(q)
Expand Down
47 changes: 37 additions & 10 deletions session_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ func TestSessionPoolApplySchema(t *testing.T) {
Type: "int64",
Nullable: true,
},
{
Field: "created_at",
Type: "timestamp",
Nullable: false,
},
},
}
_, err = sessionPool.CreateTag(tagSchema)
Expand All @@ -429,13 +434,22 @@ func TestSessionPoolApplySchema(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Equal(t, 3, len(labels), "should have 3 labels")
assert.Equal(t, "name", labels[0].Field, "field name should be name")
assert.Equal(t, "string", labels[0].Type, "field type should be string")
assert.Equal(t, "email", labels[1].Field, "field name should be email")
assert.Equal(t, "string", labels[1].Type, "field type should be string")
assert.Equal(t, "phone", labels[2].Field, "field name should be phone")
assert.Equal(t, "int64", labels[2].Type, "field type should be int64")
assert.Equal(t, 4, len(labels))
assert.Equal(t, "name", labels[0].Field)
assert.Equal(t, "string", labels[0].Type)
assert.Equal(t, "email", labels[1].Field)
assert.Equal(t, "string", labels[1].Type)
assert.Equal(t, "phone", labels[2].Field)
assert.Equal(t, "int64", labels[2].Type)
assert.Equal(t, "created_at", labels[3].Field)
assert.Equal(t, "timestamp", labels[3].Type)

// Add TTL to tag
_, err = sessionPool.AddTagTTL("account", "created_at", 86400)
if err != nil {
t.Fatal(err)
}
labels, err = sessionPool.DescTag("account")

edgeSchema := LabelSchema{
Name: "account_email",
Expand All @@ -444,6 +458,11 @@ func TestSessionPoolApplySchema(t *testing.T) {
Field: "email",
Nullable: false,
},
{
Field: "created_at",
Type: "timestamp",
Nullable: false,
},
},
}
_, err = sessionPool.CreateEdge(edgeSchema)
Expand All @@ -460,9 +479,17 @@ func TestSessionPoolApplySchema(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Equal(t, 1, len(labels), "should have 1 labels")
assert.Equal(t, "email", labels[0].Field, "field name should be email")
assert.Equal(t, "string", labels[0].Type, "field type should be string")
assert.Equal(t, 2, len(labels), "should have 2 labels")
assert.Equal(t, "email", labels[0].Field)
assert.Equal(t, "string", labels[0].Type)
assert.Equal(t, "created_at", labels[1].Field)
assert.Equal(t, "timestamp", labels[1].Type)

// Add TTL to edge
_, err = sessionPool.AddEdgeTTL("account_email", "created_at", 86400)
if err != nil {
t.Fatal(err)
}
}

func TestIdleSessionCleaner(t *testing.T) {
Expand Down

0 comments on commit c242eaf

Please sign in to comment.