com.amazonaws.services.glue.model.GetTableResult Java Examples

The following examples show how to use com.amazonaws.services.glue.model.GetTableResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testDropPartitionsException() throws Exception {
  Table table = HiveToCatalogConverter.convertTable(testTable);
  String namespaceName = testDB.getName();
  String tableName = table.getName();
  Partition partition = TestObjects.getTestPartition(namespaceName, tableName, Arrays.asList("foo", "bar"));

  mockGetPartitionsSuccess(Lists.newArrayList(partition));
  mockBatchDeleteThrowsException(new NullPointerException("foo error")); // use NPE as a specific RuntimeException
  when(glueClient.getTable(any(GetTableRequest.class)))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));

  try {
    metastoreClient.dropPartitions(namespaceName, tableName,
        Lists.newArrayList(getDumbExpression()), true, false, false);
    fail("should throw");
  } catch (TException e) {
    verify(glueClient, times(1)).batchDeletePartition(any(BatchDeletePartitionRequest.class));
    verify(wh, never()).deleteDir(any(Path.class), anyBoolean(), anyBoolean());
    assertThat(e, is(instanceOf(MetaException.class)));
    assertThat(e.getMessage(), is("foo error"));
    assertDaemonThreadPools();
  }
}
 
Example #2
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPartitionsFailedServiceException() throws Exception {
  int numPartitions = 2;
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);
  List<String> values = partitions.get(0).getValues();
  when(glueClient.batchCreatePartition(any(BatchCreatePartitionRequest.class)))
    .thenReturn(new BatchCreatePartitionResult().withErrors(TestObjects.getPartitionError(values,
      new InternalServiceException("exception"))));
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));

  try {
    metastoreClientDelegate.addPartitions(partitions, false, true);
    fail("should throw");
  } catch (Exception e) {
    assertThat(e, is(instanceOf(MetaException.class)));
    verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
    verify(glueClient, times(1)).batchCreatePartition(any(BatchCreatePartitionRequest.class));
    verify(wh, times(numPartitions)).mkdirs(any(Path.class), eq(true));
    verify(wh, times(1)).deleteDir(any(Path.class), eq(true));
    assertDaemonThreadPools();
  }
}
 
Example #3
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPartitionsFailedAlreadyExistsException() throws Exception {
  int numPartitions = 2;
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);
  List<String> values = ImmutableList.of("foo1");

  when(glueClient.batchCreatePartition(any(BatchCreatePartitionRequest.class)))
    .thenReturn(new BatchCreatePartitionResult().withErrors(TestObjects.getPartitionError(values,
      new com.amazonaws.services.glue.model.AlreadyExistsException("exception"))));
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));

  try {
    metastoreClientDelegate.addPartitions(partitions, false, true);
    fail("Should throw");
  } catch (Exception e) {
    assertThat(e, is(instanceOf(org.apache.hadoop.hive.metastore.api.AlreadyExistsException.class)));
    verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
    verify(glueClient, times(1)).batchCreatePartition(any(BatchCreatePartitionRequest.class));
    verify(wh, times(numPartitions)).mkdirs(any(Path.class), eq(true));
    verify(wh, times(1)).deleteDir(any(Path.class), eq(true));
    assertDaemonThreadPools();
  }
}
 
Example #4
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPartitionsThrowsEntityNotFoundException() throws Exception {
  when(glueClient.batchCreatePartition(any(BatchCreatePartitionRequest.class)))
    .thenThrow(new EntityNotFoundException("exception"));
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));

  int numPartitions = 2;
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);

  try {
    metastoreClientDelegate.addPartitions(partitions, false, true);
    fail("Should throw");
  } catch (Exception e) {
    assertThat(e, is(instanceOf(NoSuchObjectException.class)));
    verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
    verify(glueClient, times(1)).batchCreatePartition(any(BatchCreatePartitionRequest.class));
    verify(wh, times(numPartitions)).mkdirs(any(Path.class), eq(true));
    verify(wh, times(numPartitions)).deleteDir(any(Path.class), eq(true));
    assertDaemonThreadPools();
  }
}
 
