<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Update database from CSV files when each tables have different keys in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Update-database-from-CSV-files-when-each-tables-have-different/m-p/2246836#M32227</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;first load all the data into empty tables used only as intermediate storage either with Talend (easy with Dynamic schema) or directly from the database:&lt;/P&gt; 
&lt;PRE&gt;Talend BulkExec components or MSSQL BULK INSERT, ORACLE SQL LOADER, etc.&lt;/PRE&gt; 
&lt;P&gt;then, update final tables using intermediate tables ; two solutions :&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;1) create as many update_[tableName].sql files as needed ; in each file, manually enter the required update query such as :&lt;/P&gt; 
&lt;PRE&gt;/*update_tableTarget1.sql*/&lt;BR /&gt;UPDATE tableTarget1 t,
       tableSource1 s
SET    t.data1 = s.data1, t.data2 = s.data2
WHERE     t.id = s.id&lt;/PRE&gt; 
&lt;P&gt;Then, within your Talend job, loop over the SQL files and use a tDatabaseRow to execute the update query (you can even parallelize the iterate link after the tFileList) :&lt;/P&gt; 
&lt;PRE&gt;tFileList (*.sql) -iterate-&amp;gt; tFileInputFullRow -row-&amp;gt; tFlowToITerate -iterate-&amp;gt; t&amp;lt;DataBase&amp;gt;Row&lt;/PRE&gt; 
&lt;P&gt;the tFileInput* reads the SQL file and the tFlowToIterate put the query in globalMap but you can use others methods as well.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Or&lt;/P&gt; 
&lt;P&gt;2) build dynamically the queries from the database catalog.&lt;/P&gt; 
&lt;P&gt;You can get a list of tables to update (this heavily depends on your database) :&lt;/P&gt; 
&lt;PRE&gt;select table_name, ... from &amp;lt;system_tables&amp;gt; where ...&lt;/PRE&gt; 
&lt;P&gt;You then loop over the tables, retrieve the list of columns, identify which are keys and so one and build all the queries dynamically and use a tDatabaseRow to do all the updates.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The first method is easier but harder to maintain. The second method will ask more work at first but then, you'll be able to add tables, change formats much faster.&lt;/P&gt;</description>
    <pubDate>Tue, 17 Mar 2020 13:11:23 GMT</pubDate>
    <dc:creator>lennelei</dc:creator>
    <dc:date>2020-03-17T13:11:23Z</dc:date>
    <item>
      <title>Update database from CSV files when each tables have different keys</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Update-database-from-CSV-files-when-each-tables-have-different/m-p/2246832#M32223</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I'm trying to update database with multiple tables (100+) from CSV files (in a directory) using the following job design and components.&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="input" style="width: 531px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M9rq.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/130611i4F21E689DFF0BFF9/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M9rq.png" alt="0683p000009M9rq.png" /&gt;&lt;/span&gt;&lt;SPAN class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;input&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="output" style="width: 503px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M9go.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/143428iC0896999D29DB310/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M9go.png" alt="0683p000009M9go.png" /&gt;&lt;/span&gt;&lt;SPAN class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;output&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;The issue here is that all my tables (in a DB) have different schemas and different primary keys (most of my PK is a composite key made from multiple PK columns, usually from 1-5).&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;For example:&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mysql_pk" style="width: 200px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M9Ho.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/146214iAFDA1C643EFFA58B/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M9Ho.png" alt="0683p000009M9Ho.png" /&gt;&lt;/span&gt;&lt;SPAN class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;mysql_pk&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mysql_pk1" style="width: 200px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M9aL.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/150755i36D15245D0A7CB40/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M9aL.png" alt="0683p000009M9aL.png" /&gt;&lt;/span&gt;&lt;SPAN class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;mysql_pk1&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;So I'm not sure how I could dynamically set my PK in schema.&lt;/P&gt; 
