0 Replies Latest reply on Feb 13, 2020 2:14 PM by Rafael Manzano

    Update through Hyper API not working

    Rafael Manzano

      Hello everyone!

       

      Im trying to update some data in a .hyper file through the API,

      the connection works well and I'm able to retrieve tables and data but the update statement does not seem to have any effect although it returns a number of some apparently changed rows.


      Im new to the API and tableau, so maybe Im missing something here, but I couldn't figure it out.

       

      Here is my update function:

       

      def run_update_data_in_existing_hyper_file():
      
          path_to_source_database = "./unitpersonnel_extract.hyper"
          print(path_to_source_database)
      
          with HyperProcess(telemetry=Telemetry.SEND_USAGE_DATA_TO_TABLEAU) as hyper:
              with Connection(endpoint=hyper.endpoint,
                              database=path_to_source_database) as connection:
      
                  table_name = TableName("Extract", "Extract")
      
                  #PREUPDATE
                  rows_in_table = connection.execute_list_query(query=f"SELECT {escape_name('LOCATION_P.lat')} FROM {table_name} WHERE {escape_name('LOCATION_P.lat')} IS NOT NULL LIMIT 10")
                  print(rows_in_table)
      
                  #UPDATE
                  row_count = connection.execute_command(
                      command=f"UPDATE {table_name} "
                      f"SET {escape_name('LOCATION_P.lat')} = 50.0 "
                      f"WHERE {escape_name('LOCATION_P.lat')} IS NOT NULL")
                  print(f"The number of updated rows in table {row_count}")
      
                  #POSTUPDATE
                  rows_in_table = connection.execute_list_query(query=f"SELECT {escape_name('LOCATION_P.lat')} FROM {table_name} WHERE {escape_name('LOCATION_P.lat')} IS NOT NULL LIMIT 10")
                  print(rows_in_table)
      

       

      And the output:

      ./unitpersonnel_extract.hyper

      [[21.567], [21.567], [21.567], [38.834], [38.863], [37.209], [37.209], [38.863], [31.582], [31.582]]

      The number of updated rows in table 3484189

      [[36.625], [36.625], [39.029], [33.981], [32.299], [34.749], [34.749], [18.419], [37.884], [37.884]]

      I was expecting to see all 50.0's after the update. What am I missing?

       

      Thanks!!