data Type "boolean "

Highlighted
Six Stars

data Type "boolean "

Hello,

 

How to convert data type String with "true" to data type boolean with "1".

 

Thank you 

 

Best regards


Accepted Solutions
Six Stars

Re: data Type "boolean "

Hello,

 

my target is boolean and source is String.

when i use this method :

row2.licence_info_mutation_gratuite_confirmee == null ? null : (row2.licence_info_mutation_gratuite_confirmee.equals(true) ? true : false)  

 

i have this error:

User variable name 'tDBOutputBulkExec_1_tMBE_licence_info_mutation_gratuite_confirmee' is illegal

Thanks

Six Stars

Re: data Type "boolean "

Hi, 

I just tried your expression, still not working.


All Replies
Forteen Stars

Re: data Type "boolean "

@hamza-sellami ,can you provide some example of source and target data?

below the way.

row1.data.equals("1") ? true : false

 

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.
Six Stars

Re: data Type "boolean "

i have a an string in couloumn1 source with "true" as value. and in target i have a boolean type  with bit(1).

so i want convert "true" to "1".

 

Best regards

Forteen Stars

Re: data Type "boolean "

@hamza-sellami ,check the below way .

Untitled.png

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.
Six Stars

Re: data Type "boolean "

i want 0 or 1 in Target 

like this but not working 

row2.licence_info_mutation_gratuite_confirmee .equals(true) ? "1" : "0" 
Six Stars

Re: data Type "boolean "

and with your solution i have this message: Capture.PNG

Forteen Stars

Re: data Type "boolean "

@hamza-sellami ,i believe your source data type is boolean,you no need to convert ,what is your target type? 

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.
Employee

Re: data Type "boolean "

@hamza-sellami 

 

Assuming your source is Boolean data and target is integer, could you please try below code snippet?

row2.licence_info_mutation_gratuite_confirmee ? 1 : 0

It will pick 1 if the boolean value is true else it will be 0.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

 

 

Six Stars

Re: data Type "boolean "

Hello,

 

My target is boolean, and my source is string with 3 values (false, true or null).

 

Best regards

Employee

Re: data Type "boolean "

Hi,

 

     What is your source data type? The error is showing that source data itself is having boolean data type.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

Nine Stars JR
Nine Stars

Re: data Type "boolean "

The error "cannot convert Boolean to String does not suggest that the input is of type Boolean. This error simply occurs because you passed a boolean value into the String method "equals" when you do the following

row2.licence_info_mutation_gratuite_confirmee.equals(true) ? "1" : "0" 

Please try the following (exactly as it is shown here):

row2.licence_info_mutation_gratuite_confirmee == null ? null : (row2.licence_info_mutation_gratuite_confirmee.equals("true") ? 1 : 0)

I am not sure what you mean with the target type is "boolean with bit(1)". If it is an Integer, the above should work. If it is a Boolean, the following should work:

row2.licence_info_mutation_gratuite_confirmee == null ? null : row2.licence_info_mutation_gratuite_confirmee.equals("true")
Six Stars

Re: data Type "boolean "

Hello,

 

my target is boolean and source is String.

when i use this method :

row2.licence_info_mutation_gratuite_confirmee == null ? null : (row2.licence_info_mutation_gratuite_confirmee.equals(true) ? true : false)  

 

i have this error:

User variable name 'tDBOutputBulkExec_1_tMBE_licence_info_mutation_gratuite_confirmee' is illegal

Thanks

Nine Stars JR
Nine Stars

Re: data Type "boolean "

Hi

If you input is a string and the target is boolean, the expression has to be 

row2.licence_info_mutation_gratuite_confirmee == null ? null : row2.licence_info_mutation_gratuite_confirmee.equals("true")

Please note the double quotes around "true". Please replace "row2" with the name of your input flow.

As for your error: I do not know how your job (schemas and connections) is set up. In principle, I do not use underscores in column names (use camel case instead) and I try to avoid such long names for columns but I do not think this is the issue here. Nevertheless, I believe this has nothing to do with your original problem.

Six Stars

Re: data Type "boolean "

Hi, 

I just tried your expression, still not working.

Nine Stars JR
Nine Stars

Re: data Type "boolean "

Sorry, but if you do not provide more details about your job, no one will be able help you with this.

Six Stars

Re: data Type "boolean "

Hello,

 

my job is: 

Capture2.PNG

 

My tconvertType 2:

Capture3.PNG:

 

mon tmap is:

capture1.PNG

My error is:

Exception in component tDBOutputBulkExec_1_tMBE (ODS_Collecte_Preparation_licence_info_1)
java.sql.SQLSyntaxErrorException: User variable name 'tDBOutputBulkExec_1_tMBE_licence_info_mutation_gratuite_confirmee' is illegal
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:781)
	at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:666)
	at ffh.ods_collecte_preparation_licence_info_1_0_1.ODS_Collecte_Preparation_licence_info_1.tDBInput_1Process(ODS_Collecte_Preparation_licence_info_1.java:6664)
	at ffh.ods_collecte_preparation_licence_info_1_0_1.ODS_Collecte_Preparation_licence_info_1.runJobInTOS(ODS_Collecte_Preparation_licence_info_1.java:9494)
	at ffh.ods_collecte_preparation_licence_info_1_0_1.ODS_Collecte_Preparation_licence_info_1.main(ODS_Collecte_Preparation_licence_info_1.java:9169)

thanks for your reply

 

Nine Stars JR
Nine Stars

Re: data Type "boolean "

OK, so you are already converting your input string to a Boolean in the tConvertType component. Why are you bothering with further conversion in the tMap? You already have a boolean value in the input of the tMap and simply need to pass it along to the output:

row2.licence_info_mutation_gratuite_confirmee

Please try this again with this expression. I still believe, the error has nothing to do with your original problem and originates from the DB output component.

Six Stars

Re: data Type "boolean "

i have the same error:

 

Exception in component tDBOutputBulkExec_1_tMBE (ODS_Collecte_Preparation_licence_info_1)
java.sql.SQLSyntaxErrorException: User variable name 'tDBOutputBulkExec_1_tMBE_licence_info_mutation_gratuite_confirmee' is illegal
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:781)
	at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:666)
	at ffh.ods_collecte_preparation_licence_info_1_0_1.ODS_Collecte_Preparation_licence_info_1.tDBInput_1Process(ODS_Collecte_Preparation_licence_info_1.java:6659)
	at ffh.ods_collecte_preparation_licence_info_1_0_1.ODS_Collecte_Preparation_licence_info_1.runJobInTOS(ODS_Collecte_Preparation_licence_info_1.java:9489)
	at ffh.ods_collecte_preparation_licence_info_1_0_1.ODS_Collecte_Preparation_licence_info_1.main(ODS_Collecte_Preparation_licence_info_1.java:9164)
Mon Aug 19 10:24:58 CEST 2019 WARN:

thanks

Nine Stars JR
Nine Stars

Re: data Type "boolean "

Again, this is most likely unrelated to your original problem and lies in your output component. From the little I can see, the component cannot create a SQL statement for MySQL. Maybe the column name is too long for MySQL - I am not a MySQL expert.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog