Skip to content

Commit

Permalink
Reference table initial infra code change (#769)
Browse files Browse the repository at this point in the history
* Reference table initial infra code change

* Add test
  • Loading branch information
reshke authored Sep 16, 2024
1 parent 006a961 commit 62c9895
Show file tree
Hide file tree
Showing 11 changed files with 477 additions and 399 deletions.
3 changes: 3 additions & 0 deletions pkg/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ func processAlterDistribution(ctx context.Context, astmt spqrparser.Statement, m
rels := []*distributions.DistributedRelation{}

for _, drel := range stmt.Relations {
if stmt.Distribution.Replicated && !drel.ReplicatedRelation {
return spqrerror.New(spqrerror.SPQR_NO_DISTRIBUTION, "non replicated relation should be attached to non replicated distribution")
}
rels = append(rels, distributions.DistributedRelationFromSQL(drel))
}

Expand Down
15 changes: 13 additions & 2 deletions pkg/models/distributions/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ type DistributionKeyEntry struct {
}

type DistributedRelation struct {
Name string
DistributionKey []DistributionKeyEntry
Name string
DistributionKey []DistributionKeyEntry
ReplicatedRelation bool
}

// DistributedRelationFromDB creates a DistributedRelation object from a qdb.DistributedRelation object.
Expand All @@ -35,6 +36,8 @@ func DistributedRelationFromDB(rel *qdb.DistributedRelation) *DistributedRelatio
})
}

rdistr.ReplicatedRelation = rel.ReplicatedRelation

return rdistr
}

Expand All @@ -58,6 +61,8 @@ func DistributedRelationToDB(rel *DistributedRelation) *qdb.DistributedRelation
})
}

rdistr.ReplicatedRelation = rel.ReplicatedRelation

return rdistr
}

Expand All @@ -81,6 +86,8 @@ func DistributedRelatitonToProto(rel *DistributedRelation) *proto.DistributedRel
})
}

rdistr.ReplicatedRelation = rel.ReplicatedRelation

return rdistr
}

Expand All @@ -103,6 +110,8 @@ func DistributedRelationFromProto(rel *proto.DistributedRelation) *DistributedRe
})
}

rdistr.ReplicatedRelation = rel.ReplicatedRelation

return rdistr
}

Expand All @@ -125,6 +134,8 @@ func DistributedRelationFromSQL(rel *spqrparser.DistributedRelation) *Distribute
})
}

rdistr.ReplicatedRelation = rel.ReplicatedRelation

return rdistr
}

Expand Down
227 changes: 119 additions & 108 deletions pkg/protos/distribution.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions protos/distribution.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ message DistributionKeyEntry {
message DistributedRelation {
string name = 1;
repeated DistributionKeyEntry distributionKey = 2;
bool ReplicatedRelation = 3;
}

message Distribution {
Expand Down
5 changes: 3 additions & 2 deletions qdb/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ type DistributionKeyEntry struct {
}

type DistributedRelation struct {
Name string `json:"name"`
DistributionKey []DistributionKeyEntry `json:"column_names"`
Name string `json:"name"`
DistributionKey []DistributionKeyEntry `json:"column_names"`
ReplicatedRelation bool `json:"replicated_relation,omitempty"`
}

type Distribution struct {
Expand Down
8 changes: 5 additions & 3 deletions yacc/console/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ type ShardingRuleSelector struct {
}

type DistributionSelector struct {
ID string
ID string
Replicated bool
}

type ShardSelector struct {
Expand Down Expand Up @@ -225,8 +226,9 @@ type DistributionKeyEntry struct {
}

type DistributedRelation struct {
Name string
DistributionKey []DistributionKeyEntry
Name string
DistributionKey []DistributionKeyEntry
ReplicatedRelation bool
}

type AttachRelation struct {
Expand Down
Loading

0 comments on commit 62c9895

Please sign in to comment.