Java Code Examples for org.apache.hadoop.hive.metastore.api.InvalidOperationException

The following examples show how to use org.apache.hadoop.hive.metastore.api.InvalidOperationException. These examples are extracted from open source projects. 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
private void verifyDestinationLocation(FileSystem srcFs, FileSystem destFs, Path srcPath, Path destPath, org.apache.hadoop.hive.metastore.api.Table tbl, org.apache.hadoop.hive.metastore.api.Partition newPartition)
      throws InvalidOperationException {
    String oldPartLoc = srcPath.toString();
    String newPartLoc = destPath.toString();

    // check that src and dest are on the same file system
    if (!FileUtils.equalsFileSystem(srcFs, destFs)) {
        throw new InvalidOperationException("table new location " + destPath
              + " is on a different file system than the old location "
              + srcPath + ". This operation is not supported");
    }
    try {
        srcFs.exists(srcPath); // check that src exists and also checks
        if (newPartLoc.compareTo(oldPartLoc) != 0 && destFs.exists(destPath)) {
            throw new InvalidOperationException("New location for this partition "
                  + tbl.getDbName() + "." + tbl.getTableName() + "." + newPartition.getValues()
                  + " already exists : " + destPath);
        }
    } catch (IOException e) {
        throw new InvalidOperationException("Unable to access new location "
              + destPath + " for partition " + tbl.getDbName() + "."
              + tbl.getTableName() + " " + newPartition.getValues());
    }
}
 
Example 2
@Test(expected=InvalidOperationException.class)
public void testRenamePartitionForUnknownTable() 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)));
  doThrow(EntityNotFoundException.class).when(glueClient).getTable(any(GetTableRequest.class));
  
  when(glueClient.getPartition(any(GetPartitionRequest.class)))
    .thenReturn(new GetPartitionResult().withPartition(oldPartition));     
  
  metastoreClient.renamePartition(dbName, externalTable.getName(), oldPartition.getValues(),
      CatalogToHiveConverter.convertPartition(newPartition));
}
 
Example 3
@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 4
@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 5
private void verifyDestinationLocation(FileSystem srcFs, FileSystem destFs, Path srcPath, Path destPath, org.apache.hadoop.hive.metastore.api.Table tbl, org.apache.hadoop.hive.metastore.api.Partition newPartition)
      throws InvalidOperationException {
  String oldPartLoc = srcPath.toString();
  String newPartLoc = destPath.toString();

  // check that src and dest are on the same file system
  if (!FileUtils.equalsFileSystem(srcFs, destFs)) {
    throw new InvalidOperationException("table new location " + destPath
          + " is on a different file system than the old location "
          + srcPath + ". This operation is not supported");
  }
  try {
    srcFs.exists(srcPath); // check that src exists and also checks
    if (newPartLoc.compareTo(oldPartLoc) != 0 && destFs.exists(destPath)) {
      throw new InvalidOperationException("New location for this partition "
            + tbl.getDbName() + "." + tbl.getTableName() + "." + newPartition.getValues()
            + " already exists : " + destPath);
    }
  } catch (IOException e) {
    throw new InvalidOperationException("Unable to access new location "
          + destPath + " for partition " + tbl.getDbName() + "."
          + tbl.getTableName() + " " + newPartition.getValues());
  }
}
 
Example 6
Source Project: flink   Source File: HiveShimV100.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void alterPartition(IMetaStoreClient client, String databaseName, String tableName, Partition partition)
		throws InvalidOperationException, MetaException, TException {
	String errorMsg = "Failed to alter partition for table %s in database %s";
	try {
		Method method = client.getClass().getMethod("alter_partition", String.class, String.class, Partition.class);
		method.invoke(client, databaseName, tableName, partition);
	} catch (InvocationTargetException ite) {
		Throwable targetEx = ite.getTargetException();
		if (targetEx instanceof TException) {
			throw (TException) targetEx;
		} else {
			throw new CatalogException(String.format(errorMsg, tableName, databaseName), targetEx);
		}
	} catch (NoSuchMethodException | IllegalAccessException e) {
		throw new CatalogException(String.format(errorMsg, tableName, databaseName), e);
	}
}
 
Example 7
Source Project: flink   Source File: HiveShimV210.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void alterPartition(IMetaStoreClient client, String databaseName, String tableName, Partition partition)
		throws InvalidOperationException, MetaException, TException {
	String errorMsg = "Failed to alter partition for table %s in database %s";
	try {
		Method method = client.getClass().getMethod("alter_partition", String.class, String.class,
			Partition.class, EnvironmentContext.class);
		method.invoke(client, databaseName, tableName, partition, null);
	} catch (InvocationTargetException ite) {
		Throwable targetEx = ite.getTargetException();
		if (targetEx instanceof TException) {
			throw (TException) targetEx;
		} else {
			throw new CatalogException(String.format(errorMsg, tableName, databaseName), targetEx);
		}
	} catch (NoSuchMethodException | IllegalAccessException e) {
		throw new CatalogException(String.format(errorMsg, tableName, databaseName), e);
	}
}
 
