• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Date getting converted to 0001-01-01T00:00:00

#1 2009-04-15 14:48:14

anuradha.chaturvedi
Member
Registered: 2009-04-14
Posts: 34

Date getting converted to 0001-01-01T00:00:00

Tags: [bulk, date, mysql, pattern]

I am loading tables using pipe delimited file and tMySQLOutputBulkExec
These tables have some date columns. Date in pipe delimited file is in the following format
""|"1"|""|""|""|""|""|""|""|"0"|"5736"|"1"|""
""|"5"|""|"01-01-1970 00:00:00"|""|""|""|""|""|"0"|"5736"|"1"|""
""|"6"|""|"01-01-1970 00:00:00"|""|""|""|""|""|"0"|"5736"|"1"|""
""|"7"|""|""|""|""|""|""|""|"0"|"5736"|"1"|""

But when it is inserted in the MySQL database with tMySQLOutputBulkExec it is loaded as
0001-01-01T00:00:00.

If I am using tMySQLOutput its working fine

but with tMySQLOutputBulkExec its always inserting a value as 0001-01-01T00:00:00. whether date is blank or has some value in the input.
Please note that I am using a java project.

Regds,
Anuradha.

Last edited by anuradha.chaturvedi (2009-04-15 14:48:45)

Offline

#2 2009-04-16 07:37:16

anuradha.chaturvedi
Member
Registered: 2009-04-14
Posts: 34

Re: Date getting converted to 0001-01-01T00:00:00

Any updates please its urgent?
Would appreciate if you could respond to the same ASAP.

Thanks & Regds
Anuradha.

Offline

#3 2009-04-16 08:16:45

shong
Talend team
Registered: 2007-08-29
Posts: 10289
Website

Re: Date getting converted to 0001-01-01T00:00:00

Hello Anuradha

You need to use the same pattern as target table.
yyyy-MM-dd HH:mm:ss

Best regards

         shong


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#4 2009-04-16 10:44:35

anuradha.chaturvedi
Member
Registered: 2009-04-14
Posts: 34

Re: Date getting converted to 0001-01-01T00:00:00

Thanks alot shong for the quick update.
The issue got resolved.

But now the problem is that, it is showing correct values for non null dates.
For input dates with null string its still inserting "0001-01-01T00:00:00".

So for this input wherin 4th column is a date column
""|"1"|""|""|""|""|""|""|""|"0"|"5736"|"1"|""
""|"5"|""|"01-01-1970 00:00:00"|""|""|""|""|""|"0"|"5736"|"1"|""
""|"6"|""|"01-01-1970 00:00:00"|""|""|""|""|""|"0"|"5736"|"1"|""
""|"7"|""|""|""|""|""|""|""|"0"|"5736"|"1"|""

Its inserting following in MYSQL
0001-01-01 00:00:00       
1970-01-01 00:00:00           
1970-01-01 00:00:00
0001-01-01 00:00:00       

I could not understand why for null values it is getting converted to 0001-01-01 00:00:00?

Any other settings I need to do for null data handling.

Can you please give a demo example to load date column from delimited file to MYSQL5.0? This delimited file should have some null and some non null values as mentioned above in the input file.

Thanks & Regds,
Anuradha.

Offline

#5 2009-04-17 06:52:33

anuradha.chaturvedi
Member
Registered: 2009-04-14
Posts: 34

Re: Date getting converted to 0001-01-01T00:00:00

Waiting for the response .....

Thanks & Regds,
Anuradha.

Offline

#6 2009-04-17 08:10:48

shong
Talend team
Registered: 2007-08-29
Posts: 10289
Website

Re: Date getting converted to 0001-01-01T00:00:00

Hello

I could not understand why for null values it is getting converted to 0001-01-01 00:00:00?

Any other settings I need to do for null data handling.

if you won't get  the default value 0001-01-01 00:00:00 for null value,
you can add a new default date which you can consider invalid to replace  0001-01-01 00:00:00.
see my screenshot.