Example #5
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPartitionsThrowsExceptionSecondPage() throws Exception {
  int numPartitions = 200;
  int secondPageSize = numPartitions - BATCH_CREATE_PARTITIONS_MAX_REQUEST_SIZE;
  when(glueClient.batchCreatePartition(any(BatchCreatePartitionRequest.class)))
    .thenReturn(new BatchCreatePartitionResult())
    .thenThrow(new InvalidInputException("exception"));
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));

  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);

  try {
    metastoreClientDelegate.addPartitions(partitions, false, true);
    fail("Should throw");
  } catch (Exception e) {
    assertThat(e, is(instanceOf(InvalidObjectException.class)));
    verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
    verify(glueClient, times(2)).batchCreatePartition(any(BatchCreatePartitionRequest.class));
    verify(wh, times(numPartitions)).mkdirs(any(Path.class), eq(true));
    verify(wh, times(secondPageSize)).deleteDir(any(Path.class), eq(true));
    assertDaemonThreadPools();
  }
}
 
Example #6
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPartitionsIfNotExists() throws Exception {
  List<String> values = ImmutableList.of("foo1");
  when(glueClient.batchCreatePartition(any(BatchCreatePartitionRequest.class)))
    .thenReturn(new BatchCreatePartitionResult().withErrors(TestObjects.getPartitionError(values,
      new com.amazonaws.services.glue.model.AlreadyExistsException("exception"))));
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));

  int numPartitions = 2;
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);
  List<org.apache.hadoop.hive.metastore.api.Partition> partitionsCreated =
    metastoreClientDelegate.addPartitions(partitions, true, true);

  verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
  verify(glueClient, times(1)).batchCreatePartition(any(BatchCreatePartitionRequest.class));
  verify(wh, times(numPartitions)).mkdirs(any(Path.class), eq(true));
  verify(wh, never()).deleteDir(any(Path.class), eq(true));
  assertEquals(1, partitionsCreated.size());
  assertThat(partitionsCreated.get(0), isIn(partitions));
  assertDaemonThreadPools();
}
 
Example #7
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPartitionsKeysAndValuesNotMatch() throws Exception {
  int numPartitions = 2;
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);
  //make the partition value size inconsistent with key size
  partitions.get(1).setValues(Lists.newArrayList("foo1", "bar1"));

  when(glueClient.getTable(any(GetTableRequest.class))).thenReturn(new GetTableResult().withTable(testTbl));

  try {
    metastoreClientDelegate.addPartitions(partitions, true, true);
    fail("should throw");
  } catch (IllegalArgumentException e) {
    verify(wh, never()).getDnsPath(any(Path.class));
    assertDaemonThreadPools();
  }
}
 
Example #8
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPartitionsDeleteAddedPathsWhenAddPathFail() throws Exception {
  int numPartitions = 2;
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);

  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));
  when(wh.isDir(any(Path.class))).thenReturn(false);
  when(wh.mkdirs(any(Path.class), eq(true))).thenReturn(true).thenReturn(false); // succeed first, then fail

  try {
    metastoreClientDelegate.addPartitions(partitions, true, true);
    fail("should throw");
  } catch (MetaException e) {
    verify(wh, times(numPartitions)).getDnsPath(any(Path.class));
    verify(wh, times(numPartitions)).isDir(any(Path.class));
    verify(wh, times(numPartitions)).mkdirs(any(Path.class), eq(true));
    verify(wh, times(1)).deleteDir(any(Path.class), eq(true));
    assertDaemonThreadPools();
  }
}
 
Example #9
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testDropPartitionsClientException() throws Exception {
  Table table = HiveToCatalogConverter.convertTable(testTable);
  String namespaceName = testDB.getName();
  String tableName = table.getName();
  Partition partition = TestObjects.getTestPartition(namespaceName, tableName, Arrays.asList("foo", "bar"));

  mockGetPartitionsSuccess(Lists.newArrayList(partition));
  mockBatchDeleteThrowsException(new InvalidInputException("InvalidInputException"));
  when(glueClient.getTable(any(GetTableRequest.class)))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));

  try {
    metastoreClient.dropPartitions(namespaceName, tableName,
        Lists.newArrayList(getDumbExpression()), true, false, false);
    fail("should throw");
  } catch (TException e) {
    verify(glueClient, times(1)).batchDeletePartition(any(BatchDeletePartitionRequest.class));
    verify(glueClient, never()).getPartition(any(GetPartitionRequest.class));
    verify(wh, never()).deleteDir(any(Path.class), anyBoolean(), anyBoolean());
    assertThat(e, is(instanceOf(InvalidObjectException.class)));
    assertThat(e.getMessage(), containsString("InvalidInputException"));
  }
  assertDaemonThreadPools();
}
 