Example 8
Source Project: incubator-sentry   Source File: MetastoreAuthzBinding.java    License: Apache License 2.0 6 votes vote down vote up
private void authorizeCreateTable(PreCreateTableEvent context)
    throws InvalidOperationException, MetaException {
  HierarcyBuilder inputBuilder = new HierarcyBuilder();
  inputBuilder.addDbToOutput(getAuthServer(), context.getTable().getDbName());
  HierarcyBuilder outputBuilder = new HierarcyBuilder();
  outputBuilder.addDbToOutput(getAuthServer(), context.getTable().getDbName());

  if (!StringUtils.isEmpty(context.getTable().getSd().getLocation())) {
    String uriPath;
    try {
      uriPath = PathUtils.parseDFSURI(warehouseDir,
          getSdLocation(context.getTable().getSd()));
    } catch(URISyntaxException e) {
      throw new MetaException(e.getMessage());
    }
    inputBuilder.addUriToOutput(getAuthServer(), uriPath, warehouseDir);
  }
  authorizeMetastoreAccess(HiveOperation.CREATETABLE, inputBuilder.build(),
      outputBuilder.build());
}
 
Example 9
@Override
public void alter_index(String dbName, String tblName, String indexName, Index index) throws InvalidOperationException,
      MetaException, TException {
    Table catalogIndexTableObject =
          HiveToCatalogConverter.convertIndexToTableObject(index);
    org.apache.hadoop.hive.metastore.api.Table originTable = getTable(dbName, tblName);
    String indexTableObjectName = INDEX_PREFIX + indexName;
    if (!originTable.getParameters().containsKey(indexTableObjectName)) {
        throw new NoSuchObjectException("can not find index: " + indexName);
    }

    originTable.getParameters().put(indexTableObjectName, catalogTableToString(catalogIndexTableObject));
    alter_table(dbName, tblName, originTable);
}
 
Example 10
@Override
public void alter_table(
    String dbName,
    String tblName,
    org.apache.hadoop.hive.metastore.api.Table table
) throws InvalidOperationException, MetaException, TException {
    alter_table(dbName, tblName, table, false);
}
 
Example 11
@Override
public List<org.apache.hadoop.hive.metastore.api.Table> getTableObjectsByName(String dbName, List<String> tableNames) throws MetaException,
      InvalidOperationException, UnknownDBException, TException {
    List<org.apache.hadoop.hive.metastore.api.Table> hiveTables = Lists.newArrayList();
    for(String tableName : tableNames) {
        hiveTables.add(getTable(dbName, tableName));
    }

    return hiveTables;
}
 
Example 12
private Path getDestinationPathForRename(String dbName, org.apache.hadoop.hive.metastore.api.Table tbl, org.apache.hadoop.hive.metastore.api.Partition newPartition)
      throws InvalidOperationException, MetaException, TException {
    try {
        Path destPath = new Path(hiveShims.getDefaultTablePath(getDatabase(dbName), tbl.getTableName(), wh),
              Warehouse.makePartName(tbl.getPartitionKeys(), newPartition.getValues()));
        return constructRenamedPath(destPath, new Path(newPartition.getSd().getLocation()));
    } catch (NoSuchObjectException e) {
        throw new InvalidOperationException(
              "Unable to change partition or table. Database " + dbName + " does not exist"
                    + " Check metastore logs for detailed stack." + e.getMessage());
    }
}
 
Example 13
@Test(expected=InvalidOperationException.class)
public void testRenamePartitionDestinationAlreadyExists() throws Exception {
  String dbName = testDB.getName();
  String tblName = testTable.getTableName();
  List<String> partitionValues = testPartition.getValues();
  Partition catalogPartition = HiveToCatalogConverter.convertPartition(testPartition);
  
  Partition newPartition = new Partition()
                                .withDatabaseName(dbName).withTableName(tblName)
                                .withValues(Lists.newArrayList("newval"))
                                .withStorageDescriptor(catalogPartition.getStorageDescriptor());
  
  Path srcPath = new Path(testPartition.getSd().getLocation());
  Path expectedDestPath = new Path("/db/tbl/" , Warehouse.makePartName(testTable.getPartitionKeys(),
      newPartition.getValues()));
      
  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.getPartition(any(GetPartitionRequest.class)))
    .thenReturn(new GetPartitionResult().withPartition(catalogPartition));
  
  
  FileSystem fs = mock(FileSystem.class);
  when(fs.getUri()).thenReturn(new URI("s3://bucket"));
  when(hiveShims.getDefaultTablePath(any(org.apache.hadoop.hive.metastore.api.Database.class), anyString(), wh))
      .thenReturn(new Path("/db/tbl"));
  when(wh.getFs(any(Path.class))).thenReturn(fs);
  when(fs.exists(srcPath)).thenReturn(true);
  when(fs.exists(expectedDestPath)).thenReturn(true);
      
  metastoreClient.renamePartition(dbName, tblName, partitionValues,
      CatalogToHiveConverter.convertPartition(newPartition));
}
 
