-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support drop measurement (#157)
Signed-off-by: ZhangJian He <shoothzj@gmail.com>
- Loading branch information
ZhangJian He
authored
Aug 13, 2024
1 parent
64f8635
commit 842826a
Showing
4 changed files
with
151 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package opengemini | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestClientShowTagKeys(t *testing.T) { | ||
c := testDefaultClient(t) | ||
databaseName := randomDatabaseName() | ||
err := c.CreateDatabase(databaseName) | ||
require.Nil(t, err) | ||
measurement := randomMeasurement() | ||
cmd := fmt.Sprintf("CREATE MEASUREMENT %s (tag1 TAG,tag2 TAG,tag3 TAG, field1 INT64 FIELD, field2 BOOL, field3 STRING, field4 FLOAT64)", measurement) | ||
_, err = c.Query(Query{Command: cmd, Database: databaseName}) | ||
assert.Nil(t, err) | ||
showKeyCmd := fmt.Sprintf("SHOW TAG KEYS FROM %s limit 3 OFFSET 0", measurement) | ||
tagKeyResult, err := c.ShowTagKeys(databaseName, showKeyCmd) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 1, len(tagKeyResult)) | ||
err = c.DropDatabase(databaseName) | ||
require.Nil(t, err) | ||
} | ||
|
||
func TestClient_ShowFieldKeys(t *testing.T) { | ||
c := testDefaultClient(t) | ||
databaseName := randomDatabaseName() | ||
err := c.CreateDatabase(databaseName) | ||
require.Nil(t, err) | ||
measurement := randomMeasurement() | ||
cmd := fmt.Sprintf("CREATE MEASUREMENT %s (tag1 TAG,tag2 TAG,tag3 TAG, field1 INT64 FIELD, field2 BOOL, field3 STRING, field4 FLOAT64)", measurement) | ||
_, err = c.Query(Query{Command: cmd, Database: databaseName}) | ||
assert.Nil(t, err) | ||
tagFieldResult, err := c.ShowFieldKeys(databaseName, fmt.Sprintf("SHOW FIELD KEYS FROM %s", measurement)) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 1, len(tagFieldResult)) | ||
err = c.DropDatabase(databaseName) | ||
require.Nil(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,95 @@ | ||
package opengemini | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"context" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestClientShowTagKeys(t *testing.T) { | ||
func TestClientDropMeasurementExistSpecifyRp(t *testing.T) { | ||
c := testDefaultClient(t) | ||
databaseName := randomDatabaseName() | ||
retentionPolicy := randomRetentionPolicy() | ||
measurement := randomMeasurement() | ||
err := c.CreateDatabase(databaseName) | ||
require.Nil(t, err) | ||
measurement := randomMeasurement() | ||
cmd := fmt.Sprintf("CREATE MEASUREMENT %s (tag1 TAG,tag2 TAG,tag3 TAG, field1 INT64 FIELD, field2 BOOL, field3 STRING, field4 FLOAT64)", measurement) | ||
_, err = c.Query(Query{Command: cmd, Database: databaseName}) | ||
assert.Nil(t, err) | ||
showKeyCmd := fmt.Sprintf("SHOW TAG KEYS FROM %s limit 3 OFFSET 0", measurement) | ||
tagKeyResult, err := c.ShowTagKeys(databaseName, showKeyCmd) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 1, len(tagKeyResult)) | ||
err = c.CreateRetentionPolicy(databaseName, RpConfig{Name: retentionPolicy, Duration: "3d"}, false) | ||
require.Nil(t, err) | ||
err = c.WriteBatchPointsWithRp(context.Background(), databaseName, retentionPolicy, []*Point{ | ||
{ | ||
Measurement: measurement, | ||
Precision: 0, | ||
Time: time.Time{}, | ||
Tags: nil, | ||
Fields: nil, | ||
}, | ||
}) | ||
require.Nil(t, err) | ||
err = c.DropMeasurement(databaseName, retentionPolicy, measurement) | ||
require.Nil(t, err) | ||
err = c.DropRetentionPolicy(databaseName, retentionPolicy) | ||
require.Nil(t, err) | ||
} | ||
|
||
func TestClientDropMeasurementNonExistent(t *testing.T) { | ||
c := testDefaultClient(t) | ||
databaseName := randomDatabaseName() | ||
retentionPolicy := randomRetentionPolicy() | ||
err := c.CreateDatabase(databaseName) | ||
require.Nil(t, err) | ||
err = c.CreateRetentionPolicy(databaseName, RpConfig{Name: retentionPolicy, Duration: "3d"}, false) | ||
require.Nil(t, err) | ||
err = c.DropMeasurement(databaseName, retentionPolicy, "non_existent_measurement") | ||
require.Nil(t, err) | ||
err = c.DropRetentionPolicy(databaseName, retentionPolicy) | ||
require.Nil(t, err) | ||
err = c.DropDatabase(databaseName) | ||
require.Nil(t, err) | ||
} | ||
|
||
func TestClient_ShowFieldKeys(t *testing.T) { | ||
func TestClientDropMeasurementEmptyMeasurementName(t *testing.T) { | ||
c := testDefaultClient(t) | ||
databaseName := randomDatabaseName() | ||
retentionPolicy := randomRetentionPolicy() | ||
err := c.CreateDatabase(databaseName) | ||
require.Nil(t, err) | ||
err = c.CreateRetentionPolicy(databaseName, RpConfig{Name: retentionPolicy, Duration: "3d"}, false) | ||
require.Nil(t, err) | ||
err = c.DropMeasurement(databaseName, retentionPolicy, "") | ||
require.NotNil(t, err) | ||
err = c.DropRetentionPolicy(databaseName, retentionPolicy) | ||
require.Nil(t, err) | ||
err = c.DropDatabase(databaseName) | ||
require.Nil(t, err) | ||
} | ||
|
||
func TestClientDropMeasurementEmptyRetentionPolicy(t *testing.T) { | ||
c := testDefaultClient(t) | ||
databaseName := randomDatabaseName() | ||
measurement := randomMeasurement() | ||
cmd := fmt.Sprintf("CREATE MEASUREMENT %s (tag1 TAG,tag2 TAG,tag3 TAG, field1 INT64 FIELD, field2 BOOL, field3 STRING, field4 FLOAT64)", measurement) | ||
_, err = c.Query(Query{Command: cmd, Database: databaseName}) | ||
assert.Nil(t, err) | ||
tagFieldResult, err := c.ShowFieldKeys(databaseName, fmt.Sprintf("SHOW FIELD KEYS FROM %s", measurement)) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 1, len(tagFieldResult)) | ||
err := c.CreateDatabase(databaseName) | ||
require.Nil(t, err) | ||
err = c.WriteBatchPoints(context.Background(), databaseName, []*Point{ | ||
{ | ||
Measurement: measurement, | ||
Precision: 0, | ||
Time: time.Time{}, | ||
Tags: nil, | ||
Fields: nil, | ||
}, | ||
}) | ||
require.Nil(t, err) | ||
err = c.DropMeasurement(databaseName, "", measurement) | ||
require.NotNil(t, err) | ||
err = c.DropDatabase(databaseName) | ||
require.Nil(t, err) | ||
} | ||
|
||
func TestClientDropMeasurementEmptyDatabaseName(t *testing.T) { | ||
c := testDefaultClient(t) | ||
retentionPolicy := randomRetentionPolicy() | ||
measurement := randomMeasurement() | ||
err := c.DropMeasurement("", retentionPolicy, measurement) | ||
require.NotNil(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters