-
Notifications
You must be signed in to change notification settings - Fork 198
/
describe.go
48 lines (43 loc) · 936 Bytes
/
describe.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
package cmd
import (
"fmt"
"time"
. "github.com/cube2222/octosql/execution"
"github.com/cube2222/octosql/octosql"
"github.com/cube2222/octosql/physical"
)
var DescribeNodeSchema = physical.NewSchema(
[]physical.SchemaField{
{
Name: "name",
Type: octosql.String,
},
{
Name: "type",
Type: octosql.String,
},
{
Name: "time_field",
Type: octosql.Boolean,
},
},
-1,
)
type DescribeNode struct {
Schema physical.Schema
}
func (d *DescribeNode) Run(ctx ExecutionContext, produce ProduceFn, metaSend MetaSendFn) error {
for i, field := range d.Schema.Fields {
if err := produce(
ProduceFromExecutionContext(ctx),
NewRecord([]octosql.Value{
octosql.NewString(field.Name),
octosql.NewString(field.Type.String()),
octosql.NewBoolean(i == d.Schema.TimeField),
}, false, time.Time{}),
); err != nil {
return fmt.Errorf("couldn't produce record: %w", err)
}
}
return nil
}