Seven Stars

ClassCastException in Dynamic Schema

Hi

I am trying to use tSetDynamicSchema to check the dynamic schema definition feature of Talend.

I have defined the following schema metadata in a CSV file which the job reads using tFileInputDelimited and passes on the read data to tSetDynamicSchema.

NAME,TYPE,LENGTH
AUTHOR_ID,id_String,384
NAME,id_String,100
INITIALS,id_String,10
CREATE_DATE,id_Date,7
NOTES,id_String,250
CREATED_BY,id_String,20

The job then tries to read the input file (another CSV file) using tFileInputPositional component where I have specified the tSetDynamicSchema  as the existing dynamic.

The data read from tFileInputPositional is then printed on the console using tLogRow and then written to a database table.

However I am getting the following error when running the job:

Exception in component tLogRow_1
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
	at routines.system.DynamicUtils.formatDate(DynamicUtils.java:443)
	at routines.system.Dynamic.toString(Dynamic.java:189)
	at routines.system.Dynamic.toString(Dynamic.java:180)
	at java.lang.String.valueOf(Unknown Source)
	at etl_dev.testdynamicschema_0_1.testDynamicSchema.tFileInputPositional_1Process(testDynamicSchema.java:2307)
	at etl_dev.testdynamicschema_0_1.testDynamicSchema.tFileInputDelimited_1Process(testDynamicSchema.java:1278)
	at etl_dev.testdynamicschema_0_1.testDynamicSchema.runJobInTOS(testDynamicSchema.java:7092)
	at etl_dev.testdynamicschema_0_1.testDynamicSchema.main(testDynamicSchema.java:6830)
[FATAL]: etl_dev.testdynamicschema_0_1.testDynamicSchema - tLogRow_1 java.lang.String cannot be cast to java.util.Date

I know it is because I have defined the datatype for CREATE_DATE field as id_Date. I would like to know if there is any other way to specify DateTime datatype for a column for tSetDynamicSchema.

1 REPLY
Highlighted
Seven Stars

Re: ClassCastException in Dynamic Schema

Another addition is that when I changed the datatype of the CREATE_DATE field to id_String, I did not get any error.

However all the data read from the file was written to a single (first) column of the database table. How can I make the job output the data read to the correct columns?

Attaching a screenshot of the job I have createdDynamicSchema.png