9 Replies Latest reply on Dec 3, 2015 12:59 PM by Russell Christopher

    Refresh Extract with Data Extract API

    Gaëlle PERIAT

      Hi Guys !

       

      I use Data Extract API to create some tde files. I want to refresh the file each day but I don't find how to do. I can only re-create the file. How to do to not re-load all data.

       

      Someone did this already ?

       

      Thanks for your help !!

       

      Gaëlle

        • 1. Re: Refresh Extract with Data Extract API
          Russell Christopher

          Hi Gaelle -

           

          Currently, The API is used to create extracts, not refresh them in the Tableau Desktop/Server sense of the word.

           

          In 8.1,  you can also use the API to append new rows to an existing extract, but it would be up to you to figure out which (new) rows need to be appended.

          • 2. Re: Refresh Extract with Data Extract API
            Gaëlle PERIAT

            Thank you very much ! I will check 8.1 version

             

            Cheers,

             

            Gaëlle

            • 3. Re: Refresh Extract with Data Extract API
              Gaëlle PERIAT

              It makes what I want ! So great ! Thank you !!!

              • 4. Re: Refresh Extract with Data Extract API
                Sean Funk

                Do you have a link to the API documentation which describes this function? I'm looking through the latest 8.1 linux API and I'm not seeing this feature explicitely described (Refreshing or appending or adding - strictly creating and adding) anywhere.

                • 5. Re: Refresh Extract with Data Extract API
                  Russell Christopher

                  Take a look the sample Python code - you'll see the one method being called when an extract does not exist and we're starting from scratch and a different approach when the extract is there and we want to "append":

                   

                   

                  try:

                      with Extract('order-py.tde') as extract:

                   

                          table = None

                          if not extract.hasTable('Extract'):

                              # Table does not exist; create it

                              tableDef = makeTableDefinition()

                              table = extract.addTable('Extract', tableDef)

                          else:

                              # Open an existing table to add more rows

                              table = extract.openTable('Extract')

                   

                          tableDef = table.getTableDefinition()

                          printTableDefinition(tableDef)

                   

                          insertData(table)

                   

                  except TableauException, e:

                      print 'Something bad happened:', e

                  • 6. Re: Refresh Extract with Data Extract API
                    Mercy Joseph

                    Hi -

                    I was also lookin g for a way to append (using python) to the existing extract rather than erasing and rewriting...

                    and I tried using a modified version of the above suggested by Russell, but it doesn't seem to get into the first path - not sure why..

                    this creates table via "Except" path in first round; when I try to append a 2nd file it still goes through "Except" path and comes up with error finding a "duplicate" file..

                    Any insight will be helpful.

                     

                    this is the modified version I used:

                    **************slightly modified version*********

                    try:

                        with Extract('myNamedExtract.tde') as tdefile:

                            table = None

                            if not tdefile.hasTable('Extract'):

                                #Step 2: Create the tableDef

                                tableDef = tde.TableDefinition()

                                tableDef.addColumn('0_Field, tde.Type.CHAR_STRING)

                                tableDef.addColumn('1_Field', tde.Type.CHAR_STRING)

                                tableDef.addColumn('2_Field', tde.Type.CHAR_STRING)

                                tableDef.addColumn('3_Field', tde.Type.INTEGER)

                                tableDef.addColumn('4_Field', tde.Type.CHAR_STRING)

                                #Step 3: Create the table in the image of the tableDef

                                table = tdefile.addTable('Extract',tableDef)

                            else:

                                table=tdefile.openTable('Extract')

                                tableDef = table.getTableDefinition()

                    except:

                        tdefile = tde.Extract('myNamedExtract.tde')

                        #Step 2: Create the tableDef

                        tableDef = tde.TableDefinition()

                        tableDef.addColumn('0_Field', tde.Type.CHAR_STRING)

                        tableDef.addColumn('1_Field', tde.Type.CHAR_STRING)

                        tableDef.addColumn('2_Field', tde.Type.CHAR_STRING)

                        tableDef.addColumn('3_Field', tde.Type.INTEGER)

                        tableDef.addColumn('4_Field', tde.Type.CHAR_STRING)

                    • 7. Re: Refresh Extract with Data Extract API
                      Mercy Joseph

                      Got it worked out!!! Please dont work on this if anyone is...

                      I went through the 2 sample codes accompanying Tableau's Dataextract documentation:

                      -  makeorder.py (to check if table exists and create tabledef if not, or append if it does) and

                      - csv2tde.py to read csv input

                       

                      Many small issues about referencing the extract, and various defined routines (for creating  table and tabledef) were involved, as well as challenges in entering a date value (as I did not have a time-stamp, but just month values).

                       

                      RyRobes instructions, as well as python.org documentation also helped immensely - links below:

                      - Build Tableau Data Extracts out of CSV Files? More Python TDE API madness! | Ryan Robitaille

                      - https://docs.python.org/2/library/csv.html#writer-objects

                      - datetime – Date/time value manipulation - Python Module of the Week

                      • 8. Re: Refresh Extract with Data Extract API
                        Anuj Srivastava

                        Hi Everyone,

                         

                        Do we have any update here as to if we can refresh the extract using Data Extract API for versions 9.0 and above?

                         

                        Thanks,

                        Anuj

                        • 9. Re: Refresh Extract with Data Extract API
                          Russell Christopher

                          Same answer. No refresh, can append