Skip to content

Conversation

@AngersZhuuuu
Copy link
Contributor

What changes were proposed in this pull request?

Support cast StringType to DateType as PostgresSQL

Why are the changes needed?

Parity feature between PostgreSQL and Spark

Does this PR introduce any user-facing change?

Do SQL Like:

CREATE TABLE empsalary (                                                                                                                
    depname string,                                                                                                                     
    empno integer,                                                                                                                      
    salary int,                                                                                                                         
    enroll_date date                                                                                                                    
) USING parquet;  
INSERT INTO empsalary VALUES ('develop', 10, 5200, '2007-08-01');

How was this patch tested?

Need add UT

@AngersZhuuuu
Copy link
Contributor Author

cc @MaxGekk @maropu

Do you know any where I can add test case for this cast?

And some different, if i pass a wrong date format, spark will cast it to NULL, PostgresSQL will return error.

Spark:

INSERT INTO empsalary VALUES ('develop', 10, 5200, '2007-0128-01');
SELECT * FROM  empsalary;

develop	10	5200	NULL
Time taken: 0.164 seconds, Fetched 2 row(s)

PostgresSQL:

angerszhu=# INSERT INTO empsalary VALUES ('develop', 10, 5200, '2007-1208-01');
ERROR:  date/time field value out of range: "2007-1208-01"
LINE 1: ...NSERT INTO empsalary VALUES ('develop', 10, 5200, '2007-1208...
                                                             ^
HINT:  Perhaps you need a different "datestyle" setting.
angerszhu=# 

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@HyukjinKwon
Copy link
Member

cc @gengliangwang

@gengliangwang
Copy link
Member

I think PostgreSQL is making exception for type conversion with constant values.
If you tried the following SQL in PostgreSQL,

create table a(t timestamp);
create table b(s varchar(20));
insert into a select * from b;

You will get following error:

ERROR: column "t" is of type timestamp without time zone but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.

In the PR #26107, I disallow such conversion and update test cases intentionally.

@AngersZhuuuu
Copy link
Contributor Author

In the PR #26107, I disallow such conversion and update test cases intentionally.

Sounds good to prevent unreasonable conversions.
Some conversion is not safe.

@gengliangwang
Copy link
Member

Sounds good to prevent unreasonable conversions.
Some conversion is not safe.

@AngersZhuuuu Would you mind close this PR?

@AngersZhuuuu
Copy link
Contributor Author

Would you mind close this PR?

close it .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants