@@ -25,7 +25,6 @@ package changestreams
25
25
26
26
import (
27
27
"context"
28
- "encoding/json"
29
28
"errors"
30
29
"fmt"
31
30
"sync"
@@ -42,70 +41,6 @@ type ReadResult struct {
42
41
ChangeRecords []* ChangeRecord `spanner:"ChangeRecord" json:"change_record"`
43
42
}
44
43
45
- // ChangeRecord is the single unit of the records from the change stream.
46
- type ChangeRecord struct {
47
- DataChangeRecords []* DataChangeRecord `spanner:"data_change_record" json:"data_change_record"`
48
- HeartbeatRecords []* HeartbeatRecord `spanner:"heartbeat_record" json:"heartbeat_record"`
49
- ChildPartitionsRecords []* ChildPartitionsRecord `spanner:"child_partitions_record" json:"child_partitions_record"`
50
- }
51
-
52
- // DataChangeRecord contains a set of changes to the table.
53
- type DataChangeRecord struct {
54
- CommitTimestamp time.Time `spanner:"commit_timestamp" json:"commit_timestamp"`
55
- RecordSequence string `spanner:"record_sequence" json:"record_sequence"`
56
- ServerTransactionID string `spanner:"server_transaction_id" json:"server_transaction_id"`
57
- IsLastRecordInTransactionInPartition bool `spanner:"is_last_record_in_transaction_in_partition" json:"is_last_record_in_transaction_in_partition"`
58
- TableName string `spanner:"table_name" json:"table_name"`
59
- ColumnTypes []* ColumnType `spanner:"column_types" json:"column_types"`
60
- Mods []* Mod `spanner:"mods" json:"mods"`
61
- ModType string `spanner:"mod_type" json:"mod_type"`
62
- ValueCaptureType string `spanner:"value_capture_type" json:"value_capture_type"`
63
- NumberOfRecordsInTransaction int64 `spanner:"number_of_records_in_transaction" json:"number_of_records_in_transaction"`
64
- NumberOfPartitionsInTransaction int64 `spanner:"number_of_partitions_in_transaction" json:"number_of_partitions_in_transaction"`
65
- TransactionTag string `spanner:"transaction_tag" json:"transaction_tag"`
66
- IsSystemTransaction bool `spanner:"is_system_transaction" json:"is_system_transaction"`
67
- }
68
-
69
- // ColumnType is the metadata of the column.
70
- type ColumnType struct {
71
- Name string `spanner:"name" json:"name"`
72
- Type spanner.NullJSON `spanner:"type" json:"type"`
73
- IsPrimaryKey bool `spanner:"is_primary_key" json:"is_primary_key"`
74
- OrdinalPosition int64 `spanner:"ordinal_position" json:"ordinal_position"`
75
- }
76
-
77
- // Mod is the changes that were made on the table.
78
- type Mod struct {
79
- Keys spanner.NullJSON `spanner:"keys" json:"keys"`
80
- NewValues spanner.NullJSON `spanner:"new_values" json:"new_values"`
81
- OldValues spanner.NullJSON `spanner:"old_values" json:"old_values"`
82
- }
83
-
84
- // HeartbeatRecord is the heartbeat record returned from Cloud Spanner.
85
- type HeartbeatRecord struct {
86
- Timestamp time.Time `spanner:"timestamp" json:"timestamp"`
87
- }
88
-
89
- // ChildPartitionsRecord contains the child partitions of the stream.
90
- type ChildPartitionsRecord struct {
91
- StartTimestamp time.Time `spanner:"start_timestamp" json:"start_timestamp"`
92
- RecordSequence string `spanner:"record_sequence" json:"record_sequence"`
93
- ChildPartitions []* ChildPartition `spanner:"child_partitions" json:"child_partitions"`
94
- }
95
-
96
- // ChildPartition contains the child partition token.
97
- type ChildPartition struct {
98
- Token string `spanner:"token" json:"token"`
99
- ParentPartitionTokens []string `spanner:"parent_partition_tokens" json:"parent_partition_tokens"`
100
- }
101
-
102
- // changeRecordPostgres is an interim struct to decode change stream result for PostgreSQL.
103
- type changeRecordPostgres struct {
104
- DataChangeRecord * DataChangeRecord `spanner:"data_change_record" json:"data_change_record"`
105
- HeartbeatRecord * HeartbeatRecord `spanner:"heartbeat_record" json:"heartbeat_record"`
106
- ChildPartitionsRecord * ChildPartitionsRecord `spanner:"child_partitions_record" json:"child_partitions_record"`
107
- }
108
-
109
44
type partitionState int
110
45
111
46
const (
@@ -330,38 +265,3 @@ func (r *Reader) canReadChild(partition *ChildPartition) bool {
330
265
}
331
266
return true
332
267
}
333
-
334
- func decodePostgresRow (row * spanner.Row ) (* ChangeRecord , error ) {
335
- // Retrieve JSON bytes.
336
- var col spanner.NullJSON
337
- if err := row .Column (0 , & col ); err != nil {
338
- return nil , err
339
- }
340
- jsonBytes , err := col .MarshalJSON ()
341
- if err != nil {
342
- return nil , err
343
- }
344
-
345
- var changeRecordPG changeRecordPostgres
346
- if err := json .Unmarshal (jsonBytes , & changeRecordPG ); err != nil {
347
- return nil , err
348
- }
349
-
350
- // Convert to ChangeRecord type.
351
- changeRecord := ChangeRecord {
352
- DataChangeRecords : []* DataChangeRecord {},
353
- HeartbeatRecords : []* HeartbeatRecord {},
354
- ChildPartitionsRecords : []* ChildPartitionsRecord {},
355
- }
356
- if changeRecordPG .DataChangeRecord != nil {
357
- changeRecord .DataChangeRecords = []* DataChangeRecord {changeRecordPG .DataChangeRecord }
358
- }
359
- if changeRecordPG .HeartbeatRecord != nil {
360
- changeRecord .HeartbeatRecords = []* HeartbeatRecord {changeRecordPG .HeartbeatRecord }
361
- }
362
- if changeRecordPG .ChildPartitionsRecord != nil {
363
- changeRecord .ChildPartitionsRecords = []* ChildPartitionsRecord {changeRecordPG .ChildPartitionsRecord }
364
- }
365
-
366
- return & changeRecord , nil
367
- }
0 commit comments