&lt;P&gt;Does anyone have an idea how to make this work?&lt;/P&gt; 
&lt;P&gt;A screenshot of job design/components would be very much appreciated&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MACn.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/154443iC5B8CACEF3D12C6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MACn.png" alt="0683p000009MACn.png" /&gt;&lt;/span&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Currently, I only have a dynamic column in my schema since all my keys are different.&lt;/P&gt; 
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tMap" style="width: 545px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M9x4.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/138739i9AD2833240A27372/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M9x4.png" alt="0683p000009M9x4.png" /&gt;&lt;/span&gt;&lt;SPAN class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;tMap&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;When I tried to to run the job, it stated that 'schema must have a key'.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;Exception in component tDBOutput_2 (test02)
java.lang.RuntimeException: For update, Schema must have a key&lt;/PRE&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 03:00:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Update-database-from-CSV-files-when-each-tables-have-different/m-p/2246832#M32223</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T03:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Update database from CSV files when each tables have different keys</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Update-database-from-CSV-files-when-each-tables-have-different/m-p/2246833#M32224</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure you'll be able to achieve this without using some tricks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you should first load csv data into "loading tables" (table you'll truncate and insert only) and then update your final tables from those data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can either write manually all the queries or you can build them on the fly from the MySQL catalog.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 08:15:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Update-database-from-CSV-files-when-each-tables-have-different/m-p/2246833#M32224</guid>
      <dc:creator>lennelei</dc:creator>
      <dc:date>2020-03-12T08:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Update database from CSV files when each tables have different keys</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Update-database-from-CSV-files-when-each-tables-have-different/m-p/2246834#M32225</link>
      <description>&lt;A href="https://community.qlik.com/s/profile/0053p000007LMbuAAG"&gt;@lennelei&lt;/A&gt; 
&lt;BR /&gt;Thank you for your response. 
&lt;BR /&gt;Can you explain more on the job design/components used? or maybe a job design screenshot?? 
&lt;BR /&gt;**I'm totally new on Talend and I'm not good in database as well .... 
&lt;BR /&gt; 
&lt;BR /&gt;Thank you so much</description>
      <pubDate>Thu, 12 Mar 2020 09:01:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Update-database-from-CSV-files-when-each-tables-have-different/m-p/2246834#M32225</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-12T09:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Update database from CSV files when each tables have different keys</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Update-database-from-CSV-files-when-each-tables-have-different/m-p/2246835#M32226</link>
      <description>&lt;BLOCKQUOTE&gt; 
 &lt;HR /&gt; 
 &lt;A href="https://community.qlik.com/s/profile/0053p000007LQspAAG"&gt;@crotmn&lt;/A&gt;&amp;nbsp;wrote: 
 &lt;BR /&gt; 
 &lt;P&gt;Hi there,&lt;/P&gt; 
 &lt;P&gt;&amp;nbsp;&lt;/P&gt; 
 &lt;P&gt;I'm trying to update database with multiple tables (100+) from CSV files (in a directory) using the following job design and components.&lt;/P&gt; 
 &lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="input" style="width: 531px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M9rq.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/130611i4F21E689DFF0BFF9/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M9rq.png" alt="0683p000009M9rq.png" /&gt;&lt;/span&gt;&lt;SPAN class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;input&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt; 
 &lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="output" style="width: 503px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M9go.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/143428iC0896999D29DB310/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M9go.png" alt="0683p000009M9go.png" /&gt;&lt;/span&gt;&lt;SPAN class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;output&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt; 
 &lt;P&gt;The issue here is that all my tables (in a DB) have different schemas and different primary keys (most of my PK is a composite key made from multiple PK columns, usually from 1-5).&amp;nbsp;&lt;/P&gt; 
 &lt;P&gt;For example:&lt;/P&gt; 
 &lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mysql_pk" style="width: 200px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M9Ho.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/146214iAFDA1C643EFFA58B/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M9Ho.png" alt="0683p000009M9Ho.png" /&gt;&lt;/span&gt;&lt;SPAN class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;mysql_pk&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mysql_pk1" style="width: 200px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M9aL.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/150755i36D15245D0A7CB40/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M9aL.png" alt="0683p000009M9aL.png" /&gt;&lt;/span&gt;&lt;SPAN class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;mysql_pk1&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt; 
 &lt;P&gt;So I'm not sure how I could dynamically set my PK in schema.&lt;/P&gt; 
 &lt;P&gt;Does anyone have an idea how to make this work?&lt;/P&gt; 
 &lt;P&gt;A screenshot of job design/components would be very much appreciated&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MACn.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/154443iC5B8CACEF3D12C6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MACn.png" alt="0683p000009MACn.png" /&gt;&lt;/span&gt;&lt;/P&gt; 
 &lt;P&gt;&amp;nbsp;&lt;/P&gt; 
 &lt;P&gt;Currently, I only have a dynamic column in my schema since all my keys are different.&lt;/P&gt; 
 &lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tMap" style="width: 545px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009M9x4.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/138739i9AD2833240A27372/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009M9x4.png" alt="0683p000009M9x4.png" /&gt;&lt;/span&gt;&lt;SPAN class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;tMap&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt; 
 &lt;P&gt;&amp;nbsp;&lt;/P&gt; 
 &lt;P&gt;When I tried to to run the job, it stated that 'schema must have a key'.&lt;/P&gt; 
 &lt;P&gt;&amp;nbsp;&lt;/P&gt; 
 &lt;PRE&gt;Exception in component tDBOutput_2 (test02)
