-
Notifications
You must be signed in to change notification settings - Fork 111
/
queries_tables.go
100 lines (82 loc) · 2.56 KB
/
queries_tables.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package server
import (
"context"
runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
"github.com/rilldata/rill/runtime/pkg/observability"
"github.com/rilldata/rill/runtime/queries"
"github.com/rilldata/rill/runtime/server/auth"
"go.opentelemetry.io/otel/attribute"
)
const _tableHeadDefaultLimit = 25
// Table level profiling APIs.
func (s *Server) TableCardinality(ctx context.Context, req *runtimev1.TableCardinalityRequest) (*runtimev1.TableCardinalityResponse, error) {
observability.AddRequestAttributes(ctx,
attribute.String("args.instance_id", req.InstanceId),
attribute.String("args.table", req.TableName),
attribute.Int("args.priority", int(req.Priority)),
)
if !auth.GetClaims(ctx).CanInstance(req.InstanceId, auth.ReadProfiling) {
return nil, ErrForbidden
}
q := &queries.TableCardinality{
TableName: req.TableName,
}
err := s.runtime.Query(ctx, req.InstanceId, q, int(req.Priority))
if err != nil {
return nil, err
}
return &runtimev1.TableCardinalityResponse{
Cardinality: q.Result,
}, nil
}
type ColumnInfo struct {
Name string
Type string
Unknown int
}
func (s *Server) TableColumns(ctx context.Context, req *runtimev1.TableColumnsRequest) (*runtimev1.TableColumnsResponse, error) {
observability.AddRequestAttributes(ctx,
attribute.String("args.instance_id", req.InstanceId),
attribute.String("args.table", req.TableName),
attribute.Int("args.priority", int(req.Priority)),
)
if !auth.GetClaims(ctx).CanInstance(req.InstanceId, auth.ReadProfiling) {
return nil, ErrForbidden
}
q := &queries.TableColumns{
TableName: req.TableName,
}
err := s.runtime.Query(ctx, req.InstanceId, q, int(req.Priority))
if err != nil {
return nil, err
}
return &runtimev1.TableColumnsResponse{
ProfileColumns: q.Result,
}, nil
}
func (s *Server) TableRows(ctx context.Context, req *runtimev1.TableRowsRequest) (*runtimev1.TableRowsResponse, error) {
observability.AddRequestAttributes(ctx,
attribute.String("args.instance_id", req.InstanceId),
attribute.String("args.table", req.TableName),
attribute.Int("args.limit", int(req.Limit)),
attribute.Int("args.priority", int(req.Priority)),
)
if !auth.GetClaims(ctx).CanInstance(req.InstanceId, auth.ReadProfiling) {
return nil, ErrForbidden
}
limit := int(req.Limit)
if limit == 0 {
limit = _tableHeadDefaultLimit
}
q := &queries.TableHead{
TableName: req.TableName,
Limit: limit,
}
err := s.runtime.Query(ctx, req.InstanceId, q, int(req.Priority))
if err != nil {
return nil, err
}
return &runtimev1.TableRowsResponse{
Data: q.Result,
}, nil
}