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 56a5bbe
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
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
49 changes: 39 additions & 10 deletions session_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,24 @@ func TestSessionPoolApplySchema(t *testing.T) {
Type: "int64",
Nullable: true,
},
{
Field: "created_at",
Type: "timestamp",
Nullable: false,
},
},
}
_, err = sessionPool.CreateTag(tagSchema)
if err != nil {
t.Fatal(err)
}

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

tags, err := sessionPool.ShowTags()
if err != nil {
t.Fatal(err)
Expand All @@ -429,13 +441,15 @@ 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)

edgeSchema := LabelSchema{
Name: "account_email",
Expand All @@ -444,12 +458,24 @@ func TestSessionPoolApplySchema(t *testing.T) {
Field: "email",
Nullable: false,
},
{
Field: "created_at",
Type: "timestamp",
Nullable: false,
},
},
}
_, err = sessionPool.CreateEdge(edgeSchema)
if err != nil {
t.Fatal(err)
}

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

edges, err := sessionPool.ShowEdges()
if err != nil {
t.Fatal(err)
Expand All @@ -460,9 +486,12 @@ 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)

}

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

0 comments on commit 56a5bbe

Please sign in to comment.