Example #10
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test(expected=InvalidOperationException.class)
public void testRenamePartitionForInvalidSD() throws Exception {
  String dbName = testDB.getName();
  Table externalTable = getTestTable();
  externalTable.setTableType(TableType.EXTERNAL_TABLE.name());   
  
  StorageDescriptor sd = HiveToCatalogConverter.convertStorageDescriptor(testPartition.getSd());
  
  Partition oldPartition = new Partition()
      .withDatabaseName(dbName).withTableName(externalTable.getName())
      .withValues(Lists.newArrayList("oldval")).withStorageDescriptor(null);
  
  Partition newPartition = new Partition()
                                    .withDatabaseName(dbName).withTableName(externalTable.getName())
                                    .withValues(Lists.newArrayList("newval")).withStorageDescriptor(sd);

  when(glueClient.getDatabase(any(GetDatabaseRequest.class)))
    .thenReturn(new GetDatabaseResult().withDatabase(HiveToCatalogConverter.convertDatabase(testDB)));
  when(glueClient.getTable(any(GetTableRequest.class)))
  .thenReturn(new GetTableResult().withTable(externalTable));
  when(glueClient.getPartition(any(GetPartitionRequest.class)))
    .thenReturn(new GetPartitionResult().withPartition(oldPartition));

  metastoreClient.renamePartition(dbName, externalTable.getName(), oldPartition.getValues(),
      CatalogToHiveConverter.convertPartition(newPartition));
}
 
Example #11
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testDropPartitionsDifferentNamespace() throws Exception {
  Table table = HiveToCatalogConverter.convertTable(testTable);

  String namespaceName1 = testDB.getName();
  String tableName1 = table.getName();
  String namespaceName2 = namespaceName1 + ".2";
  String tableName2 = tableName1 + ".2";

  List<String> values1 = Arrays.asList("foo1", "bar1");
  List<String> values2 = Arrays.asList("foo2", "bar2");
  Partition partition1 = getTestPartition(namespaceName1, tableName1, values1);
  Partition partition2 = getTestPartition(namespaceName2, tableName2, values2);
  List<Partition> partitions = Lists.newArrayList(partition1, partition2);

  mockGetPartitionsSuccess(partitions);
  mockBatchDeleteSuccess();
  when(glueClient.getTable(any(GetTableRequest.class)))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));

  metastoreClient.dropPartitions(namespaceName1, tableName1,
      Lists.newArrayList(getDumbExpression()), true, false, false);
  assertDaemonThreadPools();
}
 
Example #12
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTableObjectByName() throws Exception {
  String dbName = testDB.getName();
  List<org.apache.hadoop.hive.metastore.api.Table> expectedHiveTableList = ImmutableList.of(testTable);

  List<String> tableNameList = Lists.newArrayList();
  for (org.apache.hadoop.hive.metastore.api.Table table : expectedHiveTableList) {
    tableNameList.add(table.getTableName());
  }

  when(glueClient.getTable(new GetTableRequest().withDatabaseName(dbName).withName(testTable.getTableName())))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));
  List<org.apache.hadoop.hive.metastore.api.Table> result = metastoreClient.getTableObjectsByName(dbName, tableNameList);

  verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
  assertThat(result, is(expectedHiveTableList));
}
 
