@Before public void injectMocks() throws Exception { when(mockClient.getTable(DATABASE_NAME, TABLE_NAME)).thenReturn(mockTable); when(mockTable.getDbName()).thenReturn(DATABASE_NAME); when(mockTable.getTableName()).thenReturn(TABLE_NAME); when(mockTable.getPartitionKeys()).thenReturn(PARTITION_KEYS); when(mockTable.getSd()).thenReturn(tableStorageDescriptor); tableStorageDescriptor.setLocation(TABLE_LOCATION); when(mockClient.getPartition(DATABASE_NAME, TABLE_NAME, PARTITIONED_VALUES)).thenReturn(mockPartition); when(mockPartition.getSd()).thenReturn(mockPartitionStorageDescriptor); when(mockPartitionStorageDescriptor.getLocation()).thenReturn(PARTITION_LOCATION); helper = new MetaStorePartitionHelper(mockClient, DATABASE_NAME, TABLE_NAME, TABLE_PATH); }
public static void dropDB(HiveConf conf, String databaseName) throws HiveException, MetaException { IMetaStoreClient client = new HiveMetaStoreClient(conf); try { for (String table : client.listTableNamesByFilter(databaseName, "", (short) -1)) { client.dropTable(databaseName, table, true, true); } client.dropDatabase(databaseName); } catch (TException e) { client.close(); } }
private static void addPartition(IMetaStoreClient client, Table tbl , List<String> partValues) throws IOException, TException { Partition part = new Partition(); part.setDbName(tbl.getDbName()); part.setTableName(tbl.getTableName()); StorageDescriptor sd = new StorageDescriptor(tbl.getSd()); sd.setLocation(sd.getLocation() + Path.SEPARATOR + makePartPath(tbl.getPartitionKeys(), partValues)); part.setSd(sd); part.setValues(partValues); client.add_partition(part); }
private void dropDbTable() { // cleanup try { msc.dropTable(catName, dbName, tableName, true, true); msc.dropDatabase(catName, dbName, true, true, true); } catch (TException e) { // ignore } }
public static void dropDB(IMetaStoreClient client, String databaseName) { try { for (String table : client.listTableNamesByFilter(databaseName, "", (short) -1)) { client.dropTable(databaseName, table, true, true); } client.dropDatabase(databaseName); } catch (TException e) { } }
@Test public void testAddPartitionSpecSetRootPath() throws Exception { Table table = createTable(); String rootPath = table.getSd().getLocation() + "/addPartSpecRootPath/"; String rootPath1 = table.getSd().getLocation() + "/someotherpath/"; Partition partition = buildPartition(DB_NAME, TABLE_NAME, "2007", rootPath + "part2007/"); PartitionSpecProxy partitionSpecProxy = buildPartitionSpec(DB_NAME, TABLE_NAME, rootPath1, Lists.newArrayList(partition)); client.add_partitions_pspec(partitionSpecProxy); Partition resultPart = client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList("2007")); Assert.assertEquals(rootPath + "part2007", resultPart.getSd().getLocation()); }
@Test public void testDropPartitionNullPartDropOptions() throws Exception { client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), null); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[1], PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, true, false); }
@Test(expected = InvalidOperationException.class) public void testRenamePartitionNoDbName() throws Exception { List<List<String>> oldValues = createTable4PartColsParts(client); List<Partition> oldParts = client.listPartitions(DB_NAME, TABLE_NAME, (short)-1); Partition partToRename = oldParts.get(3); partToRename.setValues(Lists.newArrayList("2018", "01", "16")); client.renamePartition("", TABLE_NAME, oldValues.get(3), partToRename); }
@Test(expected = MetaException.class) public void testAlterPartitionsMissingPartitionVals() throws Exception { createTable4PartColsParts(client); Table t = client.getTable(DB_NAME, TABLE_NAME); PartitionBuilder builder = new PartitionBuilder(); Partition part = builder.inTable(t).build(metaStore.getConf()); Partition part1 = client.listPartitions(DB_NAME, TABLE_NAME, (short)-1).get(0); client.alter_partitions(DB_NAME, TABLE_NAME, Lists.newArrayList(part, part1)); }
@Test public void testDropPartitionDeleteParentDir() throws Exception { client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[0].getValues(), true); client.dropPartition(DB_NAME, TABLE_NAME, PARTITIONS[1].getValues(), true); List<Partition> droppedPartitions = Lists.newArrayList(PARTITIONS[0], PARTITIONS[1]); List<Partition> remainingPartitions = Lists.newArrayList(PARTITIONS[2]); checkPartitionsAfterDelete(TABLE_NAME, droppedPartitions, remainingPartitions, true, false); Path parentPath = new Path(PARTITIONS[0].getSd().getLocation()).getParent(); Assert.assertFalse("The parent path '" + parentPath.toString() + "' should not exist.", metaStore.isPathExists(parentPath)); }
@Test public void testAddPartitionEmptyColsInSd() throws Exception { createTable(); Partition partition = buildPartition(DB_NAME, TABLE_NAME, DEFAULT_YEAR_VALUE); partition.getSd().setCols(new ArrayList<>()); client.add_partition(partition); // TODO: Not sure that this is the correct behavior. It doesn't make sense to create the // partition without column info. This should be investigated later. Partition part = client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList(DEFAULT_YEAR_VALUE)); Assert.assertNotNull(part); Assert.assertTrue(part.getSd().getCols().isEmpty()); }
@Test public void testAddPartitionUpperCase() throws Exception { String tableLocation = metaStore.getWarehouseRoot() + "/" + TABLE_NAME; createTable(DB_NAME, TABLE_NAME, getMonthPartCol(), tableLocation); Partition partition = buildPartition(Lists.newArrayList("APRIL"), getMonthPartCol(), 1); client.add_partition(partition); Partition part = client.getPartition(DB_NAME, TABLE_NAME, "month=APRIL"); Assert.assertNotNull(part); Assert.assertEquals(TABLE_NAME, part.getTableName()); Assert.assertEquals(DB_NAME, part.getDbName()); Assert.assertEquals("APRIL", part.getValues().get(0)); Assert.assertEquals(tableLocation + "/month=APRIL", part.getSd().getLocation()); Assert.assertTrue(metaStore.isPathExists(new Path(part.getSd().getLocation()))); }
@Test(expected = InvalidOperationException.class) public void testAlterPartitionsChangeValues() throws Exception { createTable4PartColsParts(client); List<Partition> partitions = client.listPartitions(DB_NAME, TABLE_NAME, (short)-1); Partition p = partitions.get(3); p.setValues(Lists.newArrayList("1", "2", "3")); client.alter_partitions(DB_NAME, TABLE_NAME, Lists.newArrayList(p)); }
@Test(expected = NoSuchObjectException.class) public void testGetPartitionByValuesNoDb() throws Exception { client.dropDatabase(DB_NAME); client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList("1997", "05", "16")); }
@Test(expected = NoSuchObjectException.class) public void testListPartitionsByValuesNoDb() throws Exception { client.dropDatabase(DB_NAME); client.listPartitions(DB_NAME, TABLE_NAME, Lists.newArrayList("1999"), (short)-1); }
@Test public void testAddPartitionsForViewNullPartLocation() throws Exception { String tableName = "test_add_partition_view"; createView(tableName); Partition partition = buildPartition(DB_NAME, tableName, DEFAULT_YEAR_VALUE); partition.getSd().setLocation(null); List<Partition> partitions = Lists.newArrayList(partition); client.add_partitions(partitions); Partition part = client.getPartition(DB_NAME, tableName, "year=2017"); Assert.assertNull(part.getSd().getLocation()); }
@Test public void testGetTableMetaNullNoDbNoTbl() throws Exception { client.dropDatabase(DB_NAME + "_one", true, true, true); client.dropDatabase(DB_NAME + "_two", true, true, true); List<TableMeta> tableMetas = client.getTableMeta("*", "*", Lists.newArrayList()); assertTableMetas(new int[]{}, tableMetas); }
@Test public void testAddPartitionSpecForViewNullPartLocation() throws Exception { String tableName = "test_add_partition_view"; createView(tableName); Partition partition = buildPartition(DB_NAME, tableName, DEFAULT_YEAR_VALUE); partition.getSd().setLocation(null); PartitionSpecProxy partitionSpecProxy = buildPartitionSpec(DB_NAME, tableName, null, Lists.newArrayList(partition)); client.add_partitions_pspec(partitionSpecProxy); Partition part = client.getPartition(DB_NAME, tableName, "year=2017"); Assert.assertNull(part.getSd().getLocation()); }
@Test(expected = MetaException.class) public void testListPartitionValuesNoDb() throws Exception { client.dropDatabase(DB_NAME); List<FieldSchema> partitionSchema = Lists.newArrayList( new FieldSchema("yyyy", "string", ""), new FieldSchema("mm", "string", "")); PartitionValuesRequest request = new PartitionValuesRequest(DB_NAME, TABLE_NAME, partitionSchema); client.listPartitionValues(request); }
@Test public void testDropTableExternalWithoutPurge() throws Exception { Table table = externalTable; client.dropTable(table.getDbName(), table.getTableName(), true, true, false); Assert.assertTrue("Table path should not be removed", metaStore.isPathExists(new Path(table.getSd().getLocation()))); Assert.assertFalse("Table path should be in trash", metaStore.isPathExistsInTrash(new Path(table.getSd().getLocation()))); }