@@ -109,7 +109,7 @@ DataTypePtr typeFromString(const String & str)
109
109
TEST (ChunkColumnCast_test, CastNumeric)
110
110
{
111
111
{
112
- const Strings to_types = {" UInt16" , " UInt32" , " UInt64" };
112
+ const Strings to_types = {" UInt8 " , " UInt16" , " UInt32" , " UInt64" };
113
113
114
114
DataTypePtr disk_data_type = typeFromString (" UInt8" );
115
115
MutableColumnPtr disk_col = disk_data_type->createColumn ();
@@ -133,7 +133,55 @@ TEST(ChunkColumnCast_test, CastNumeric)
133
133
}
134
134
135
135
{
136
- const Strings to_types = {" Int16" , " Int32" , " Int64" };
136
+ const Strings to_types = {" UInt16" , " UInt32" , " UInt64" };
137
+
138
+ DataTypePtr disk_data_type = typeFromString (" UInt16" );
139
+ MutableColumnPtr disk_col = disk_data_type->createColumn ();
140
+ disk_col->insert (Field (UInt64 (15 )));
141
+ disk_col->insert (Field (UInt64 (255 )));
142
+
143
+ for (const String & to_type : to_types)
144
+ {
145
+ DataTypePtr read_data_type = typeFromString (to_type);
146
+ ColumnDefine read_define (0 , " c" , read_data_type);
147
+ MutableColumnPtr memory_column = read_data_type->createColumn ();
148
+ memory_column->reserve (2 );
149
+
150
+ castColumnAccordingToColumnDefine (disk_data_type, disk_col->getPtr (), read_define, memory_column->getPtr (), 0 , 2 );
151
+
152
+ UInt64 val1 = memory_column->getUInt (0 );
153
+ ASSERT_EQ (val1, 15UL );
154
+ UInt64 val2 = memory_column->getUInt (1 );
155
+ ASSERT_EQ (val2, 255UL );
156
+ }
157
+ }
158
+
159
+ {
160
+ const Strings to_types = {" UInt32" , " UInt64" };
161
+
162
+ DataTypePtr disk_data_type = typeFromString (" UInt32" );
163
+ MutableColumnPtr disk_col = disk_data_type->createColumn ();
164
+ disk_col->insert (Field (UInt64 (15 )));
165
+ disk_col->insert (Field (UInt64 (255 )));
166
+
167
+ for (const String & to_type : to_types)
168
+ {
169
+ DataTypePtr read_data_type = typeFromString (to_type);
170
+ ColumnDefine read_define (0 , " c" , read_data_type);
171
+ MutableColumnPtr memory_column = read_data_type->createColumn ();
172
+ memory_column->reserve (2 );
173
+
174
+ castColumnAccordingToColumnDefine (disk_data_type, disk_col->getPtr (), read_define, memory_column->getPtr (), 0 , 2 );
175
+
176
+ UInt64 val1 = memory_column->getUInt (0 );
177
+ ASSERT_EQ (val1, 15UL );
178
+ UInt64 val2 = memory_column->getUInt (1 );
179
+ ASSERT_EQ (val2, 255UL );
180
+ }
181
+ }
182
+
183
+ {
184
+ const Strings to_types = {" Int8" , " Int16" , " Int32" , " Int64" };
137
185
138
186
DataTypePtr disk_data_type = typeFromString (" Int8" );
139
187
MutableColumnPtr disk_col = disk_data_type->createColumn ();
@@ -155,6 +203,54 @@ TEST(ChunkColumnCast_test, CastNumeric)
155
203
ASSERT_EQ (val2, -1L );
156
204
}
157
205
}
206
+
207
+ {
208
+ const Strings to_types = {" Int16" , " Int32" , " Int64" };
209
+
210
+ DataTypePtr disk_data_type = typeFromString (" Int16" );
211
+ MutableColumnPtr disk_col = disk_data_type->createColumn ();
212
+ disk_col->insert (Field (Int64 (127 )));
213
+ disk_col->insert (Field (Int64 (-1 )));
214
+
215
+ for (const String & to_type : to_types)
216
+ {
217
+ DataTypePtr read_data_type = typeFromString (to_type);
218
+ ColumnDefine read_define (0 , " c" , read_data_type);
219
+ MutableColumnPtr memory_column = read_data_type->createColumn ();
220
+ memory_column->reserve (2 );
221
+
222
+ castColumnAccordingToColumnDefine (disk_data_type, disk_col->getPtr (), read_define, memory_column->getPtr (), 0 , 2 );
223
+
224
+ Int64 val1 = memory_column->getInt (0 );
225
+ ASSERT_EQ (val1, 127L );
226
+ Int64 val2 = memory_column->getInt (1 );
227
+ ASSERT_EQ (val2, -1L );
228
+ }
229
+ }
230
+
231
+ {
232
+ const Strings to_types = {" Int32" , " Int64" };
233
+
234
+ DataTypePtr disk_data_type = typeFromString (" Int32" );
235
+ MutableColumnPtr disk_col = disk_data_type->createColumn ();
236
+ disk_col->insert (Field (Int64 (127 )));
237
+ disk_col->insert (Field (Int64 (-1 )));
238
+
239
+ for (const String & to_type : to_types)
240
+ {
241
+ DataTypePtr read_data_type = typeFromString (to_type);
242
+ ColumnDefine read_define (0 , " c" , read_data_type);
243
+ MutableColumnPtr memory_column = read_data_type->createColumn ();
244
+ memory_column->reserve (2 );
245
+
246
+ castColumnAccordingToColumnDefine (disk_data_type, disk_col->getPtr (), read_define, memory_column->getPtr (), 0 , 2 );
247
+
248
+ Int64 val1 = memory_column->getInt (0 );
249
+ ASSERT_EQ (val1, 127L );
250
+ Int64 val2 = memory_column->getInt (1 );
251
+ ASSERT_EQ (val2, -1L );
252
+ }
253
+ }
158
254
}
159
255
160
256
TEST (ChunkColumnCast_test, CastNullableToNotNull)
@@ -216,7 +312,7 @@ TEST(ChunkColumnCast_test, DISABLED_CastNullableToNotNullWithNonZeroDefaultValue
216
312
217
313
TEST (ChunkColumnCast_test, CastNullableToNullable)
218
314
{
219
- const Strings to_types = {" Nullable(Int16)" , " Nullable(Int32)" , " Nullable(Int64)" };
315
+ const Strings to_types = {" Nullable(Int8) " , " Nullable( Int16)" , " Nullable(Int32)" , " Nullable(Int64)" };
220
316
221
317
DataTypePtr disk_data_type = typeFromString (" Nullable(Int8)" );
222
318
MutableColumnPtr disk_col = disk_data_type->createColumn ();
@@ -251,7 +347,7 @@ TEST(ChunkColumnCast_test, CastNullableToNullable)
251
347
252
348
TEST (ChunkColumnCast_test, CastNotNullToNullable)
253
349
{
254
- const Strings to_types = {" Nullable(Int16)" , " Nullable(Int32)" , " Nullable(Int64)" };
350
+ const Strings to_types = {" Nullable(Int8) " , " Nullable( Int16)" , " Nullable(Int32)" , " Nullable(Int64)" };
255
351
256
352
DataTypePtr disk_data_type = typeFromString (" Int8" );
257
353
MutableColumnPtr disk_col = disk_data_type->createColumn ();
0 commit comments