Skip to content

Commit

Permalink
Merge pull request #214 from scylladb/mv_reads_off_by_one
Browse files Browse the repository at this point in the history
schema: append newly generated values for mv queries
  • Loading branch information
Henrik Johansson authored Dec 3, 2019
2 parents 6993fd8 + 730bf0e commit c4e2a9d
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,20 +884,26 @@ func (s *Schema) genMultiplePartitionQuery(t *Table, g *Generator, r *rand.Rand,
tableName = t.MaterializedViews[view].Name
partitionKeys = t.MaterializedViews[view].PartitionKeys
}
pkNum := r.Intn(len(partitionKeys))
if pkNum == 0 {
pkNum = 1
numQueryPKs := r.Intn(len(partitionKeys))
if numQueryPKs == 0 {
numQueryPKs = 1
}
builder := qb.Select(s.Keyspace.Name + "." + tableName)
for i, pk := range partitionKeys {
builder = builder.Where(qb.InTuple(pk.Name, pkNum))
for j := 0; j < pkNum; j++ {
builder = builder.Where(qb.InTuple(pk.Name, numQueryPKs))
for j := 0; j < numQueryPKs; j++ {
vs, ok := g.GetOld()
if !ok {
return nil
}
values = append(values, vs.Value[i])
typs = append(typs, pk.Type)
numMVKeys := len(partitionKeys) - len(vs.Value)
if i < numMVKeys {
values = appendValue(pk.Type, r, p, values)
typs = append(typs, pk.Type)
} else {
values = append(values, vs.Value[i-numMVKeys])
typs = append(typs, pk.Type)
}
}
}
return &Stmt{
Expand Down Expand Up @@ -976,20 +982,26 @@ func (s *Schema) genMultiplePartitionClusteringRangeQuery(t *Table, g *Generator
partitionKeys = t.MaterializedViews[view].PartitionKeys
clusteringKeys = t.MaterializedViews[view].ClusteringKeys
}
pkNum := r.Intn(len(partitionKeys))
if pkNum == 0 {
pkNum = 1
numQueryPKs := r.Intn(len(partitionKeys))
if numQueryPKs == 0 {
numQueryPKs = 1
}
builder := qb.Select(s.Keyspace.Name + "." + tableName)
for i, pk := range partitionKeys {
builder = builder.Where(qb.InTuple(pk.Name, pkNum))
for j := 0; j < pkNum; j++ {
builder = builder.Where(qb.InTuple(pk.Name, numQueryPKs))
for j := 0; j < numQueryPKs; j++ {
vs, ok := g.GetOld()
if !ok {
return nil
}
values = append(values, vs.Value[i])
typs = append(typs, pk.Type)
numMVKeys := len(partitionKeys) - len(vs.Value)
if i < numMVKeys {
values = appendValue(pk.Type, r, p, values)
typs = append(typs, pk.Type)
} else {
values = append(values, vs.Value[i-numMVKeys])
typs = append(typs, pk.Type)
}
}
}
if len(clusteringKeys) > 0 {
Expand Down

0 comments on commit c4e2a9d

Please sign in to comment.