Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Lramos2
Contributor
Contributor

Issue using global variable in query

Hi, I'm new using Talend, and I was trying to use a global variable inside query but it is displaying an error that I couldn't sort it, so then I was wondering if you can suggest me another way to do it or do you know how to sort this issue?

  • This is my job

0693p00000BXiwzAAD.png 

  • I'm storing a global variable from tjava1 component :

  System.out.println("The sample data should be: " + sampleDataround);

  

  //Set SampleDataround as a global variable to be used in next steps...

  

  globalMap.put("sampleData",sampleDataround);

  

  int test = (int)globalMap.get("sampleData");

  System.out.println("Sample data value is: "+test);

  

  • Besides that, I also did a test assigning test variable and then display it and it worked.
  • This is my query in component GMIP_Inquiry:

  "SELECT * 

  FROM " + context.GMIP_INQUIRY_MART_RW_schema + "." + context.GMIP_INQUIRY_TABLES_CASE_TEST + "

  order by 

  random() limit "+globalMap.get("sampleData")+""

  • The after run the job I'm getting this error:

  Exception in component tDBInput_1 (job_fact_inquiry_cases_a_test)

  

  [FATAL]: seu_gmip_inquiry_raw_mart_load.job_fact_inquiry_cases_a_test_10_3.job_fact_inquiry_cases_a_test - tDBInput_1 [Amazon][JDBC](10140) Error converting value to int.

  java.sql.SQL

  

  • I already tried query using : "+(int)globalMap.get("sampleData")+"
  • " but each time that I tried is displaying errors
Labels (4)
3 Replies
JohnRMK
Creator II
Creator II

Hello,

 

Replace (int)globalMap.get("sampleData") by (Integer)globalMap.get("sampleData").

you can try to display the query in a tJava (on Component Ok ) after GMIP tDBInput.

Lramos2
Contributor
Contributor
Author

Hello,

I did, and it's the same failure, I notice if I delete the delimited output component the error goes away, I don't know why that is happening

Anonymous
Not applicable

Hi

Check if you have defined the schema, in addition, replace the global variable with a constant in query to see if you have the same issue.

 "SELECT * 

  FROM " + context.GMIP_INQUIRY_MART_RW_schema + "." + context.GMIP_INQUIRY_TABLES_CASE_TEST + "

  order by 

  random() limit 10"

 

Regards

Shong