Example 14
@Override
public void alter_index(String dbName, String tblName, String indexName, Index index) throws InvalidOperationException,
      MetaException, TException {
  Table catalogIndexTableObject = HiveToCatalogConverter.convertIndexToTableObject(index);
  org.apache.hadoop.hive.metastore.api.Table originTable = getTable(dbName, tblName);
  String indexTableObjectName = INDEX_PREFIX + indexName;
  if (!originTable.getParameters().containsKey(indexTableObjectName)) {
    throw new NoSuchObjectException("can not find index: " + indexName);
  }

  originTable.getParameters().put(indexTableObjectName, catalogTableToString(catalogIndexTableObject));
  alter_table(dbName, tblName, originTable);
}
 
Example 15
@Override
public void alter_partition(
    String dbName,
    String tblName,
    org.apache.hadoop.hive.metastore.api.Partition partition
) throws InvalidOperationException, MetaException, TException {
  glueMetastoreClientDelegate.alterPartitions(dbName, tblName, Lists.newArrayList(partition));
}
 
Example 16
@Override
public void alter_partition(
    String dbName,
    String tblName,
    org.apache.hadoop.hive.metastore.api.Partition partition,
    EnvironmentContext environmentContext
) throws InvalidOperationException, MetaException, TException {
  glueMetastoreClientDelegate.alterPartitions(dbName, tblName, Lists.newArrayList(partition));
}
 
Example 17
@Override
public void alter_partitions(
    String dbName,
    String tblName,
    List<org.apache.hadoop.hive.metastore.api.Partition> partitions
) throws InvalidOperationException, MetaException, TException {
  glueMetastoreClientDelegate.alterPartitions(dbName, tblName, partitions);
}
 
Example 18
@Override
public void alter_partitions(
    String dbName,
    String tblName,
    List<org.apache.hadoop.hive.metastore.api.Partition> partitions,
    EnvironmentContext environmentContext
) throws InvalidOperationException, MetaException, TException {
  glueMetastoreClientDelegate.alterPartitions(dbName, tblName, partitions);
}
 
Example 19
@Override
public void alter_table_with_environmentContext(
    String dbName,
    String tblName,
    org.apache.hadoop.hive.metastore.api.Table table,
    EnvironmentContext environmentContext
) throws InvalidOperationException, MetaException, TException {
  glueMetastoreClientDelegate.alterTable(dbName, tblName, table, environmentContext);
}
 
Example 20
@Override
public List<org.apache.hadoop.hive.metastore.api.Table> getTableObjectsByName(String dbName, List<String> tableNames) throws MetaException,
      InvalidOperationException, UnknownDBException, TException {
  List<org.apache.hadoop.hive.metastore.api.Table> hiveTables = Lists.newArrayList();
  for(String tableName : tableNames) {
    hiveTables.add(getTable(dbName, tableName));
  }

  return hiveTables;
}
 
Example 21
private Path getDestinationPathForRename(String dbName, org.apache.hadoop.hive.metastore.api.Table tbl, org.apache.hadoop.hive.metastore.api.Partition newPartition)
      throws InvalidOperationException, MetaException, TException {
  try {
    Path destPath = new Path(hiveShims.getDefaultTablePath(getDatabase(dbName), tbl.getTableName(), wh),
          Warehouse.makePartName(tbl.getPartitionKeys(), newPartition.getValues()));
    return constructRenamedPath(destPath, new Path(newPartition.getSd().getLocation()));
  } catch (NoSuchObjectException e) {
    throw new InvalidOperationException(
          "Unable to change partition or table. Database " + dbName + " does not exist"
                + " Check metastore logs for detailed stack." + e.getMessage());
  }
}
 
Example 22
private void renamePartitionInCatalog(String databaseName, String tableName,
                                      List<String> partitionValues, org.apache.hadoop.hive.metastore.api.Partition newPartition)
      throws InvalidOperationException, MetaException, TException {
  try {
    glueClient.updatePartition(
        new UpdatePartitionRequest()
        .withDatabaseName(databaseName)
        .withTableName(tableName)
        .withPartitionValueList(partitionValues)
        .withPartitionInput(GlueInputConverter.convertToPartitionInput(newPartition)));
  } catch (AmazonServiceException e) {
    throw CatalogToHiveConverter.wrapInHiveException(e);
  }
}
 
