Skip to content

Commit

Permalink
schema: Sort results by partition keys in multi-partition tests
Browse files Browse the repository at this point in the history
The order of "IN" queries for multiple partitions is different in
Cassandra and Scylla:

scylladb/scylladb#2029

Gemini finds this problem, of course, but since this is a known issue,
let's work around it by sorting the results explicitly (suggested by
Avi).

We can revert the change when the problems is fixed in upstream Scylla.
  • Loading branch information
penberg committed Dec 17, 2018
1 parent 819f30f commit 4ec328f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,15 @@ func (s *schema) genMultiplePartitionQuery(t Table, p *PartitionRange) *Stmt {
relations := []string{}
values := make([]interface{}, 0)
pkNum := rand.Intn(10)
pkNames := []string{}
for _, pk := range t.PartitionKeys {
pkNames = append(pkNames, pk.Name)
relations = append(relations, fmt.Sprintf("%s IN (%s)", pk.Name, strings.TrimRight(strings.Repeat("?,", pkNum), ",")))
for i := 0; i < pkNum; i++ {
values = generateValue(pk.Type, p, values)
}
}
query := fmt.Sprintf("SELECT * FROM %s.%s WHERE %s", s.keyspace.Name, t.Name, strings.Join(relations, " AND "))
query := fmt.Sprintf("SELECT * FROM %s.%s WHERE %s ORDER BY %s", s.keyspace.Name, t.Name, strings.Join(relations, " AND "), strings.Join(pkNames, ","))
return &Stmt{
Query: query,
Values: func() []interface{} {
Expand Down Expand Up @@ -266,8 +268,10 @@ func (s *schema) genClusteringRangeQuery(t Table, p *PartitionRange) *Stmt {
func (s *schema) genMultiplePartitionClusteringRangeQuery(t Table, p *PartitionRange) *Stmt {
relations := []string{}
pkNum := rand.Intn(10)
pkNames := []string{}
values := make([]interface{}, 0)
for _, pk := range t.PartitionKeys {
pkNames = append(pkNames, pk.Name)
relations = append(relations, fmt.Sprintf("%s IN (%s)", pk.Name, strings.TrimRight(strings.Repeat("?,", pkNum), ",")))
for i := 0; i < pkNum; i++ {
values = generateValue(pk.Type, p, values)
Expand All @@ -277,7 +281,7 @@ func (s *schema) genMultiplePartitionClusteringRangeQuery(t Table, p *PartitionR
relations = append(relations, fmt.Sprintf("%s >= ? AND %s <= ?", ck.Name, ck.Name))
values = generateValue(ck.Type+"_range", p, values)
}
query := fmt.Sprintf("SELECT * FROM %s.%s WHERE %s", s.keyspace.Name, t.Name, strings.Join(relations, " AND "))
query := fmt.Sprintf("SELECT * FROM %s.%s WHERE %s ORDER BY %s", s.keyspace.Name, t.Name, strings.Join(relations, " AND "), strings.Join(pkNames, ","))
return &Stmt{
Query: query,
Values: func() []interface{} {
Expand Down

0 comments on commit 4ec328f

Please sign in to comment.