Best regards

           shong


Uploaded Images


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#7 2009-04-17 08:34:18

anuradha.chaturvedi
Member
Registered: 2009-04-14
Posts: 34

Re: Date getting converted to 0001-01-01T00:00:00

Thanks shong, but the issue is I am migrating some data from Interbase to MYSQL now if something is null in Interbase I cant load it with some default value in MYSQL. I need to load it as null only.... Thats the issue.

I am new to both MySQL/Interbase and also TOS.

I had used the following flow.
t_InterbaseInput-->t_Map-->t_FileDelimitedOutput-->t_MySQLBulkExecuteOutput.

t_InterbaseInput--> reads data from Interbase table with Dates as String
t_Map-->Converts String to date format -- "yyyy-MM-dd HH:mm:ss"
t_FileDelimitedOutput-->Generates a pipe delimited file with each field enclosed by "" seperated by |.
t_MySQLBulkExecuteOutput--Read input delimted file and loads data in bulk to target table.

Now I used Logrow after each step to identify what values are passing at each step
t_InterbaseInput--> displays null as null in LogRow output
t_Map-->displays null as null in LogRow output
t_FileDelimitedOutput-->Converts null to ""
t_MySQLBulkExecuteOutput--Reads "" in date and load it as 0001-01-01 00:00:00 .

I also used a Java row in between t_FileDelimitedOutput and t_MySQLBulkExecuteOutput and found that Javarow reads "" as null only but loads its as  0001-01-01 00:00:00 . Please find the code below
**************************************************
output_row.SSN = input_row.SSN;
output_row.ACCOUNT_NUMBER = input_row.ACCOUNT_NUMBER;
output_row.COMMENTS = input_row.COMMENTS;
if (input_row.DATE_OF_BIRTH==null)
{
output_row.DATE_OF_BIRTH = TalendDate.parseDate("yyyy-MM-dd HH:mm:ss","9999-09-09 01:01:01");
}
else
output_row.DATE_OF_BIRTH=input_row.DATE_OF_BIRTH;

**************************************************
On running this code null dates were replaced by "9999-09-09 01:01:01" but not as "null" or "".

Could you make out where I am doing something wrong??

Thanks & Regds,
Anuradha.

Offline

#8 2009-04-17 09:23:59

shong
Talend team
Registered: 2007-08-29
Posts: 10289
Website

Re: Date getting converted to 0001-01-01T00:00:00

Hello

Could you make out where I am doing something wrong??

I see that your code in tJavaRow is right, you are using 9999-09-09 01:01:01 replace 0001-01-01 00:00:00 when the date is null.
About replace null value wtih 0001-01-01 00:00:00, I think it  is due to mysql bulk action. tMysqlOutput can load it with 'null' value.

Best regards

            shong


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#9 2009-04-17 12:00:16

anuradha.chaturvedi
Member
Registered: 2009-04-14
Posts: 34

Re: Date getting converted to 0001-01-01T00:00:00

But tMySQLOutput is too slow with large amount of data thats why I opted tMySQLBulkOutput.
Any other option to pass it as a null value.

tMySQLBulkOutput takes few secs to load 60,000 data while tMySQLOutput takes more than a minute.

Last edited by anuradha.chaturvedi (2009-04-17 12:02:13)

Offline

#10 2009-04-20 07:15:43

anuradha.chaturvedi
Member
Registered: 2009-04-14
Posts: 34

Re: Date getting converted to 0001-01-01T00:00:00

Hi Shong,

Any other work around to resolve this issue?

Thanks & Regds,
Anuradha.

Offline

#11 2009-04-21 15:02:30

anuradha.chaturvedi
Member
Registered: 2009-04-14
Posts: 34

Re: Date getting converted to 0001-01-01T00:00:00

Shong,

As you know I am using following flow:
t_InterbaseInput-->t_Map-->t_FileDelimitedOutput-->t_MySQLBulkExecuteOutput.

