-
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 cd117fa
Showing
10 changed files
with
135 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 to define builder methods to be implemented.""" | ||
|
||
@abstractmethod | ||
def build(self) -> object: | ||
""" | ||
To be implemented by each subclass and build the respective object. | ||
:return: an instance of the object to be built | ||
""" | ||
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,47 @@ | ||
"""Database Builder Class.""" | ||
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): | ||
"""Builder class for 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, | ||
): | ||
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: | ||
""" | ||
Builds Database object given builder parameters. | ||
:return: Database object built | ||
""" | ||
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 |
18 changes: 18 additions & 0 deletions
18
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,18 @@ | ||
from hive_metastore_client.builders.database_builder import DatabaseBuilder | ||
from thrift_files.libraries.thrift_hive_metastore_client.ttypes import Database | ||
|
||
|
||
class TestDatabaseBuilder: | ||
def test_build_with_name(self): | ||
database_builder = DatabaseBuilder(name="database_name") | ||
database = Database(name="database_name") | ||
|
||
assert database == database_builder.build() | ||
|
||
def test_build_with_description(self): | ||
database_builder = DatabaseBuilder( | ||
name="database_name", description="description" | ||
) | ||
database = Database(name="database_name", description="description") | ||
|
||
assert database == database_builder.build() |