Date_Parse INVALID_FUNCTION_ARGUMENT: Invalid format

0

I am trying to convert string into timestamp however getting INVALID_FUNCTION_ARGUMENT: Invalid format: "2010-12-23 00:00:00" is malformed at " 00:00:00" error.

The source data is in CSV format. Sample output below..
110100001,48,F,5182210000,1,2011-01-03 09:34:00,2010-12-23 00:00:00,CRDINV,CLOSED,280,0,0,,,,,,,,,,,,,,CCCOMP,,<Error>,89,,E:\OPTIMDATA\ARCHIVE\ABC\ABAF

The query I am using is :
SELECT date_parse(aws_athena_div99.DATE_CLM_RPTD, '%Y-%m-%dT%H:%i:%s') as DateConvertedToTimestamp FROM athenadb.aws_athena_div99;

I am storing data as TEXTFILE in Athena.

DATE_CLM_RPTD is column #7.

Please help.

Div99
gefragt vor 5 Jahren9649 Aufrufe
4 Antworten
0

Hi,

Please check on the below working solution:
sample string is “2010-12-23 00:00:00”
query:
SELECT date_parse(‘2010-12-23 00:00:00’,'%Y-%m-%d %H:%i:%s');
Result:

   _col0  
  1. 2010-12-23 00:00:00.000
    Note : Format of the date parse should match the sample date string.

I hope above helps.

have a good day :)

AWS
beantwortet vor 5 Jahren
0

Unfortunately, it did not help. Got following error:

Your query has the following error(s):
INVALID_FUNCTION_ARGUMENT: Invalid format: ""

I understand when you say format should match the input and it is matching however its not working.. Not sure why.

I wonder if the format is getting changed while Athena is reading from S3 and hence when I query it does not match. One reason why explicitly specified TEXTFILE as store format but still the same result.

Div99
beantwortet vor 5 Jahren
0

Hi! Did you manage to solve this?
I have the same issue. I have a the column 'date_x' that contains the date of purchase but it appears in Athena as VARCHAR.
And I want to retrieve from the table the lines that have the purchase date between 1st of September and 3rd of November. I tried to use the following condition:
WHERE date_parse(date_x, 'YYYY-MM-DD') BETWEEN date_parse('2020-09-01', 'yyyy-mm-dd') AND date_parse('2020-11-03', 'yyyy-mm-dd')
and i get the same error as you:
INVALID_FUNCTION_ARGUMENT: Invalid format: "2020-09-01"

Edited by: GabrielaS on Nov 3, 2020 9:04 AM

Edited by: GabrielaS on Nov 3, 2020 9:05 AM

beantwortet vor 4 Jahren
0

HI man I have been bumping my head against the wall with this one. however, in my case, similar to your case I was using data_format(string_column_name, 'YYYY-MM-dd HH:mm:ss') but I was getting the same error and after looking everywhere I found that since athena uses presto under the hood they both have a similar catch, which is that there is confusing naming between the MySQL data functions and the Java data functions, MySQL functions are data_parse and date_format; the java functions are format_date and parse_datetime. details here https://github.com/prestodb/presto/issues/1019

long story short, for date_parse you shouldn't be using the YYYY-MM-DD format (Java simple date format), instead you should use the %Y-%m-%d format, so the expressions in your query should look like this

date_parse ( date_x, '%Y-%m-%d') assuming date_x follows something similar to the others
date_parse ( '2020-09-01', '%Y-%m-%d')
date_parse ( '2020-11-03', '%Y-%m-%d')

in my specific scenario I was trying to parse a column where the values where strings that look like "2020-01-20 00:00:00" and I was getting the invalid format error; once I changed the format to the %Y etc form, I still go the error, but, it was because the function was evaluating the double quotes as part of the string so I had to account for those on my format and my expression ended up looking like this:

date_parse(string_date_column,'"%Y-%m-%d %H:%i:%s"')

hope this helps

Edited by: Elruncho35 on Nov 24, 2020 6:03 PM

Edited by: Elruncho35 on Nov 24, 2020 6:07 PM

beantwortet vor 3 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen