Add back the protobuf marshaling inside of influxql

pull/8737/head
Jonathan A. Sternberg 2017-08-23 13:57:47 -05:00
parent ae66d327a7
commit 9cba52b675
4 changed files with 195 additions and 4 deletions

View File

@ -12,6 +12,8 @@ import (
"strings"
"time"
"github.com/gogo/protobuf/proto"
internal "github.com/influxdata/influxdb/influxql/internal"
"github.com/influxdata/influxdb/models"
)
@ -443,6 +445,33 @@ func (a Sources) Measurements() []*Measurement {
return mms
}
// MarshalBinary encodes a list of sources to a binary format.
func (a Sources) MarshalBinary() ([]byte, error) {
var pb internal.Measurements
pb.Items = make([]*internal.Measurement, len(a))
for i, source := range a {
pb.Items[i] = encodeMeasurement(source.(*Measurement))
}
return proto.Marshal(&pb)
}
// UnmarshalBinary decodes binary data into a list of sources.
func (a *Sources) UnmarshalBinary(buf []byte) error {
var pb internal.Measurements
if err := proto.Unmarshal(buf, &pb); err != nil {
return err
}
*a = make(Sources, len(pb.GetItems()))
for i := range pb.GetItems() {
mm, err := decodeMeasurement(pb.GetItems()[i])
if err != nil {
return err
}
(*a)[i] = mm
}
return nil
}
// RequiredPrivileges recursively returns a list of execution privileges required.
func (a Sources) RequiredPrivileges() (ExecutionPrivileges, error) {
var ep ExecutionPrivileges
@ -2423,6 +2452,38 @@ func (s *SelectStatement) NamesInDimension() []string {
return a
}
func encodeMeasurement(mm *Measurement) *internal.Measurement {
pb := &internal.Measurement{
Database: proto.String(mm.Database),
RetentionPolicy: proto.String(mm.RetentionPolicy),
Name: proto.String(mm.Name),
IsTarget: proto.Bool(mm.IsTarget),
}
if mm.Regex != nil {
pb.Regex = proto.String(mm.Regex.Val.String())
}
return pb
}
func decodeMeasurement(pb *internal.Measurement) (*Measurement, error) {
mm := &Measurement{
Database: pb.GetDatabase(),
RetentionPolicy: pb.GetRetentionPolicy(),
Name: pb.GetName(),
IsTarget: pb.GetIsTarget(),
}
if pb.Regex != nil {
regex, err := regexp.Compile(pb.GetRegex())
if err != nil {
return nil, fmt.Errorf("invalid binary measurement regex: value=%q, err=%s", pb.GetRegex(), err)
}
mm.Regex = &RegexLiteral{Val: regex}
}
return mm, nil
}
// walkNames will walk the Expr and return the identifier names used.
func walkNames(exp Expr) []string {
switch expr := exp.(type) {

View File

@ -1,7 +1,3 @@
package influxql // import "github.com/influxdata/influxdb/influxql"
//go:generate tmpl -data=@tmpldata iterator.gen.go.tmpl
//go:generate tmpl -data=@tmpldata point.gen.go.tmpl
//go:generate tmpl -data=@tmpldata functions.gen.go.tmpl
//go:generate protoc --gogo_out=. internal/internal.proto

View File

@ -0,0 +1,120 @@
// Code generated by protoc-gen-gogo.
// source: internal/internal.proto
// DO NOT EDIT!
/*
Package influxql is a generated protocol buffer package.
It is generated from these files:
internal/internal.proto
It has these top-level messages:
Measurements
Measurement
*/
package influxql
import proto "github.com/gogo/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
type Measurements struct {
Items []*Measurement `protobuf:"bytes,1,rep,name=Items" json:"Items,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *Measurements) Reset() { *m = Measurements{} }
func (m *Measurements) String() string { return proto.CompactTextString(m) }
func (*Measurements) ProtoMessage() {}
func (*Measurements) Descriptor() ([]byte, []int) { return fileDescriptorInternal, []int{0} }
func (m *Measurements) GetItems() []*Measurement {
if m != nil {
return m.Items
}
return nil
}
type Measurement struct {
Database *string `protobuf:"bytes,1,opt,name=Database" json:"Database,omitempty"`
RetentionPolicy *string `protobuf:"bytes,2,opt,name=RetentionPolicy" json:"RetentionPolicy,omitempty"`
Name *string `protobuf:"bytes,3,opt,name=Name" json:"Name,omitempty"`
Regex *string `protobuf:"bytes,4,opt,name=Regex" json:"Regex,omitempty"`
IsTarget *bool `protobuf:"varint,5,opt,name=IsTarget" json:"IsTarget,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *Measurement) Reset() { *m = Measurement{} }
func (m *Measurement) String() string { return proto.CompactTextString(m) }
func (*Measurement) ProtoMessage() {}
func (*Measurement) Descriptor() ([]byte, []int) { return fileDescriptorInternal, []int{1} }
func (m *Measurement) GetDatabase() string {
if m != nil && m.Database != nil {
return *m.Database
}
return ""
}
func (m *Measurement) GetRetentionPolicy() string {
if m != nil && m.RetentionPolicy != nil {
return *m.RetentionPolicy
}
return ""
}
func (m *Measurement) GetName() string {
if m != nil && m.Name != nil {
return *m.Name
}
return ""
}
func (m *Measurement) GetRegex() string {
if m != nil && m.Regex != nil {
return *m.Regex
}
return ""
}
func (m *Measurement) GetIsTarget() bool {
if m != nil && m.IsTarget != nil {
return *m.IsTarget
}
return false
}
func init() {
proto.RegisterType((*Measurements)(nil), "influxql.Measurements")
proto.RegisterType((*Measurement)(nil), "influxql.Measurement")
}
func init() { proto.RegisterFile("internal/internal.proto", fileDescriptorInternal) }
var fileDescriptorInternal = []byte{
// 195 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcf, 0xcc, 0x2b, 0x49,
0x2d, 0xca, 0x4b, 0xcc, 0xd1, 0x87, 0x31, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x38, 0x32,
0xf3, 0xd2, 0x72, 0x4a, 0x2b, 0x0a, 0x73, 0x94, 0xac, 0xb9, 0x78, 0x7c, 0x53, 0x13, 0x8b, 0x4b,
0x8b, 0x52, 0x73, 0x53, 0xf3, 0x4a, 0x8a, 0x85, 0xb4, 0xb9, 0x58, 0x3d, 0x4b, 0x52, 0x73, 0x8b,
0x25, 0x18, 0x15, 0x98, 0x35, 0xb8, 0x8d, 0x44, 0xf5, 0x60, 0x2a, 0xf5, 0x90, 0x94, 0x05, 0x41,
0xd4, 0x28, 0xcd, 0x64, 0xe4, 0xe2, 0x46, 0x12, 0x16, 0x92, 0xe2, 0xe2, 0x70, 0x49, 0x2c, 0x49,
0x4c, 0x4a, 0x2c, 0x4e, 0x95, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, 0xf3, 0x85, 0x34, 0xb8,
0xf8, 0x83, 0x52, 0x4b, 0x52, 0xf3, 0x4a, 0x32, 0xf3, 0xf3, 0x02, 0xf2, 0x73, 0x32, 0x93, 0x2b,
0x25, 0x98, 0xc0, 0x4a, 0xd0, 0x85, 0x85, 0x84, 0xb8, 0x58, 0xfc, 0x12, 0x73, 0x53, 0x25, 0x98,
0xc1, 0xd2, 0x60, 0xb6, 0x90, 0x08, 0x17, 0x6b, 0x50, 0x6a, 0x7a, 0x6a, 0x85, 0x04, 0x0b, 0x58,
0x10, 0xc2, 0x01, 0xd9, 0xe7, 0x59, 0x1c, 0x92, 0x58, 0x94, 0x9e, 0x5a, 0x22, 0xc1, 0xaa, 0xc0,
0xa8, 0xc1, 0x11, 0x04, 0xe7, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb8, 0x16, 0x06, 0x23, 0xfc,
0x00, 0x00, 0x00,
}

View File

@ -0,0 +1,14 @@
syntax = "proto2";
package influxql;
message Measurements {
repeated Measurement Items = 1;
}
message Measurement {
optional string Database = 1;
optional string RetentionPolicy = 2;
optional string Name = 3;
optional string Regex = 4;
optional bool IsTarget = 5;
}