Example #13
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAlterIndex() throws Exception {
  Table catalogIndexTable = HiveToCatalogConverter.convertIndexToTableObject(testIndex);
  testTable.getParameters().put(INDEX_PREFIX + testIndex.getIndexName(), catalogTableToString(catalogIndexTable));

  when(glueClient.getTable(new GetTableRequest().withDatabaseName(testDB.getName()).withName(testTable.getTableName())))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));
  when(glueClient.getDatabase(new GetDatabaseRequest().withName(testDB.getName())))
    .thenReturn(new GetDatabaseResult().withDatabase(HiveToCatalogConverter.convertDatabase(testDB)));

  testIndex.setIndexHandlerClass("test_alter");
  Table updatedIndex = HiveToCatalogConverter.convertIndexToTableObject(testIndex);
  TableInput expectedTableInputWithIndex = GlueInputConverter.convertToTableInput(testTable);
  expectedTableInputWithIndex.getParameters().put(INDEX_PREFIX + testIndex.getIndexName(), catalogTableToString(updatedIndex));

  metastoreClient.alter_index(testDB.getName(), testTable.getTableName(), testIndex.getIndexName(), testIndex);

  // verify UpdateRequestTable call is made with expected table input containing new Index
  ArgumentCaptor<UpdateTableRequest> captor = ArgumentCaptor.forClass(UpdateTableRequest.class);
  verify(glueClient, times(1)).updateTable(captor.capture());
  assertEquals(expectedTableInputWithIndex, captor.getValue().getTableInput());
}
 
Example #14
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testDropPartitionUsingName() throws Exception {
  Table table = HiveToCatalogConverter.convertTable(testTable);
  List<String> values = Arrays.asList("foo", "bar");
  Partition partition = new Partition().withDatabaseName(testDB.getName())
      .withTableName(table.getName())
      .withValues(values)
      .withStorageDescriptor(TestObjects.getTestStorageDescriptor());
  when(glueClient.deletePartition(any(DeletePartitionRequest.class))).thenReturn(new DeletePartitionResult());
  when(glueClient.getPartition(any(GetPartitionRequest.class)))
    .thenReturn(new GetPartitionResult().withPartition(partition));
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(table));
  when(glueClient.getPartitions(any(GetPartitionsRequest.class)))
    .thenReturn(new GetPartitionsResult().withPartitions(partition));
  // Warehouse is expecting a pattern of /key=val
  String partitionName = table.getPartitionKeys().get(0).getName() + "=foo";
  boolean deleteData = true;
  metastoreClient.dropPartition(testDB.getName(), table.getName(), partitionName, deleteData);
  verify(glueClient).deletePartition(any(DeletePartitionRequest.class));
  verify(glueClient).getPartition(any(GetPartitionRequest.class));
  verify(glueClient).getTable(any(GetTableRequest.class));
  assertDaemonThreadPools();
}
 
Example #15
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testListIndexNames() throws Exception{
  Index testIndex2 = getTestHiveIndex(testDB.getName());
  List<String> expectedIndexNameList = ImmutableList.of(testIndex.getIndexName(), testIndex2.getIndexName());
  List<Index> indexList = ImmutableList.of(testIndex, testIndex2);
  for (Index index : indexList) {
    Table catalogIndex = HiveToCatalogConverter.convertIndexToTableObject(index);
    testTable.getParameters().put(INDEX_PREFIX + index.getIndexName(), catalogTableToString(catalogIndex));
  }

  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));
  List<String> result = metastoreClient.listIndexNames(testTable.getDbName(), testTable.getTableName(), (short)2);

  verify(glueClient).getTable(any(GetTableRequest.class));
  assertEquals(expectedIndexNameList.size(), result.size());
  for (String indexName : expectedIndexNameList) {
    assertTrue(result.contains(indexName));
  }
}
 
Example #16
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateIndex() throws Exception {
  Table catalogIndexTable = getTestTable();
  org.apache.hadoop.hive.metastore.api.Table hiveIndexTable = CatalogToHiveConverter.convertTable(catalogIndexTable, testDB.getName());
  testIndex.setOrigTableName(testTable.getTableName());
  testIndex.setIndexTableName(hiveIndexTable.getTableName());

  when(glueClient.getDatabase(new GetDatabaseRequest().withName(testDB.getName())))
      .thenReturn(new GetDatabaseResult().withDatabase(HiveToCatalogConverter.convertDatabase(testDB)));
  when(glueClient.getTable(new GetTableRequest().withDatabaseName(testDB.getName()).withName(testTable.getTableName())))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));
  when(glueClient.getTable(new GetTableRequest().withDatabaseName(testDB.getName()).withName(hiveIndexTable.getTableName())))
      .thenThrow(EntityNotFoundException.class);
  when(glueClient.getPartitions(any(GetPartitionsRequest.class)))
      .thenReturn(new GetPartitionsResult().withPartitions(ImmutableList.<Partition>of()));

  metastoreClient.createIndex(testIndex, hiveIndexTable);

  TableInput expectedTableInputWithIndex = GlueInputConverter.convertToTableInput(testTable);
  expectedTableInputWithIndex.getParameters().put(INDEX_PREFIX + testIndex.getIndexName(), catalogTableToString(catalogIndexTable));
  verify(glueClient).createTable(any(CreateTableRequest.class));
  verify(glueClient).updateTable(new UpdateTableRequest().withDatabaseName(testDB.getName()).withTableInput(expectedTableInputWithIndex));
}
 
