diff --git a/pkg/meta/meta.go b/pkg/meta/meta.go index d00ad068a..057844654 100644 --- a/pkg/meta/meta.go +++ b/pkg/meta/meta.go @@ -206,10 +206,8 @@ func processAlter(ctx context.Context, astmt spqrparser.Statement, mngr EntityMg func processAlterDistribution(ctx context.Context, astmt spqrparser.Statement, mngr EntityMgr, cli *clientinteractor.PSQLInteractor) error { switch stmt := astmt.(type) { case *spqrparser.AttachRelation: - rels := []*distributions.DistributedRelation{{ - Name: stmt.Relation.Name, - ColumnNames: stmt.Relation.Columns, - }, + rels := []*distributions.DistributedRelation{ + distributions.DistributedRelationFromSQL(stmt.Relation), } if err := mngr.AlterDistributionAttach(ctx, stmt.Distribution.ID, rels); err != nil { return err diff --git a/pkg/models/distributions/distribution.go b/pkg/models/distributions/distribution.go index cff05c90b..e72ecfc17 100644 --- a/pkg/models/distributions/distribution.go +++ b/pkg/models/distributions/distribution.go @@ -3,39 +3,92 @@ package distributions import ( proto "github.com/pg-sharding/spqr/pkg/protos" "github.com/pg-sharding/spqr/qdb" + spqrparser "github.com/pg-sharding/spqr/yacc/console" ) +type DistributionKeyEntry struct { + Column string + HashFunction string +} + type DistributedRelation struct { - Name string - ColumnNames []string + Name string + DistributionKey []DistributionKeyEntry } -func DistributedRelationFromDB(distr *qdb.DistributedRelation) *DistributedRelation { - return &DistributedRelation{ - Name: distr.Name, - ColumnNames: distr.ColumnNames, +func DistributedRelationFromDB(rel *qdb.DistributedRelation) *DistributedRelation { + rdistr := &DistributedRelation{ + Name: rel.Name, } + + for _, e := range rel.DistributionKey { + rdistr.DistributionKey = append(rdistr.DistributionKey, DistributionKeyEntry{ + Column: e.Column, + HashFunction: e.HashFunction, + }) + } + + return rdistr } -func DistributedRelationToDB(distr *DistributedRelation) *qdb.DistributedRelation { - return &qdb.DistributedRelation{ - Name: distr.Name, - ColumnNames: distr.ColumnNames, +func DistributedRelationToDB(rel *DistributedRelation) *qdb.DistributedRelation { + rdistr := &qdb.DistributedRelation{ + Name: rel.Name, } + + for _, e := range rel.DistributionKey { + rdistr.DistributionKey = append(rdistr.DistributionKey, qdb.DistributionKeyEntry{ + Column: e.Column, + HashFunction: e.HashFunction, + }) + } + + return rdistr } -func DistributedRelatitonToProto(distr *DistributedRelation) *proto.DistributedRelation { - return &proto.DistributedRelation{ - Name: distr.Name, - Columns: distr.ColumnNames, +func DistributedRelatitonToProto(rel *DistributedRelation) *proto.DistributedRelation { + rdistr := &proto.DistributedRelation{ + Name: rel.Name, + } + + for _, e := range rel.DistributionKey { + rdistr.DistributionKey = append(rdistr.DistributionKey, &proto.DistributionKeyEntry{ + Column: e.Column, + HashFunction: e.HashFunction, + }) } + + return rdistr } func DistributedRelationFromProto(rel *proto.DistributedRelation) *DistributedRelation { - return &DistributedRelation{ - Name: rel.Name, - ColumnNames: rel.Columns, + rdistr := &DistributedRelation{ + Name: rel.Name, + } + + for _, e := range rel.DistributionKey { + rdistr.DistributionKey = append(rdistr.DistributionKey, DistributionKeyEntry{ + Column: e.Column, + HashFunction: e.HashFunction, + }) } + + return rdistr +} + +func DistributedRelationFromSQL(rel *spqrparser.DistributedRelation) *DistributedRelation { + rdistr := &DistributedRelation{ + Name: rel.Name, + } + + for _, e := range rel.DistributionKey { + rdistr.DistributionKey = append(rdistr.DistributionKey, DistributionKeyEntry{ + Column: e.Column, + HashFunction: e.HashFunction, + }) + } + + return rdistr } type Distribution struct { @@ -77,10 +130,7 @@ func DistributionFromProto(ds *proto.Distribution) *Distribution { func DistributionToProto(ds *Distribution) *proto.Distribution { drels := make([]*proto.DistributedRelation, 0) for _, r := range ds.Relations { - drels = append(drels, &proto.DistributedRelation{ - Name: r.Name, - Columns: r.ColumnNames, - }) + drels = append(drels, DistributedRelatitonToProto(r)) } return &proto.Distribution{ Id: ds.Id, diff --git a/pkg/protos/distribution.pb.go b/pkg/protos/distribution.pb.go index 3420d0e8a..980aab253 100644 --- a/pkg/protos/distribution.pb.go +++ b/pkg/protos/distribution.pb.go @@ -20,19 +20,74 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type DistributionKeyEntry struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Column string `protobuf:"bytes,1,opt,name=column,proto3" json:"column,omitempty"` + HashFunction string `protobuf:"bytes,2,opt,name=hashFunction,proto3" json:"hashFunction,omitempty"` +} + +func (x *DistributionKeyEntry) Reset() { + *x = DistributionKeyEntry{} + if protoimpl.UnsafeEnabled { + mi := &file_protos_distribution_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DistributionKeyEntry) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DistributionKeyEntry) ProtoMessage() {} + +func (x *DistributionKeyEntry) ProtoReflect() protoreflect.Message { + mi := &file_protos_distribution_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DistributionKeyEntry.ProtoReflect.Descriptor instead. +func (*DistributionKeyEntry) Descriptor() ([]byte, []int) { + return file_protos_distribution_proto_rawDescGZIP(), []int{0} +} + +func (x *DistributionKeyEntry) GetColumn() string { + if x != nil { + return x.Column + } + return "" +} + +func (x *DistributionKeyEntry) GetHashFunction() string { + if x != nil { + return x.HashFunction + } + return "" +} + type DistributedRelation struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Columns []string `protobuf:"bytes,2,rep,name=columns,proto3" json:"columns,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + DistributionKey []*DistributionKeyEntry `protobuf:"bytes,2,rep,name=distributionKey,proto3" json:"distributionKey,omitempty"` } func (x *DistributedRelation) Reset() { *x = DistributedRelation{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[0] + mi := &file_protos_distribution_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -45,7 +100,7 @@ func (x *DistributedRelation) String() string { func (*DistributedRelation) ProtoMessage() {} func (x *DistributedRelation) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[0] + mi := &file_protos_distribution_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -58,7 +113,7 @@ func (x *DistributedRelation) ProtoReflect() protoreflect.Message { // Deprecated: Use DistributedRelation.ProtoReflect.Descriptor instead. func (*DistributedRelation) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{0} + return file_protos_distribution_proto_rawDescGZIP(), []int{1} } func (x *DistributedRelation) GetName() string { @@ -68,9 +123,9 @@ func (x *DistributedRelation) GetName() string { return "" } -func (x *DistributedRelation) GetColumns() []string { +func (x *DistributedRelation) GetDistributionKey() []*DistributionKeyEntry { if x != nil { - return x.Columns + return x.DistributionKey } return nil } @@ -88,7 +143,7 @@ type Distribution struct { func (x *Distribution) Reset() { *x = Distribution{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[1] + mi := &file_protos_distribution_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -101,7 +156,7 @@ func (x *Distribution) String() string { func (*Distribution) ProtoMessage() {} func (x *Distribution) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[1] + mi := &file_protos_distribution_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -114,7 +169,7 @@ func (x *Distribution) ProtoReflect() protoreflect.Message { // Deprecated: Use Distribution.ProtoReflect.Descriptor instead. func (*Distribution) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{1} + return file_protos_distribution_proto_rawDescGZIP(), []int{2} } func (x *Distribution) GetId() string { @@ -149,7 +204,7 @@ type CreateDistributionRequest struct { func (x *CreateDistributionRequest) Reset() { *x = CreateDistributionRequest{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[2] + mi := &file_protos_distribution_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -162,7 +217,7 @@ func (x *CreateDistributionRequest) String() string { func (*CreateDistributionRequest) ProtoMessage() {} func (x *CreateDistributionRequest) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[2] + mi := &file_protos_distribution_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -175,7 +230,7 @@ func (x *CreateDistributionRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use CreateDistributionRequest.ProtoReflect.Descriptor instead. func (*CreateDistributionRequest) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{2} + return file_protos_distribution_proto_rawDescGZIP(), []int{3} } func (x *CreateDistributionRequest) GetDistributions() []*Distribution { @@ -194,7 +249,7 @@ type CreateDistributionReply struct { func (x *CreateDistributionReply) Reset() { *x = CreateDistributionReply{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[3] + mi := &file_protos_distribution_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -207,7 +262,7 @@ func (x *CreateDistributionReply) String() string { func (*CreateDistributionReply) ProtoMessage() {} func (x *CreateDistributionReply) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[3] + mi := &file_protos_distribution_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -220,7 +275,7 @@ func (x *CreateDistributionReply) ProtoReflect() protoreflect.Message { // Deprecated: Use CreateDistributionReply.ProtoReflect.Descriptor instead. func (*CreateDistributionReply) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{3} + return file_protos_distribution_proto_rawDescGZIP(), []int{4} } type ListDistributionsRequest struct { @@ -232,7 +287,7 @@ type ListDistributionsRequest struct { func (x *ListDistributionsRequest) Reset() { *x = ListDistributionsRequest{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[4] + mi := &file_protos_distribution_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -245,7 +300,7 @@ func (x *ListDistributionsRequest) String() string { func (*ListDistributionsRequest) ProtoMessage() {} func (x *ListDistributionsRequest) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[4] + mi := &file_protos_distribution_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -258,7 +313,7 @@ func (x *ListDistributionsRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ListDistributionsRequest.ProtoReflect.Descriptor instead. func (*ListDistributionsRequest) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{4} + return file_protos_distribution_proto_rawDescGZIP(), []int{5} } type ListDistributionsReply struct { @@ -272,7 +327,7 @@ type ListDistributionsReply struct { func (x *ListDistributionsReply) Reset() { *x = ListDistributionsReply{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[5] + mi := &file_protos_distribution_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -285,7 +340,7 @@ func (x *ListDistributionsReply) String() string { func (*ListDistributionsReply) ProtoMessage() {} func (x *ListDistributionsReply) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[5] + mi := &file_protos_distribution_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -298,7 +353,7 @@ func (x *ListDistributionsReply) ProtoReflect() protoreflect.Message { // Deprecated: Use ListDistributionsReply.ProtoReflect.Descriptor instead. func (*ListDistributionsReply) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{5} + return file_protos_distribution_proto_rawDescGZIP(), []int{6} } func (x *ListDistributionsReply) GetDistributions() []*Distribution { @@ -319,7 +374,7 @@ type DropDistributionRequest struct { func (x *DropDistributionRequest) Reset() { *x = DropDistributionRequest{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[6] + mi := &file_protos_distribution_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -332,7 +387,7 @@ func (x *DropDistributionRequest) String() string { func (*DropDistributionRequest) ProtoMessage() {} func (x *DropDistributionRequest) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[6] + mi := &file_protos_distribution_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -345,7 +400,7 @@ func (x *DropDistributionRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DropDistributionRequest.ProtoReflect.Descriptor instead. func (*DropDistributionRequest) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{6} + return file_protos_distribution_proto_rawDescGZIP(), []int{7} } func (x *DropDistributionRequest) GetIds() []string { @@ -364,7 +419,7 @@ type DropDistributionReply struct { func (x *DropDistributionReply) Reset() { *x = DropDistributionReply{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[7] + mi := &file_protos_distribution_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -377,7 +432,7 @@ func (x *DropDistributionReply) String() string { func (*DropDistributionReply) ProtoMessage() {} func (x *DropDistributionReply) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[7] + mi := &file_protos_distribution_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -390,7 +445,7 @@ func (x *DropDistributionReply) ProtoReflect() protoreflect.Message { // Deprecated: Use DropDistributionReply.ProtoReflect.Descriptor instead. func (*DropDistributionReply) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{7} + return file_protos_distribution_proto_rawDescGZIP(), []int{8} } type AlterDistributionAttachRequest struct { @@ -406,7 +461,7 @@ type AlterDistributionAttachRequest struct { func (x *AlterDistributionAttachRequest) Reset() { *x = AlterDistributionAttachRequest{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[8] + mi := &file_protos_distribution_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -419,7 +474,7 @@ func (x *AlterDistributionAttachRequest) String() string { func (*AlterDistributionAttachRequest) ProtoMessage() {} func (x *AlterDistributionAttachRequest) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[8] + mi := &file_protos_distribution_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -432,7 +487,7 @@ func (x *AlterDistributionAttachRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use AlterDistributionAttachRequest.ProtoReflect.Descriptor instead. func (*AlterDistributionAttachRequest) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{8} + return file_protos_distribution_proto_rawDescGZIP(), []int{9} } func (x *AlterDistributionAttachRequest) GetId() string { @@ -465,7 +520,7 @@ type AlterDistributionAttachReply struct { func (x *AlterDistributionAttachReply) Reset() { *x = AlterDistributionAttachReply{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[9] + mi := &file_protos_distribution_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -478,7 +533,7 @@ func (x *AlterDistributionAttachReply) String() string { func (*AlterDistributionAttachReply) ProtoMessage() {} func (x *AlterDistributionAttachReply) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[9] + mi := &file_protos_distribution_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -491,7 +546,7 @@ func (x *AlterDistributionAttachReply) ProtoReflect() protoreflect.Message { // Deprecated: Use AlterDistributionAttachReply.ProtoReflect.Descriptor instead. func (*AlterDistributionAttachReply) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{9} + return file_protos_distribution_proto_rawDescGZIP(), []int{10} } type AlterDistributionDetachRequest struct { @@ -506,7 +561,7 @@ type AlterDistributionDetachRequest struct { func (x *AlterDistributionDetachRequest) Reset() { *x = AlterDistributionDetachRequest{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[10] + mi := &file_protos_distribution_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -519,7 +574,7 @@ func (x *AlterDistributionDetachRequest) String() string { func (*AlterDistributionDetachRequest) ProtoMessage() {} func (x *AlterDistributionDetachRequest) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[10] + mi := &file_protos_distribution_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -532,7 +587,7 @@ func (x *AlterDistributionDetachRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use AlterDistributionDetachRequest.ProtoReflect.Descriptor instead. func (*AlterDistributionDetachRequest) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{10} + return file_protos_distribution_proto_rawDescGZIP(), []int{11} } func (x *AlterDistributionDetachRequest) GetId() string { @@ -558,7 +613,7 @@ type AlterDistributionDetachReply struct { func (x *AlterDistributionDetachReply) Reset() { *x = AlterDistributionDetachReply{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[11] + mi := &file_protos_distribution_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -571,7 +626,7 @@ func (x *AlterDistributionDetachReply) String() string { func (*AlterDistributionDetachReply) ProtoMessage() {} func (x *AlterDistributionDetachReply) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[11] + mi := &file_protos_distribution_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -584,7 +639,7 @@ func (x *AlterDistributionDetachReply) ProtoReflect() protoreflect.Message { // Deprecated: Use AlterDistributionDetachReply.ProtoReflect.Descriptor instead. func (*AlterDistributionDetachReply) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{11} + return file_protos_distribution_proto_rawDescGZIP(), []int{12} } type GetDistributionRequest struct { @@ -598,7 +653,7 @@ type GetDistributionRequest struct { func (x *GetDistributionRequest) Reset() { *x = GetDistributionRequest{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[12] + mi := &file_protos_distribution_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -611,7 +666,7 @@ func (x *GetDistributionRequest) String() string { func (*GetDistributionRequest) ProtoMessage() {} func (x *GetDistributionRequest) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[12] + mi := &file_protos_distribution_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -624,7 +679,7 @@ func (x *GetDistributionRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetDistributionRequest.ProtoReflect.Descriptor instead. func (*GetDistributionRequest) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{12} + return file_protos_distribution_proto_rawDescGZIP(), []int{13} } func (x *GetDistributionRequest) GetId() string { @@ -645,7 +700,7 @@ type GetDistributionReply struct { func (x *GetDistributionReply) Reset() { *x = GetDistributionReply{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[13] + mi := &file_protos_distribution_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -658,7 +713,7 @@ func (x *GetDistributionReply) String() string { func (*GetDistributionReply) ProtoMessage() {} func (x *GetDistributionReply) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[13] + mi := &file_protos_distribution_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -671,7 +726,7 @@ func (x *GetDistributionReply) ProtoReflect() protoreflect.Message { // Deprecated: Use GetDistributionReply.ProtoReflect.Descriptor instead. func (*GetDistributionReply) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{13} + return file_protos_distribution_proto_rawDescGZIP(), []int{14} } func (x *GetDistributionReply) GetDistribution() *Distribution { @@ -692,7 +747,7 @@ type GetRelationDistributionRequest struct { func (x *GetRelationDistributionRequest) Reset() { *x = GetRelationDistributionRequest{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[14] + mi := &file_protos_distribution_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -705,7 +760,7 @@ func (x *GetRelationDistributionRequest) String() string { func (*GetRelationDistributionRequest) ProtoMessage() {} func (x *GetRelationDistributionRequest) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[14] + mi := &file_protos_distribution_proto_msgTypes[15] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -718,7 +773,7 @@ func (x *GetRelationDistributionRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetRelationDistributionRequest.ProtoReflect.Descriptor instead. func (*GetRelationDistributionRequest) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{14} + return file_protos_distribution_proto_rawDescGZIP(), []int{15} } func (x *GetRelationDistributionRequest) GetId() string { @@ -739,7 +794,7 @@ type GetRelationDistributionReply struct { func (x *GetRelationDistributionReply) Reset() { *x = GetRelationDistributionReply{} if protoimpl.UnsafeEnabled { - mi := &file_protos_distribution_proto_msgTypes[15] + mi := &file_protos_distribution_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -752,7 +807,7 @@ func (x *GetRelationDistributionReply) String() string { func (*GetRelationDistributionReply) ProtoMessage() {} func (x *GetRelationDistributionReply) ProtoReflect() protoreflect.Message { - mi := &file_protos_distribution_proto_msgTypes[15] + mi := &file_protos_distribution_proto_msgTypes[16] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -765,7 +820,7 @@ func (x *GetRelationDistributionReply) ProtoReflect() protoreflect.Message { // Deprecated: Use GetRelationDistributionReply.ProtoReflect.Descriptor instead. func (*GetRelationDistributionReply) Descriptor() ([]byte, []int) { - return file_protos_distribution_proto_rawDescGZIP(), []int{15} + return file_protos_distribution_proto_rawDescGZIP(), []int{16} } func (x *GetRelationDistributionReply) GetDistribution() *Distribution { @@ -780,11 +835,19 @@ var File_protos_distribution_proto protoreflect.FileDescriptor var file_protos_distribution_proto_rawDesc = []byte{ 0x0a, 0x19, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x73, 0x70, 0x71, - 0x72, 0x22, 0x43, 0x0a, 0x13, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, - 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, - 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x63, - 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x22, 0x79, 0x0a, 0x0c, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, + 0x72, 0x22, 0x52, 0x0a, 0x14, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, + 0x6e, 0x4b, 0x65, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, 0x6c, + 0x75, 0x6d, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x6f, 0x6c, 0x75, 0x6d, + 0x6e, 0x12, 0x22, 0x0a, 0x0c, 0x68, 0x61, 0x73, 0x68, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x68, 0x61, 0x73, 0x68, 0x46, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x6f, 0x0a, 0x13, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, + 0x75, 0x74, 0x65, 0x64, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x12, 0x44, 0x0a, 0x0f, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, + 0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x73, 0x70, 0x71, 0x72, + 0x2e, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x4b, 0x65, 0x79, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0f, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, + 0x69, 0x6f, 0x6e, 0x4b, 0x65, 0x79, 0x22, 0x79, 0x0a, 0x0c, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x43, 0x6f, 0x6c, @@ -902,51 +965,53 @@ func file_protos_distribution_proto_rawDescGZIP() []byte { return file_protos_distribution_proto_rawDescData } -var file_protos_distribution_proto_msgTypes = make([]protoimpl.MessageInfo, 16) +var file_protos_distribution_proto_msgTypes = make([]protoimpl.MessageInfo, 17) var file_protos_distribution_proto_goTypes = []interface{}{ - (*DistributedRelation)(nil), // 0: spqr.DistributedRelation - (*Distribution)(nil), // 1: spqr.Distribution - (*CreateDistributionRequest)(nil), // 2: spqr.CreateDistributionRequest - (*CreateDistributionReply)(nil), // 3: spqr.CreateDistributionReply - (*ListDistributionsRequest)(nil), // 4: spqr.ListDistributionsRequest - (*ListDistributionsReply)(nil), // 5: spqr.ListDistributionsReply - (*DropDistributionRequest)(nil), // 6: spqr.DropDistributionRequest - (*DropDistributionReply)(nil), // 7: spqr.DropDistributionReply - (*AlterDistributionAttachRequest)(nil), // 8: spqr.AlterDistributionAttachRequest - (*AlterDistributionAttachReply)(nil), // 9: spqr.AlterDistributionAttachReply - (*AlterDistributionDetachRequest)(nil), // 10: spqr.AlterDistributionDetachRequest - (*AlterDistributionDetachReply)(nil), // 11: spqr.AlterDistributionDetachReply - (*GetDistributionRequest)(nil), // 12: spqr.GetDistributionRequest - (*GetDistributionReply)(nil), // 13: spqr.GetDistributionReply - (*GetRelationDistributionRequest)(nil), // 14: spqr.GetRelationDistributionRequest - (*GetRelationDistributionReply)(nil), // 15: spqr.GetRelationDistributionReply + (*DistributionKeyEntry)(nil), // 0: spqr.DistributionKeyEntry + (*DistributedRelation)(nil), // 1: spqr.DistributedRelation + (*Distribution)(nil), // 2: spqr.Distribution + (*CreateDistributionRequest)(nil), // 3: spqr.CreateDistributionRequest + (*CreateDistributionReply)(nil), // 4: spqr.CreateDistributionReply + (*ListDistributionsRequest)(nil), // 5: spqr.ListDistributionsRequest + (*ListDistributionsReply)(nil), // 6: spqr.ListDistributionsReply + (*DropDistributionRequest)(nil), // 7: spqr.DropDistributionRequest + (*DropDistributionReply)(nil), // 8: spqr.DropDistributionReply + (*AlterDistributionAttachRequest)(nil), // 9: spqr.AlterDistributionAttachRequest + (*AlterDistributionAttachReply)(nil), // 10: spqr.AlterDistributionAttachReply + (*AlterDistributionDetachRequest)(nil), // 11: spqr.AlterDistributionDetachRequest + (*AlterDistributionDetachReply)(nil), // 12: spqr.AlterDistributionDetachReply + (*GetDistributionRequest)(nil), // 13: spqr.GetDistributionRequest + (*GetDistributionReply)(nil), // 14: spqr.GetDistributionReply + (*GetRelationDistributionRequest)(nil), // 15: spqr.GetRelationDistributionRequest + (*GetRelationDistributionReply)(nil), // 16: spqr.GetRelationDistributionReply } var file_protos_distribution_proto_depIdxs = []int32{ - 0, // 0: spqr.Distribution.relations:type_name -> spqr.DistributedRelation - 1, // 1: spqr.CreateDistributionRequest.distributions:type_name -> spqr.Distribution - 1, // 2: spqr.ListDistributionsReply.distributions:type_name -> spqr.Distribution - 0, // 3: spqr.AlterDistributionAttachRequest.relations:type_name -> spqr.DistributedRelation - 1, // 4: spqr.GetDistributionReply.distribution:type_name -> spqr.Distribution - 1, // 5: spqr.GetRelationDistributionReply.distribution:type_name -> spqr.Distribution - 2, // 6: spqr.DistributionService.CreateDistribution:input_type -> spqr.CreateDistributionRequest - 6, // 7: spqr.DistributionService.DropDistribution:input_type -> spqr.DropDistributionRequest - 4, // 8: spqr.DistributionService.ListDistributions:input_type -> spqr.ListDistributionsRequest - 8, // 9: spqr.DistributionService.AlterDistributionAttach:input_type -> spqr.AlterDistributionAttachRequest - 10, // 10: spqr.DistributionService.AlterDistributionDetach:input_type -> spqr.AlterDistributionDetachRequest - 12, // 11: spqr.DistributionService.GetDistribution:input_type -> spqr.GetDistributionRequest - 14, // 12: spqr.DistributionService.GetRelationDistribution:input_type -> spqr.GetRelationDistributionRequest - 3, // 13: spqr.DistributionService.CreateDistribution:output_type -> spqr.CreateDistributionReply - 7, // 14: spqr.DistributionService.DropDistribution:output_type -> spqr.DropDistributionReply - 5, // 15: spqr.DistributionService.ListDistributions:output_type -> spqr.ListDistributionsReply - 9, // 16: spqr.DistributionService.AlterDistributionAttach:output_type -> spqr.AlterDistributionAttachReply - 11, // 17: spqr.DistributionService.AlterDistributionDetach:output_type -> spqr.AlterDistributionDetachReply - 13, // 18: spqr.DistributionService.GetDistribution:output_type -> spqr.GetDistributionReply - 15, // 19: spqr.DistributionService.GetRelationDistribution:output_type -> spqr.GetRelationDistributionReply - 13, // [13:20] is the sub-list for method output_type - 6, // [6:13] is the sub-list for method input_type - 6, // [6:6] is the sub-list for extension type_name - 6, // [6:6] is the sub-list for extension extendee - 0, // [0:6] is the sub-list for field type_name + 0, // 0: spqr.DistributedRelation.distributionKey:type_name -> spqr.DistributionKeyEntry + 1, // 1: spqr.Distribution.relations:type_name -> spqr.DistributedRelation + 2, // 2: spqr.CreateDistributionRequest.distributions:type_name -> spqr.Distribution + 2, // 3: spqr.ListDistributionsReply.distributions:type_name -> spqr.Distribution + 1, // 4: spqr.AlterDistributionAttachRequest.relations:type_name -> spqr.DistributedRelation + 2, // 5: spqr.GetDistributionReply.distribution:type_name -> spqr.Distribution + 2, // 6: spqr.GetRelationDistributionReply.distribution:type_name -> spqr.Distribution + 3, // 7: spqr.DistributionService.CreateDistribution:input_type -> spqr.CreateDistributionRequest + 7, // 8: spqr.DistributionService.DropDistribution:input_type -> spqr.DropDistributionRequest + 5, // 9: spqr.DistributionService.ListDistributions:input_type -> spqr.ListDistributionsRequest + 9, // 10: spqr.DistributionService.AlterDistributionAttach:input_type -> spqr.AlterDistributionAttachRequest + 11, // 11: spqr.DistributionService.AlterDistributionDetach:input_type -> spqr.AlterDistributionDetachRequest + 13, // 12: spqr.DistributionService.GetDistribution:input_type -> spqr.GetDistributionRequest + 15, // 13: spqr.DistributionService.GetRelationDistribution:input_type -> spqr.GetRelationDistributionRequest + 4, // 14: spqr.DistributionService.CreateDistribution:output_type -> spqr.CreateDistributionReply + 8, // 15: spqr.DistributionService.DropDistribution:output_type -> spqr.DropDistributionReply + 6, // 16: spqr.DistributionService.ListDistributions:output_type -> spqr.ListDistributionsReply + 10, // 17: spqr.DistributionService.AlterDistributionAttach:output_type -> spqr.AlterDistributionAttachReply + 12, // 18: spqr.DistributionService.AlterDistributionDetach:output_type -> spqr.AlterDistributionDetachReply + 14, // 19: spqr.DistributionService.GetDistribution:output_type -> spqr.GetDistributionReply + 16, // 20: spqr.DistributionService.GetRelationDistribution:output_type -> spqr.GetRelationDistributionReply + 14, // [14:21] is the sub-list for method output_type + 7, // [7:14] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name } func init() { file_protos_distribution_proto_init() } @@ -956,7 +1021,7 @@ func file_protos_distribution_proto_init() { } if !protoimpl.UnsafeEnabled { file_protos_distribution_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DistributedRelation); i { + switch v := v.(*DistributionKeyEntry); i { case 0: return &v.state case 1: @@ -968,7 +1033,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Distribution); i { + switch v := v.(*DistributedRelation); i { case 0: return &v.state case 1: @@ -980,7 +1045,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateDistributionRequest); i { + switch v := v.(*Distribution); i { case 0: return &v.state case 1: @@ -992,7 +1057,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CreateDistributionReply); i { + switch v := v.(*CreateDistributionRequest); i { case 0: return &v.state case 1: @@ -1004,7 +1069,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListDistributionsRequest); i { + switch v := v.(*CreateDistributionReply); i { case 0: return &v.state case 1: @@ -1016,7 +1081,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ListDistributionsReply); i { + switch v := v.(*ListDistributionsRequest); i { case 0: return &v.state case 1: @@ -1028,7 +1093,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DropDistributionRequest); i { + switch v := v.(*ListDistributionsReply); i { case 0: return &v.state case 1: @@ -1040,7 +1105,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DropDistributionReply); i { + switch v := v.(*DropDistributionRequest); i { case 0: return &v.state case 1: @@ -1052,7 +1117,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AlterDistributionAttachRequest); i { + switch v := v.(*DropDistributionReply); i { case 0: return &v.state case 1: @@ -1064,7 +1129,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AlterDistributionAttachReply); i { + switch v := v.(*AlterDistributionAttachRequest); i { case 0: return &v.state case 1: @@ -1076,7 +1141,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AlterDistributionDetachRequest); i { + switch v := v.(*AlterDistributionAttachReply); i { case 0: return &v.state case 1: @@ -1088,7 +1153,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AlterDistributionDetachReply); i { + switch v := v.(*AlterDistributionDetachRequest); i { case 0: return &v.state case 1: @@ -1100,7 +1165,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetDistributionRequest); i { + switch v := v.(*AlterDistributionDetachReply); i { case 0: return &v.state case 1: @@ -1112,7 +1177,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetDistributionReply); i { + switch v := v.(*GetDistributionRequest); i { case 0: return &v.state case 1: @@ -1124,7 +1189,7 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetRelationDistributionRequest); i { + switch v := v.(*GetDistributionReply); i { case 0: return &v.state case 1: @@ -1136,6 +1201,18 @@ func file_protos_distribution_proto_init() { } } file_protos_distribution_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetRelationDistributionRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_protos_distribution_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetRelationDistributionReply); i { case 0: return &v.state @@ -1154,7 +1231,7 @@ func file_protos_distribution_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_protos_distribution_proto_rawDesc, NumEnums: 0, - NumMessages: 16, + NumMessages: 17, NumExtensions: 0, NumServices: 1, }, diff --git a/protos/distribution.proto b/protos/distribution.proto index 8c9786dc9..494e6c287 100644 --- a/protos/distribution.proto +++ b/protos/distribution.proto @@ -4,9 +4,14 @@ package spqr; option go_package = "spqr/proto"; +message DistributionKeyEntry { + string column = 1; + string hashFunction = 2; +} + message DistributedRelation { string name = 1; - repeated string columns = 2; + repeated DistributionKeyEntry distributionKey = 2; } message Distribution{ diff --git a/qdb/memqdb.go b/qdb/memqdb.go index cc1300cd7..f7ea05bf3 100644 --- a/qdb/memqdb.go +++ b/qdb/memqdb.go @@ -754,8 +754,8 @@ func (q *MemQDB) AlterDistributionAttach(_ context.Context, id string, rels []*D } ds.Relations[r.Name] = &DistributedRelation{ - Name: r.Name, - ColumnNames: r.ColumnNames, + Name: r.Name, + DistributionKey: r.DistributionKey, } q.RelationDistribution[r.Name] = id if err := ExecuteCommands(q.DumpState, NewUpdateCommand(q.RelationDistribution, r.Name, id)); err != nil { diff --git a/qdb/memqdb_test.go b/qdb/memqdb_test.go index 8430e66d2..c9d32c4c2 100644 --- a/qdb/memqdb_test.go +++ b/qdb/memqdb_test.go @@ -134,8 +134,11 @@ func TestDistributions(t *testing.T) { relation := &qdb.DistributedRelation{ Name: "r1", - ColumnNames: []string{ - "c1", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "c1", + HashFunction: "", + }, }, } assert.NoError(memqdb.AlterDistributionAttach(ctx, "ds1", []*qdb.DistributedRelation{ diff --git a/qdb/models.go b/qdb/models.go index 750a14f7e..9db362d69 100644 --- a/qdb/models.go +++ b/qdb/models.go @@ -87,9 +87,14 @@ var ( ColumnTypeUinteger = "uinteger" ) +type DistributionKeyEntry struct { + Column string `json:"column"` + HashFunction string `json:"hash"` +} + type DistributedRelation struct { - Name string `json:"name"` - ColumnNames []string `json:"column_names"` + Name string `json:"name"` + DistributionKey []DistributionKeyEntry `json:"column_names"` } type Distribution struct { diff --git a/router/qrouter/proxy_routing.go b/router/qrouter/proxy_routing.go index 72dedb4af..5c9e6bdfe 100644 --- a/router/qrouter/proxy_routing.go +++ b/router/qrouter/proxy_routing.go @@ -251,8 +251,8 @@ func (qr *ProxyQrouter) RecordShardingColumnValue(meta *RoutingMetadataContext, } else { // TODO: optimize ok := false - for _, c := range ds.Relations[resolvedRelation.RelationName].ColumnNames { - if c == colname { + for _, de := range ds.Relations[resolvedRelation.RelationName].DistributionKey { + if de.Column == colname { ok = true break } diff --git a/router/qrouter/proxy_routing_test.go b/router/qrouter/proxy_routing_test.go index 9bc33cba3..081590515 100644 --- a/router/qrouter/proxy_routing_test.go +++ b/router/qrouter/proxy_routing_test.go @@ -130,8 +130,12 @@ func TestComment(t *testing.T) { ID: distribution, Relations: map[string]*qdb.DistributedRelation{ "xx": { - Name: "xx", - ColumnNames: []string{"i"}, + Name: "xx", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, }, }) @@ -228,24 +232,44 @@ func TestSingleShard(t *testing.T) { ID: distribution, Relations: map[string]*qdb.DistributedRelation{ "t": { - Name: "t", - ColumnNames: []string{"i"}, + Name: "t", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, "yy": { - Name: "yy", - ColumnNames: []string{"i"}, + Name: "yy", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, "xxtt1": { - Name: "xxtt1", - ColumnNames: []string{"i"}, + Name: "xxtt1", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, "xx": { - Name: "xx", - ColumnNames: []string{"i"}, + Name: "xx", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, "xxmixed": { - Name: "xxmixed", - ColumnNames: []string{"i"}, + Name: "xxmixed", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, }, }) @@ -507,8 +531,12 @@ func TestInsertOffsets(t *testing.T) { ID: distribution, Relations: map[string]*qdb.DistributedRelation{ "xx": { - Name: "xx", - ColumnNames: []string{"i"}, + Name: "xx", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, }, }) @@ -607,16 +635,28 @@ func TestJoins(t *testing.T) { ColTypes: []string{qdb.ColumnTypeVarchar}, Relations: map[string]*qdb.DistributedRelation{ "sshjt1": { - Name: "sshjt1", - ColumnNames: []string{"i"}, + Name: "sshjt1", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, "xjoin": { - Name: "xjoin", - ColumnNames: []string{"i"}, + Name: "xjoin", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, "yjoin": { - Name: "yjoin", - ColumnNames: []string{"i"}, + Name: "yjoin", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, }, }) @@ -740,8 +780,12 @@ func TestUnnest(t *testing.T) { ID: distribution, Relations: map[string]*qdb.DistributedRelation{ "xxtt1": { - Name: "xxtt1", - ColumnNames: []string{"i"}, + Name: "xxtt1", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, }, }) @@ -858,8 +902,12 @@ func TestCopySingleShard(t *testing.T) { ID: distribution, Relations: map[string]*qdb.DistributedRelation{ "xx": { - Name: "xx", - ColumnNames: []string{"i"}, + Name: "xx", + DistributionKey: []qdb.DistributionKeyEntry{ + { + Column: "i", + }, + }, }, }, }) diff --git a/test/feature/conf/init.sql b/test/feature/conf/init.sql index 01b9e5791..8a8fce411 100644 --- a/test/feature/conf/init.sql +++ b/test/feature/conf/init.sql @@ -2,4 +2,4 @@ CREATE DISTRIBUTION ds1 COLUMN TYPES integer; ADD SHARDING RULE rule1 COLUMNS id FOR DISTRIBUTION ds1; ADD SHARDING RULE rule2 TABLE test COLUMNS idx FOR DISTRIBUTION ds1; ADD SHARDING RULE rule3 COLUMNS idy FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION test COLUMNS idx; \ No newline at end of file +ALTER DISTRIBUTION ds1 ATTACH RELATION test DISTRIBUTION KEY idx; \ No newline at end of file diff --git a/test/feature/features/coordinator.feature b/test/feature/features/coordinator.feature index a94459aa7..b984a4baf 100644 --- a/test/feature/features/coordinator.feature +++ b/test/feature/features/coordinator.feature @@ -19,7 +19,7 @@ Feature: Coordinator test CREATE SHARDING RULE r1 COLUMN id FOR DISTRIBUTION ds1; CREATE KEY RANGE krid1 FROM 0 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1; - ALTER DISTRIBUTION ds1 ATTACH RELATION test COLUMNS id; + ALTER DISTRIBUTION ds1 ATTACH RELATION test DISTRIBUTION KEY id; """ Then command return code should be "0" diff --git a/test/feature/features/move.feature b/test/feature/features/move.feature index cfdfd0168..f54bd4534 100644 --- a/test/feature/features/move.feature +++ b/test/feature/features/move.feature @@ -13,8 +13,8 @@ Feature: Move test ADD SHARDING RULE r1 COLUMNS w_id FOR DISTRIBUTION ds1; ADD KEY RANGE krid1 FROM 1 TO 10 ROUTE TO sh1 FOR DISTRIBUTION ds1; ADD KEY RANGE krid2 FROM 11 TO 20 ROUTE TO sh2 FOR DISTRIBUTION ds1; - ALTER DISTRIBUTION ds1 ATTACH RELATION xMove COLUMNS w_id; - ALTER DISTRIBUTION ds1 ATTACH RELATION xMove2 COLUMNS w_id; + ALTER DISTRIBUTION ds1 ATTACH RELATION xMove DISTRIBUTION KEY w_id; + ALTER DISTRIBUTION ds1 ATTACH RELATION xMove2 DISTRIBUTION KEY w_id; """ Then command return code should be "0" diff --git a/test/feature/features/move_recover.feature b/test/feature/features/move_recover.feature index 4adb106ab..cac2d638e 100644 --- a/test/feature/features/move_recover.feature +++ b/test/feature/features/move_recover.feature @@ -10,7 +10,7 @@ Feature: Move recover test ADD SHARDING RULE r1 COLUMNS w_id FOR DISTRIBUTION ds1; ADD KEY RANGE krid1 FROM 1 TO 10 ROUTE TO sh1 FOR DISTRIBUTION ds1; ADD KEY RANGE krid2 FROM 11 TO 20 ROUTE TO sh2 FOR DISTRIBUTION ds1; - ALTER DISTRIBUTION ds1 ATTACH RELATION xMove COLUMNS w_id; + ALTER DISTRIBUTION ds1 ATTACH RELATION xMove DISTRIBUTION KEY w_id; """ Then command return code should be "0" diff --git a/test/feature/features/proxy_console.feature b/test/feature/features/proxy_console.feature index b43da43e3..942805b7f 100644 --- a/test/feature/features/proxy_console.feature +++ b/test/feature/features/proxy_console.feature @@ -105,7 +105,7 @@ Feature: Proxy console CREATE DISTRIBUTION ds1 COLUMN TYPES integer; CREATE KEY RANGE krid1 FROM 0 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE SHARDING RULE r1 COLUMN id FOR DISTRIBUTION ds1; - ALTER DISTRIBUTION ds1 ATTACH RELATION test COLUMNS id; + ALTER DISTRIBUTION ds1 ATTACH RELATION test DISTRIBUTION KEY id; """ Then command return code should be "0" @@ -197,7 +197,7 @@ Feature: Proxy console CREATE DISTRIBUTION ds1 COLUMN TYPES integer; CREATE SHARDING RULE r1 COLUMN id FOR DISTRIBUTION ds1; CREATE KEY RANGE krid1 FROM 0 ROUTE TO sh1 FOR DISTRIBUTION ds1; - ALTER DISTRIBUTION ds1 ATTACH RELATION test COLUMNS id; + ALTER DISTRIBUTION ds1 ATTACH RELATION test DISTRIBUTION KEY id; """ Then command return code should be "0" diff --git a/test/feature/features/workloadlog.feature b/test/feature/features/workloadlog.feature index 061272564..c021c6518 100644 --- a/test/feature/features/workloadlog.feature +++ b/test/feature/features/workloadlog.feature @@ -30,7 +30,7 @@ Feature: Check WorkloadLog working ADD SHARDING RULE r1 COLUMNS w_id FOR DISTRIBUTION ds1; ADD KEY RANGE krid1 FROM 1 TO 10 ROUTE TO sh1 FOR DISTRIBUTION ds1; ADD KEY RANGE krid2 FROM 11 TO 20 ROUTE TO sh2 FOR DISTRIBUTION ds1; - ALTER DISTRIBUTION ds1 ATTACH RELATION xMove COLUMNS w_id; + ALTER DISTRIBUTION ds1 ATTACH RELATION xMove DISTRIBUTION KEY w_id; START TRACE ALL MESSAGES; """ Then command return code should be "0" @@ -59,7 +59,7 @@ Feature: Check WorkloadLog working ADD SHARDING RULE r1 COLUMNS w_id FOR DISTRIBUTION ds1; ADD KEY RANGE krid1 FROM 1 TO 10 ROUTE TO sh1 FOR DISTRIBUTION ds1; ADD KEY RANGE krid2 FROM 11 TO 20 ROUTE TO sh2 FOR DISTRIBUTION ds1; - ALTER DISTRIBUTION ds1 ATTACH RELATION xMove COLUMNS w_id; + ALTER DISTRIBUTION ds1 ATTACH RELATION xMove DISTRIBUTION KEY w_id; START TRACE ALL MESSAGES """ Then command return code should be "0" diff --git a/test/regress/tests/router/expected/alter_distribution.out b/test/regress/tests/router/expected/alter_distribution.out index b0f69ef7a..838034fbf 100644 --- a/test/regress/tests/router/expected/alter_distribution.out +++ b/test/regress/tests/router/expected/alter_distribution.out @@ -54,19 +54,19 @@ CREATE KEY RANGE FROM 1 ROUTE TO sh2 FOR DISTRIBUTION ds2; created key range with bound 1 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION xx COLUMNS w_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xx DISTRIBUTION KEY w_id; attach table ------------------------------------------ attached relation xx to distribution ds1 (1 row) -ALTER DISTRIBUTION ds2 ATTACH RELATION yy COLUMNS w_id; +ALTER DISTRIBUTION ds2 ATTACH RELATION yy DISTRIBUTION KEY w_id; attach table ------------------------------------------ attached relation yy to distribution ds2 (1 row) -ALTER DISTRIBUTION ds3 ATTACH RELATION xx COLUMNS w_id; +ALTER DISTRIBUTION ds3 ATTACH RELATION xx DISTRIBUTION KEY w_id; ERROR: no such distribution. \c regress DROP TABLE IF EXISTS xx; @@ -100,7 +100,7 @@ NOTICE: send query to shard(s) : sh2 You can find documentation here https://github.com/pg-sharding/spqr/tree/master/docs -ALTER DISTRIBUTION ds1 ATTACH RELATION yy COLUMNS w_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION yy DISTRIBUTION KEY w_id; ERROR: relation "yy" is already attached. ALTER DISTRIBUTION ds2 DETACH RELATION yy; detach relation @@ -114,7 +114,7 @@ ALTER DISTRIBUTION ds2 DETACH RELATION yy; detached relation yy from distribution ds2 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION yy COLUMNS w_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION yy DISTRIBUTION KEY w_id; attach table ------------------------------------------ attached relation yy to distribution ds1 diff --git a/test/regress/tests/router/expected/begin.out b/test/regress/tests/router/expected/begin.out index 6f3cb4674..415203e65 100644 --- a/test/regress/tests/router/expected/begin.out +++ b/test/regress/tests/router/expected/begin.out @@ -30,7 +30,7 @@ CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1; created key range with bound 11 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION test_beg COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION test_beg DISTRIBUTION KEY id; attach table ------------------------------------------------ attached relation test_beg to distribution ds1 diff --git a/test/regress/tests/router/expected/copy_routing.out b/test/regress/tests/router/expected/copy_routing.out index 9152fae49..41414a40e 100644 --- a/test/regress/tests/router/expected/copy_routing.out +++ b/test/regress/tests/router/expected/copy_routing.out @@ -30,7 +30,7 @@ CREATE KEY RANGE krid2 FROM 30 ROUTE TO sh2 FOR DISTRIBUTION ds1; created key range with bound 30 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION copy_test COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION copy_test DISTRIBUTION KEY id; attach table ------------------------------------------------- attached relation copy_test to distribution ds1 diff --git a/test/regress/tests/router/expected/error.out b/test/regress/tests/router/expected/error.out index af17df5b1..c26c2c395 100644 --- a/test/regress/tests/router/expected/error.out +++ b/test/regress/tests/router/expected/error.out @@ -30,7 +30,7 @@ CREATE KEY RANGE kridi2 from 11 route to sh2 FOR DISTRIBUTION ds1; created key range with bound 11 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION x COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION x DISTRIBUTION KEY id; attach table ----------------------------------------- attached relation x to distribution ds1 diff --git a/test/regress/tests/router/expected/joins.out b/test/regress/tests/router/expected/joins.out index c561fd1dc..ffd70349c 100644 --- a/test/regress/tests/router/expected/joins.out +++ b/test/regress/tests/router/expected/joins.out @@ -36,13 +36,13 @@ CREATE KEY RANGE kridi2 from 11 route to sh2 FOR DISTRIBUTION ds1; created key range with bound 11 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION xjoin COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xjoin DISTRIBUTION KEY id; attach table --------------------------------------------- attached relation xjoin to distribution ds1 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION yjoin COLUMNS w_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION yjoin DISTRIBUTION KEY w_id; attach table --------------------------------------------- attached relation yjoin to distribution ds1 diff --git a/test/regress/tests/router/expected/mixed_routing.out b/test/regress/tests/router/expected/mixed_routing.out index 11b77df99..962da2704 100644 --- a/test/regress/tests/router/expected/mixed_routing.out +++ b/test/regress/tests/router/expected/mixed_routing.out @@ -31,7 +31,7 @@ CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1; created key range with bound 11 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION xxmixed COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xxmixed DISTRIBUTION KEY id; attach table ----------------------------------------------- attached relation xxmixed to distribution ds1 @@ -175,7 +175,7 @@ CREATE KEY RANGE krid4 FROM 88888888-8888-8888-8888-888888888888 ROUTE TO sh2 FO created key range with bound 88888888-8888-8888-8888-888888888888 (1 row) -ALTER DISTRIBUTION ds2 ATTACH RELATION xxmixeduuid COLUMNS id; +ALTER DISTRIBUTION ds2 ATTACH RELATION xxmixeduuid DISTRIBUTION KEY id; attach table --------------------------------------------------- attached relation xxmixeduuid to distribution ds2 diff --git a/test/regress/tests/router/expected/multishard.out b/test/regress/tests/router/expected/multishard.out index 853dea356..889578a09 100644 --- a/test/regress/tests/router/expected/multishard.out +++ b/test/regress/tests/router/expected/multishard.out @@ -31,7 +31,7 @@ CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1; created key range with bound 11 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION xxmixed COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xxmixed DISTRIBUTION KEY id; attach table ----------------------------------------------- attached relation xxmixed to distribution ds1 diff --git a/test/regress/tests/router/expected/routing_hint.out b/test/regress/tests/router/expected/routing_hint.out index fb482487a..a84ec860c 100644 --- a/test/regress/tests/router/expected/routing_hint.out +++ b/test/regress/tests/router/expected/routing_hint.out @@ -30,7 +30,7 @@ CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1; created key range with bound 11 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION test COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION test DISTRIBUTION KEY id; attach table -------------------------------------------- attached relation test to distribution ds1 diff --git a/test/regress/tests/router/expected/shard_routing.out b/test/regress/tests/router/expected/shard_routing.out index f055c9cf8..7aaa58e7a 100644 --- a/test/regress/tests/router/expected/shard_routing.out +++ b/test/regress/tests/router/expected/shard_routing.out @@ -42,19 +42,19 @@ CREATE KEY RANGE krid3 FROM 21 ROUTE TO sh2 FOR DISTRIBUTION ds1; created key range with bound 21 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION xx COLUMNS w_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xx DISTRIBUTION KEY w_id; attach table ------------------------------------------ attached relation xx to distribution ds1 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION xxerr COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xxerr DISTRIBUTION KEY id; attach table --------------------------------------------- attached relation xxerr to distribution ds1 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION xxtt1 COLUMNS w_id, id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xxtt1 DISTRIBUTION KEY w_id, id; attach table --------------------------------------------- attached relation xxtt1 to distribution ds1 diff --git a/test/regress/tests/router/expected/single_shard_joins.out b/test/regress/tests/router/expected/single_shard_joins.out index 755069541..4549a8ab9 100644 --- a/test/regress/tests/router/expected/single_shard_joins.out +++ b/test/regress/tests/router/expected/single_shard_joins.out @@ -30,7 +30,7 @@ CREATE KEY RANGE kridi2 from 11 route to sh2 FOR DISTRIBUTION ds1; created key range with bound 11 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION sshjt1 COLUMNS i; +ALTER DISTRIBUTION ds1 ATTACH RELATION sshjt1 DISTRIBUTION KEY i; attach table ---------------------------------------------- attached relation sshjt1 to distribution ds1 diff --git a/test/regress/tests/router/expected/target_session_attrs.out b/test/regress/tests/router/expected/target_session_attrs.out index e90cfe300..271b433b1 100644 --- a/test/regress/tests/router/expected/target_session_attrs.out +++ b/test/regress/tests/router/expected/target_session_attrs.out @@ -30,7 +30,7 @@ CREATE KEY RANGE krid2 FROM 101 ROUTE TO sh2 FOR DISTRIBUTION ds1; created key range with bound 101 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION tsa_test COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION tsa_test DISTRIBUTION KEY id; attach table ------------------------------------------------ attached relation tsa_test to distribution ds1 diff --git a/test/regress/tests/router/expected/transactions.out b/test/regress/tests/router/expected/transactions.out index b3d9d78d1..241c400fc 100644 --- a/test/regress/tests/router/expected/transactions.out +++ b/test/regress/tests/router/expected/transactions.out @@ -30,7 +30,7 @@ CREATE KEY RANGE krid2 FROM 101 ROUTE TO sh2 FOR DISTRIBUTION ds1; created key range with bound 101 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION transactions_test COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION transactions_test DISTRIBUTION KEY id; attach table --------------------------------------------------------- attached relation transactions_test to distribution ds1 diff --git a/test/regress/tests/router/expected/with_tables.out b/test/regress/tests/router/expected/with_tables.out index 87f485719..b2b231950 100644 --- a/test/regress/tests/router/expected/with_tables.out +++ b/test/regress/tests/router/expected/with_tables.out @@ -36,13 +36,13 @@ CREATE KEY RANGE krid2 FROM 101 ROUTE TO sh2 FOR DISTRIBUTION ds1; created key range with bound 101 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION orders COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION orders DISTRIBUTION KEY id; attach table ---------------------------------------------- attached relation orders to distribution ds1 (1 row) -ALTER DISTRIBUTION ds1 ATTACH RELATION delivery COLUMNS order_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION delivery DISTRIBUTION KEY order_id; attach table ------------------------------------------------ attached relation delivery to distribution ds1 diff --git a/test/regress/tests/router/sql/alter_distribution.sql b/test/regress/tests/router/sql/alter_distribution.sql index 0fef59d67..adcb29535 100644 --- a/test/regress/tests/router/sql/alter_distribution.sql +++ b/test/regress/tests/router/sql/alter_distribution.sql @@ -12,9 +12,9 @@ CREATE KEY RANGE krid3 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds2; CREATE KEY RANGE FROM 1 ROUTE TO sh2 FOR DISTRIBUTION ds2; -ALTER DISTRIBUTION ds1 ATTACH RELATION xx COLUMNS w_id; -ALTER DISTRIBUTION ds2 ATTACH RELATION yy COLUMNS w_id; -ALTER DISTRIBUTION ds3 ATTACH RELATION xx COLUMNS w_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xx DISTRIBUTION KEY w_id; +ALTER DISTRIBUTION ds2 ATTACH RELATION yy DISTRIBUTION KEY w_id; +ALTER DISTRIBUTION ds3 ATTACH RELATION xx DISTRIBUTION KEY w_id; \c regress @@ -34,10 +34,10 @@ SELECT * FROM yy WHERE w_id=5; \c spqr-console -ALTER DISTRIBUTION ds1 ATTACH RELATION yy COLUMNS w_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION yy DISTRIBUTION KEY w_id; ALTER DISTRIBUTION ds2 DETACH RELATION yy; ALTER DISTRIBUTION ds2 DETACH RELATION yy; -ALTER DISTRIBUTION ds1 ATTACH RELATION yy COLUMNS w_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION yy DISTRIBUTION KEY w_id; \c regress diff --git a/test/regress/tests/router/sql/begin.sql b/test/regress/tests/router/sql/begin.sql index d73124de4..e72e0a25c 100644 --- a/test/regress/tests/router/sql/begin.sql +++ b/test/regress/tests/router/sql/begin.sql @@ -3,7 +3,7 @@ CREATE DISTRIBUTION ds1 COLUMN TYPES integer; CREATE SHARDING RULE t1 COLUMNS id FOR DISTRIBUTION ds1; CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION test_beg COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION test_beg DISTRIBUTION KEY id; \c regress CREATE TABLE test_beg(id int, age int); diff --git a/test/regress/tests/router/sql/copy_routing.sql b/test/regress/tests/router/sql/copy_routing.sql index 4e56d2fe2..a975ea9fc 100644 --- a/test/regress/tests/router/sql/copy_routing.sql +++ b/test/regress/tests/router/sql/copy_routing.sql @@ -3,7 +3,7 @@ CREATE DISTRIBUTION ds1; CREATE SHARDING RULE t1 COLUMNS id FOR DISTRIBUTION ds1; CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE krid2 FROM 30 ROUTE TO sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION copy_test COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION copy_test DISTRIBUTION KEY id; \c regress CREATE TABLE copy_test (id int); diff --git a/test/regress/tests/router/sql/error.sql b/test/regress/tests/router/sql/error.sql index 70f32aaf4..0286ddec8 100644 --- a/test/regress/tests/router/sql/error.sql +++ b/test/regress/tests/router/sql/error.sql @@ -4,7 +4,7 @@ CREATE SHARDING RULE r1 COLUMN id FOR DISTRIBUTION ds1; CREATE KEY RANGE kridi1 from 1 route to sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE kridi2 from 11 route to sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION x COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION x DISTRIBUTION KEY id; \c regress diff --git a/test/regress/tests/router/sql/joins.sql b/test/regress/tests/router/sql/joins.sql index 24906a2b8..c90e9db58 100644 --- a/test/regress/tests/router/sql/joins.sql +++ b/test/regress/tests/router/sql/joins.sql @@ -5,8 +5,8 @@ CREATE SHARDING RULE r1 COLUMN id FOR DISTRIBUTION ds1; CREATE SHARDING RULE r2 COLUMN w_id FOR DISTRIBUTION ds1; CREATE KEY RANGE kridi1 from 0 route to sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE kridi2 from 11 route to sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION xjoin COLUMNS id; -ALTER DISTRIBUTION ds1 ATTACH RELATION yjoin COLUMNS w_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xjoin DISTRIBUTION KEY id; +ALTER DISTRIBUTION ds1 ATTACH RELATION yjoin DISTRIBUTION KEY w_id; \c regress diff --git a/test/regress/tests/router/sql/mixed_routing.sql b/test/regress/tests/router/sql/mixed_routing.sql index eade7eac2..7b3700226 100644 --- a/test/regress/tests/router/sql/mixed_routing.sql +++ b/test/regress/tests/router/sql/mixed_routing.sql @@ -5,7 +5,7 @@ CREATE DISTRIBUTION ds1 COLUMN TYPES integer; CREATE SHARDING RULE t1 COLUMNS id FOR DISTRIBUTION ds1; CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION xxmixed COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xxmixed DISTRIBUTION KEY id; \c regress @@ -40,7 +40,7 @@ CREATE DISTRIBUTION ds2 COLUMN TYPES varchar; CREATE SHARDING RULE t2 COLUMNS id FOR DISTRIBUTION ds2; CREATE KEY RANGE krid3 FROM 00000000-0000-0000-0000-000000000000 ROUTE TO sh1 FOR DISTRIBUTION ds2; CREATE KEY RANGE krid4 FROM 88888888-8888-8888-8888-888888888888 ROUTE TO sh2 FOR DISTRIBUTION ds2; -ALTER DISTRIBUTION ds2 ATTACH RELATION xxmixeduuid COLUMNS id; +ALTER DISTRIBUTION ds2 ATTACH RELATION xxmixeduuid DISTRIBUTION KEY id; \c regress CREATE TABLE xxmixeduuid(id uuid); diff --git a/test/regress/tests/router/sql/multishard.sql b/test/regress/tests/router/sql/multishard.sql index 7542f2260..2e35d0345 100644 --- a/test/regress/tests/router/sql/multishard.sql +++ b/test/regress/tests/router/sql/multishard.sql @@ -5,7 +5,7 @@ CREATE DISTRIBUTION ds1 COLUMN TYPES integer; CREATE SHARDING RULE t1 COLUMNS id FOR DISTRIBUTION ds1; CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION xxmixed COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xxmixed DISTRIBUTION KEY id; \c regress diff --git a/test/regress/tests/router/sql/routing_hint.sql b/test/regress/tests/router/sql/routing_hint.sql index a349a26e3..7b7f73a4e 100644 --- a/test/regress/tests/router/sql/routing_hint.sql +++ b/test/regress/tests/router/sql/routing_hint.sql @@ -4,7 +4,7 @@ CREATE DISTRIBUTION ds1 COLUMN TYPES integer; CREATE SHARDING RULE t1 COLUMNS id FOR DISTRIBUTION ds1; CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION test COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION test DISTRIBUTION KEY id; \c regress diff --git a/test/regress/tests/router/sql/shard_routing.sql b/test/regress/tests/router/sql/shard_routing.sql index e95a5a9bf..bb87e6939 100644 --- a/test/regress/tests/router/sql/shard_routing.sql +++ b/test/regress/tests/router/sql/shard_routing.sql @@ -8,9 +8,9 @@ CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE krid3 FROM 21 ROUTE TO sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION xx COLUMNS w_id; -ALTER DISTRIBUTION ds1 ATTACH RELATION xxerr COLUMNS id; -ALTER DISTRIBUTION ds1 ATTACH RELATION xxtt1 COLUMNS w_id, id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xx DISTRIBUTION KEY w_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xxerr DISTRIBUTION KEY id; +ALTER DISTRIBUTION ds1 ATTACH RELATION xxtt1 DISTRIBUTION KEY w_id, id; \c regress CREATE TABLE xx (w_id int); diff --git a/test/regress/tests/router/sql/single_shard_joins.sql b/test/regress/tests/router/sql/single_shard_joins.sql index 6f00c788d..ee3601082 100644 --- a/test/regress/tests/router/sql/single_shard_joins.sql +++ b/test/regress/tests/router/sql/single_shard_joins.sql @@ -3,7 +3,7 @@ CREATE DISTRIBUTION ds1 COLUMN TYPES integer; CREATE SHARDING RULE r1 COLUMN i FOR DISTRIBUTION ds1; CREATE KEY RANGE kridi1 from 0 route to sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE kridi2 from 11 route to sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION sshjt1 COLUMNS i; +ALTER DISTRIBUTION ds1 ATTACH RELATION sshjt1 DISTRIBUTION KEY i; \c regress diff --git a/test/regress/tests/router/sql/target_session_attrs.sql b/test/regress/tests/router/sql/target_session_attrs.sql index 647348b7e..2c3272b16 100644 --- a/test/regress/tests/router/sql/target_session_attrs.sql +++ b/test/regress/tests/router/sql/target_session_attrs.sql @@ -4,7 +4,7 @@ CREATE DISTRIBUTION ds1 COLUMN TYPES integer; CREATE SHARDING RULE t1 COLUMNS id FOR DISTRIBUTION ds1; CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE krid2 FROM 101 ROUTE TO sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION tsa_test COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION tsa_test DISTRIBUTION KEY id; \c regress CREATE TABLE tsa_test (id int); diff --git a/test/regress/tests/router/sql/transactions.sql b/test/regress/tests/router/sql/transactions.sql index 134f1a1eb..5c36b0982 100644 --- a/test/regress/tests/router/sql/transactions.sql +++ b/test/regress/tests/router/sql/transactions.sql @@ -3,7 +3,7 @@ CREATE DISTRIBUTION ds1 COLUMN TYPES integer; CREATE SHARDING RULE t1 COLUMNS id FOR DISTRIBUTION ds1; CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE krid2 FROM 101 ROUTE TO sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION transactions_test COLUMNS id; +ALTER DISTRIBUTION ds1 ATTACH RELATION transactions_test DISTRIBUTION KEY id; \c regress diff --git a/test/regress/tests/router/sql/with_tables.sql b/test/regress/tests/router/sql/with_tables.sql index 889a8dabc..ca9b087ac 100644 --- a/test/regress/tests/router/sql/with_tables.sql +++ b/test/regress/tests/router/sql/with_tables.sql @@ -8,8 +8,8 @@ CREATE SHARDING RULE t2 TABLE delivery COLUMN order_id FOR DISTRIBUTION ds1; CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1; CREATE KEY RANGE krid2 FROM 101 ROUTE TO sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION orders COLUMNS id; -ALTER DISTRIBUTION ds1 ATTACH RELATION delivery COLUMNS order_id; +ALTER DISTRIBUTION ds1 ATTACH RELATION orders DISTRIBUTION KEY id; +ALTER DISTRIBUTION ds1 ATTACH RELATION delivery DISTRIBUTION KEY order_id; \c regress diff --git a/test/stress/init.sql b/test/stress/init.sql index d3a26d421..934255e8c 100644 --- a/test/stress/init.sql +++ b/test/stress/init.sql @@ -8,4 +8,4 @@ ADD SHARDING RULE r1 TABLE pgbench_accounts COLUMNS aid FOR DISTRIBUTION ds1; ADD KEY RANGE krid1 FROM 1 TO 50000 ROUTE TO sh1 FOR DISTRIBUTION ds1; ADD KEY RANGE krid2 FROM 50001 TO 100000 ROUTE TO sh2 FOR DISTRIBUTION ds1; -ALTER DISTRIBUTION ds1 ATTACH RELATION pgbench_accounts COLUMNS aid; +ALTER DISTRIBUTION ds1 ATTACH RELATION pgbench_accounts DISTRIBUTION KEY aid; diff --git a/test/xproto/proto_test.go b/test/xproto/proto_test.go index 4ea74413f..c9b41f511 100644 --- a/test/xproto/proto_test.go +++ b/test/xproto/proto_test.go @@ -114,7 +114,7 @@ func SetupSharding() { if err != nil { _, _ = fmt.Fprintf(os.Stderr, "could not setup sharding: %s\n", err) } - _, err = conn.Exec(context.Background(), "ALTER DISTRIBUTION ds1 ATTACH RELATION t COLUMNS id;") + _, err = conn.Exec(context.Background(), "ALTER DISTRIBUTION ds1 ATTACH RELATION t DISTRIBUTION KEY id;") if err != nil { _, _ = fmt.Fprintf(os.Stderr, "could not setup sharding: %s\n", err) } @@ -134,7 +134,7 @@ func SetupSharding() { if err != nil { _, _ = fmt.Fprintf(os.Stderr, "could not setup sharding: %s\n", err) } - _, err = conn.Exec(context.Background(), "ALTER DISTRIBUTION ds2 ATTACH RELATION text_table COLUMNS id;") + _, err = conn.Exec(context.Background(), "ALTER DISTRIBUTION ds2 ATTACH RELATION text_table DISTRIBUTION KEY id;") if err != nil { _, _ = fmt.Fprintf(os.Stderr, "could not setup sharding: %s\n", err) } diff --git a/yacc/console/ast.go b/yacc/console/ast.go index 374115c9e..5ece89873 100644 --- a/yacc/console/ast.go +++ b/yacc/console/ast.go @@ -198,9 +198,14 @@ func (*AlterDistribution) iStatement() {} func (*AlterDistribution) iAlter() {} func (*AlterDistribution) iAlterDistribution() {} +type DistributionKeyEntry struct { + Column string + HashFunction string +} + type DistributedRelation struct { - Name string - Columns []string + Name string + DistributionKey []DistributionKeyEntry } type AttachRelation struct { diff --git a/yacc/console/gram.go b/yacc/console/gram.go index 55344ffd0..ce31ec0cb 100644 --- a/yacc/console/gram.go +++ b/yacc/console/gram.go @@ -69,9 +69,13 @@ type yySymType struct { alter_distribution *AlterDistribution distributed_relation *DistributedRelation - entrieslist []ShardingRuleEntry + entrieslist []ShardingRuleEntry + dEntrieslist []DistributionKeyEntry + shruleEntry ShardingRuleEntry + distrKeyEntry DistributionKeyEntry + sharding_rule_selector *ShardingRuleSelector key_range_selector *KeyRangeSelector distribution_selector *DistributionSelector @@ -237,7 +241,7 @@ const yyEofCode = 1 const yyErrCode = 2 const yyInitialStackSize = 16 -//line gram.y:778 +//line gram.y:799 //line yacctab:1 var yyExca = [...]int8{ @@ -248,83 +252,84 @@ var yyExca = [...]int8{ const yyPrivate = 57344 -const yyLast = 240 +const yyLast = 242 var yyAct = [...]uint8{ - 128, 167, 138, 162, 67, 97, 125, 137, 27, 28, - 135, 176, 112, 90, 163, 164, 165, 118, 87, 52, - 30, 29, 34, 35, 51, 140, 21, 20, 24, 25, - 26, 31, 32, 200, 201, 202, 85, 36, 66, 86, - 141, 169, 132, 80, 79, 211, 80, 83, 80, 169, - 116, 80, 80, 102, 210, 206, 205, 177, 80, 93, - 101, 33, 143, 100, 157, 140, 184, 89, 81, 22, - 23, 99, 147, 117, 134, 103, 104, 133, 94, 93, - 141, 187, 111, 114, 78, 60, 44, 188, 88, 121, - 123, 45, 119, 43, 82, 121, 209, 65, 46, 122, - 84, 129, 130, 131, 120, 208, 124, 105, 92, 171, - 115, 56, 80, 110, 142, 113, 54, 108, 58, 107, - 144, 145, 148, 57, 136, 91, 204, 203, 194, 191, - 38, 75, 74, 153, 159, 160, 42, 158, 53, 41, - 168, 172, 173, 80, 166, 40, 98, 113, 174, 175, - 207, 39, 179, 185, 96, 126, 180, 178, 50, 182, - 77, 49, 183, 80, 59, 61, 69, 48, 186, 168, - 71, 72, 73, 47, 150, 68, 146, 63, 37, 152, - 151, 1, 192, 193, 69, 196, 189, 190, 198, 197, - 150, 155, 18, 68, 70, 152, 151, 17, 156, 16, - 15, 14, 12, 181, 13, 8, 212, 213, 214, 9, - 195, 215, 216, 109, 217, 218, 161, 219, 220, 106, - 76, 19, 199, 170, 139, 6, 5, 4, 3, 7, - 11, 10, 64, 62, 55, 2, 127, 154, 149, 95, + 128, 162, 176, 167, 207, 67, 97, 138, 170, 125, + 137, 90, 112, 163, 164, 165, 27, 28, 135, 118, + 87, 52, 51, 199, 200, 201, 140, 66, 30, 29, + 34, 35, 169, 132, 21, 20, 24, 25, 26, 31, + 32, 141, 80, 85, 79, 36, 86, 83, 116, 80, + 169, 80, 80, 102, 210, 80, 209, 205, 204, 93, + 177, 80, 101, 143, 100, 140, 157, 89, 81, 33, + 147, 117, 99, 134, 133, 103, 104, 22, 23, 93, + 141, 187, 111, 114, 184, 78, 65, 44, 195, 121, + 123, 60, 45, 119, 43, 121, 94, 88, 122, 46, + 188, 129, 130, 131, 124, 120, 82, 105, 92, 84, + 56, 171, 110, 115, 142, 54, 80, 58, 113, 57, + 91, 144, 145, 148, 136, 108, 203, 107, 202, 194, + 191, 75, 74, 42, 159, 160, 153, 38, 158, 53, + 41, 172, 173, 98, 213, 168, 40, 166, 178, 174, + 175, 113, 80, 179, 39, 50, 77, 185, 96, 180, + 182, 80, 49, 183, 126, 59, 61, 63, 48, 37, + 186, 71, 72, 73, 168, 155, 47, 189, 190, 1, + 150, 69, 156, 192, 193, 152, 151, 196, 197, 69, + 68, 146, 18, 181, 17, 150, 208, 16, 68, 70, + 152, 151, 15, 14, 12, 211, 212, 13, 8, 9, + 215, 216, 109, 161, 208, 217, 218, 214, 219, 220, + 221, 106, 76, 19, 198, 139, 206, 6, 5, 4, + 3, 7, 11, 10, 64, 62, 55, 2, 127, 154, + 149, 95, } var yyPact = [...]int16{ - 2, -1000, 115, -1000, -1000, -1000, -1000, -1000, -1000, -1000, + 10, -1000, 122, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, - 49, 49, -45, -50, 74, 43, 43, 173, 34, 180, - -1000, 43, 43, 43, 110, 109, 40, -1000, -1000, -1000, - -1000, -1000, -1000, 159, 16, 51, 42, -1000, -1000, -1000, - -1000, -24, -52, -1000, 45, -1000, 15, 92, 48, -1000, - 35, -1000, 146, -1000, 132, 132, -1000, -1000, -1000, -1000, - -1000, 7, 3, -5, 159, 47, -1000, 83, 159, 75, - -1000, 108, 54, -8, 23, -53, 132, -1000, 44, 39, - -1000, -1000, 92, -1000, 159, -1000, 139, -1000, -1000, -1000, - 159, 159, 159, -19, -1000, -1000, -1000, 32, 29, -1000, - -64, 76, 27, 159, 6, 162, 22, 180, -1000, -1000, - -1000, -1000, -1000, -1000, -1000, 170, 139, 187, -1000, 9, - -1000, -1000, 180, 159, 159, -57, 27, -13, -1000, 69, - 159, 159, -1000, 162, 0, 0, -1000, 180, -1000, 139, - -1000, -1000, -1000, 186, 180, -1000, -1000, 180, -1000, -1000, - 13, 141, -1000, -1000, -1000, -1000, -13, -1000, -1000, 37, - -1000, 46, -1000, -1000, 0, 0, 106, 162, 105, -1000, - 170, -1000, -1000, -1000, 159, -57, -1000, 159, -31, 104, - 103, -1, -1000, -1000, -2, 138, -1000, -1000, -1000, -1000, - -1000, 65, 56, -3, -12, 159, 159, 159, -1000, -1000, - 159, 159, -21, -21, -1000, -21, -21, -1000, -1000, -1000, - -1000, + 50, 50, -47, -48, 73, 49, 49, 163, 23, 185, + -1000, 49, 49, 49, 110, 109, 41, -1000, -1000, -1000, + -1000, -1000, -1000, 157, 16, 63, 51, -1000, -1000, -1000, + -1000, -17, -50, -1000, 54, -1000, 15, 87, 48, -1000, + 53, -1000, 150, -1000, 129, 129, -1000, -1000, -1000, -1000, + -1000, 8, 5, -5, 157, 47, -1000, 91, 157, 74, + -1000, 112, 57, -10, 21, -51, 129, -1000, 45, 38, + -1000, -1000, 87, -1000, 157, -1000, 148, -1000, -1000, -1000, + 157, 157, 157, -28, -1000, -1000, -1000, 29, 28, -1000, + -56, 79, 27, 157, 7, 177, 20, 185, -1000, -1000, + -1000, -1000, -1000, -1000, -1000, 191, 148, 171, -1000, 11, + -1000, -1000, 185, 157, 157, -58, 27, -12, -1000, 71, + 157, 157, -1000, 177, 3, 3, -1000, 185, -1000, 148, + -1000, -1000, -1000, 176, 185, -1000, -1000, 185, -1000, -1000, + 40, 145, -1000, -1000, -1000, -1000, -12, -1000, -1000, 37, + -1000, 59, -1000, -1000, 3, 3, 107, 177, 106, -1000, + 191, -1000, -1000, -1000, 46, -58, -1000, 157, -41, 105, + 103, 1, -1000, -1000, 0, 157, -1000, -1000, -1000, -1000, + -1000, -1000, -1, -3, 157, 157, 132, -1000, 71, 157, + 157, -30, -30, 157, -1000, -30, -30, -1000, -1000, -1000, + -1000, -1000, } var yyPgo = [...]uint8{ - 0, 239, 6, 238, 237, 236, 4, 0, 5, 235, - 234, 138, 123, 233, 232, 231, 230, 229, 228, 227, - 226, 225, 151, 145, 139, 136, 7, 2, 12, 224, - 223, 222, 1, 221, 220, 219, 216, 213, 210, 3, - 13, 209, 205, 204, 202, 201, 200, 199, 197, 192, - 181, 178, 11, + 0, 241, 9, 240, 239, 238, 5, 0, 6, 237, + 236, 139, 119, 235, 234, 233, 232, 231, 230, 229, + 228, 227, 154, 146, 140, 133, 10, 226, 7, 4, + 12, 225, 8, 224, 3, 223, 222, 221, 213, 212, + 1, 11, 209, 208, 207, 204, 203, 202, 197, 194, + 192, 179, 169, 2, } var yyR1 = [...]int8{ - 0, 50, 51, 51, 9, 9, 9, 9, 9, 9, + 0, 51, 52, 52, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 6, 6, 6, 7, 3, 3, 3, 4, - 4, 5, 2, 2, 2, 1, 1, 13, 14, 40, - 40, 17, 17, 17, 17, 17, 17, 18, 18, 18, - 18, 20, 20, 21, 33, 34, 34, 35, 38, 38, - 19, 19, 19, 19, 15, 42, 22, 37, 37, 36, - 36, 39, 39, 39, 23, 23, 26, 26, 27, 28, - 28, 29, 29, 31, 31, 31, 30, 30, 32, 52, - 52, 52, 24, 24, 24, 24, 25, 25, 41, 10, - 11, 12, 45, 16, 16, 46, 47, 44, 43, 48, - 49, 49, + 4, 5, 2, 2, 2, 1, 1, 13, 14, 41, + 41, 17, 17, 17, 17, 17, 17, 18, 18, 18, + 18, 20, 20, 21, 35, 36, 36, 27, 27, 29, + 37, 19, 19, 19, 19, 15, 43, 22, 39, 39, + 38, 38, 40, 40, 40, 23, 23, 26, 26, 28, + 30, 30, 31, 31, 33, 33, 33, 32, 32, 34, + 53, 53, 53, 24, 24, 24, 24, 25, 25, 42, + 10, 11, 12, 46, 16, 16, 47, 48, 45, 44, + 49, 50, 50, } var yyR2 = [...]int8{ @@ -333,65 +338,65 @@ var yyR2 = [...]int8{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 0, 2, 1, 1, 1, 0, 2, 4, 2, 4, 3, 4, 2, 2, 2, - 2, 4, 4, 3, 2, 2, 4, 5, 3, 1, - 2, 2, 2, 2, 3, 2, 3, 3, 0, 3, - 1, 1, 1, 1, 6, 5, 1, 2, 2, 2, - 0, 2, 2, 1, 2, 2, 3, 0, 3, 2, - 2, 0, 10, 10, 9, 9, 5, 4, 2, 3, - 3, 2, 6, 3, 3, 4, 4, 2, 1, 5, - 3, 3, + 2, 4, 4, 3, 2, 2, 4, 3, 1, 2, + 6, 2, 2, 2, 2, 3, 2, 3, 3, 0, + 3, 1, 1, 1, 1, 6, 5, 1, 2, 2, + 2, 0, 2, 2, 1, 1, 1, 3, 0, 3, + 2, 2, 0, 10, 10, 9, 9, 5, 4, 2, + 3, 3, 2, 6, 3, 3, 4, 4, 2, 1, + 5, 3, 3, } var yyChk = [...]int16{ - -1000, -50, -9, -18, -19, -20, -21, -17, -42, -41, - -15, -16, -44, -43, -45, -46, -47, -48, -49, -33, + -1000, -51, -9, -18, -19, -20, -21, -17, -43, -42, + -15, -16, -45, -44, -46, -47, -48, -49, -50, -35, 25, 24, 67, 68, 26, 27, 28, 6, 7, 19, - 18, 29, 30, 59, 20, 21, 35, -51, 15, -22, + 18, 29, 30, 59, 20, 21, 35, -52, 15, -22, -23, -24, -25, 44, 37, 42, 49, -22, -23, -24, -25, 69, 69, -11, 42, -10, 37, -12, 44, -11, 42, -11, -13, 4, -14, 63, 4, -6, 13, 4, - 14, -11, -11, -11, 22, 22, -34, -12, 44, -7, + 14, -11, -11, -11, 22, 22, -36, -12, 44, -7, 4, 52, 43, -7, 58, 60, 63, 70, 43, 52, - -40, 33, 60, -7, 43, -1, 8, -8, 14, -8, - 56, 57, 58, -7, -7, 60, -35, 36, 34, -37, - 38, -7, -28, 39, -7, 56, 58, 50, 70, -8, - 60, -7, 60, -7, -40, -2, 16, -5, -7, -7, - -7, -7, 61, 45, 45, 74, -28, -26, -27, -29, + -41, 33, 60, -7, 43, -1, 8, -8, 14, -8, + 56, 57, 58, -7, -7, 60, -37, 36, 34, -39, + 38, -7, -30, 39, -7, 56, 58, 50, 70, -8, + 60, -7, 60, -7, -41, -2, 16, -5, -7, -7, + -7, -7, 61, 45, 45, 74, -30, -26, -28, -31, 38, 53, -7, 56, -6, -8, 14, 50, -6, -3, 4, 10, 9, -2, -4, 4, 11, 55, -6, -7, - -7, -36, -39, 71, 72, 73, -26, -32, -27, 62, - -30, 40, -7, -7, -6, -8, -52, 57, -52, -6, - -2, 17, -6, -6, 53, 12, -32, 44, 41, -52, - -52, 23, -6, -8, 23, -38, -7, -39, -7, -31, - 64, 65, 66, 23, 23, 57, 57, 12, 40, 40, - 57, 57, -7, -7, -7, -7, -7, -32, -32, -32, - -32, + -7, -38, -40, 71, 72, 73, -26, -34, -28, 62, + -32, 40, -7, -7, -6, -8, -53, 57, -53, -6, + -2, 17, -6, -6, 44, 12, -34, 44, 41, -53, + -53, 23, -6, -8, 23, 42, -40, -7, -33, 64, + 65, 66, 23, 23, 57, 57, -27, -29, -7, 57, + 57, -7, -7, 12, -32, -7, -7, -34, -34, -29, + -34, -34, } var yyDef = [...]int8{ 0, -2, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 108, 0, 0, 0, 0, 0, 0, 1, 3, 47, - 48, 49, 50, 0, 0, 0, 0, 60, 61, 62, - 63, 0, 0, 41, 0, 43, 0, 40, 0, 65, - 0, 98, 35, 37, 0, 0, 38, 107, 22, 23, - 24, 0, 0, 0, 0, 0, 54, 0, 0, 68, - 25, 80, 0, 0, 0, 0, 0, 53, 0, 0, - 45, 39, 40, 101, 0, 64, 0, 103, 21, 104, - 0, 0, 0, 0, 110, 111, 55, 0, 0, 66, - 0, 80, 0, 0, 0, 0, 0, 0, 51, 52, - 42, 100, 44, 99, 46, 36, 0, 0, 31, 0, - 105, 106, 0, 0, 0, 0, 0, 0, 76, 87, - 0, 0, 79, 0, 91, 91, 21, 0, 97, 0, - 26, 27, 28, 0, 0, 29, 30, 0, 109, 56, - 0, 67, 70, 71, 72, 73, 0, 75, 77, 0, - 78, 0, 81, 82, 91, 91, 0, 0, 0, 96, - 34, 32, 33, 102, 0, 0, 74, 0, 0, 0, - 0, 0, 89, 90, 0, 57, 59, 69, 88, 86, - 83, 0, 0, 0, 0, 0, 0, 0, 84, 85, - 0, 0, 0, 0, 58, 0, 0, 94, 95, 92, - 93, + 109, 0, 0, 0, 0, 0, 0, 1, 3, 47, + 48, 49, 50, 0, 0, 0, 0, 61, 62, 63, + 64, 0, 0, 41, 0, 43, 0, 40, 0, 66, + 0, 99, 35, 37, 0, 0, 38, 108, 22, 23, + 24, 0, 0, 0, 0, 0, 54, 0, 0, 69, + 25, 81, 0, 0, 0, 0, 0, 53, 0, 0, + 45, 39, 40, 102, 0, 65, 0, 104, 21, 105, + 0, 0, 0, 0, 111, 112, 55, 0, 0, 67, + 0, 81, 0, 0, 0, 0, 0, 0, 51, 52, + 42, 101, 44, 100, 46, 36, 0, 0, 31, 0, + 106, 107, 0, 0, 0, 0, 0, 0, 77, 88, + 0, 0, 80, 0, 92, 92, 21, 0, 98, 0, + 26, 27, 28, 0, 0, 29, 30, 0, 110, 56, + 0, 68, 71, 72, 73, 74, 0, 76, 78, 0, + 79, 0, 82, 83, 92, 92, 0, 0, 0, 97, + 34, 32, 33, 103, 0, 0, 75, 0, 0, 0, + 0, 0, 90, 91, 0, 0, 70, 89, 87, 84, + 85, 86, 0, 0, 0, 0, 60, 58, 88, 0, + 0, 0, 0, 0, 59, 0, 0, 95, 96, 57, + 93, 94, } var yyTok1 = [...]int8{ @@ -752,179 +757,179 @@ yydefault: case 2: yyDollar = yyS[yypt-0 : yypt+1] -//line gram.y:200 +//line gram.y:207 { } case 3: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:201 +//line gram.y:208 { } case 4: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:206 +//line gram.y:213 { setParseTree(yylex, yyDollar[1].create) } case 5: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:210 +//line gram.y:217 { setParseTree(yylex, yyDollar[1].create) } case 6: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:214 +//line gram.y:221 { setParseTree(yylex, yyDollar[1].trace) } case 7: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:218 +//line gram.y:225 { setParseTree(yylex, yyDollar[1].stoptrace) } case 8: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:222 +//line gram.y:229 { setParseTree(yylex, yyDollar[1].drop) } case 9: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:226 +//line gram.y:233 { setParseTree(yylex, yyDollar[1].lock) } case 10: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:230 +//line gram.y:237 { setParseTree(yylex, yyDollar[1].unlock) } case 11: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:234 +//line gram.y:241 { setParseTree(yylex, yyDollar[1].show) } case 12: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:238 +//line gram.y:245 { setParseTree(yylex, yyDollar[1].kill) } case 13: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:242 +//line gram.y:249 { setParseTree(yylex, yyDollar[1].listen) } case 14: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:246 +//line gram.y:253 { setParseTree(yylex, yyDollar[1].shutdown) } case 15: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:250 +//line gram.y:257 { setParseTree(yylex, yyDollar[1].split) } case 16: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:254 +//line gram.y:261 { setParseTree(yylex, yyDollar[1].move) } case 17: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:258 +//line gram.y:265 { setParseTree(yylex, yyDollar[1].unite) } case 18: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:262 +//line gram.y:269 { setParseTree(yylex, yyDollar[1].register_router) } case 19: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:266 +//line gram.y:273 { setParseTree(yylex, yyDollar[1].unregister_router) } case 20: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:270 +//line gram.y:277 { setParseTree(yylex, yyDollar[1].alter) } case 21: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:275 +//line gram.y:282 { yyVAL.uinteger = uint(yyDollar[1].uinteger) } case 22: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:280 +//line gram.y:287 { yyVAL.str = string(yyDollar[1].str) } case 23: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:284 +//line gram.y:291 { yyVAL.str = string(yyDollar[1].str) } case 24: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:286 +//line gram.y:293 { yyVAL.str = strconv.Itoa(int(yyDollar[1].uinteger)) } case 25: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:291 +//line gram.y:298 { yyVAL.str = string(yyDollar[1].str) } case 26: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:297 +//line gram.y:304 { yyVAL.str = yyDollar[1].str } case 27: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:299 +//line gram.y:306 { yyVAL.str = "AND" } case 28: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:301 +//line gram.y:308 { yyVAL.str = "OR" } case 29: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:306 +//line gram.y:313 { yyVAL.str = yyDollar[1].str } case 30: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:308 +//line gram.y:315 { yyVAL.str = "=" } case 31: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:314 +//line gram.y:321 { yyVAL.colref = ColumnRef{ ColName: yyDollar[1].str, @@ -932,13 +937,13 @@ yydefault: } case 32: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:322 +//line gram.y:329 { yyVAL.where = yyDollar[2].where } case 33: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:325 +//line gram.y:332 { yyVAL.where = WhereClauseLeaf{ ColRef: yyDollar[1].colref, @@ -948,7 +953,7 @@ yydefault: } case 34: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:333 +//line gram.y:340 { yyVAL.where = WhereClauseOp{ Op: yyDollar[2].str, @@ -958,19 +963,19 @@ yydefault: } case 35: yyDollar = yyS[yypt-0 : yypt+1] -//line gram.y:343 +//line gram.y:350 { yyVAL.where = WhereClauseEmpty{} } case 36: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:347 +//line gram.y:354 { yyVAL.where = yyDollar[2].where } case 37: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:354 +//line gram.y:361 { switch v := strings.ToLower(string(yyDollar[1].str)); v { case DatabasesStr, RoutersStr, PoolsStr, ShardsStr, BackendConnectionsStr, KeyRangesStr, ShardingRules, ClientsStr, StatusStr, DistributionsStr, VersionStr: @@ -981,7 +986,7 @@ yydefault: } case 38: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:365 +//line gram.y:372 { switch v := string(yyDollar[1].str); v { case ClientStr: @@ -992,85 +997,85 @@ yydefault: } case 39: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:375 +//line gram.y:382 { yyVAL.bool = true } case 40: yyDollar = yyS[yypt-0 : yypt+1] -//line gram.y:375 +//line gram.y:382 { yyVAL.bool = false } case 41: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:379 +//line gram.y:386 { yyVAL.drop = &Drop{Element: yyDollar[2].key_range_selector} } case 42: yyDollar = yyS[yypt-4 : yypt+1] -//line gram.y:383 +//line gram.y:390 { yyVAL.drop = &Drop{Element: &KeyRangeSelector{KeyRangeID: `*`}} } case 43: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:387 +//line gram.y:394 { yyVAL.drop = &Drop{Element: yyDollar[2].sharding_rule_selector} } case 44: yyDollar = yyS[yypt-4 : yypt+1] -//line gram.y:391 +//line gram.y:398 { yyVAL.drop = &Drop{Element: &ShardingRuleSelector{ID: `*`}} } case 45: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:395 +//line gram.y:402 { yyVAL.drop = &Drop{Element: yyDollar[2].distribution_selector, CascadeDelete: yyDollar[3].bool} } case 46: yyDollar = yyS[yypt-4 : yypt+1] -//line gram.y:399 +//line gram.y:406 { yyVAL.drop = &Drop{Element: &DistributionSelector{ID: `*`}, CascadeDelete: yyDollar[4].bool} } case 47: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:406 +//line gram.y:413 { yyVAL.create = &Create{Element: yyDollar[2].ds} } case 48: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:411 +//line gram.y:418 { yyVAL.create = &Create{Element: yyDollar[2].sharding_rule} } case 49: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:416 +//line gram.y:423 { yyVAL.create = &Create{Element: yyDollar[2].kr} } case 50: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:420 +//line gram.y:427 { yyVAL.create = &Create{Element: yyDollar[2].shard} } case 51: yyDollar = yyS[yypt-4 : yypt+1] -//line gram.y:426 +//line gram.y:433 { yyVAL.trace = &TraceStmt{All: true} } case 52: yyDollar = yyS[yypt-4 : yypt+1] -//line gram.y:429 +//line gram.y:436 { yyVAL.trace = &TraceStmt{ Client: yyDollar[4].uinteger, @@ -1078,19 +1083,19 @@ yydefault: } case 53: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:437 +//line gram.y:444 { yyVAL.stoptrace = &StopTraceStmt{} } case 54: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:443 +//line gram.y:450 { yyVAL.alter = &Alter{Element: yyDollar[2].alter_distribution} } case 55: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:449 +//line gram.y:456 { yyVAL.alter_distribution = &AlterDistribution{ Element: &AttachRelation{ @@ -1101,7 +1106,7 @@ yydefault: } case 56: yyDollar = yyS[yypt-4 : yypt+1] -//line gram.y:458 +//line gram.y:465 { yyVAL.alter_distribution = &AlterDistribution{ Element: &DetachRelation{ @@ -1111,127 +1116,136 @@ yydefault: } } case 57: - yyDollar = yyS[yypt-5 : yypt+1] -//line gram.y:469 - { - yyVAL.distributed_relation = &DistributedRelation{ - Name: yyDollar[3].str, - Columns: yyDollar[5].strlist, - } - } - case 58: yyDollar = yyS[yypt-3 : yypt+1] //line gram.y:477 { - yyVAL.strlist = append(yyDollar[1].strlist, yyDollar[3].str) + yyVAL.dEntrieslist = append(yyDollar[1].dEntrieslist, yyDollar[3].distrKeyEntry) } - case 59: + case 58: yyDollar = yyS[yypt-1 : yypt+1] //line gram.y:479 { - yyVAL.strlist = []string{ - yyDollar[1].str, + yyVAL.dEntrieslist = []DistributionKeyEntry{ + yyDollar[1].distrKeyEntry, + } + } + case 59: + yyDollar = yyS[yypt-2 : yypt+1] +//line gram.y:489 + { + yyVAL.distrKeyEntry = DistributionKeyEntry{ + Column: yyDollar[1].str, + HashFunction: yyDollar[2].str, } } case 60: + yyDollar = yyS[yypt-6 : yypt+1] +//line gram.y:498 + { + yyVAL.distributed_relation = &DistributedRelation{ + Name: yyDollar[3].str, + DistributionKey: yyDollar[6].dEntrieslist, + } + } + case 61: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:488 +//line gram.y:508 { yyVAL.create = &Create{Element: yyDollar[2].ds} } - case 61: + case 62: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:493 +//line gram.y:513 { yyVAL.create = &Create{Element: yyDollar[2].sharding_rule} } - case 62: + case 63: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:498 +//line gram.y:518 { yyVAL.create = &Create{Element: yyDollar[2].kr} } - case 63: + case 64: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:502 +//line gram.y:522 { yyVAL.create = &Create{Element: yyDollar[2].shard} } - case 64: + case 65: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:509 +//line gram.y:529 { yyVAL.show = &Show{Cmd: yyDollar[2].str, Where: yyDollar[3].where} } - case 65: + case 66: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:515 +//line gram.y:535 { yyVAL.lock = &Lock{KeyRangeID: yyDollar[2].key_range_selector.KeyRangeID} } - case 66: + case 67: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:523 +//line gram.y:543 { yyVAL.ds = &DistributionDefinition{ ID: yyDollar[2].str, ColTypes: yyDollar[3].strlist, } } - case 67: + case 68: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:531 +//line gram.y:551 { yyVAL.strlist = yyDollar[3].strlist } - case 68: + case 69: yyDollar = yyS[yypt-0 : yypt+1] -//line gram.y:533 +//line gram.y:553 { /* empty column types should be prohibited */ yyVAL.strlist = nil } - case 69: + case 70: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:539 +//line gram.y:559 { yyVAL.strlist = append(yyDollar[1].strlist, yyDollar[3].str) } - case 70: + case 71: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:541 +//line gram.y:561 { yyVAL.strlist = []string{ yyDollar[1].str, } } - case 71: + case 72: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:548 +//line gram.y:568 { yyVAL.str = "varchar" } - case 72: + case 73: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:550 +//line gram.y:570 { yyVAL.str = "integer" } - case 73: + case 74: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:552 +//line gram.y:572 { yyVAL.str = "integer" } - case 74: + case 75: yyDollar = yyS[yypt-6 : yypt+1] -//line gram.y:558 +//line gram.y:578 { yyVAL.sharding_rule = &ShardingRuleDefinition{ID: yyDollar[3].str, TableName: yyDollar[4].str, Entries: yyDollar[5].entrieslist, Distribution: yyDollar[6].str} } - case 75: + case 76: yyDollar = yyS[yypt-5 : yypt+1] -//line gram.y:563 +//line gram.y:583 { str, err := randomHex(6) if err != nil { @@ -1239,106 +1253,106 @@ yydefault: } yyVAL.sharding_rule = &ShardingRuleDefinition{ID: "shrule" + str, TableName: yyDollar[3].str, Entries: yyDollar[4].entrieslist, Distribution: yyDollar[5].str} } - case 76: + case 77: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:572 +//line gram.y:592 { yyVAL.entrieslist = make([]ShardingRuleEntry, 0) yyVAL.entrieslist = append(yyVAL.entrieslist, yyDollar[1].shruleEntry) } - case 77: + case 78: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:578 +//line gram.y:598 { yyVAL.entrieslist = append(yyDollar[1].entrieslist, yyDollar[2].shruleEntry) } - case 78: + case 79: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:584 +//line gram.y:604 { yyVAL.shruleEntry = ShardingRuleEntry{ Column: yyDollar[1].str, HashFunction: yyDollar[2].str, } } - case 79: + case 80: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:593 +//line gram.y:613 { yyVAL.str = yyDollar[2].str } - case 80: + case 81: yyDollar = yyS[yypt-0 : yypt+1] -//line gram.y:596 +//line gram.y:616 { yyVAL.str = "" } - case 81: + case 82: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:600 +//line gram.y:620 { yyVAL.str = yyDollar[2].str } - case 82: + case 83: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:605 +//line gram.y:625 { yyVAL.str = yyDollar[2].str } - case 83: + case 84: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:611 +//line gram.y:631 { yyVAL.str = "identity" } - case 84: - yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:613 + case 85: + yyDollar = yyS[yypt-1 : yypt+1] +//line gram.y:633 { yyVAL.str = "murmur" } - case 85: - yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:615 + case 86: + yyDollar = yyS[yypt-1 : yypt+1] +//line gram.y:635 { yyVAL.str = "city" } - case 86: + case 87: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:621 +//line gram.y:641 { yyVAL.str = yyDollar[3].str } - case 87: + case 88: yyDollar = yyS[yypt-0 : yypt+1] -//line gram.y:624 +//line gram.y:643 { yyVAL.str = "" } - case 88: + case 89: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:627 +//line gram.y:648 { yyVAL.str = yyDollar[3].str } - case 89: + case 90: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:632 +//line gram.y:653 { } - case 90: + case 91: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:632 +//line gram.y:653 { } - case 91: + case 92: yyDollar = yyS[yypt-0 : yypt+1] -//line gram.y:632 +//line gram.y:653 { } - case 92: + case 93: yyDollar = yyS[yypt-10 : yypt+1] -//line gram.y:636 +//line gram.y:657 { yyVAL.kr = &KeyRangeDefinition{ KeyRangeID: yyDollar[3].str, @@ -1347,9 +1361,9 @@ yydefault: Distribution: yyDollar[10].str, } } - case 93: + case 94: yyDollar = yyS[yypt-10 : yypt+1] -//line gram.y:645 +//line gram.y:666 { yyVAL.kr = &KeyRangeDefinition{ KeyRangeID: yyDollar[3].str, @@ -1358,9 +1372,9 @@ yydefault: Distribution: yyDollar[10].str, } } - case 94: + case 95: yyDollar = yyS[yypt-9 : yypt+1] -//line gram.y:654 +//line gram.y:675 { str, err := randomHex(6) if err != nil { @@ -1373,9 +1387,9 @@ yydefault: KeyRangeID: "kr" + str, } } - case 95: + case 96: yyDollar = yyS[yypt-9 : yypt+1] -//line gram.y:667 +//line gram.y:688 { str, err := randomHex(6) if err != nil { @@ -1388,15 +1402,15 @@ yydefault: Distribution: yyDollar[9].str, } } - case 96: + case 97: yyDollar = yyS[yypt-5 : yypt+1] -//line gram.y:683 +//line gram.y:704 { yyVAL.shard = &ShardDefinition{Id: yyDollar[2].str, Hosts: []string{yyDollar[5].str}} } - case 97: + case 98: yyDollar = yyS[yypt-4 : yypt+1] -//line gram.y:688 +//line gram.y:709 { str, err := randomHex(6) if err != nil { @@ -1404,87 +1418,87 @@ yydefault: } yyVAL.shard = &ShardDefinition{Id: "shard" + str, Hosts: []string{yyDollar[4].str}} } - case 98: + case 99: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:699 +//line gram.y:720 { yyVAL.unlock = &Unlock{KeyRangeID: yyDollar[2].key_range_selector.KeyRangeID} } - case 99: + case 100: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:705 +//line gram.y:726 { yyVAL.sharding_rule_selector = &ShardingRuleSelector{ID: yyDollar[3].str} } - case 100: + case 101: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:711 +//line gram.y:732 { yyVAL.key_range_selector = &KeyRangeSelector{KeyRangeID: yyDollar[3].str} } - case 101: + case 102: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:717 +//line gram.y:738 { yyVAL.distribution_selector = &DistributionSelector{ID: yyDollar[2].str} } - case 102: + case 103: yyDollar = yyS[yypt-6 : yypt+1] -//line gram.y:723 +//line gram.y:744 { yyVAL.split = &SplitKeyRange{KeyRangeID: yyDollar[2].key_range_selector.KeyRangeID, KeyRangeFromID: yyDollar[4].str, Border: []byte(yyDollar[6].str)} } - case 103: + case 104: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:729 +//line gram.y:750 { yyVAL.kill = &Kill{Cmd: yyDollar[2].str, Target: yyDollar[3].uinteger} } - case 104: + case 105: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:732 +//line gram.y:753 { yyVAL.kill = &Kill{Cmd: "client", Target: yyDollar[3].uinteger} } - case 105: + case 106: yyDollar = yyS[yypt-4 : yypt+1] -//line gram.y:738 +//line gram.y:759 { yyVAL.move = &MoveKeyRange{KeyRangeID: yyDollar[2].key_range_selector.KeyRangeID, DestShardID: yyDollar[4].str} } - case 106: + case 107: yyDollar = yyS[yypt-4 : yypt+1] -//line gram.y:744 +//line gram.y:765 { yyVAL.unite = &UniteKeyRange{KeyRangeIDL: yyDollar[2].key_range_selector.KeyRangeID, KeyRangeIDR: yyDollar[4].str} } - case 107: + case 108: yyDollar = yyS[yypt-2 : yypt+1] -//line gram.y:750 +//line gram.y:771 { yyVAL.listen = &Listen{addr: yyDollar[2].str} } - case 108: + case 109: yyDollar = yyS[yypt-1 : yypt+1] -//line gram.y:756 +//line gram.y:777 { yyVAL.shutdown = &Shutdown{} } - case 109: + case 110: yyDollar = yyS[yypt-5 : yypt+1] -//line gram.y:764 +//line gram.y:785 { yyVAL.register_router = &RegisterRouter{ID: yyDollar[3].str, Addr: yyDollar[5].str} } - case 110: + case 111: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:770 +//line gram.y:791 { yyVAL.unregister_router = &UnregisterRouter{ID: yyDollar[3].str} } - case 111: + case 112: yyDollar = yyS[yypt-3 : yypt+1] -//line gram.y:775 +//line gram.y:796 { yyVAL.unregister_router = &UnregisterRouter{ID: `*`} } diff --git a/yacc/console/gram.y b/yacc/console/gram.y index e6f0cb518..035a3c7a0 100644 --- a/yacc/console/gram.y +++ b/yacc/console/gram.y @@ -64,11 +64,15 @@ func randomHex(n int) (string, error) { alter *Alter alter_distribution *AlterDistribution - distributed_relation *DistributedRelation + distributed_relation *DistributedRelation entrieslist []ShardingRuleEntry + dEntrieslist []DistributionKeyEntry + shruleEntry ShardingRuleEntry + distrKeyEntry DistributionKeyEntry + sharding_rule_selector *ShardingRuleSelector key_range_selector *KeyRangeSelector distribution_selector *DistributionSelector @@ -161,11 +165,14 @@ func randomHex(n int) (string, error) { %type shard_define_stmt %type sharding_rule_argument_list +%type distribution_key_argument_list %type sharding_rule_entry +%type distribution_key_entry + %type sharding_rule_table_clause %type sharding_rule_column_clause -%type sharding_rule_hash_function_clause +%type opt_hash_function_clause %type hash_function_name %type distribution_membership @@ -174,7 +181,7 @@ func randomHex(n int) (string, error) { %type relation_attach_stmt -%type col_types_list opt_col_types col_list +%type col_types_list opt_col_types %type col_types_elem %type opt_cascade @@ -464,21 +471,34 @@ distribution_alter_stmt: } } -relation_attach_stmt: - ATTACH RELATION any_id COLUMNS col_list + +distribution_key_argument_list: + distribution_key_argument_list TCOMMA distribution_key_entry + { + $$ = append($1, $3) + } | distribution_key_entry { + $$ = []DistributionKeyEntry { + $1, + } + } + + + +distribution_key_entry: + any_id opt_hash_function_clause { - $$ = &DistributedRelation{ - Name: $3, - Columns: $5, + $$ = DistributionKeyEntry { + Column: $1, + HashFunction: $2, } } -col_list: - col_list TCOMMA any_id { - $$ = append($1, $3) - } | any_id { - $$ = []string { - $1, +relation_attach_stmt: + ATTACH RELATION any_id DISTRIBUTION KEY distribution_key_argument_list + { + $$ = &DistributedRelation{ + Name: $3, + DistributionKey: $6, } } @@ -580,7 +600,7 @@ sharding_rule_argument_list: sharding_rule_entry } sharding_rule_entry: - sharding_rule_column_clause sharding_rule_hash_function_clause + sharding_rule_column_clause opt_hash_function_clause { $$ = ShardingRuleEntry{ Column: $1, @@ -610,18 +630,19 @@ sharding_rule_column_clause: hash_function_name: IDENTITY { $$ = "identity" - } | MURMUR HASH { + } | MURMUR { $$ = "murmur" - } | CITY HASH { + } | CITY { $$ = "city" } -sharding_rule_hash_function_clause: +opt_hash_function_clause: HASH FUNCTION hash_function_name { $$ = $3 + } | /* EMPTY */ { + $$ = "" } - | /*EMPTY*/ { $$ = ""; } distribution_membership: FOR DISTRIBUTION any_id{ diff --git a/yacc/console/lex.go b/yacc/console/lex.go index 97007f0be..778150994 100644 --- a/yacc/console/lex.go +++ b/yacc/console/lex.go @@ -1,12 +1,15 @@ + //line lex.rl:1 //nolint:all package spqrparser import ( - "strconv" - "strings" + "strings" + "strconv" ) + + //line lex.go:12 const lexer_start int = 4 const lexer_first_final int = 4 @@ -14,44 +17,47 @@ const lexer_error int = 0 const lexer_en_main int = 4 + //line lex.rl:16 + + type Lexer struct { - data []byte - p, pe, cs int - ts, te, act int + data []byte + p, pe, cs int + ts, te, act int result []string } func NewLexer(data []byte) *Lexer { - lex := &Lexer{ - data: data, - pe: len(data), - } - + lex := &Lexer{ + data: data, + pe: len(data), + } + //line lex.go:36 { - lex.cs = lexer_start - lex.ts = 0 - lex.te = 0 - lex.act = 0 + lex.cs = lexer_start + lex.ts = 0 + lex.te = 0 + lex.act = 0 } //line lex.rl:33 - return lex + return lex } func ResetLexer(lex *Lexer, data []byte) { - lex.pe = len(data) - lex.data = data - + lex.pe = len(data) + lex.data = data + //line lex.go:50 { - lex.cs = lexer_start - lex.ts = 0 - lex.te = 0 - lex.act = 0 + lex.cs = lexer_start + lex.ts = 0 + lex.te = 0 + lex.act = 0 } //line lex.rl:40 @@ -61,199 +67,153 @@ func (l *Lexer) Error(msg string) { println(msg) } + func (lex *Lexer) Lex(lval *yySymType) int { - eof := lex.pe - var tok int + eof := lex.pe + var tok int + //line lex.go:69 { - if (lex.p) == (lex.pe) { - goto _test_eof - } - switch lex.cs { - case 4: - goto st_case_4 - case 0: - goto st_case_0 - case 5: - goto st_case_5 - case 6: - goto st_case_6 - case 7: - goto st_case_7 - case 8: - goto st_case_8 - case 1: - goto st_case_1 - case 9: - goto st_case_9 - case 10: - goto st_case_10 - case 11: - goto st_case_11 - case 12: - goto st_case_12 - case 2: - goto st_case_2 - case 3: - goto st_case_3 - case 13: - goto st_case_13 - case 14: - goto st_case_14 - } - goto st_out - tr1: + if ( lex.p) == ( lex.pe) { + goto _test_eof + } + switch lex.cs { + case 4: + goto st_case_4 + case 0: + goto st_case_0 + case 5: + goto st_case_5 + case 6: + goto st_case_6 + case 7: + goto st_case_7 + case 8: + goto st_case_8 + case 1: + goto st_case_1 + case 9: + goto st_case_9 + case 10: + goto st_case_10 + case 11: + goto st_case_11 + case 12: + goto st_case_12 + case 2: + goto st_case_2 + case 3: + goto st_case_3 + case 13: + goto st_case_13 + case 14: + goto st_case_14 + } + goto st_out +tr1: //line lex.rl:99 - lex.te = (lex.p) + 1 - { - lval.str = string(lex.data[lex.ts+1 : lex.te-1]) - tok = SCONST - { - (lex.p)++ - lex.cs = 4 - goto _out - } - } - goto st4 - tr2: + lex.te = ( lex.p)+1 +{ lval.str = string(lex.data[lex.ts + 1:lex.te - 1]); tok = SCONST; {( lex.p)++; lex.cs = 4; goto _out }} + goto st4 +tr2: //line NONE:1 - switch lex.act { - case 2: - { - (lex.p) = (lex.te) - 1 - /* nothing */ - } - case 4: - { - (lex.p) = (lex.te) - 1 - lval.str = string(lex.data[lex.ts+1 : lex.te-1]) - tok = IDENT - { - (lex.p)++ - lex.cs = 4 - goto _out - } - } - case 5: - { - (lex.p) = (lex.te) - 1 - - lval.str = string(lex.data[lex.ts:lex.te]) - if ttype, ok := reservedWords[strings.ToLower(lval.str)]; ok { - tok = ttype - } else { - tok = IDENT - } - { - (lex.p)++ - lex.cs = 4 - goto _out - } - } - case 7: - { - (lex.p) = (lex.te) - 1 - lval.str = string(lex.data[lex.ts:lex.te]) - tok = TEQ - { - (lex.p)++ - lex.cs = 4 - goto _out - } - } - case 9: - { - (lex.p) = (lex.te) - 1 - - lval.str = string(lex.data[lex.ts:lex.te]) - tok = int(OP) - { - (lex.p)++ - lex.cs = 4 - goto _out - } - } - } + switch lex.act { + case 2: + {( lex.p) = ( lex.te) - 1 +/* nothing */} + case 4: + {( lex.p) = ( lex.te) - 1 + lval.str = string(lex.data[lex.ts + 1:lex.te - 1]); tok = IDENT; {( lex.p)++; lex.cs = 4; goto _out }} + case 5: + {( lex.p) = ( lex.te) - 1 + + + lval.str = string(lex.data[lex.ts:lex.te]); + if ttype, ok := reservedWords[strings.ToLower(lval.str)]; ok { + tok = ttype; + } else { + tok = IDENT; + } + {( lex.p)++; lex.cs = 4; goto _out }} + case 7: + {( lex.p) = ( lex.te) - 1 + lval.str = string(lex.data[lex.ts:lex.te]); tok = TEQ; {( lex.p)++; lex.cs = 4; goto _out }} + case 11: + {( lex.p) = ( lex.te) - 1 - goto st4 - tr11: + lval.str = string(lex.data[lex.ts:lex.te]); tok = int(OP); + {( lex.p)++; lex.cs = 4; goto _out } + } + } + + goto st4 +tr11: +//line lex.rl:104 + lex.te = ( lex.p)+1 +{ lval.str = string(lex.data[lex.ts:lex.te]); tok = TOPENBR; {( lex.p)++; lex.cs = 4; goto _out }} + goto st4 +tr12: +//line lex.rl:105 + lex.te = ( lex.p)+1 +{ lval.str = string(lex.data[lex.ts:lex.te]); tok = TCLOSEBR; {( lex.p)++; lex.cs = 4; goto _out }} + goto st4 +tr13: //line lex.rl:102 - lex.te = (lex.p) + 1 - { - lval.str = string(lex.data[lex.ts:lex.te]) - tok = TCOMMA - { - (lex.p)++ - lex.cs = 4 - goto _out - } - } - goto st4 - tr16: + lex.te = ( lex.p)+1 +{ lval.str = string(lex.data[lex.ts:lex.te]); tok = TCOMMA; {( lex.p)++; lex.cs = 4; goto _out }} + goto st4 +tr18: //line lex.rl:77 - lex.te = (lex.p) - (lex.p)-- - { /* do nothing */ - } - goto st4 - tr18: + lex.te = ( lex.p) +( lex.p)-- +{ /* do nothing */ } + goto st4 +tr20: //line lex.rl:90 - lex.te = (lex.p) - (lex.p)-- - { - - lval.str = string(lex.data[lex.ts:lex.te]) - if ttype, ok := reservedWords[strings.ToLower(lval.str)]; ok { - tok = ttype - } else { - tok = IDENT - } - { - (lex.p)++ - lex.cs = 4 - goto _out - } - } - goto st4 - tr20: + lex.te = ( lex.p) +( lex.p)-- +{ + + lval.str = string(lex.data[lex.ts:lex.te]); + if ttype, ok := reservedWords[strings.ToLower(lval.str)]; ok { + tok = ttype; + } else { + tok = IDENT; + } + {( lex.p)++; lex.cs = 4; goto _out }} + goto st4 +tr22: //line lex.rl:79 - lex.te = (lex.p) - (lex.p)-- - { /* nothing */ - } - goto st4 - tr22: + lex.te = ( lex.p) +( lex.p)-- +{/* nothing */} + goto st4 +tr24: //line lex.rl:80 - lex.te = (lex.p) - (lex.p)-- - { - vl, err := strconv.Atoi(string(lex.data[lex.ts:lex.te])) - if err != nil { - vl = 0 - } - lval.uinteger = uint(vl) - tok = ICONST - { - (lex.p)++ - lex.cs = 4 - goto _out - } - } - goto st4 + lex.te = ( lex.p) +( lex.p)-- +{ + vl, err := strconv.Atoi(string(lex.data[lex.ts:lex.te])) + if err != nil { + vl = 0 + } + lval.uinteger = uint(vl); tok = ICONST; {( lex.p)++; lex.cs = 4; goto _out } + } + goto st4 st4: //line NONE:1 - lex.ts = 0 + lex.ts = 0 - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof4 } st_case_4: //line NONE:1 - lex.ts = (lex.p) + lex.ts = ( lex.p) -//line lex.go:198 - switch lex.data[(lex.p)] { +//line lex.go:208 + switch lex.data[( lex.p)] { case 32: goto st5 case 34: @@ -262,18 +222,22 @@ func (lex *Lexer) Lex(lval *yySymType) int { goto st8 case 39: goto st1 - case 44: + case 40: goto tr11 + case 41: + goto tr12 + case 44: + goto tr13 case 45: goto st9 case 46: goto st8 case 47: - goto tr13 + goto tr15 case 58: goto st8 case 61: - goto tr15 + goto tr17 case 92: goto tr8 case 94: @@ -286,73 +250,65 @@ func (lex *Lexer) Lex(lval *yySymType) int { goto tr8 } switch { - case lex.data[(lex.p)] < 42: + case lex.data[( lex.p)] < 48: switch { - case lex.data[(lex.p)] < 33: - if 9 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 13 { - goto st5 - } - case lex.data[(lex.p)] > 38: - if 40 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 41 { - goto st8 + case lex.data[( lex.p)] > 13: + if 33 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 43 { + goto tr8 } - default: - goto tr8 + case lex.data[( lex.p)] >= 9: + goto st5 } - case lex.data[(lex.p)] > 43: + case lex.data[( lex.p)] > 57: switch { - case lex.data[(lex.p)] < 60: - if 48 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 57 { - goto st14 - } - case lex.data[(lex.p)] > 64: - if 65 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 125 { + case lex.data[( lex.p)] > 64: + if 65 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 125 { goto st8 } - default: + case lex.data[( lex.p)] >= 60: goto tr8 } default: - goto tr8 + goto st14 } goto st0 - st_case_0: +st_case_0: st0: - lex.cs = 0 + lex.cs = 0 goto _out st5: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof5 } st_case_5: - if lex.data[(lex.p)] == 32 { + if lex.data[( lex.p)] == 32 { goto st5 } - if 9 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 13 { + if 9 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 13 { goto st5 } - goto tr16 - tr8: + goto tr18 +tr8: //line NONE:1 - lex.te = (lex.p) + 1 + lex.te = ( lex.p)+1 -//line lex.rl:104 - lex.act = 9 - goto st6 - tr15: +//line lex.rl:107 + lex.act = 11; + goto st6 +tr17: //line NONE:1 - lex.te = (lex.p) + 1 + lex.te = ( lex.p)+1 //line lex.rl:101 - lex.act = 7 - goto st6 + lex.act = 7; + goto st6 st6: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof6 } st_case_6: -//line lex.go:297 - switch lex.data[(lex.p)] { +//line lex.go:303 + switch lex.data[( lex.p)] { case 33: goto tr8 case 35: @@ -369,41 +325,41 @@ func (lex *Lexer) Lex(lval *yySymType) int { goto tr8 } switch { - case lex.data[(lex.p)] < 42: - if 37 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 38 { + case lex.data[( lex.p)] < 42: + if 37 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 38 { goto tr8 } - case lex.data[(lex.p)] > 43: - if 60 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 64 { + case lex.data[( lex.p)] > 43: + if 60 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 64 { goto tr8 } default: goto tr8 } goto tr2 - tr9: +tr9: //line NONE:1 - lex.te = (lex.p) + 1 + lex.te = ( lex.p)+1 //line lex.rl:90 - lex.act = 5 - goto st7 - tr17: + lex.act = 5; + goto st7 +tr19: //line NONE:1 - lex.te = (lex.p) + 1 + lex.te = ( lex.p)+1 //line lex.rl:89 - lex.act = 4 - goto st7 + lex.act = 4; + goto st7 st7: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof7 } st_case_7: -//line lex.go:346 - switch lex.data[(lex.p)] { +//line lex.go:352 + switch lex.data[( lex.p)] { case 34: - goto tr17 + goto tr19 case 36: goto tr9 case 93: @@ -414,17 +370,12 @@ func (lex *Lexer) Lex(lval *yySymType) int { goto tr9 } switch { - case lex.data[(lex.p)] < 45: - if 40 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 41 { + case lex.data[( lex.p)] < 65: + if 45 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 58 { goto tr9 } - case lex.data[(lex.p)] > 58: - switch { - case lex.data[(lex.p)] > 91: - if 97 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 123 { - goto tr9 - } - case lex.data[(lex.p)] >= 65: + case lex.data[( lex.p)] > 91: + if 97 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 123 { goto tr9 } default: @@ -432,11 +383,11 @@ func (lex *Lexer) Lex(lval *yySymType) int { } goto tr2 st8: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof8 } st_case_8: - switch lex.data[(lex.p)] { + switch lex.data[( lex.p)] { case 34: goto st8 case 36: @@ -449,38 +400,33 @@ func (lex *Lexer) Lex(lval *yySymType) int { goto st8 } switch { - case lex.data[(lex.p)] < 45: - if 40 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 41 { + case lex.data[( lex.p)] < 65: + if 45 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 58 { goto st8 } - case lex.data[(lex.p)] > 58: - switch { - case lex.data[(lex.p)] > 91: - if 97 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 123 { - goto st8 - } - case lex.data[(lex.p)] >= 65: + case lex.data[( lex.p)] > 91: + if 97 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 123 { goto st8 } default: goto st8 } - goto tr18 + goto tr20 st1: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof1 } st_case_1: - if lex.data[(lex.p)] == 39 { + if lex.data[( lex.p)] == 39 { goto tr1 } goto st1 st9: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof9 } st_case_9: - switch lex.data[(lex.p)] { + switch lex.data[( lex.p)] { case 34: goto st8 case 36: @@ -495,33 +441,28 @@ func (lex *Lexer) Lex(lval *yySymType) int { goto st8 } switch { - case lex.data[(lex.p)] < 46: - if 40 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 41 { + case lex.data[( lex.p)] < 65: + if 46 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 58 { goto st8 } - case lex.data[(lex.p)] > 58: - switch { - case lex.data[(lex.p)] > 91: - if 97 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 123 { - goto st8 - } - case lex.data[(lex.p)] >= 65: + case lex.data[( lex.p)] > 91: + if 97 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 123 { goto st8 } default: goto st8 } - goto tr18 + goto tr20 st10: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof10 } st_case_10: - switch lex.data[(lex.p)] { + switch lex.data[( lex.p)] { case 10: - goto tr20 + goto tr22 case 13: - goto tr20 + goto tr22 case 34: goto st10 case 36: @@ -534,17 +475,12 @@ func (lex *Lexer) Lex(lval *yySymType) int { goto st10 } switch { - case lex.data[(lex.p)] < 45: - if 40 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 41 { + case lex.data[( lex.p)] < 65: + if 45 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 58 { goto st10 } - case lex.data[(lex.p)] > 58: - switch { - case lex.data[(lex.p)] > 91: - if 97 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 123 { - goto st10 - } - case lex.data[(lex.p)] >= 65: + case lex.data[( lex.p)] > 91: + if 97 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 123 { goto st10 } default: @@ -552,31 +488,31 @@ func (lex *Lexer) Lex(lval *yySymType) int { } goto st11 st11: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof11 } st_case_11: - switch lex.data[(lex.p)] { + switch lex.data[( lex.p)] { case 10: - goto tr20 + goto tr22 case 13: - goto tr20 + goto tr22 } goto st11 - tr13: +tr15: //line NONE:1 - lex.te = (lex.p) + 1 + lex.te = ( lex.p)+1 //line lex.rl:90 - lex.act = 5 - goto st12 + lex.act = 5; + goto st12 st12: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof12 } st_case_12: -//line lex.go:521 - switch lex.data[(lex.p)] { +//line lex.go:507 + switch lex.data[( lex.p)] { case 34: goto st8 case 36: @@ -591,67 +527,62 @@ func (lex *Lexer) Lex(lval *yySymType) int { goto st8 } switch { - case lex.data[(lex.p)] < 45: - if 40 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 41 { + case lex.data[( lex.p)] < 65: + if 45 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 58 { goto st8 } - case lex.data[(lex.p)] > 58: - switch { - case lex.data[(lex.p)] > 91: - if 97 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 123 { - goto st8 - } - case lex.data[(lex.p)] >= 65: + case lex.data[( lex.p)] > 91: + if 97 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 123 { goto st8 } default: goto st8 } - goto tr18 + goto tr20 st2: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof2 } st_case_2: - if lex.data[(lex.p)] == 42 { + if lex.data[( lex.p)] == 42 { goto st3 } goto st2 st3: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof3 } st_case_3: - switch lex.data[(lex.p)] { + switch lex.data[( lex.p)] { case 42: goto st3 case 47: goto tr5 } goto st2 - tr5: +tr5: //line NONE:1 - lex.te = (lex.p) + 1 + lex.te = ( lex.p)+1 //line lex.rl:79 - lex.act = 2 - goto st13 + lex.act = 2; + goto st13 st13: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof13 } st_case_13: -//line lex.go:587 - if lex.data[(lex.p)] == 42 { +//line lex.go:568 + if lex.data[( lex.p)] == 42 { goto st3 } goto st2 st14: - if (lex.p)++; (lex.p) == (lex.pe) { + if ( lex.p)++; ( lex.p) == ( lex.pe) { goto _test_eof14 } st_case_14: - switch lex.data[(lex.p)] { + switch lex.data[( lex.p)] { case 34: goto st8 case 36: @@ -666,110 +597,74 @@ func (lex *Lexer) Lex(lval *yySymType) int { goto st8 } switch { - case lex.data[(lex.p)] < 48: - switch { - case lex.data[(lex.p)] > 41: - if 45 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 47 { - goto st8 - } - case lex.data[(lex.p)] >= 40: + case lex.data[( lex.p)] < 48: + if 45 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 47 { goto st8 } - case lex.data[(lex.p)] > 57: + case lex.data[( lex.p)] > 57: switch { - case lex.data[(lex.p)] > 91: - if 97 <= lex.data[(lex.p)] && lex.data[(lex.p)] <= 123 { + case lex.data[( lex.p)] > 91: + if 97 <= lex.data[( lex.p)] && lex.data[( lex.p)] <= 123 { goto st8 } - case lex.data[(lex.p)] >= 65: + case lex.data[( lex.p)] >= 65: goto st8 } default: goto st14 } - goto tr22 + goto tr24 st_out: - _test_eof4: - lex.cs = 4 - goto _test_eof - _test_eof5: - lex.cs = 5 - goto _test_eof - _test_eof6: - lex.cs = 6 - goto _test_eof - _test_eof7: - lex.cs = 7 - goto _test_eof - _test_eof8: - lex.cs = 8 - goto _test_eof - _test_eof1: - lex.cs = 1 - goto _test_eof - _test_eof9: - lex.cs = 9 - goto _test_eof - _test_eof10: - lex.cs = 10 - goto _test_eof - _test_eof11: - lex.cs = 11 - goto _test_eof - _test_eof12: - lex.cs = 12 - goto _test_eof - _test_eof2: - lex.cs = 2 - goto _test_eof - _test_eof3: - lex.cs = 3 - goto _test_eof - _test_eof13: - lex.cs = 13 - goto _test_eof - _test_eof14: - lex.cs = 14 - goto _test_eof + _test_eof4: lex.cs = 4; goto _test_eof + _test_eof5: lex.cs = 5; goto _test_eof + _test_eof6: lex.cs = 6; goto _test_eof + _test_eof7: lex.cs = 7; goto _test_eof + _test_eof8: lex.cs = 8; goto _test_eof + _test_eof1: lex.cs = 1; goto _test_eof + _test_eof9: lex.cs = 9; goto _test_eof + _test_eof10: lex.cs = 10; goto _test_eof + _test_eof11: lex.cs = 11; goto _test_eof + _test_eof12: lex.cs = 12; goto _test_eof + _test_eof2: lex.cs = 2; goto _test_eof + _test_eof3: lex.cs = 3; goto _test_eof + _test_eof13: lex.cs = 13; goto _test_eof + _test_eof14: lex.cs = 14; goto _test_eof - _test_eof: - { - } - if (lex.p) == eof { - switch lex.cs { - case 5: - goto tr16 - case 6: - goto tr2 - case 7: - goto tr2 - case 8: - goto tr18 - case 9: - goto tr18 - case 10: - goto tr20 - case 11: - goto tr20 - case 12: - goto tr18 - case 2: - goto tr2 - case 3: - goto tr2 - case 13: - goto tr20 - case 14: - goto tr22 - } + _test_eof: {} + if ( lex.p) == eof { + switch lex.cs { + case 5: + goto tr18 + case 6: + goto tr2 + case 7: + goto tr2 + case 8: + goto tr20 + case 9: + goto tr20 + case 10: + goto tr22 + case 11: + goto tr22 + case 12: + goto tr20 + case 2: + goto tr2 + case 3: + goto tr2 + case 13: + goto tr22 + case 14: + goto tr24 } + } - _out: - { - } + _out: {} } -//line lex.rl:111 +//line lex.rl:114 - return int(tok) -} + + return int(tok); +} \ No newline at end of file diff --git a/yacc/console/lex.rl b/yacc/console/lex.rl index 9c53560ac..f9cac4466 100644 --- a/yacc/console/lex.rl +++ b/yacc/console/lex.rl @@ -53,7 +53,7 @@ func (lex *Lexer) Lex(lval *yySymType) int { op_chars = ( '~' | '!' | '@' | '#' | '^' | '&' | '|' | '`' | '?' | '+' | '*' | '\\' | '%' | '<' | '>' | '=' ) ; sconst = '\'' (any-'\'')* '\''; - identifier = (print - space - op_chars-'\'' - ';' - ',')*; + identifier = (print - space - op_chars-'\'' - ';' - ',' - '(' - ')')*; qidentifier = '"' identifier '"'; @@ -101,6 +101,9 @@ func (lex *Lexer) Lex(lval *yySymType) int { '=' => { lval.str = string(lex.data[lex.ts:lex.te]); tok = TEQ; fbreak;}; ',' => { lval.str = string(lex.data[lex.ts:lex.te]); tok = TCOMMA; fbreak;}; + '(' => { lval.str = string(lex.data[lex.ts:lex.te]); tok = TOPENBR; fbreak;}; + ')' => { lval.str = string(lex.data[lex.ts:lex.te]); tok = TCLOSEBR; fbreak;}; + operator => { lval.str = string(lex.data[lex.ts:lex.te]); tok = int(OP); fbreak; diff --git a/yacc/console/lx_test.go b/yacc/console/lx_test.go index dc354d3d9..1b6dba1cd 100644 --- a/yacc/console/lx_test.go +++ b/yacc/console/lx_test.go @@ -100,7 +100,7 @@ func TestSimpleLex(t *testing.T) { }, }, { - query: "ALTER DISTRIBUTION ds1 ATTACH RELATION t COLUMNS id", + query: "ALTER DISTRIBUTION ds1 ATTACH RELATION t DISTRIBUTION KEY id", exp: []int{ spqrparser.ALTER, spqrparser.DISTRIBUTION, @@ -108,12 +108,13 @@ func TestSimpleLex(t *testing.T) { spqrparser.ATTACH, spqrparser.RELATION, spqrparser.IDENT, - spqrparser.COLUMNS, + spqrparser.DISTRIBUTION, + spqrparser.KEY, spqrparser.IDENT, }, }, { - query: "ALTER DISTRIBUTION ds1 ATTACH RELATION t COLUMNS id1, id2", + query: "ALTER DISTRIBUTION ds1 ATTACH RELATION t DISTRIBUTION KEY id1, id2", exp: []int{ spqrparser.ALTER, spqrparser.DISTRIBUTION, @@ -121,7 +122,8 @@ func TestSimpleLex(t *testing.T) { spqrparser.ATTACH, spqrparser.RELATION, spqrparser.IDENT, - spqrparser.COLUMNS, + spqrparser.DISTRIBUTION, + spqrparser.KEY, spqrparser.IDENT, spqrparser.TCOMMA, spqrparser.IDENT, diff --git a/yacc/console/yx_test.go b/yacc/console/yx_test.go index b41373573..8228eb5e8 100644 --- a/yacc/console/yx_test.go +++ b/yacc/console/yx_test.go @@ -335,13 +335,17 @@ func TestAlter(t *testing.T) { for _, tt := range []tcase{ { - query: "ALTER DISTRIBUTION ds1 ATTACH RELATION t COLUMNS id;", + query: "ALTER DISTRIBUTION ds1 ATTACH RELATION t DISTRIBUTION KEY id;", exp: &spqrparser.Alter{ Element: &spqrparser.AlterDistribution{ Element: &spqrparser.AttachRelation{ Relation: &spqrparser.DistributedRelation{ - Name: "t", - Columns: []string{"id"}, + Name: "t", + DistributionKey: []spqrparser.DistributionKeyEntry{ + { + Column: "id", + }, + }, }, Distribution: &spqrparser.DistributionSelector{ID: "ds1"}, }, @@ -350,13 +354,43 @@ func TestAlter(t *testing.T) { err: nil, }, { - query: "ALTER DISTRIBUTION ds1 ATTACH RELATION t COLUMNS id1, id2;", + query: "ALTER DISTRIBUTION ds1 ATTACH RELATION t DISTRIBUTION KEY id1, id2;", exp: &spqrparser.Alter{ Element: &spqrparser.AlterDistribution{ Element: &spqrparser.AttachRelation{ Relation: &spqrparser.DistributedRelation{ - Name: "t", - Columns: []string{"id1", "id2"}, + Name: "t", + DistributionKey: []spqrparser.DistributionKeyEntry{ + { + Column: "id1", + }, + { + Column: "id2", + }, + }, + }, + Distribution: &spqrparser.DistributionSelector{ID: "ds1"}, + }, + }, + }, + err: nil, + }, + { + query: "ALTER DISTRIBUTION ds1 ATTACH RELATION t DISTRIBUTION KEY id1, id2 HASH FUNCTION murmur;", + exp: &spqrparser.Alter{ + Element: &spqrparser.AlterDistribution{ + Element: &spqrparser.AttachRelation{ + Relation: &spqrparser.DistributedRelation{ + Name: "t", + DistributionKey: []spqrparser.DistributionKeyEntry{ + { + Column: "id1", + }, + { + Column: "id2", + HashFunction: "murmur", + }, + }, }, Distribution: &spqrparser.DistributionSelector{ID: "ds1"}, },