java.lang.RuntimeException: For update, Schema must have a key&lt;/PRE&gt; 
 &lt;P&gt;&amp;nbsp;&lt;/P&gt; 
 &lt;P&gt;&amp;nbsp;&lt;/P&gt; 
 &lt;P&gt;&amp;nbsp;&lt;/P&gt; 
 &lt;HR /&gt; 
&lt;/BLOCKQUOTE&gt; 
&lt;P&gt;Right now, I'm trying a lengthy method below.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Job1: Load CSV and insert into a temporary database(dynamic schema)&lt;/P&gt; 
&lt;P&gt;Job2: Inject constraint into the tables (temporary DB)&lt;/P&gt; 
&lt;P&gt;Job3: Update tables (temporary DB)'s data into the real database&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;If there's a precise and better way to do this, please let me know.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 16:54:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Update-database-from-CSV-files-when-each-tables-have-different/m-p/2246835#M32226</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-16T16:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Update database from CSV files when each tables have different keys</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Update-database-from-CSV-files-when-each-tables-have-different/m-p/2246836#M32227</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;first load all the data into empty tables used only as intermediate storage either with Talend (easy with Dynamic schema) or directly from the database:&lt;/P&gt; 
&lt;PRE&gt;Talend BulkExec components or MSSQL BULK INSERT, ORACLE SQL LOADER, etc.&lt;/PRE&gt; 
&lt;P&gt;then, update final tables using intermediate tables ; two solutions :&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;1) create as many update_[tableName].sql files as needed ; in each file, manually enter the required update query such as :&lt;/P&gt; 
&lt;PRE&gt;/*update_tableTarget1.sql*/&lt;BR /&gt;UPDATE tableTarget1 t,
       tableSource1 s
SET    t.data1 = s.data1, t.data2 = s.data2
WHERE     t.id = s.id&lt;/PRE&gt; 
&lt;P&gt;Then, within your Talend job, loop over the SQL files and use a tDatabaseRow to execute the update query (you can even parallelize the iterate link after the tFileList) :&lt;/P&gt; 
&lt;PRE&gt;tFileList (*.sql) -iterate-&amp;gt; tFileInputFullRow -row-&amp;gt; tFlowToITerate -iterate-&amp;gt; t&amp;lt;DataBase&amp;gt;Row&lt;/PRE&gt; 
&lt;P&gt;the tFileInput* reads the SQL file and the tFlowToIterate put the query in globalMap but you can use others methods as well.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Or&lt;/P&gt; 
&lt;P&gt;2) build dynamically the queries from the database catalog.&lt;/P&gt; 
&lt;P&gt;You can get a list of tables to update (this heavily depends on your database) :&lt;/P&gt; 
&lt;PRE&gt;select table_name, ... from &amp;lt;system_tables&amp;gt; where ...&lt;/PRE&gt; 
&lt;P&gt;You then loop over the tables, retrieve the list of columns, identify which are keys and so one and build all the queries dynamically and use a tDatabaseRow to do all the updates.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The first method is easier but harder to maintain. The second method will ask more work at first but then, you'll be able to add tables, change formats much faster.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 13:11:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Update-database-from-CSV-files-when-each-tables-have-different/m-p/2246836#M32227</guid>
      <dc:creator>lennelei</dc:creator>
      <dc:date>2020-03-17T13:11:23Z</dc:date>
    </item>
  </channel>
</rss>

