Open sundy-li opened 2 weeks ago
load_can_auto_cast_to
is much more strict, only used for load, not suitable for here.
we may introduce another help function like https://github.com/databendlabs/databend/pull/16072
this closed pr was intended to be used in copy only too (replaced by load_can_auto_cast_to
later)
but @andylokandy said
็่ฎบไธ ไปปไฝ็ฑปๅ้ฝๅฏไปฅไบ่ฝฌ
ๆไปฅไนๅๆฒกๆ can_cast_to ๏ผcast ไธ่ฟๅปๆฏๅผ็้ฎ้ขไธๆฏ็ฑปๅ้ฎ้ข
I think since currently our cast (run_cast) do report error on some (src, dst) pairs.
may be it is ok to add a can_cast_to
which is consistent with run_cast
to report error earlier when building pipeline,
and check it when constructing TransformCastSchema
But run_cast
will check the cast types and throw
_ => Err(ErrorCode::BadArguments(format!(
"unable to cast type `{src_type}` to type `{dest_type}`"
))
.set_span(span)),
We can say that a value is not able to be cast to another type, e.g. CAST('a' AS INT)
, but we can not say that all String
can not be cast to Int
. The former will throw at evaluation, and the latter will throw at type checking.
The former will throw at evaluation, and the latter will throw at type checking.
The latter will not throw errors at type checking, let's add it.
It will always return Expr::Cast
fn check_cast<Index: ColumnIndex> ... {
Ok(Expr::Cast {
span,
is_try,
expr: Box::new(expr),
dest_type: wrapped_dest_type,
})
}
A simple case, the error is thrown during sql pipeline execution.
๐ณ :) create table a (t decimal(15,2));
processed in (0.018 sec)
๐ณ :) insert into a select * from b;
error: APIError: ResponseError with 1006: fail to auto cast column t (Variant NULL) to column t (Decimal(15, 2) NULL)
unable to cast type `Variant` to type `Decimal(15, 2)`, during run expr: `CAST(t AS Decimal(15, 2) NULL)`
The former will throw at evaluation, and the latter will throw at type checking.
I mean, if we agree that all types can convert between each other, i.e.
We can say that a value is not able to be cast to another type, e.g. CAST('a' AS INT), but we can not say that all String can not be cast to Int
.๏ผ we should not throw at type checking.
Summary
Description for this feature.