Example #17
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testDropIndex() throws Exception {
  Table catalogIndexTable = getTestTable();
  setIndexParametersForIndexTable(catalogIndexTable, testDB.getName(), testTable.getTableName());
  testIndex.setOrigTableName(testTable.getTableName());
  testIndex.setIndexTableName(catalogIndexTable.getName());
  testTable.getParameters().put(INDEX_PREFIX + testIndex.getIndexName(), catalogTableToString(catalogIndexTable));

  when(glueClient.getTable(new GetTableRequest().withDatabaseName(testDB.getName()).withName(testTable.getTableName())))
    .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));
  when(glueClient.getTable(new GetTableRequest().withDatabaseName(testDB.getName()).withName(testIndex.getIndexTableName())))
    .thenReturn(new GetTableResult().withTable(catalogIndexTable));
  when(glueClient.getDatabase(new GetDatabaseRequest().withName(testDB.getName())))
    .thenReturn(new GetDatabaseResult().withDatabase(HiveToCatalogConverter.convertDatabase(testDB)));
  when(glueClient.getPartitions(any(GetPartitionsRequest.class)))
    .thenReturn(new GetPartitionsResult().withPartitions(ImmutableList.<Partition>of()));

  metastoreClient.dropIndex(testDB.getName(), testTable.getTableName(), testIndex.getIndexName(), true);

  TableInput expectedTableInput = GlueInputConverter.convertToTableInput(testTable);
  verify(glueClient).updateTable(new UpdateTableRequest().withDatabaseName(testDB.getName()).withTableInput(expectedTableInput));
  verify(glueClient).deleteTable(new DeleteTableRequest().withDatabaseName(testDB.getName()).withName(testIndex.getIndexTableName()));
}
 
Example #18
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAppendPartitionByName() throws Exception {    
  List<String> values = Arrays.asList("foo");
  when(glueClient.getTable(any(GetTableRequest.class)))
      .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));
  Path partLocation = new Path(testTable.getSd().getLocation(), Warehouse
          .makePartName(testTable.getPartitionKeys(), values));
  setupMockWarehouseForPath(partLocation, false, true);
  mockBatchCreatePartitionsSucceed();

  org.apache.hadoop.hive.metastore.api.Partition res = metastoreClient.appendPartition(
      testDB.getName(),
      testTable.getTableName(),
      testTable.getPartitionKeys().get(0).getName() + "=foo");
  assertThat(res.getValues(), is(values));
  assertDaemonThreadPools();
}
 
Example #19
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPartitionsTwoPages() throws Exception {
  mockBatchCreatePartitionsSucceed();
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));

  int numPartitions = (int) (BATCH_CREATE_PARTITIONS_MAX_REQUEST_SIZE * 1.2);
  int expectedBatches = 2;
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);
  List<org.apache.hadoop.hive.metastore.api.Partition> partitionsCreated =
    metastoreClientDelegate.addPartitions(partitions, false, true);

  verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
  verify(glueClient, times(expectedBatches)).batchCreatePartition(any(BatchCreatePartitionRequest.class));
  verify(wh, times(numPartitions)).mkdirs(any(Path.class), eq(true));
  verify(wh, never()).deleteDir(any(Path.class), eq(true));
  assertEquals(numPartitions, partitionsCreated.size());
  assertThat(partitionsCreated, containsInAnyOrder(partitions.toArray()));
  assertDaemonThreadPools();
}
 
