@@ -140,21 +140,28 @@ class TransactionStateTest extends AnyWordSpec with Matchers with OptionValues {
140
140
}
141
141
142
142
" transform binlog write event into json" in {
143
- val skuMeta =
144
- models.TableMetadata (
145
- " sku" ,
146
- Map (
147
- 1 -> models.ColumnMetadata (" id" , " int" , 1 , isPk = true ),
148
- 2 -> models.ColumnMetadata (" sku" , " varchar" , 2 , isPk = false )
149
- )
150
- )
151
- val schemaMeta =
152
- models
153
- .SchemaMetadata (tables = Map (" sku" -> skuMeta), idToTable = mutable.Map (123L -> skuMeta))
143
+
144
+ val TableName = " all_types_table"
145
+
146
+ val allTypes =
147
+ List (" int" , " tinyint" , " bigint" , " date" , " datetime" , " decimal" , " float" , " text" , " tinytext" , " mediumtext" , " longtext" , " varchar" )
148
+
149
+ val columnMeta = allTypes.zipWithIndex.map { case (mType, idx) =>
150
+ val colName = s " ${mType}Col "
151
+ val ordinal = idx + 1
152
+ ordinal -> models.ColumnMetadata (colName, mType, ordinal, isPk = colName == " intCol" )
153
+ }.toMap
154
+
155
+ val tableMeta = models.TableMetadata (TableName , columnMeta)
156
+
157
+ val schemaMeta = models.SchemaMetadata (
158
+ tables = Map (" all_types_table" -> tableMeta),
159
+ idToTable = mutable.Map (123L -> tableMeta)
160
+ )
154
161
155
162
val json = TransactionState .convertToJson(
156
- tableMeta = schemaMeta.tables(" sku " ),
157
- includedColumns = Array ( 0 , 1 ) ,
163
+ tableMeta = schemaMeta.tables(TableName ),
164
+ includedColumns = 0 .until(columnMeta.size).toArray ,
158
165
timestamp = 12345L ,
159
166
action = " create" ,
160
167
fileName = " file.12345" ,
@@ -163,20 +170,41 @@ class TransactionStateTest extends AnyWordSpec with Matchers with OptionValues {
163
170
None ,
164
171
Some (
165
172
Array (
166
- Some (1 .asInstanceOf [io.Serializable ]),
167
- Some (" sku1" .getBytes.asInstanceOf [io.Serializable ])
173
+ Some (100 .asInstanceOf [io.Serializable ]), // int
174
+ Some (200 .asInstanceOf [io.Serializable ]), // tinyint
175
+ Some (Long .MaxValue .asInstanceOf [io.Serializable ]), // bigint
176
+ Some (1672531200000L .asInstanceOf [io.Serializable ]), // date
177
+ Some (1672567872000L .asInstanceOf [io.Serializable ]), // datetime
178
+ Some (java.math.BigDecimal .valueOf(99887766 ).asInstanceOf [io.Serializable ]), // decimal
179
+ Some (111.222f .asInstanceOf [io.Serializable ]), // float
180
+ Some (" some text" .getBytes.asInstanceOf [io.Serializable ]), // text
181
+ Some (" some tinytext" .getBytes.asInstanceOf [io.Serializable ]), // tinytext
182
+ Some (" some mediumtext" .getBytes.asInstanceOf [io.Serializable ]), // mediumtext
183
+ Some (" some longtext" .getBytes.asInstanceOf [io.Serializable ]), // longtext
184
+ Some (" a varchar" .getBytes.asInstanceOf [io.Serializable ]) // varchar
168
185
)
169
186
)
170
187
)
171
188
)
172
- val _pk = root.id.int
173
- val _id = root.after.id.int
174
- val _sku = root.after.sku.string
175
- json.table should be(" sku" )
189
+
190
+ json.table should be(TableName )
176
191
json.timestamp should be(12345L )
177
- _id.getOption(json.row).value should be(1 )
178
- _sku.getOption(json.row).value should be(" sku1" )
179
- _pk.getOption(json.pk).value should be(1 )
192
+
193
+ val after = root.after
194
+
195
+ after.intCol.int.getOption(json.row).value should be(100 )
196
+ after.tinyintCol.int.getOption(json.row).value should be(200 )
197
+ after.bigintCol.long.getOption(json.row).value should be(Long .MaxValue )
198
+ after.dateCol.long.getOption(json.row).value should be(1672531200000L )
199
+ after.datetimeCol.long.getOption(json.row).value should be(1672567872000L )
200
+ after.decimalCol.bigDecimal.getOption(json.row).value should be(BigDecimal .valueOf(99887766 ))
201
+ after.floatCol.double.getOption(json.row).value should be(111.222 )
202
+ after.textCol.string.getOption(json.row).value should be(" some text" )
203
+ after.tinytextCol.string.getOption(json.row).value should be(" some tinytext" )
204
+ after.mediumtextCol.string.getOption(json.row).value should be(" some mediumtext" )
205
+ after.longtextCol.string.getOption(json.row).value should be(" some longtext" )
206
+ after.varcharCol.string.getOption(json.row).value should be(" a varchar" )
207
+
180
208
}
181
209
182
210
" extract 'truncated table sku' from SQL" in {
0 commit comments