Example 23
Source Project: flink   Source File: HiveShimV1.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void alterTable(IMetaStoreClient client, String databaseName, String tableName, Table table) throws InvalidOperationException, MetaException, TException {
	// For Hive-1.2.1, we need to tell HMS not to update stats. Otherwise, the stats we put in the table
	// parameters can be overridden. The extra config we add here will be removed by HMS after it's used.
	table.getParameters().put(StatsSetupConst.DO_NOT_UPDATE_STATS, "true");
	client.alter_table(databaseName, tableName, table);
}
 
Example 24
Source Project: waggle-dance   Source File: FederatedHMSHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
public List<Table> get_table_objects_by_name(String dbname, List<String> tbl_names)
    throws MetaException, InvalidOperationException, UnknownDBException, TException {
  DatabaseMapping mapping = databaseMappingService.databaseMapping(dbname);
  List<Table> tables = mapping
      .getClient()
      .get_table_objects_by_name(mapping.transformInboundDatabaseName(dbname), tbl_names);
  List<Table> outboundTables = new ArrayList<>(tables.size());
  for (Table table : tables) {
    outboundTables.add(mapping.transformOutboundTable(table));
  }
  return outboundTables;
}
 
Example 25
Source Project: waggle-dance   Source File: FederatedHMSHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
public List<String> get_table_names_by_filter(String dbname, String filter, short max_tables)
    throws MetaException, InvalidOperationException, UnknownDBException, TException {
  DatabaseMapping mapping = databaseMappingService.databaseMapping(dbname);
  return mapping
      .getClient()
      .get_table_names_by_filter(mapping.transformInboundDatabaseName(dbname), filter, max_tables);
}
 
Example 26
Source Project: waggle-dance   Source File: FederatedHMSHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
public void alter_table(String dbname, String tbl_name, Table new_tbl)
    throws InvalidOperationException, MetaException, TException {
  DatabaseMapping mapping = checkWritePermissions(dbname);
  mapping.checkWritePermissions(new_tbl.getDbName());
  mapping
      .getClient()
      .alter_table(mapping.transformInboundDatabaseName(dbname), tbl_name, mapping.transformInboundTable(new_tbl));
}
 
Example 27
Source Project: waggle-dance   Source File: FederatedHMSHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
public void alter_table_with_environment_context(
    String dbname,
    String tbl_name,
    Table new_tbl,
    EnvironmentContext environment_context)
    throws InvalidOperationException, MetaException, TException {
  DatabaseMapping mapping = checkWritePermissions(dbname);
  mapping.checkWritePermissions(new_tbl.getDbName());
  mapping
      .getClient()
      .alter_table_with_environment_context(mapping.transformInboundDatabaseName(dbname), tbl_name,
          mapping.transformInboundTable(new_tbl), environment_context);
}
 
Example 28
Source Project: waggle-dance   Source File: FederatedHMSHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
public void alter_partition(String db_name, String tbl_name, Partition new_part)
    throws InvalidOperationException, MetaException, TException {
  DatabaseMapping mapping = checkWritePermissions(db_name);
  mapping.checkWritePermissions(new_part.getDbName());
  mapping
      .getClient()
      .alter_partition(mapping.transformInboundDatabaseName(db_name), tbl_name,
          mapping.transformInboundPartition(new_part));
}
 
Example 29
Source Project: waggle-dance   Source File: FederatedHMSHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
public void alter_partitions(String db_name, String tbl_name, List<Partition> new_parts)
    throws InvalidOperationException, MetaException, TException {
  DatabaseMapping mapping = checkWritePermissions(db_name);
  for (Partition newPart : new_parts) {
    mapping.checkWritePermissions(newPart.getDbName());
  }
  mapping
      .getClient()
      .alter_partitions(mapping.transformInboundDatabaseName(db_name), tbl_name,
          mapping.transformInboundPartitions(new_parts));
}
 
Example 30
Source Project: waggle-dance   Source File: FederatedHMSHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
public void alter_partition_with_environment_context(
    String db_name,
    String tbl_name,
    Partition new_part,
    EnvironmentContext environment_context)
    throws InvalidOperationException, MetaException, TException {
  DatabaseMapping mapping = checkWritePermissions(db_name);
  mapping.checkWritePermissions(new_part.getDbName());
  mapping
      .getClient()
      .alter_partition_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name,
          mapping.transformInboundPartition(new_part), environment_context);
}