Skip to content

Commit

Permalink
Add schema description (#101)
Browse files Browse the repository at this point in the history
* Add schema description

* Update
  • Loading branch information
jinhyukchang authored Apr 30, 2020
1 parent 1552f17 commit 82bcc39
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion search_service/api/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"badges": fields.List(fields.Nested(tag_fields)),
# last etl timestamp as epoch
"last_updated_timestamp": fields.Integer,
"display_name": fields.String
"display_name": fields.String,
"schema_description": fields.String
}

search_table_results = {
Expand Down
4 changes: 3 additions & 1 deletion search_service/models/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Table(Base):
column_descriptions: List[str] = []
# The following are search-only properties:
total_usage: int = 0
schema_description: Optional[str] = attr.ib(default=None)

def get_id(self) -> str:
# uses the table key as the document id in ES
Expand All @@ -45,7 +46,8 @@ def get_attrs(cls) -> Set:
'tags',
'badges',
'last_updated_timestamp',
'display_name'
'display_name',
'schema_description'
}

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup, find_packages

__version__ = '2.3.0'
__version__ = '2.3.1'

requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')
with open(requirements_path) as requirements_file:
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/api/table/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def mock_proxy_results() -> Table:
column_names=['col1', 'col2'],
tags=[Tag(tag_name='tag')],
badges=[Tag(tag_name='badge1')],
last_updated_timestamp=1568324871)
last_updated_timestamp=1568324871,
schema_description='schema description')


def mock_json_response() -> dict:
Expand All @@ -29,6 +30,7 @@ def mock_json_response() -> dict:
"tags": [{'tag_name': 'tag'}],
"badges": [{'tag_name': 'badge1'}],
"last_updated_timestamp": 1568324871,
"schema_description": 'schema description',
}


Expand All @@ -45,4 +47,5 @@ def default_json_response() -> dict:
"tags": None,
"badges": None,
"last_updated_timestamp": 0,
"schema_description": None,
}
18 changes: 12 additions & 6 deletions tests/unit/proxy/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def test_search_with_one_user_result(self,
def test_create_document_with_no_data(self) -> None:
expected = ''
result = self.es_proxy.create_document(data=None, index='table_search_index')
print('result: {}'.format(result))
self.assertEquals(expected, result)

@patch('uuid.uuid4')
Expand All @@ -476,11 +477,12 @@ def test_create_document(self, mock_uuid: MagicMock) -> None:
schema='test_schema', description='A table for something',
key='snowflake://blue.test_schema/bank_accounts',
last_updated_timestamp=0, name='bank_accounts', tags=[], badges=self.mock_empty_badge,
column_descriptions=['desc']),
column_descriptions=['desc'], schema_description='schema description 1'),
Table(cluster='blue', column_names=['5', '6'], database='snowflake',
schema='test_schema', description='A table for lots of things!',
key='snowflake://blue.test_schema/bitcoin_wallets',
last_updated_timestamp=0, name='bitcoin_wallets', tags=[], badges=self.mock_empty_badge)
last_updated_timestamp=0, name='bitcoin_wallets', tags=[], badges=self.mock_empty_badge,
schema_description='schema description 2')
]
expected_data = [
{
Expand All @@ -503,7 +505,8 @@ def test_create_document(self, mock_uuid: MagicMock) -> None:
'name': 'bank_accounts',
'tags': [],
'badges': [],
'total_usage': 0
'total_usage': 0,
'schema_description': 'schema description 1',
},
{
'index': {
Expand All @@ -525,7 +528,8 @@ def test_create_document(self, mock_uuid: MagicMock) -> None:
'name': 'bitcoin_wallets',
'tags': [],
'badges': [],
'total_usage': 0
'total_usage': 0,
'schema_description': 'schema description 2',
}
]
mock_elasticsearch.bulk.return_value = {'errors': False}
Expand All @@ -552,7 +556,8 @@ def test_update_document(self, mock_uuid: MagicMock) -> None:
Table(cluster='blue', column_names=['5', '6'], database='snowflake',
schema='test_schema', description='A table for lots of things!',
key=table_key, last_updated_timestamp=0, name='bitcoin_wallets',
tags=[], column_descriptions=['hello'], badges=self.mock_empty_badge)
tags=[], column_descriptions=['hello'], badges=self.mock_empty_badge,
schema_description='schema description 1')
]
expected_data = [
{
Expand All @@ -576,7 +581,8 @@ def test_update_document(self, mock_uuid: MagicMock) -> None:
'name': 'bitcoin_wallets',
'tags': [],
'badges': [],
'total_usage': 0
'total_usage': 0,
'schema_description': 'schema description 1',
}
}
]
Expand Down

0 comments on commit 82bcc39

Please sign in to comment.