Skip to content

Commit

Permalink
Merge pull request #47 from CityOfPhiladelphia/handle_allowed_nonoid_…
Browse files Browse the repository at this point in the history
…fields_w_objectid

Allow list of fieldnames that contain 'objectid' to not be treated li…
  • Loading branch information
floptical authored Oct 11, 2024
2 parents f8fda7f + 9da9d63 commit ad4f584
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions databridge_etl_tools/oracle/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, connection_string, table_name, table_schema, s3_bucket, s3_ke
self.s3_bucket = s3_bucket
self.s3_key = s3_key
self.times_db_called = 0
self.nonoid_fields_w_objectid = ['addressobjectid']
# just initialize this self variable here so we connect first
self.conn

Expand Down Expand Up @@ -392,6 +393,7 @@ def load(self):
WHERE table_name = '{self.table_name.upper()}'
AND owner = '{self.table_schema.upper()}'
AND column_name not like 'SYS_%'
AND (column_name not like '%OBJECTID%' or column_name in ({','.join(self.nonoid_fields_w_objectid.upper())}))
'''
cursor.execute(cols_stmt)
cols = cursor.fetchall()[0][0]
Expand All @@ -412,14 +414,21 @@ def load(self):
srid = response[0] if response else None

# Detect if registered through existence of objectid column
oid_stmt = f'''SELECT LISTAGG(column_name, ', ') WITHIN GROUP (ORDER BY column_id)
FROM all_tab_cols
WHERE table_name = '{self.table_name.upper()}'
AND owner = '{self.table_schema.upper()}'
AND column_name like '%OBJECTID%'
AND column_name not in ({','.join(self.nonoid_fields_w_objectid.upper())})
'''
cursor.execute(cols_stmt)
oids = cursor.fetchall()[0][0]
sde_registered = False
if 'OBJECTID_' in cols:
if 'OBJECTID_' in oids:
raise AssertionError('Nonstandard OBJECTID columm detected! Please correct your objectid column to be named just "OBJECTID"!!')
if 'OBJECTID' in cols:
if 'OBJECTID' in oids:
sde_registered = True
print('objectid found, assuming sde registered.')
cols = cols.replace('OBJECTID,', '')
cols = cols.replace(', OBJECTID', '')

# Create a temp table name exactly 30 characters in length so we don't go over oracle 11g's table name limit
# and then hash it so that it's unique to our table name.
Expand Down

0 comments on commit ad4f584

Please sign in to comment.