Commit 1debb152 authored by mborukhava's avatar mborukhava Committed by Tao Feng

Fixed Snowflake views being captured as tables (#164)

* Fixed Snowflake views being captured as tables

Updated snowflake_metadata_extractor.py and fixed that Snowflake views were captured as tables.

* Fixed unit tests for snowflake metadata extraction

* Fix lint error
parent 49d2c46f
...@@ -127,7 +127,8 @@ class SnowflakeMetadataExtractor(Extractor): ...@@ -127,7 +127,8 @@ class SnowflakeMetadataExtractor(Extractor):
last_row['schema_name'], last_row['schema_name'],
last_row['name'], last_row['name'],
unidecode(last_row['description']) if last_row['description'] else None, unidecode(last_row['description']) if last_row['description'] else None,
columns) columns,
last_row['is_view'] == 'true')
def _get_raw_extract_iter(self): def _get_raw_extract_iter(self):
# type: () -> Iterator[Dict[str, Any]] # type: () -> Iterator[Dict[str, Any]]
......
...@@ -50,7 +50,8 @@ class TestSnowflakeMetadataExtractor(unittest.TestCase): ...@@ -50,7 +50,8 @@ class TestSnowflakeMetadataExtractor(unittest.TestCase):
'name': 'test_table', 'name': 'test_table',
'description': 'a table for testing', 'description': 'a table for testing',
'cluster': 'cluster':
self.conf['extractor.snowflake_metadata.{}'.format(SnowflakeMetadataExtractor.CLUSTER_KEY)] self.conf['extractor.snowflake_metadata.{}'.format(SnowflakeMetadataExtractor.CLUSTER_KEY)],
'is_view': 'false'
} }
sql_execute.return_value = [ sql_execute.return_value = [
...@@ -112,21 +113,24 @@ class TestSnowflakeMetadataExtractor(unittest.TestCase): ...@@ -112,21 +113,24 @@ class TestSnowflakeMetadataExtractor(unittest.TestCase):
'name': 'test_table1', 'name': 'test_table1',
'description': 'test table 1', 'description': 'test table 1',
'cluster': 'cluster':
self.conf['extractor.snowflake_metadata.{}'.format(SnowflakeMetadataExtractor.CLUSTER_KEY)] self.conf['extractor.snowflake_metadata.{}'.format(SnowflakeMetadataExtractor.CLUSTER_KEY)],
'is_view': 'nottrue'
} }
table1 = {'schema_name': 'test_schema1', table1 = {'schema_name': 'test_schema1',
'name': 'test_table2', 'name': 'test_table2',
'description': 'test table 2', 'description': 'test table 2',
'cluster': 'cluster':
self.conf['extractor.snowflake_metadata.{}'.format(SnowflakeMetadataExtractor.CLUSTER_KEY)] self.conf['extractor.snowflake_metadata.{}'.format(SnowflakeMetadataExtractor.CLUSTER_KEY)],
'is_view': 'false'
} }
table2 = {'schema_name': 'test_schema2', table2 = {'schema_name': 'test_schema2',
'name': 'test_table3', 'name': 'test_table3',
'description': 'test table 3', 'description': 'test table 3',
'cluster': 'cluster':
self.conf['extractor.snowflake_metadata.{}'.format(SnowflakeMetadataExtractor.CLUSTER_KEY)] self.conf['extractor.snowflake_metadata.{}'.format(SnowflakeMetadataExtractor.CLUSTER_KEY)],
'is_view': 'true'
} }
sql_execute.return_value = [ sql_execute.return_value = [
...@@ -212,7 +216,8 @@ class TestSnowflakeMetadataExtractor(unittest.TestCase): ...@@ -212,7 +216,8 @@ class TestSnowflakeMetadataExtractor(unittest.TestCase):
'test_schema2', 'test_table3', 'test table 3', 'test_schema2', 'test_table3', 'test table 3',
[ColumnMetadata('col_id3', 'description of col_id3', 'varchar', 0), [ColumnMetadata('col_id3', 'description of col_id3', 'varchar', 0),
ColumnMetadata('col_name3', 'description of col_name3', ColumnMetadata('col_name3', 'description of col_name3',
'varchar', 1)]) 'varchar', 1)],
True)
self.assertEqual(expected.__repr__(), extractor.extract().__repr__()) self.assertEqual(expected.__repr__(), extractor.extract().__repr__())
self.assertIsNone(extractor.extract()) self.assertIsNone(extractor.extract())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment