Skip to content

Commit

Permalink
fix: unify varchar format_type display with PostgreSQL (#12648)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetjinser authored and stdrc committed Oct 10, 2023
1 parent adec267 commit 5375919
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions e2e_test/batch/basic/array.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ double precision[]
query T
select pg_typeof(arr::varchar[]) from (values ('{1, 2, 3}'), ('{4, 5, 6}')) as t(arr);
----
varchar[]
varchar[]
character varying[]
character varying[]

# Test explicit cast to nested integer array
query T
Expand Down
6 changes: 3 additions & 3 deletions e2e_test/batch/basic/func.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ unknown
query T
select pg_typeof('123'::varchar);
----
varchar
character varying

query T
select pg_typeof('123'::int);
Expand All @@ -276,7 +276,7 @@ unknown
query T
select pg_typeof(null::varchar);
----
varchar
character varying

query T
select pg_typeof(null::bool);
Expand Down Expand Up @@ -649,4 +649,4 @@ select regexp_count('foobar', 'b..', 1, 'g');
query T
select regexp_count('💩💩💩💩💩foo🤔️bar亲爱的😭baz这不是爱情❤️‍🔥', '亲爱的😭', 1, 'i');
----
1
1
5 changes: 5 additions & 0 deletions e2e_test/batch/functions/format_type.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ query T
SELECT format_type(NULL, 0);
----
NULL

query T
SELECT format_type(1043, '-1');
----
character varying
12 changes: 6 additions & 6 deletions e2e_test/udf/udf.slt
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ as return_all_arrays using link 'http://localhost:8815';
query TTTTT rowsort
show functions
----
array_access varchar[], integer varchar (empty) http://localhost:8815
extract_tcp_info bytea struct<src_ip varchar,dst_ip varchar,src_port smallint,dst_port smallint> (empty) http://localhost:8815
array_access character varying[], integer character varying (empty) http://localhost:8815
extract_tcp_info bytea struct<src_ip character varying,dst_ip character varying,src_port smallint,dst_port smallint> (empty) http://localhost:8815
gcd integer, integer integer (empty) http://localhost:8815
gcd integer, integer, integer integer (empty) http://localhost:8815
hex_to_dec varchar numeric (empty) http://localhost:8815
hex_to_dec character varying numeric (empty) http://localhost:8815
int_42 (empty) integer (empty) http://localhost:8815
jsonb_access jsonb, integer jsonb (empty) http://localhost:8815
jsonb_array_identity jsonb[] jsonb[] (empty) http://localhost:8815
jsonb_array_struct_identity struct<v jsonb[],len integer> struct<v jsonb[],len integer> (empty) http://localhost:8815
jsonb_concat jsonb[] jsonb (empty) http://localhost:8815
return_all boolean, smallint, integer, bigint, real, double precision, numeric, date, time without time zone, timestamp without time zone, interval, varchar, bytea, jsonb struct<bool boolean,i16 smallint,i32 integer,i64 bigint,f32 real,f64 double precision,decimal numeric,date date,time time without time zone,timestamp timestamp without time zone,interval interval,varchar varchar,bytea bytea,jsonb jsonb> (empty) http://localhost:8815
return_all_arrays boolean[], smallint[], integer[], bigint[], real[], double precision[], numeric[], date[], time without time zone[], timestamp without time zone[], interval[], varchar[], bytea[], jsonb[] struct<bool boolean[],i16 smallint[],i32 integer[],i64 bigint[],f32 real[],f64 double precision[],decimal numeric[],date date[],time time without time zone[],timestamp timestamp without time zone[],interval interval[],varchar varchar[],bytea bytea[],jsonb jsonb[]> (empty) http://localhost:8815
return_all boolean, smallint, integer, bigint, real, double precision, numeric, date, time without time zone, timestamp without time zone, interval, character varying, bytea, jsonb struct<bool boolean,i16 smallint,i32 integer,i64 bigint,f32 real,f64 double precision,decimal numeric,date date,time time without time zone,timestamp timestamp without time zone,interval interval,varchar character varying,bytea bytea,jsonb jsonb> (empty) http://localhost:8815
return_all_arrays boolean[], smallint[], integer[], bigint[], real[], double precision[], numeric[], date[], time without time zone[], timestamp without time zone[], interval[], character varying[], bytea[], jsonb[] struct<bool boolean[],i16 smallint[],i32 integer[],i64 bigint[],f32 real[],f64 double precision[],decimal numeric[],date date[],time time without time zone[],timestamp timestamp without time zone[],interval interval[],varchar character varying[],bytea bytea[],jsonb jsonb[]> (empty) http://localhost:8815
series integer integer (empty) http://localhost:8815
split varchar struct<word varchar,length integer> (empty) http://localhost:8815
split character varying struct<word character varying,length integer> (empty) http://localhost:8815

query I
select int_42();
Expand Down
9 changes: 6 additions & 3 deletions src/common/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ pub enum DataType {
#[display("date")]
#[from_str(regex = "(?i)^date$")]
Date,
#[display("varchar")]
#[from_str(regex = "(?i)^varchar$")]
#[display("character varying")]
#[from_str(regex = "(?i)^character varying$|^varchar$")]
Varchar,
#[display("time without time zone")]
#[from_str(regex = "(?i)^time$|^time without time zone$")]
Expand Down Expand Up @@ -1196,7 +1196,10 @@ mod tests {
vec![DataType::Int32, DataType::Varchar],
vec!["i".to_string(), "j".to_string()],
);
assert_eq!(format!("{}", d), "struct<i integer,j varchar>".to_string());
assert_eq!(
format!("{}", d),
"struct<i integer,j character varying>".to_string()
);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/planner_test/tests/testdata/output/array.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
Bind error: failed to bind expression: array_cat('{1}', 2)
Caused by:
Bind error: Cannot concatenate varchar and integer
Bind error: Cannot concatenate character varying and integer
- sql: |
select array_append(array[66], 123);
logical_plan: |-
Expand Down Expand Up @@ -190,7 +190,7 @@
sql: |
create table t (v1 varchar[]);
insert into t values ('{c,' || 'd}');
binder_error: 'Bind error: cannot cast type "varchar" to "varchar[]" in Assign context'
binder_error: 'Bind error: cannot cast type "character varying" to "character varying[]" in Assign context'
- name: string to varchar[] in explicit context
sql: |
select ('{c,' || 'd}')::varchar[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Bind error: failed to bind expression: ARRAY[1] || s
Caused by:
Bind error: Cannot append varchar to integer[]
Bind error: Cannot append character varying to integer[]
- name: jsonb || jsonb -> jsonb
sql: |
select '1'::jsonb || '2'::jsonb;
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/planner_test/tests/testdata/output/expr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
Bind error: failed to bind expression: concat_ws(v1, 1.2)
Caused by:
Bind error: cannot cast type "integer" to "varchar" in Implicit context
Bind error: cannot cast type "integer" to "character varying" in Implicit context
- sql: |
create table t (v1 int);
select concat_ws() from t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
Bind error: failed to bind expression: avg(country)
Caused by:
Invalid input syntax: Invalid aggregation: avg(struct<address varchar,zipcode varchar>)
Invalid input syntax: Invalid aggregation: avg(struct<address character varying,zipcode character varying>)
create_source:
format: plain
encode: protobuf
Expand Down Expand Up @@ -346,7 +346,7 @@
- sql: |
create materialized view t as select * from s;
select (country).address.* from t;
binder_error: 'Bind error: type "varchar" is not composite'
binder_error: 'Bind error: type "character varying" is not composite'
create_source:
format: plain
encode: protobuf
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/src/handler/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,12 @@ mod tests {

let expected_columns: HashMap<String, String> = maplit::hashmap! {
"id".into() => "integer".into(),
"country.zipcode".into() => "varchar".into(),
"country.zipcode".into() => "character varying".into(),
"zipcode".into() => "bigint".into(),
"country.city.address".into() => "varchar".into(),
"country.address".into() => "varchar".into(),
"country.city.address".into() => "character varying".into(),
"country.address".into() => "character varying".into(),
"country.city".into() => "test.City".into(),
"country.city.zipcode".into() => "varchar".into(),
"country.city.zipcode".into() => "character varying".into(),
"rate".into() => "real".into(),
"country".into() => "test.Country".into(),
};
Expand Down

0 comments on commit 5375919

Please sign in to comment.