Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add description for Client interface #114

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions opengemini/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ type Client interface {
ShowRetentionPolicies(database string) ([]RetentionPolicy, error)
DropRetentionPolicy(database, retentionPolicy string) error

// ShowTagKeys get key field names from a database, return []{"Measurement":"XXX","Values":[]string{"TAG1"}}
// command such as: show tag keys | show tag keys from MEASUREMENT_NAME | show tag keys from MEASUREMENT_NAME limit N offset M
ShowTagKeys(database, command string) ([]ValuesResult, error)
// ShowTagValues get key field values from a measurement, return []{"Measurement":"XXX","Values":[]string{"tagName", "tagValue"}}
// command such as: show tag values from MEASUREMENT_NAME with key = "TAG_NAME"
ShowTagValues(database, command string) ([]ValuesResult, error)
// ShowFieldKeys get field key names from a database, return []{"Measurement":"XXX","Values":[]string{"fieldName", "fieldType"}}
// command such as: show field keys | show field keys from MEASUREMENT_NAME
ShowFieldKeys(database, command string) ([]ValuesResult, error)
// ShowSeries returns the series of specified databases
// return [measurement1,tag1=value1 measurement2,tag2=value2]
Expand Down
2 changes: 1 addition & 1 deletion opengemini/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (c *client) ShowFieldKeys(database, command string) ([]ValuesResult, error)
}

func (c *client) ShowSeries(database, command string) ([]string, error) {
var series = make([]string, 0)
if len(database) == 0 {
return nil, errors.New("empty database name")
}
Expand All @@ -63,6 +62,7 @@ func (c *client) ShowSeries(database, command string) ([]string, error) {
if len(seriesResult) == 0 {
return []string{}, nil
}
var series = make([]string, 0, len(seriesResult[0].Values))
for _, v := range seriesResult[0].Values {
strV, ok := v.(string)
if !ok {
Expand Down
13 changes: 6 additions & 7 deletions opengemini/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,27 @@ func (c *client) queryPost(q Query) (*QueryResult, error) {
}

func (c *client) showTagSeriesQuery(database, command string) ([]ValuesResult, error) {
tagSeries := make([]ValuesResult, 0)
tagSeriesResult, err := c.Query(Query{Database: database, Command: command})
if err != nil {
return tagSeries, err
return nil, err
}

err = tagSeriesResult.hasError()
if err != nil {
return tagSeries, fmt.Errorf("get tagSeriesResult failed, error: %s", err)
return nil, fmt.Errorf("get tagSeriesResult failed, error: %s", err)
}
if len(tagSeriesResult.Results) == 0 {
return tagSeries, nil
return []ValuesResult{}, nil
}

tagSeries := make([]ValuesResult, 0, len(tagSeriesResult.Results[0].Series))
for _, res := range tagSeriesResult.Results[0].Series {
tagSeriesRes := new(ValuesResult)
tagSeriesRes.Measurement = res.Name
for _, valRes := range res.Values {
for _, value := range valRes {
strVal, ok := value.(string)
if !ok {
return tagSeries, nil
return []ValuesResult{}, errors.New("value is not string")
}
tagSeriesRes.Values = append(tagSeriesRes.Values, strVal)
}
Expand Down Expand Up @@ -142,7 +141,7 @@ func (c *client) showTagFieldQuery(database, command string) ([]ValuesResult, er
for _, valRes := range res.Values {
tagValue := new(keyValue)
if len(valRes) < 2 {
return tagValueResult, nil
return nil, errors.New("invalid tag value format")
}
if strVal, ok := valRes[0].(string); ok {
tagValue.Name = strVal
Expand Down
Loading