Where
t_InterbaseInput--> reads data from Interbase table with Dates as String
t_Map-->Converts String to date format -- "yyyy-MM-dd HH:mm:ss"
t_FileDelimitedOutput-->Generates a pipe delimited file with each field enclosed by "" seperated by |.
t_MySQLBulkExecuteOutput--Read input delimted file and loads data in bulk to target table.

Currently for Null Dates file is generated as
"1"|"5736"|"0"||""|||||"*"|"*** CASH SALE ***"|||||||"1"|"N"|"Admin               "|"1"|"1"|||||||||||||||||||||"1"|""
"5"|"5736"|"0"||"1970-01-01"|||||"STOCK"|"****"|||||||"1"|"N"|"Admin               "|"1"|"1"|||||||||||||||||||||"1"|""

Here 5th column is Date where  "" in first record indicate null  date value and "1970-01-01" valid date in the second record.

And with this file For input dates with null string t_MySQLBulkExecuteOutput is  inserting "0001-01-01T00:00:00".

********************************************************************************
I found a solution that if in the file we pass null date as "\N" instead of "" the LOAD INFILE utility which is used by tMySQLBulkOutputExec interprets it as NULL.

I tested it by running LOAD INFILE on MySQL prompt and in the csv file I passed NULL as "\N" and it loaded data as NULL.

Command:---
LOAD DATA  INFILE '/home/vanket/poc_demo/patients.csv' IGNORE INTO table I_PATIENTS FIELDS TERMINATED BY '|'  ESCAPED BY '\\' ENCLOSED BY '"' LINES TERMINATED BY  '\n';

the input patients.csv file was
"1"|"5736"|"0"||"\N"|||||"*"|"*** CASH SALE ***"|||||||"1"|"N"|"Admin               "|"1"|"1"|||||||||||||||||||||"1"|""
"5"|"5736"|"0"||"1970-01-01"|||||"STOCK"|"****"|||||||"1"|"N"|"Admin               "|"1"|"1"|||||||||||||||||||||"1"|""

Here 5th column is Date where I had passed "\N" in first record to load null value and a valid date in the second record.

***************************************************************************************

I tried to implement the same in TOS, what I am doing is , I tried passing date value as string and hardcoded it as "\N" in date column just to see all date values are getting inserted as NULL  for each record.
But its giving error  "Invalid escape sequence( valid ones are \n,\r etc.......

In the delimited file - Escape Char is set as -- "\\"
Also in t_MySQLBulkExecuteOutput Escape Char is set as -- "\\"


Can you please help, its really urgent as we have alot of tables with date columns.
And we have to implement this at all places.

Thanks .
Anuradha.

Last edited by anuradha.chaturvedi (2009-04-21 15:33:22)

Offline

#12 2009-04-22 06:57:58

anuradha.chaturvedi
Member
Registered: 2009-04-14
Posts: 34

Re: Date getting converted to 0001-01-01T00:00:00

Waiting for reply ... from Talend Team ..... sad

Offline

#13 2009-04-22 11:47:17

shong
Talend team
Registered: 2007-08-29
Posts: 10289
Website

Re: Date getting converted to 0001-01-01T00:00:00

Hello Anuradha
Let's go ahead...
First, output the result to a txt file, then use tMysqlBulkExec instead of tMysqlOutputBulkExec to run the txt file. See my screenshot.

in.csv:

1;2009-02-26 01:02:33
2;
3;2009-02-27 01:02:33

expression of date column:

Code:

(row1.date.equals("")?"\"\\N\"":row1.date)

Best regards

          shong


Uploaded Images


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#14 2009-04-22 12:53:52

anuradha.chaturvedi
Member
Registered: 2009-04-14
Posts: 34

Re: Date getting converted to 0001-01-01T00:00:00

Thanks alot shong for this demo.It solved my problem that was like a bottleneck.

Thanks Again.

Anuradha.

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Date getting converted to 0001-01-01T00:00:00

Board footer

Powered by FluxBB