forked from Azure/azure-kusto-go
/
frames.go
98 lines (86 loc) · 3.56 KB
/
frames.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
package frames
import (
"context"
"fmt"
"io"
"github.com/SilverdewBaker/azure-kusto-go/kusto/data/errors"
)
const (
// TypeDataTable is the .FrameType that indicates a Kusto DataTable.
TypeDataTable = "DataTable"
// TypeDataSetCompletion is the .FrameType that indicates a Kusto DataSetCompletion.
TypeDataSetCompletion = "DataSetCompletion"
// TypeDataSetHeader is the .FrameType that indicates a Kusto DataSetHeader.
TypeDataSetHeader = "DataSetHeader"
// TypeTableHeader is the .FrameType that indicates a Kusto TableHeader.
TypeTableHeader = "TableHeader"
// TypeTableFragment is the .FrameType that indicates a Kusto TableFragment.
TypeTableFragment = "TableFragment"
// TypeTableProgress is the .FrameType that indicates a Kusto TableProgress.
TypeTableProgress = "TableProgress"
// TypeTableCompletion is the .FrameType that indicates a Kusto TableCompletion.
TypeTableCompletion = "TableCompletion"
)
// These constants represent keys for fields when unmarshalling various JSON dicts representing Kusto frames.
const (
FieldFrameType = "FrameType"
FieldTableID = "TableId"
FieldTableKind = "TableKind"
FieldTableName = "TableName"
FieldColumns = "Columns"
FieldRows = "Rows"
FieldColumnName = "ColumnName"
FieldColumnType = "ColumnType"
FieldCount = "FieldCount"
FieldTableFragmentType = "TableFragmentType"
FieldTableProgress = "TableProgress"
FieldRowCount = "RowCount"
)
// TableKind describes the kind of table.
type TableKind string
const (
// QueryProperties is a dataTable.TableKind that contains properties about the query itself.
// The dataTable.TableName is usually ExtendedProperties.
QueryProperties TableKind = "QueryProperties"
// PrimaryResult is a dataTable.TableKind that contains the query information the user wants.
// The dataTable.TableName is PrimaryResult.
PrimaryResult TableKind = "PrimaryResult"
// QueryCompletionInformation contains information on how long the query took.
// The dataTable.TableName is QueryCompletionInformation.
QueryCompletionInformation TableKind = "QueryCompletionInformation"
QueryTraceLog TableKind = "QueryTraceLog"
QueryPerfLog TableKind = "QueryPerfLog"
QueryResult TableKind = "QueryResult"
TableOfContents TableKind = "TableOfContents"
QueryPlan TableKind = "QueryPlan"
ExtendedProperties TableKind = "@ExtendedProperties"
UnknownTableKind TableKind = "Unknown"
)
// Decoder provides a function that will decode an incoming data stream and return a channel of Frame objects.
type Decoder interface {
// Decode decodes an io.Reader representing a stream of Kusto frames into our Frame representation.
// The type and order of frames is dependent on the REST interface version and the progressive frame settings.
Decode(ctx context.Context, r io.ReadCloser, op errors.Op) chan Frame
}
// Frame is a type of Kusto frame as defined in the reference document.
type Frame interface {
IsFrame()
}
// Error is not actually a Kusto frame, but is used to signal the end of a stream
// where we encountered an error. Error implements error.
type Error struct {
Msg string
}
// Error implements error.Error().
func (e Error) Error() string {
return e.Msg
}
// IsFrame implements Frame.IsFrame().
func (Error) IsFrame() {}
// Errorf write a frames.Error to ch with fmt.Sprint(s, a...).
func Errorf(ctx context.Context, ch chan Frame, s string, a ...interface{}) {
select {
case <-ctx.Done():
case ch <- Error{Msg: fmt.Sprintf(s, a...)}:
}
}