File tree Expand file tree Collapse file tree 3 files changed +34
-22
lines changed
tests/sqllogictests/suites/base/03_common Expand file tree Collapse file tree 3 files changed +34
-22
lines changed Original file line number Diff line number Diff line change @@ -377,14 +377,9 @@ impl<'a> Evaluator<'a> {
377
377
. set_span ( span) )
378
378
}
379
379
}
380
- (
381
- DataType :: Nullable ( box DataType :: Variant ) | DataType :: Variant ,
382
- DataType :: Boolean
383
- | DataType :: Number ( _)
384
- | DataType :: String
385
- | DataType :: Date
386
- | DataType :: Timestamp ,
387
- ) => {
380
+ ( DataType :: Nullable ( box DataType :: Variant ) | DataType :: Variant , other)
381
+ if !other. is_nullable ( ) =>
382
+ {
388
383
// allow cast variant to not null types.
389
384
let cast_fn = format ! ( "to_{}" , dest_type. to_string( ) . to_lowercase( ) ) ;
390
385
if let Some ( new_value) = self . run_simple_cast (
@@ -396,20 +391,13 @@ impl<'a> Evaluator<'a> {
396
391
validity. clone ( ) ,
397
392
options,
398
393
) ? {
399
- // remove wrapped null values.
400
- let new_value = match new_value {
401
- Value :: Scalar ( scalar) => {
402
- if scalar == Scalar :: Null {
403
- Value :: Scalar ( Scalar :: default_value ( dest_type) )
404
- } else {
405
- Value :: Scalar ( scalar)
406
- }
407
- }
408
- Value :: Column ( column) => {
409
- let nullable_column = column. as_nullable ( ) . unwrap ( ) ;
410
- Value :: Column ( nullable_column. column . clone ( ) )
411
- }
412
- } ;
394
+ let ( new_value, has_null) = new_value. remove_nullable ( ) ;
395
+ if has_null {
396
+ return Err ( ErrorCode :: BadArguments ( format ! (
397
+ "unable to cast type `{src_type}` to type `{dest_type}`, result has null values"
398
+ ) )
399
+ . set_span ( span) ) ;
400
+ }
413
401
Ok ( new_value)
414
402
} else {
415
403
Err ( ErrorCode :: BadArguments ( format ! (
Original file line number Diff line number Diff line change @@ -345,6 +345,24 @@ impl Value<AnyType> {
345
345
}
346
346
}
347
347
348
+ // returns result without nullable and has_null flag
349
+ pub fn remove_nullable ( self ) -> ( Self , bool ) {
350
+ let mut has_null = false ;
351
+ match self {
352
+ Value :: Scalar ( scalar) => {
353
+ if scalar == Scalar :: Null {
354
+ has_null = true ;
355
+ }
356
+ ( Value :: Scalar ( scalar) , has_null)
357
+ }
358
+ Value :: Column ( column) => {
359
+ let nullable_column = column. as_nullable ( ) . unwrap ( ) ;
360
+ has_null = nullable_column. validity . null_count ( ) > 0 ;
361
+ ( Value :: Column ( nullable_column. column . clone ( ) ) , has_null)
362
+ }
363
+ }
364
+ }
365
+
348
366
pub fn domain ( & self , data_type : & DataType ) -> Domain {
349
367
match self {
350
368
Value :: Scalar ( scalar) => scalar. as_ref ( ) . domain ( data_type) ,
Original file line number Diff line number Diff line change @@ -142,5 +142,11 @@ SELECT * FROM t5;
142
142
{"user_id":1} 1
143
143
{"user_id":2} 2
144
144
145
+ statement ok
146
+ INSERT INTO t4 values('{}');
147
+
148
+ statement error
149
+ INSERT INTO t5 SELECT data, data:user_id AS user_id FROM t4;
150
+
145
151
statement ok
146
152
DROP DATABASE db1
You can’t perform that action at this time.
0 commit comments