Example #20
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test(expected=InvalidOperationException.class)
public void testRenamePartitionForUnknownPartition() throws Exception {
  String dbName = testDB.getName();
  Table externalTable = getTestTable();
  externalTable.setTableType(TableType.EXTERNAL_TABLE.name());   
  
  StorageDescriptor sd = HiveToCatalogConverter.convertStorageDescriptor(testPartition.getSd());
  
  Partition oldPartition = new Partition()
      .withDatabaseName(dbName).withTableName(externalTable.getName())
      .withValues(Lists.newArrayList("oldval")).withStorageDescriptor(sd);
  
  Partition newPartition = new Partition()
                                    .withDatabaseName(dbName).withTableName(externalTable.getName())
                                    .withValues(Lists.newArrayList("newval")).withStorageDescriptor(sd);

  when(glueClient.getDatabase(any(GetDatabaseRequest.class)))
    .thenReturn(new GetDatabaseResult().withDatabase(HiveToCatalogConverter.convertDatabase(testDB)));
  when(glueClient.getTable(any(GetTableRequest.class)))
  .thenReturn(new GetTableResult().withTable(externalTable));
  doThrow(EntityNotFoundException.class).when(glueClient).getPartition(any(GetPartitionRequest.class));
  
  metastoreClient.renamePartition(dbName, externalTable.getName(), oldPartition.getValues(),
      CatalogToHiveConverter.convertPartition(newPartition));
}
 
Example #21
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAlterTable() throws Exception {
  org.apache.hadoop.hive.metastore.api.Table newHiveTable
      = CatalogToHiveConverter.convertTable(getTestTable(), testDb.getName());
  newHiveTable.setTableName(testTbl.getName());

  when(glueClient.getDatabase(any(GetDatabaseRequest.class))).thenReturn(new GetDatabaseResult().withDatabase((testDb)));
  when(glueClient.getTable(any(GetTableRequest.class))).thenReturn(new GetTableResult().withTable((testTbl)));
  metastoreClientDelegateCatalogId.alterTable(testDb.getName(), testTbl.getName(), newHiveTable, null);

  ArgumentCaptor<UpdateTableRequest> captor = ArgumentCaptor.forClass(UpdateTableRequest.class);
  verify(glueClient, times(1)).updateTable(captor.capture());

  TableInput expectedTableInput = GlueInputConverter.convertToTableInput(newHiveTable);
  assertEquals(expectedTableInput, captor.getValue().getTableInput());
}
 
Example #22
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testDropTableWithDeleteData() throws Exception {
  Path tbl_path = new Path(testTbl.getStorageDescriptor().getLocation());
  List<String> values = Lists.newArrayList("foo");
  Partition partition = new Partition().withDatabaseName(testDb.getName())
    .withTableName(testTbl.getName()).withValues(values)
    .withStorageDescriptor(TestObjects.getTestStorageDescriptor());

  when(glueClient.getTable(new GetTableRequest()
    .withDatabaseName(testTbl.getDatabaseName()).withName(testTbl.getName())))
    .thenReturn(new GetTableResult().withTable(testTbl));
  when(glueClient.deletePartition(new DeletePartitionRequest()
    .withDatabaseName(testDb.getName()).withPartitionValues(values).withTableName(testTbl.getName())))
    .thenReturn(new DeletePartitionResult());
  when(glueClient.getPartitions(any(GetPartitionsRequest.class)))
    .thenReturn(new GetPartitionsResult().withPartitions(partition));
  when(glueClient.getPartition(new GetPartitionRequest()
    .withDatabaseName(testDb.getName()).withTableName(testTbl.getName()).withPartitionValues(values)))
    .thenReturn(new GetPartitionResult().withPartition(partition));
  when(glueClient.getDatabase(any(GetDatabaseRequest.class)))
    .thenReturn(new GetDatabaseResult().withDatabase(testDb));
  metastoreClientDelegate.dropTable(testTbl.getDatabaseName(), testTbl.getName(), true, true, true);

  verify(glueClient).deleteTable(new DeleteTableRequest().withDatabaseName(testTbl.getDatabaseName()).withName(testTbl.getName()));
  verify(wh).deleteDir(tbl_path, true, true);
}
 
