influxdb query sql bug fix (#313)

* bug fix influxdb query data, query index

Co-authored-by: litianshun <litianshun@meicai.cn>
master
litianshun 4 years ago committed by GitHub
parent ceb86a2d5f
commit 68b213b737
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -84,11 +84,11 @@ type CludeRecv struct {
} }
type XcludeResp struct { type XcludeResp struct {
Endpoints []string `json:"endpoints"` Endpoint string `json:"endpoint"`
Metric string `json:"metric"` Metric string `json:"metric"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
Step int `json:"step"` Step int `json:"step"`
DsType string `json:"dstype"` DsType string `json:"dstype"`
} }
type IndexByFullTagsRecv struct { type IndexByFullTagsRecv struct {

@ -36,43 +36,51 @@ func (query *ShowSeries) renderEndpoints() {
} }
endpointPart = endpointPart[:len(endpointPart)-len("OR")] endpointPart = endpointPart[:len(endpointPart)-len("OR")]
endpointPart += ")" endpointPart += ")"
query.RawQuery = fmt.Sprintf("\"%s\" WHERE \"%s\"", query.RawQuery, endpointPart) query.RawQuery = fmt.Sprintf("%s WHERE %s", query.RawQuery, endpointPart)
} }
} }
func (query *ShowSeries) renderInclude() { func (query *ShowSeries) renderInclude() {
if len(query.Include) > 0 { if len(query.Include) > 0 {
// include // include
if len(query.Include) == 1 && query.Include[0] == nil {
return
}
includePart := "(" includePart := "("
for _, include := range query.Include { for _, include := range query.Include {
for _, value := range include.Values { for _, value := range include.Values {
includePart += fmt.Sprintf(" \"%s\"='%s' OR", include.Key, value) includePart += fmt.Sprintf(" \"%s\"='%s' OR", include.Key, value)
} }
} }
includePart = includePart[:len(includePart)-len("OR")] includePart = includePart[:len(includePart)-len("AND")]
includePart += ")" includePart += ")"
if !strings.Contains(query.RawQuery, "WHERE") { if !strings.Contains(query.RawQuery, "WHERE") {
query.RawQuery += " WHERE" query.RawQuery = fmt.Sprintf(" %s WHERE %s", query.RawQuery, includePart)
} else {
query.RawQuery = fmt.Sprintf(" %s AND %s", query.RawQuery, includePart)
} }
query.RawQuery = fmt.Sprintf(" %s AND %s", query.RawQuery, includePart)
} }
} }
func (query *ShowSeries) renderExclude() { func (query *ShowSeries) renderExclude() {
if len(query.Exclude) > 0 { if len(query.Exclude) > 0 {
// exclude // exclude
if len(query.Exclude) == 1 && query.Exclude[0] == nil {
return
}
excludePart := "(" excludePart := "("
for _, exclude := range query.Exclude { for _, exclude := range query.Exclude {
for _, value := range exclude.Values { for _, value := range exclude.Values {
excludePart += fmt.Sprintf(" \"%s\"='%s' OR", exclude.Key, value) excludePart += fmt.Sprintf(" \"%s\"!='%s' AND", exclude.Key, value)
} }
} }
excludePart = excludePart[:len(excludePart)-len("OR")] excludePart = excludePart[:len(excludePart)-len("AND")]
excludePart += ")" excludePart += ")"
if !strings.Contains(query.RawQuery, "WHERE") { if !strings.Contains(query.RawQuery, "WHERE") {
query.RawQuery += " WHERE" query.RawQuery = fmt.Sprintf(" %s WHERE %s", query.RawQuery, excludePart)
} else {
query.RawQuery = fmt.Sprintf(" %s AND %s", query.RawQuery, excludePart)
} }
query.RawQuery = fmt.Sprintf(" %s AND %s", query.RawQuery, excludePart)
} }
} }

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save