Skip to content

Commit 321e355

Browse files
authored
feat: Expose Migration test for new special case for moving to _cq_id as only primary key (#1480)
#### Summary Destinations can now verify the new `MoveToCQIDPrimaryKey` change type that was introduced in #1470 Depends on #1479
1 parent 78027f0 commit 321e355

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

plugin/testing_write.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type SafeMigrations struct {
4242
RemoveColumn bool
4343
RemoveColumnNotNull bool
4444
ChangeColumn bool
45+
MovePKToCQOnly bool
4546
}
4647

4748
type WriterTestSuiteTests struct {

plugin/testing_write_migrate.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,32 @@ func (s *WriterTestSuite) testMigrate(
230230
}
231231
})
232232

233+
t.Run("move_to_cq_id_only"+suffix, func(t *testing.T) {
234+
if !forceMigrate && !s.tests.SafeMigrations.MovePKToCQOnly {
235+
t.Skip("skipping test: move_to_cq_id_only")
236+
}
237+
tableName := "move_to_cq_id_only" + suffix + "_" + tableUUIDSuffix()
238+
source := &schema.Table{
239+
Name: tableName,
240+
Columns: schema.ColumnList{
241+
{Name: "_cq_id", Type: types.ExtensionTypes.UUID, NotNull: true, Unique: true},
242+
{Name: "id", Type: arrow.PrimitiveTypes.Int64, PrimaryKey: true},
243+
{Name: "uuid", Type: types.ExtensionTypes.UUID},
244+
{Name: "bool", Type: arrow.FixedWidthTypes.Boolean, NotNull: true},
245+
}}
246+
target := &schema.Table{
247+
Name: tableName,
248+
Columns: schema.ColumnList{
249+
{Name: "_cq_id", Type: types.ExtensionTypes.UUID, NotNull: true, Unique: true, PrimaryKey: true},
250+
{Name: "id", Type: arrow.PrimitiveTypes.Int64},
251+
{Name: "uuid", Type: types.ExtensionTypes.UUID},
252+
{Name: "bool", Type: arrow.FixedWidthTypes.Boolean, NotNull: true},
253+
}}
254+
if err := s.migrate(ctx, target, source, s.tests.SafeMigrations.MovePKToCQOnly, forceMigrate); err != nil {
255+
t.Fatalf("failed to migrate move_to_cq_id_only: %v", err)
256+
}
257+
})
258+
233259
t.Run("double_migration", func(t *testing.T) {
234260
if forceMigrate {
235261
t.Skip("double migration test has sense only for safe migrations")

schema/testdata.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"crypto/sha256"
55
"encoding/base64"
66
"fmt"
7-
"sort"
87
"strconv"
98
"strings"
109
"time"
@@ -251,16 +250,7 @@ func (tg *TestDataGenerator) Generate(table *Table, opts GenTestDataOptions) arr
251250
records = append(records, bldr.NewRecord())
252251
bldr.Release()
253252
}
254-
if indices := sc.FieldIndices(CqIDColumn.Name); len(indices) > 0 {
255-
cqIDIndex := indices[0]
256-
sort.Slice(records, func(i, j int) bool {
257-
firstUUID := records[i].Column(cqIDIndex).(*types.UUIDArray).Value(0).String()
258-
secondUUID := records[j].Column(cqIDIndex).(*types.UUIDArray).Value(0).String()
259-
return strings.Compare(firstUUID, secondUUID) < 0
260-
})
261-
}
262253

263-
// now we have sorted 1-row-records. Transform them into a single record with opts.MaxRows rows
264254
arrowTable := array.NewTableFromRecords(sc, records)
265255
columns := make([]arrow.Array, sc.NumFields())
266256
for n := 0; n < sc.NumFields(); n++ {

0 commit comments

Comments
 (0)