Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAE-133] Removing types-comparison when dropping a column #56

Merged
merged 2 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions hive_metastore_client/hive_metastore_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
class HiveMetastoreClient(ThriftClient):
"""User main interface with the metastore server methods."""

COL_TYPE_INCOMPATIBILITY_DISALLOW_CONFIG = (
"hive.metastore.disallow.incompatible.col.type.changes"
)

def __init__(self, host: str, port: int = 9083) -> None:
"""
Instantiates the client object for given host and port.
Expand Down Expand Up @@ -113,6 +117,11 @@ def drop_columns_from_table(
cols.append(col)
table.sd.cols = cols

# Hive Metastore enforces that the schema prior and after
# an ALTER TABLE should be the same,
# however when dropping a column the schema will definitely change
self.setMetaConf(self.COL_TYPE_INCOMPATIBILITY_DISALLOW_CONFIG, "false")

# call alter table to drop columns removed from list of table columns
self.alter_table(dbname=db_name, tbl_name=table_name, new_tbl=table)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ def test_add_columns_to_table(

@mock.patch.object(HiveMetastoreClient, "get_table")
@mock.patch.object(HiveMetastoreClient, "alter_table")
@mock.patch.object(HiveMetastoreClient, "setMetaConf")
def test_drop_columns_from_table(
self, mocked_alter_table, mocked_get_table, hive_metastore_client
self,
mocked_set_meta_conf,
mocked_alter_table,
mocked_get_table,
hive_metastore_client,
):
# arrange
db_name = "db_name"
Expand All @@ -131,6 +136,9 @@ def test_drop_columns_from_table(
)

# assert
mocked_set_meta_conf.assert_called_once_with(
hive_metastore_client.COL_TYPE_INCOMPATIBILITY_DISALLOW_CONFIG, "false"
)
mocked_get_table.assert_called_once_with(dbname=db_name, tbl_name=table_name)
mocked_alter_table.assert_called_once_with(
dbname=db_name, tbl_name=table_name, new_tbl=expected_mocked_table
Expand Down