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

chore: clickhouse sql support for v3 #6778

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
19 changes: 18 additions & 1 deletion pkg/query-service/app/clickhouseReader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4198,9 +4198,26 @@ func (r *ClickHouseReader) GetListResultV3(ctx context.Context, query string) ([
var t time.Time
for idx, v := range vars {
if columnNames[idx] == "timestamp" {
t = time.Unix(0, int64(*v.(*uint64)))
switch v := v.(type) {
case *uint64:
t = time.Unix(0, int64(*v))
case *time.Time:
t = *v
}
} else if columnNames[idx] == "timestamp_datetime" {
t = *v.(*time.Time)
} else if columnNames[idx] == "events" {
var events []map[string]interface{}
eventsFromDB, ok := v.(*[]string)
if !ok {
continue
}
for _, event := range *eventsFromDB {
var eventMap map[string]interface{}
json.Unmarshal([]byte(event), &eventMap)
events = append(events, eventMap)
}
row[columnNames[idx]] = events
} else {
row[columnNames[idx]] = v
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/query-service/app/clickhouseReader/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"regexp"
"strings"

"github.com/ClickHouse/clickhouse-go/v2"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
Expand Down Expand Up @@ -44,6 +45,10 @@ func (c clickhouseConnWrapper) addClickHouseSettings(ctx context.Context, query
settings["log_comment"] = logComment
}

if strings.Contains(query, "signoz_traces") {
settings["max_result_rows"] = 100000
}

if c.settings.MaxBytesToRead != "" {
settings["max_bytes_to_read"] = c.settings.MaxBytesToRead
}
Expand Down
16 changes: 14 additions & 2 deletions pkg/query-service/app/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,15 @@ func (q *querier) runBuilderListQueries(ctx context.Context, params *v3.QueryRan
}
}

queries, err := q.builder.PrepareQueries(params)
queries := make(map[string]string)
var err error
if params.CompositeQuery.QueryType == v3.QueryTypeBuilder {
queries, err = q.builder.PrepareQueries(params)
} else if params.CompositeQuery.QueryType == v3.QueryTypeClickHouseSQL {
for name, chQuery := range params.CompositeQuery.ClickHouseQueries {
queries[name] = chQuery.Query
}
}

if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -534,7 +542,11 @@ func (q *querier) QueryRange(ctx context.Context, params *v3.QueryRangeParamsV3)
case v3.QueryTypePromQL:
results, errQueriesByName, err = q.runPromQueries(ctx, params)
case v3.QueryTypeClickHouseSQL:
results, errQueriesByName, err = q.runClickHouseQueries(ctx, params)
if params.CompositeQuery.PanelType == v3.PanelTypeList || params.CompositeQuery.PanelType == v3.PanelTypeTrace {
results, errQueriesByName, err = q.runBuilderListQueries(ctx, params)
} else {
results, errQueriesByName, err = q.runClickHouseQueries(ctx, params)
}
default:
err = fmt.Errorf("invalid query type")
}
Expand Down
Loading