CAST(expr AS type) as DataFusion performs it (verified against InfluxDB 3
Core).
INTEGER and INT are Int32, SMALLINT is Int16, TINYINT is Int8
and BIGINT is Int64; a value outside the target's range cannot be
cast. Text becomes a number only when the whole string is one ("2.5" is
not an integer, and a space around a number spoils it; +7, 007, .5,
5. and 1E3 are numbers, and inf, infinity and nan in any case are
the float's specials). A float or a decimal becomes an integer by truncation
toward zero, a number or boolean becomes text by rendering (a float as the
engine writes it, 5000.0 and never 5.0e3; a decimal with its scale,
2.5000; an infinity inf or -inf, a NaN NaN) and a boolean becomes 0
or 1. Null stays null.
A cast that cannot be performed — text that is not a number, an infinity or
a NaN as an integer, a number outside the target's range — fails the query
on the engine in one of two ways. Over a column, mid-response: InfluxDB 3
Core closes the connection, which Client.HTTP reports as a transport
error, so the double reports the same shape. Over a constant, the
optimizer folds it first and fails the query before any row is read, with a
500 whose body names the value (see fold/2).
FLOAT and REAL are Float32, which the double does not model: refused
by name. A cast of a timestamp is its nanoseconds, which the double keeps
only to the microsecond: refused by name, except into a type too narrow for
any recent time, which fails as the engine's cast does.
Summary
Functions
The Arrow type name of a cast type.
The width in bits of an integer cast type, or nil for any other.
The value cast to type, or the throw of the query's failure.
Whether the integer is in the range of the integer type with bits bits.
Whether the optimizer can fold the cast of a constant value: :ok, or the
message it fails the query with, as the planner words it
(Can't cast value 3000000000 to type Int32, or for text Cannot cast string 'x' to value of Int32 type).
Functions
@spec arrow_type(InfluxElixir.Client.Local.SQLExpr.cast_type()) :: binary()
The Arrow type name of a cast type.
@spec bits(InfluxElixir.Client.Local.SQLExpr.cast_type()) :: 8 | 16 | 32 | 64 | nil
The width in bits of an integer cast type, or nil for any other.
@spec cast(term(), InfluxElixir.Client.Local.SQLExpr.cast_type()) :: term()
The value cast to type, or the throw of the query's failure.
Whether the integer is in the range of the integer type with bits bits.
@spec fold(term(), InfluxElixir.Client.Local.SQLExpr.cast_type()) :: :ok | {:error, binary()}
Whether the optimizer can fold the cast of a constant value: :ok, or the
message it fails the query with, as the planner words it
(Can't cast value 3000000000 to type Int32, or for text Cannot cast string 'x' to value of Int32 type).