subkanthi commented on issue #19891:
URL: https://github.com/apache/airflow/issues/19891#issuecomment-1003432071


   I briefly looked at vertica_to_mysql.py, tmpfile is accessed here in this 
block
   ```
                           cursor.execute(
                               f"LOAD DATA LOCAL INFILE '{tmpfile.name}' "
                               f"INTO TABLE {self.mysql_table} "
                               f"LINES TERMINATED BY '\r\n' ({', 
'.join(selected_columns)})"
                           )
   ```
    which is outside of the with block, not sure if this is a bug or maybe Im  
missing something.
   
   ```                    with NamedTemporaryFile("w") as tmpfile:```
   
   ```
           count = 0
           with closing(vertica.get_conn()) as conn:
               with closing(conn.cursor()) as cursor:
                   cursor.execute(self.sql)
                   selected_columns = [d.name for d in cursor.description]
   
                   if self.bulk_load:
                       with NamedTemporaryFile("w") as tmpfile:
                           self.log.info("Selecting rows from Vertica to local 
file %s...", tmpfile.name)
                           self.log.info(self.sql)
   
                           csv_writer = csv.writer(tmpfile, delimiter='\t', 
encoding='utf-8')
                           for row in cursor.iterate():
                               csv_writer.writerow(row)
                               count += 1
   
                           tmpfile.flush()
                   else:
                       self.log.info("Selecting rows from Vertica...")
                       self.log.info(self.sql)
   
                       result = cursor.fetchall()
                       count = len(result)
   
                   self.log.info("Selected rows from Vertica %s", count)
   
           if self.mysql_preoperator:
               self.log.info("Running MySQL preoperator...")
               mysql.run(self.mysql_preoperator)
   
           try:
               if self.bulk_load:
                   self.log.info("Bulk inserting rows into MySQL...")
                   with closing(mysql.get_conn()) as conn:
                       with closing(conn.cursor()) as cursor:
                           cursor.execute(
                               f"LOAD DATA LOCAL INFILE '{tmpfile.name}' "
                               f"INTO TABLE {self.mysql_table} "
                               f"LINES TERMINATED BY '\r\n' ({', 
'.join(selected_columns)})"
                           )
                           conn.commit()
                   tmpfile.close()
               else:
                   self.log.info("Inserting rows into MySQL...")
                   mysql.insert_rows(table=self.mysql_table, rows=result, 
target_fields=selected_columns)
               self.log.info("Inserted rows into MySQL %s", count)
           except (MySQLdb.Error, MySQLdb.Warning):
               self.log.info("Inserted rows into MySQL 0")
               raise
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to