Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support hash functions in distributions. Add distribution key in inte… #503

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pkg/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
92 changes: 71 additions & 21 deletions pkg/models/distributions/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
EinKrebs marked this conversation as resolved.
Show resolved Hide resolved
}

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 {
Expand Down Expand Up @@ -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,
Expand Down
Loading
Loading