CAST(value AS type)
This function is used to forcibly convert types.
Convert amount into a string. The specified length of the string is invalid after the conversion.
insert into temp select cast(amount as VARCHAR(10)) from source_stream;
Function |
Description |
---|---|
Converts v1 to a string. The value of v1 can be of the numeric type or of the timestamp, date, or time type. |
|
Converts v1 to the int type. The value of v1 can be a number or a character. |
|
Converts v1 to the timestamp type. The value of v1 can be of the string, date, or time type. |
|
Converts v1 to the date type. The value of v1 can be of the string or timestamp type. |
SELECT cast(content as varchar) FROM T1;
content (INT) |
varchar |
---|---|
5 |
"5" |
SELECT cast(content as int) FROM T1;
content (STRING) |
int |
---|---|
"5" |
5 |
SELECT cast(content as timestamp) FROM T1;
content (STRING) |
timestamp |
---|---|
"2018-01-01 00:00:01" |
1514736001000 |
SELECT cast(content as date) FROM T1;
content (TIMESTAMP) |
date |
---|---|
1514736001000 |
"2018-01-01" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /** source **/ CREATE SOURCE STREAM car_infos (cast_int_to_varchar int, cast_String_to_int string, case_string_to_timestamp string, case_timestamp_to_date timestamp) WITH ( type = "dis", region = "xxxxx", channel = "dis-input", partition_count = "1", encode = "json", offset = "13", json_config = "cast_int_to_varchar=cast_int_to_varchar;cast_String_to_int=cast_String_to_int;case_string_to_timestamp=case_string_to_timestamp;case_timestamp_to_date=case_timestamp_to_date" ); /** sink **/ CREATE SINK STREAM cars_infos_out (cast_int_to_varchar varchar, cast_String_to_int int, case_string_to_timestamp timestamp, case_timestamp_to_date date) WITH ( type = "dis", region = "xxxxx", channel = "dis-output", partition_count = "1", encode = "json", offset = "4", json_config = "cast_int_to_varchar=cast_int_to_varchar;cast_String_to_int=cast_String_to_int;case_string_to_timestamp=case_string_to_timestamp;case_timestamp_to_date=case_timestamp_to_date", enable_output_null="true" ); /** Statistics on static car information**/ INSERT INTO cars_infos_out SELECT cast(cast_int_to_varchar as varchar), cast(cast_String_to_int as int), cast(case_string_to_timestamp as timestamp), cast(case_timestamp_to_date as date) FROM car_infos; |
Returned data
{"case_string_to_timestamp":1514736001000,"cast_int_to_varchar":"5","case_timestamp_to_date":"2018-01-01","cast_String_to_int":100}