-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Juliana Freire
committed
Nov 30, 2020
1 parent
18e04fe
commit df73584
Showing
10 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ exclude_lines = | |
raise AssertionError | ||
raise NotImplementedError | ||
super | ||
|
||
pass | ||
|
||
[run] | ||
omit = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
hive\_metastore\_client.builders package | ||
======================================== | ||
|
||
Submodules | ||
---------- | ||
|
||
|
||
.. automodule:: hive_metastore_client.builders.abstract_builder | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
|
||
.. automodule:: hive_metastore_client.builders.database_builder | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
|
||
Module contents | ||
--------------- | ||
|
||
.. automodule:: hive_metastore_client.builders | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from hive_metastore_client.builders.database_builder import DatabaseBuilder | ||
from hive_metastore_client.hive_mestastore_client import HiveMetastoreClient | ||
|
||
HIVE_HOST = "<ADD_HIVE_HOST_HERE>" | ||
HIVE_PORT = 9083 | ||
|
||
with HiveMetastoreClient(HIVE_HOST, HIVE_PORT) as hive_client: | ||
|
||
database_builder = DatabaseBuilder("database_name") | ||
database = database_builder.build() | ||
|
||
hive_client.create_database(database) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Builder Classes.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Abstract Builder Class.""" | ||
from abc import ABCMeta, abstractmethod | ||
|
||
|
||
class AbstractBuilder(metaclass=ABCMeta): | ||
"""Abstract Builder class with builder methods.""" | ||
|
||
@abstractmethod | ||
def build(self) -> object: | ||
""" | ||
Builds the respective Thrift object. | ||
:return: an instance of the built object | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""DatabaseBuilder.""" | ||
from typing import Mapping | ||
|
||
from hive_metastore_client.builders.abstract_builder import AbstractBuilder | ||
from thrift_files.libraries.thrift_hive_metastore_client.ttypes import Database, PrincipalPrivilegeSet, PrincipalType # type: ignore # noqa: E501 | ||
|
||
|
||
class DatabaseBuilder(AbstractBuilder): | ||
"""Builds thrift Database object.""" | ||
|
||
def __init__( | ||
self, | ||
name: str, | ||
description: str = None, | ||
location_uri: str = None, | ||
parameters: Mapping[str, str] = None, | ||
privileges: PrincipalPrivilegeSet = None, | ||
owner_name: str = None, | ||
owner_type: PrincipalType = None, | ||
catalog_name: str = None, | ||
): | ||
""" | ||
Constructor. | ||
:param name: name of the database | ||
:param description: description of the database | ||
:param location_uri: location for the database | ||
:param parameters: properties associated with the database | ||
:param privileges: privilege grant info for the database | ||
:param owner_name: owner name for the database | ||
:param owner_type: owner type for the database | ||
:param catalog_name: catalog name for the database | ||
""" | ||
self.name = name | ||
self.description = description | ||
self.location_uri = location_uri | ||
self.parameters = parameters | ||
self.privileges = privileges | ||
self.owner_name = owner_name | ||
self.owner_type = owner_type | ||
self.catalog_name = catalog_name | ||
|
||
def build(self) -> Database: | ||
"""Returns the thrift Database object.""" | ||
database = Database( | ||
name=self.name, | ||
description=self.description, | ||
locationUri=self.location_uri, | ||
parameters=self.parameters, | ||
privileges=self.privileges, | ||
ownerName=self.owner_name, | ||
ownerType=self.owner_type, | ||
catalogName=self.catalog_name, | ||
) | ||
return database |
29 changes: 29 additions & 0 deletions
29
tests/unit/hive_metastore_client/builders/test_database_builder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from unittest import mock | ||
from unittest.mock import Mock | ||
from hive_metastore_client.builders.database_builder import DatabaseBuilder | ||
|
||
|
||
class TestDatabaseBuilder: | ||
@mock.patch("hive_metastore_client.builders.database_builder.Database") | ||
def test_build(self, mocked_database): | ||
# arrange | ||
mocked_database_name = "database_name" | ||
|
||
mocked_obj = Mock() | ||
mocked_database.return_value = mocked_obj | ||
|
||
# act | ||
returned_value = DatabaseBuilder(name=mocked_database_name).build() | ||
|
||
# assert | ||
assert returned_value == mocked_obj | ||
mocked_database.assert_called_once_with( | ||
name=mocked_database_name, | ||
description=None, | ||
locationUri=None, | ||
parameters=None, | ||
privileges=None, | ||
ownerName=None, | ||
ownerType=None, | ||
catalogName=None, | ||
) |