Example #23
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testDropTableWithoutDeleteData() throws  Exception {
  Path tblPath = new Path(testTbl.getStorageDescriptor().getLocation());
  List<String> values = Lists.newArrayList("foo");
  Partition partition = new Partition().withDatabaseName(testDb.getName())
    .withTableName(testTbl.getName()).withValues(values)
    .withStorageDescriptor(TestObjects.getTestStorageDescriptor());

  when(glueClient.getTable(new GetTableRequest()
    .withDatabaseName(testTbl.getDatabaseName()).withName(testTbl.getName())))
    .thenReturn(new GetTableResult().withTable(testTbl));
  when(glueClient.deletePartition(new DeletePartitionRequest()
    .withDatabaseName(testDb.getName()).withPartitionValues(values).withTableName(testTbl.getName())))
    .thenReturn(new DeletePartitionResult());
  when(glueClient.getPartitions(any(GetPartitionsRequest.class)))
    .thenReturn(new GetPartitionsResult().withPartitions(partition));
  when(glueClient.getPartition(new GetPartitionRequest()
    .withDatabaseName(testDb.getName()).withTableName(testTbl.getName()).withPartitionValues(values)))
    .thenReturn(new GetPartitionResult().withPartition(partition));
  when(glueClient.getDatabase(any(GetDatabaseRequest.class)))
    .thenReturn(new GetDatabaseResult().withDatabase(testDb));
  metastoreClientDelegate.dropTable(testTbl.getDatabaseName(), testTbl.getName(), false, true, true);

  verify(glueClient).deleteTable(new DeleteTableRequest().withDatabaseName(testTbl.getDatabaseName()).withName(testTbl.getName()));
  verify(wh, never()).deleteDir(tblPath, true, true);
}
 
Example #24
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testDropPartitionUsingValues() throws Exception {
  List<String> values = Lists.newArrayList("foo", "bar");
  Partition partition = new Partition().withDatabaseName(testDb.getName())
    .withTableName(testTbl.getName())
    .withValues(values)
    .withStorageDescriptor(TestObjects.getTestStorageDescriptor());
  DeletePartitionRequest request = new DeletePartitionRequest()
    .withDatabaseName(testDb.getName())
    .withTableName(testTbl.getName())
    .withPartitionValues(values);

  when(glueClient.deletePartition(request)).thenReturn(new DeletePartitionResult());
  when(glueClient.getPartition(any(GetPartitionRequest.class))).thenReturn(new GetPartitionResult().withPartition(partition));
  when(glueClient.getTable(any(GetTableRequest.class))).thenReturn(new GetTableResult().withTable(testTbl));

  metastoreClientDelegate.dropPartition(testDb.getName(), testTbl.getName(), values, false, false, false);
  verify(glueClient, times(1)).deletePartition(request);
}
 
Example #25
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testDropPartitionUsingValuesWithCatalogId() throws Exception {
  List<String> values = Lists.newArrayList("foo", "bar");
  Partition partition = new Partition().withDatabaseName(testDb.getName())
    .withTableName(testTbl.getName())
    .withValues(values)
    .withStorageDescriptor(TestObjects.getTestStorageDescriptor());
  DeletePartitionRequest request = new DeletePartitionRequest()
    .withDatabaseName(testDb.getName())
    .withTableName(testTbl.getName())
    .withPartitionValues(values);

  when(glueClient.deletePartition(request)).thenReturn(new DeletePartitionResult());
  when(glueClient.getPartition(any(GetPartitionRequest.class))).thenReturn(new GetPartitionResult().withPartition(partition));
  when(glueClient.getTable(any(GetTableRequest.class))).thenReturn(new GetTableResult().withTable(testTbl));

  metastoreClientDelegateCatalogId.dropPartition(testDb.getName(), testTbl.getName(), values, false, false, false);
  ArgumentCaptor<DeletePartitionRequest> captor = ArgumentCaptor.forClass(DeletePartitionRequest.class);
  verify(glueClient, times(1)).deletePartition(captor.capture());
  assertEquals(CATALOG_ID, captor.getValue().getCatalogId());
}
 
