diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java index b4feb09ee084fa79eb74202afcc60b52a4ef483f..47bd68524f572bab6d441280cfc4927c456b87fd 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java @@ -408,6 +408,327 @@ public void testListPartitionsByValuesNullValues() throws Exception { + /** + * Testing getPartition(String,String,String) -> + * get_partition_by_name(String,String,String) + * @throws Exception + */ + @Test + public void testGetPartition() throws Exception { + createTable3PartCols1Part(client); + Partition partition = client.getPartition(DB_NAME, TABLE_NAME, "yyyy=1997/mm=05/dd=16"); + assertNotNull(partition); + assertEquals(Lists.newArrayList("1997","05", "16"), partition.getValues()); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionIncompletePartName() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, TABLE_NAME, "yyyy=1997/mm=05"); + } + + @Test(expected = MetaException.class) + public void testGetPartitionEmptyPartName() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, TABLE_NAME, ""); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionNonexistingPart() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, TABLE_NAME, "yyyy=1997/mm=05/dd=99"); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionNoDbName() throws Exception { + createTable3PartCols1Part(client); + client.getPartition("", TABLE_NAME, "yyyy=1997/mm=05/dd=16"); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionNoTblName() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, "", "yyyy=1997/mm=05/dd=16"); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionNoTable() throws Exception { + client.getPartition(DB_NAME, TABLE_NAME, "yyyy=1997/mm=05/dd=16"); + } + + @Test(expected = MetaException.class) + public void testGetPartitionNullDbName() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(null, TABLE_NAME, "yyyy=1997/mm=05/dd=16"); + } + + @Test(expected = MetaException.class) + public void testGetPartitionNullTblName() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, null, "yyyy=1997/mm=05/dd=16"); + } + + @Test(expected = MetaException.class) + public void testGetPartitionNullPartName() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, TABLE_NAME, (String)null); + } + + + + /** + * Testing getPartition(String,String,List(String)) -> + * get_partition(String,String,List(String)) + * @throws Exception + */ + @Test + public void testGetPartitionByValues() throws Exception { + createTable3PartCols1Part(client); + List parts = Lists.newArrayList("1997", "05", "16"); + Partition partition = client.getPartition(DB_NAME, TABLE_NAME, parts); + assertNotNull(partition); + assertEquals(parts, partition.getValues()); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionByValuesWrongPart() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList("1997", "05", "66")); + } + + @Test(expected = MetaException.class) + public void testGetPartitionByValuesWrongNumOfPartVals() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList("1997", "05")); + } + + @Test(expected = MetaException.class) + public void testGetPartitionByValuesEmptyPartVals() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList()); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionByValuesNoDbName() throws Exception { + createTable3PartCols1Part(client); + client.getPartition("", TABLE_NAME, Lists.newArrayList("1997", "05", "16")); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionByValuesNoTblName() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, "", Lists.newArrayList("1997", "05", "16")); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionByValuesNoTable() throws Exception { + client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList("1997", "05", "16")); + } + + @Test(expected = MetaException.class) + public void testGetPartitionByValuesNullDbName() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(null, TABLE_NAME, Lists.newArrayList("1997", "05", "16")); + } + + @Test(expected = MetaException.class) + public void testGetPartitionByValuesNullTblName() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, null, Lists.newArrayList("1997", "05", "16")); + } + + @Test(expected = MetaException.class) + public void testGetPartitionByValuesNullValues() throws Exception { + createTable3PartCols1Part(client); + client.getPartition(DB_NAME, TABLE_NAME, (List)null); + } + + + + /** + * Testing getPartitionsByNames(String,String,List(String)) -> + * get_partitions_by_names(String,String,List(String)) + * @throws Exception + */ + @Test + public void testGetPartitionsByNames() throws Exception { + List> testValues = createTable4PartColsParts(client); + + List partitions = client.getPartitionsByNames(DB_NAME, TABLE_NAME, + Lists.newArrayList("yyyy=2017/mm=11/dd=27","yyyy=1999/mm=01/dd=02")); + assertEquals(2, partitions.size()); + assertEquals(testValues.get(0), partitions.get(0).getValues()); + assertEquals(testValues.get(3), partitions.get(1).getValues()); + + + partitions = client.getPartitionsByNames(DB_NAME, TABLE_NAME, + Lists.newArrayList("yyyy=2017","yyyy=1999/mm=01/dd=02")); + assertEquals(testValues.get(0), partitions.get(0).getValues()); + } + + @Test + public void testGetPartitionsByNamesEmptyParts() throws Exception { + List> testValues = createTable4PartColsParts(client); + + List partitions = client.getPartitionsByNames(DB_NAME, TABLE_NAME, + Lists.newArrayList("","")); + assertEquals(0, partitions.size()); + + partitions = client.getPartitionsByNames(DB_NAME, TABLE_NAME, + Lists.newArrayList()); + assertEquals(0, partitions.size()); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionsByNamesNoDbName() throws Exception { + createTable3PartCols1Part(client); + client.getPartitionsByNames("", TABLE_NAME, Lists.newArrayList("yyyy=2000/mm=01/dd=02")); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionsByNamesNoTblName() throws Exception { + createTable3PartCols1Part(client); + client.getPartitionsByNames(DB_NAME, "", Lists.newArrayList("yyyy=2000/mm=01/dd=02")); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionsByNamesNoTable() throws Exception { + client.getPartitionsByNames(DB_NAME, TABLE_NAME, Lists.newArrayList("yyyy=2000/mm=01/dd=02")); + } + + @Test + public void testGetPartitionsByNamesNullDbName() throws Exception { + try { + createTable3PartCols1Part(client); + client.getPartitionsByNames(null, TABLE_NAME, Lists.newArrayList("yyyy=2000/mm=01/dd=02")); + fail("Should have thrown exception"); + } catch (NullPointerException | TTransportException e) { + } + } + + @Test + public void testGetPartitionsByNamesNullTblName() throws Exception { + try { + createTable3PartCols1Part(client); + client.getPartitionsByNames(DB_NAME, null, Lists.newArrayList("yyyy=2000/mm=01/dd=02")); + fail("Should have thrown exception"); + } catch (NullPointerException | TTransportException e) { + } + } + + @Test(expected = MetaException.class) + public void testGetPartitionsByNamesNullNames() throws Exception { + createTable3PartCols1Part(client); + client.getPartitionsByNames(DB_NAME, TABLE_NAME, (List)null); + } + + + + /** + * Testing getPartitionWithAuthInfo(String,String,List(String),String,List(String)) -> + * get_partition_with_auth(String,String,List(String),String,List(String)) + * @throws Exception + */ + @Test + public void testGetPartitionWithAuthInfoNoPrivilagesSet() throws Exception { + createTable3PartCols1Part(client); + Partition partition = client.getPartitionWithAuthInfo(DB_NAME, TABLE_NAME, Lists.newArrayList + ("1997","05", "16"),"", Lists.newArrayList()); + assertNotNull(partition); + assertNull(partition.getPrivileges()); + } + + @Test + public void testGetPartitionWithAuthInfo() throws Exception { + createTable3PartCols1PartAuthOn(client); + Partition partition = client.getPartitionWithAuthInfo(DB_NAME, TABLE_NAME, + Lists.newArrayList("1997","05", "16"),"user0", Lists.newArrayList("group0")); + assertNotNull(partition); + assertAuthInfoReturned("user0", "group0", partition); + } + + @Test + public void testGetPartitionWithAuthInfoEmptyUserGroup() throws Exception { + createTable3PartCols1PartAuthOn(client); + Partition partition = client.getPartitionWithAuthInfo(DB_NAME, TABLE_NAME, + Lists.newArrayList("1997","05", "16"),"", Lists.newArrayList("")); + assertNotNull(partition); + assertAuthInfoReturned("", "", partition); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionWithAuthInfoNoDbName() throws Exception { + createTable3PartCols1PartAuthOn(client); + client.getPartitionWithAuthInfo("", TABLE_NAME, + Lists.newArrayList("1997","05", "16"),"user0", Lists.newArrayList("group0")); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionWithAuthInfoNoTblName() throws Exception { + createTable3PartCols1PartAuthOn(client); + client.getPartitionWithAuthInfo(DB_NAME, "", + Lists.newArrayList("1997","05", "16"),"user0", Lists.newArrayList("group0")); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionWithAuthInfoNoSuchPart() throws Exception { + createTable3PartCols1PartAuthOn(client); + client.getPartitionWithAuthInfo(DB_NAME, TABLE_NAME, + Lists.newArrayList("1997","05", "66"),"user0", Lists.newArrayList("group0")); + } + + @Test(expected = MetaException.class) + public void testGetPartitionWithAuthInfoWrongNumOfPartVals() throws Exception { + createTable3PartCols1PartAuthOn(client); + client.getPartitionWithAuthInfo(DB_NAME, TABLE_NAME, + Lists.newArrayList("1997","05"),"user0", Lists.newArrayList("group0")); + } + + @Test + public void testGetPartitionWithAuthInfoNullDbName() throws Exception { + try { + createTable3PartCols1PartAuthOn(client); + client.getPartitionWithAuthInfo(null, TABLE_NAME, + Lists.newArrayList("1997","05", "16"),"user0", Lists.newArrayList("group0")); + fail("Should have thrown exception"); + } catch (NullPointerException | TTransportException e) { + } + } + + @Test + public void testGetPartitionWithAuthInfoNullTblName() throws Exception { + try { + createTable3PartCols1PartAuthOn(client); + client.getPartitionWithAuthInfo(DB_NAME, null, + Lists.newArrayList("1997","05", "16"),"user0", Lists.newArrayList("group0")); + fail("Should have thrown exception"); + } catch (NullPointerException | TTransportException e) { + } + } + + @Test(expected = MetaException.class) + public void testGetPartitionWithAuthInfoNullValues() throws Exception { + createTable3PartCols1PartAuthOn(client); + client.getPartitionWithAuthInfo(DB_NAME, TABLE_NAME, + null,"user0", Lists.newArrayList("group0")); + } + + @Test(expected = NoSuchObjectException.class) + public void testGetPartitionWithAuthInfoNullUser() throws Exception { + createTable3PartCols1PartAuthOn(client); + client.getPartitionWithAuthInfo(DB_NAME, "", + Lists.newArrayList("1997","05", "16"),null, Lists.newArrayList("group0")); + } + + @Test + public void testGetPartitionWithAuthInfoNullGroups() throws Exception { + createTable3PartCols1PartAuthOn(client); + client.getPartitionWithAuthInfo(DB_NAME, TABLE_NAME, + Lists.newArrayList("1997","05", "16"),"user0", null); + } + + + /** * Testing listPartitionSpecs(String,String,int) -> * get_partitions_pspec(String,String,int)