Skip to content

Commit

Permalink
Merge pull request #164 from tcezard/Fix_ftp_usage
Browse files Browse the repository at this point in the history
Allow update of FTP usage entries
  • Loading branch information
tcezard authored Jan 8, 2024
2 parents 8bb20ab + 0cc99a0 commit 219c744
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions eva-usage-stats/ftp_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,21 @@ def load_batch_to_table(batch, private_config_xml_file, ftp_table_name):
with get_metadata_connection_handle('production_processing', private_config_xml_file) as metadata_connection_handle:
with metadata_connection_handle.cursor() as cursor:
query_insert = (
f'INSERT INTO {ftp_table_name} '
f'INSERT INTO {ftp_table_name} ('
f'_index, _id, event_ts_txt, event_ts, host, uhost, request_time, request_year, request_ts, file_name, '
f'file_size, transfer_time, transfer_type, direction, special_action, access_mode, country, region, '
f'city, domain_name, isp, usage_type)'
'VALUES (%s, %s, %s, cast(%s as timestamp with time zone), %s, %s, %s, %s, '
'cast(%s as timestamp without time zone), %s, %s, %s, %s, %s, %s, '
'%s, %s, %s, %s, %s, %s, %s)'
'cast(%s as timestamp without time zone), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'
'ON CONFLICT (_index, _id) DO UPDATE SET '
f'(_index, _id, event_ts_txt, event_ts, host, uhost, request_time, request_year, request_ts, file_name,'
f'file_size, transfer_time, transfer_type, direction, special_action, access_mode, country, region, '
f'city, domain_name, isp, usage_type) = (EXCLUDED._index, EXCLUDED._id, EXCLUDED.event_ts_txt, '
f'EXCLUDED.event_ts, EXCLUDED.host, EXCLUDED.uhost, EXCLUDED.request_time, EXCLUDED.request_year, '
f'EXCLUDED.request_ts, EXCLUDED.file_name, EXCLUDED.file_size, EXCLUDED.transfer_time, '
f'EXCLUDED.transfer_type, EXCLUDED.direction, EXCLUDED.special_action, EXCLUDED.access_mode, '
f'EXCLUDED.country, EXCLUDED.region, EXCLUDED.city, EXCLUDED.domain_name, EXCLUDED.isp, '
f'EXCLUDED.usage_type)'
)
psycopg2.extras.execute_batch(cursor, query_insert, rows)

Expand Down

0 comments on commit 219c744

Please sign in to comment.