Example #26
Source File: AWSCatalogMetastoreClientTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testListPartitionsWithAuthInfo() throws Exception {
  String dbName = "default";
  String tblName = "foo";
  List<String> values = ImmutableList.of("1970-01-01 12%3A34%3A56");
  Partition partition = TestObjects.getTestPartition(dbName, tblName, values);

  String expression = ExpressionHelper.buildExpressionFromPartialSpecification(testTable, values);
  GetPartitionsRequest expectedRequest = new GetPartitionsRequest()
    .withDatabaseName(dbName)
    .withTableName(tblName)
    .withExpression(expression);

  when(glueClient.getDatabase(any(GetDatabaseRequest.class)))
  .thenReturn(new GetDatabaseResult().withDatabase(HiveToCatalogConverter.convertDatabase(testDB)));
  when(glueClient.getTable(any(GetTableRequest.class)))
  .thenReturn(new GetTableResult().withTable(HiveToCatalogConverter.convertTable(testTable)));
  when(glueClient.getPartitions(expectedRequest))
    .thenReturn(new GetPartitionsResult().withPartitions(ImmutableList.of(partition)));
  
  metastoreClient.listPartitionsWithAuthInfo(dbName, tblName, values, (short) 1, null, null);

  // Ensure the call reaches here despite the exception thrown by getPrincipalPrivilegeSet
  verify(glueClient).getPartitions(expectedRequest);
}
 
Example #27
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPartitions() throws Exception {
  mockBatchCreatePartitionsSucceed();
  setupMockWarehouseForPath(new Path(testTbl.getStorageDescriptor().getLocation().toString()), false, true);
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));

  int numPartitions = 2;
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);
  List<org.apache.hadoop.hive.metastore.api.Partition> partitionsCreated =
    metastoreClientDelegate.addPartitions(partitions, false, true);

  verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
  verify(glueClient, times(1)).batchCreatePartition(any(BatchCreatePartitionRequest.class));
  verify(wh, times(numPartitions)).mkdirs(any(Path.class), eq(true));
  verify(wh, never()).deleteDir(any(Path.class), eq(true));
  assertEquals(numPartitions, partitionsCreated.size());
  assertThat(partitionsCreated, containsInAnyOrder(partitions.toArray()));
  assertDaemonThreadPools();
}
 
Example #28
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
private List<org.apache.hadoop.hive.metastore.api.Partition> addPartitionsWithEmptyLocationsValid(int numPartitions) throws Exception {
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);
  for (org.apache.hadoop.hive.metastore.api.Partition partition : partitions) {
    partition.getSd().setLocation(null);
  }
  mockBatchCreatePartitionsSucceed();
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));
  when(wh.mkdirs(any(Path.class), anyBoolean())).thenReturn(true);

  List<org.apache.hadoop.hive.metastore.api.Partition> partitionsCreated =
    metastoreClientDelegate.addPartitions(partitions, false, true);
  verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
  verify(glueClient, times(1)).batchCreatePartition(any(BatchCreatePartitionRequest.class));
  verify(wh, never()).deleteDir(any(Path.class), anyBoolean());
  assertEquals(numPartitions, partitionsCreated.size());
  assertThat(partitionsCreated, containsInAnyOrder(partitions.toArray()));
  return partitionsCreated;
}
 
Example #29
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test(expected = MetaException.class)
public void testAddPartitions_PartitionViewWithLocation() throws Exception {
  // Case: table location is empty (VIRTUAL_VIEW) with partition containing location
  // In Hive, this throws MetaException because it doesn't allow parititon views to have location
  Table table = testTbl;
  table.getStorageDescriptor().setLocation(null);

  int numPartitions = 2;
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);

  mockBatchCreatePartitionsSucceed();
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(table));
  when(wh.mkdirs(any(Path.class), anyBoolean())).thenReturn(true);

  metastoreClientDelegate.addPartitions(partitions, false, true);

  assertDaemonThreadPools();
}
 
Example #30
Source File: GlueMetastoreClientDelegateTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPartitionsDoNotNeedResult() throws Exception {
  mockBatchCreatePartitionsSucceed();
  when(glueClient.getTable(any(GetTableRequest.class)))
    .thenReturn(new GetTableResult().withTable(testTbl));

  int numPartitions = 2;
  List<org.apache.hadoop.hive.metastore.api.Partition> partitions = getTestPartitions(numPartitions);
  List<org.apache.hadoop.hive.metastore.api.Partition> partitionsCreated =
    metastoreClientDelegate.addPartitions(partitions, false, false);

  verify(glueClient, times(1)).getTable(any(GetTableRequest.class));
  verify(glueClient, times(1)).batchCreatePartition(any(BatchCreatePartitionRequest.class));
  verify(wh, times(numPartitions)).mkdirs(any(Path.class), eq(true));
  verify(wh, never()).deleteDir(any(Path.class), eq(true));
  assertThat(partitionsCreated, is(nullValue()));
  assertDaemonThreadPools();
}