Skip to content

Commit

Permalink
Ignore properties with no valid characters. (GoogleCloudPlatform#577)
Browse files Browse the repository at this point in the history
- Drop resource properties that don't contain any BigQuery valid characters from
the schema. Prevoiusly such properties caused an 'string index out of range'
errors during import.
- Upgrade to latest beam sdk.

Co-authored-by: Jacob Ferriero <[email protected]>
  • Loading branch information
bmenasha and Jacob Ferriero authored Nov 4, 2020
1 parent f244a36 commit d57d4f9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 4 additions & 0 deletions tools/asset-inventory/asset_inventory/bigquery_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ def _sanitize_property(property_name, parent, depth, num_properties):

# enforce column name requirements (condition #2).
new_property_name = CLEAN_UP_REGEX.sub('', property_name)
# contains only non-word characters. just drop the property.
if not new_property_name:
parent.pop(property_name)
return
first_character = new_property_name[0]
if not first_character.isalpha() and first_character != '_':
new_property_name = '_' + new_property_name
Expand Down
2 changes: 1 addition & 1 deletion tools/asset-inventory/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
apache-beam[gcp]==2.17.0
apache-beam[gcp]==2.25.0
mock==2.0.0
pytest
6 changes: 1 addition & 5 deletions tools/asset-inventory/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@
keywords='gcp asset inventory',
packages=['asset_inventory'],
setup_requires=['pytest-runner'],
# https://beam.apache.org/get-started/downloads
# Can't use 2.18, 2.19
# due to https://issues.apache.org/jira/browse/BEAM-9218
# should be fixed in 2.20 when released.
extras_require = {
'testing': ['mock==2.0.0', 'pytest==4.6.6', 'apache-beamn[gcp]==2.17.0'],
'testing': ['mock==2.0.0', 'pytest==4.6.6', 'apache-beamn[gcp]==2.25.0'],
},
include_package_data=True,
# https://pypi.org/project/google-cloud-asset/#history
Expand Down
1 change: 1 addition & 0 deletions tools/asset-inventory/tests/test_bigquery_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def test_sanitize_property_value(self):
'empyty_dict': {},
'empyty_dict_list': [{}, {}],
'a' * 200: 'value0',
'@!@': 'deleteme',
'@2_3': 'value1',
'invalid_numeric': 9.300000191734863,
'labels': {
Expand Down

0 comments on commit d57d4f9

Please sign in to comment.