Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
dwhdeveloper
Contributor
Contributor

concatenate context variable in a table name

I have to extract data daily from big query. There is a new table created daily with the timestamp in it. 

for example [dw-bigquery:45234.ga_table_20170626]

 

I am using a context variable which receives the date from a table in YYYY-mm-dd format.

 

Following is my query.

 

select * from 

'[dw-bigquery:45234.ga_table_' +TalendDate.formatDate("yyyyMMdd", context.load_date)+ ']'

 

I get an error for invalid assignment operator.

 

 

Labels (3)
8 Replies
TRF
Champion II
Champion II

Try this:

"select * from 
[dw-bigquery:45234.ga_table_" +TalendDate.formatDate("yyyyMMdd", context.load_date)+ "]"

because each string part must be enclosed between "" (don't know if you need ' and [] for big query).

 

 

dwhdeveloper
Contributor
Contributor
Author

I was still getting errors. 

So I made it more simple 

 

"select * from 
[dw-bigquery:45234.ga_table_" +context.load_date+ "]"

When I run it does not recognise context variable and the table looks like following 

[dw-bigquery:45234.ga_table_]

 

Anonymous
Not applicable

Your context variable appears to be holding an empty String.

cterenzi
Specialist
Specialist

Can you show us the part of your job that retrieves the date and sets the context variable?

dwhdeveloper
Contributor
Contributor
Author

I set a value where I define my context. Somehow it is not being passed.
But when I set it from sql in tjavarow it works
dwhdeveloper
Contributor
Contributor
Author

I found a way by using tposgresqlinput and tjavarow
Anonymous
Not applicable

What was your solution using tjavarow?

dwhdeveloper
Contributor
Contributor
Author

First I select the date from my table using tPostgresqlInput and then assign it to context variable in t_javarow.

context.load_date=input.load_date

and later in tBigQueryInput I use the context variable as following for table name

 

[project-bigquery:123456.ga_sessions_" + context.load_date + "]