rdblue commented on code in PR #5391: URL: https://github.com/apache/iceberg/pull/5391#discussion_r934035501
########## python/tests/catalog/test_hive.py: ########## @@ -0,0 +1,386 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# pylint: disable=protected-access,redefined-outer-name +from unittest.mock import MagicMock + +import pytest +from hive_metastore.ttypes import AlreadyExistsException +from hive_metastore.ttypes import Database as HiveDatabase +from hive_metastore.ttypes import ( + FieldSchema, + InvalidOperationException, + MetaException, + NoSuchObjectException, + SerDeInfo, + SkewedInfo, + StorageDescriptor, +) +from hive_metastore.ttypes import Table as HiveTable + +from pyiceberg.catalog.base import PropertiesUpdateSummary +from pyiceberg.catalog.hive import HiveCatalog +from pyiceberg.exceptions import ( + AlreadyExistsError, + NamespaceNotEmptyError, + NoSuchNamespaceError, + NoSuchTableError, +) +from pyiceberg.schema import Schema + +HIVE_CATALOG_NAME = "hive" +HIVE_METASTORE_FAKE_URL = "thrift://unknown:9083" + + +@pytest.fixture +def hive_table() -> HiveTable: + return HiveTable( + tableName="new_tabl2e", + dbName="default", + owner="fokkodriesprong", + createTime=1659092339, + lastAccessTime=1659092, + retention=0, + sd=StorageDescriptor( + cols=[ + FieldSchema(name="foo", type="string", comment=None), + FieldSchema(name="bar", type="int", comment=None), + FieldSchema(name="baz", type="boolean", comment=None), + ], + location="file:/tmp/new_tabl2e", + inputFormat="org.apache.hadoop.mapred.FileInputFormat", + outputFormat="org.apache.hadoop.mapred.FileOutputFormat", + compressed=False, + numBuckets=0, + serdeInfo=SerDeInfo( + name=None, + serializationLib="org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe", + parameters={}, + description=None, + serializerClass=None, + deserializerClass=None, + serdeType=None, + ), + bucketCols=[], + sortCols=[], + parameters={}, + skewedInfo=SkewedInfo(skewedColNames=[], skewedColValues=[], skewedColValueLocationMaps={}), + storedAsSubDirectories=False, + ), + partitionKeys=[], + parameters={"EXTERNAL": "TRUE", "transient_lastDdlTime": "1659092339"}, + viewOriginalText=None, + viewExpandedText=None, + tableType="EXTERNAL_TABLE", + privileges=None, + temporary=False, + rewriteEnabled=False, + creationMetadata=None, + catName="hive", + ownerType=1, + writeId=-1, + isStatsCompliant=None, + colStats=None, + accessType=None, + requiredReadCapabilities=None, + requiredWriteCapabilities=None, + id=None, + fileMetadata=None, + dictionary=None, + txnId=None, + ) + + +@pytest.fixture +def hive_database() -> HiveDatabase: + return HiveDatabase( + name="default", + description=None, + locationUri="file:/tmp/default2.db", + parameters={"test": "property"}, + privileges=None, + ownerName=None, + ownerType=1, + catalogName="hive", + createTime=None, + managedLocationUri=None, + type=None, + connector_name=None, + remote_dbname=None, + ) + + +def test_check_number_of_namespaces(table_schema_simple: Schema): + catalog = HiveCatalog(HIVE_CATALOG_NAME, {}, url=HIVE_METASTORE_FAKE_URL) + + with pytest.raises(ValueError): + catalog.create_table(("default", "namespace", "table"), schema=table_schema_simple) + + with pytest.raises(ValueError): + catalog.create_table("default.namespace.table", schema=table_schema_simple) + + with pytest.raises(ValueError): + catalog.create_table(("table",), schema=table_schema_simple) + + with pytest.raises(ValueError): + catalog.create_table("table", schema=table_schema_simple) + + +def test_create_table(table_schema_simple: Schema, hive_table: HiveTable): + catalog = HiveCatalog(HIVE_CATALOG_NAME, {}, url=HIVE_METASTORE_FAKE_URL) + + catalog._client = MagicMock() + catalog._client.__enter__().create_table.return_value = hive_table + catalog._client.__enter__().get_table.return_value = hive_table + + catalog.create_table(("default", "table"), schema=table_schema_simple) + + catalog._client.__enter__().create_table.assert_called_with( Review Comment: Can you add `assert_called_with` for more of the test cases? I think we should validate what is passed to HMS wherever we can. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org