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

The following examples show how to use org.apache.hadoop.hive.metastore.api.EnvironmentContext. 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
Source Project: metacat   Source File: CatalogThriftHiveMetastore.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void alter_partition_with_environment_context(
    final String dbName,
    final String tblName,
    final Partition newPart,
    @Nullable final EnvironmentContext ec
) throws TException {
    final String databaseName = normalizeIdentifier(dbName);
    final String tableName = normalizeIdentifier(tblName);
    requestWrapper("alter_partition_with_environment_context", new Object[]{databaseName, tableName, ec},
        () -> {
            addPartitionsCore(dbName, tableName, ImmutableList.of(newPart), false);
            return null;
        });
}
 
Example 2
Source Project: metacat   Source File: CatalogThriftHiveMetastore.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void alter_table_with_environment_context(
    final String dbname,
    final String tblName,
    final Table newTbl,
    @Nullable final EnvironmentContext environmentContext
) throws TException {
    requestWrapper("alter_table_with_environment_context",
        new Object[]{dbname, tblName, newTbl, environmentContext}, () -> {
            final String databaseName = normalizeIdentifier(dbname);
            final String tableName = normalizeIdentifier(tblName);
            final QualifiedName oldName = QualifiedName.ofTable(catalogName, databaseName, tableName);
            final QualifiedName newName = QualifiedName
                .ofTable(catalogName, newTbl.getDbName(), newTbl.getTableName());

            final TableDto dto = hiveConverters.hiveToMetacatTable(newName, newTbl);
            if (!oldName.equals(newName)) {
                v1.renameTable(catalogName, oldName.getDatabaseName(), oldName.getTableName(),
                    newName.getTableName());
            }
            v1.updateTable(catalogName, dbname, newName.getTableName(), dto);
            return null;
        });
}
 
Example 3
Source Project: metacat   Source File: CatalogThriftHiveMetastore.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Partition append_partition_with_environment_context(
    final String dbName,
    final String tblName,
    final List<String> partVals,
    @Nullable final EnvironmentContext environmentContext
) throws TException {
    return requestWrapper("append_partition_by_name_with_environment_context",
        new Object[]{dbName, tblName, partVals}, () -> {
            final TableDto tableDto = getTableDto(dbName, tblName);
            final String partName = hiveConverters.getNameFromPartVals(tableDto, partVals);
            appendPartitionsCore(dbName, tblName, partName);
            return hiveConverters.metacatToHivePartition(getPartitionDtoByName(tableDto, partName), tableDto);
        });
}
 
Example 4
Source Project: metacat   Source File: CatalogThriftHiveMetastore.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void create_table_with_environment_context(
    final Table tbl,
    @Nullable final EnvironmentContext environmentContext
) throws TException {
    requestWrapper("create_table_with_environment_context", new Object[]{tbl, environmentContext}, () -> {
        final String dbname = normalizeIdentifier(tbl.getDbName());
        final String tblName = normalizeIdentifier(tbl.getTableName());
        final QualifiedName name = QualifiedName.ofTable(catalogName, dbname, tblName);

        final TableDto dto = hiveConverters.hiveToMetacatTable(name, tbl);
        v1.createTable(catalogName, dbname, tblName, dto);
        return null;
    });
}
 
Example 5
Source Project: metacat   Source File: CatalogThriftHiveMetastore.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean drop_partition_by_name_with_environment_context(
    final String dbName, final String tblName,
    final String partName,
    final boolean deleteData,
    @Nullable final EnvironmentContext environmentContext
) throws TException {
    return requestWrapper("drop_partition_by_name_with_environment_context",
        new Object[]{dbName, tblName, partName, deleteData, environmentContext}, () -> {
            final String databaseName = normalizeIdentifier(dbName);
            final String tableName = normalizeIdentifier(tblName);

            if (deleteData) {
                log.warn("Ignoring command to delete data for {}/{}/{}/{}",
                    catalogName, databaseName, tableName, partName);
            }

            partV1.deletePartitions(catalogName, databaseName, tableName, ImmutableList.of(partName));

            return true;
        });
}
 
Example 6
Source Project: metacat   Source File: CatalogThriftHiveMetastore.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void drop_table_with_environment_context(final String dbname, final String name,
                                                final boolean deleteData,
                                                @Nullable final EnvironmentContext ec) throws TException {
    requestWrapper("drop_table_with_environment_context", new Object[]{dbname, name, deleteData, ec}, () -> {
        final String databaseName = normalizeIdentifier(dbname);
        final String tableName = normalizeIdentifier(name);

        if (deleteData) {
            log.warn("Ignoring command to delete data for {}/{}/{}", catalogName, databaseName, tableName);
        }

        return v1.deleteTable(catalogName, databaseName, tableName);
    });
}
 
Example 7
Source Project: metacat   Source File: CatalogThriftHiveMetastore.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<FieldSchema> get_fields_with_environment_context(
    final String dbName,
    final String tableName,
    @Nullable final EnvironmentContext environmentContext
) throws TException {
    return requestWrapper("get_fields_with_environment_context",
        new Object[]{dbName, tableName, environmentContext}, () -> {
            final Table table = get_table(dbName, tableName);

            if (table == null || table.getSd() == null || table.getSd().getCols() == null) {
                throw new MetaException("Unable to get fields for " + dbName + "." + tableName);
            }
            return table.getSd().getCols();
        });
}
 
Example 8
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 9
@Override
public boolean requireCalStats(
    Configuration conf,
    Partition oldPart,
    Partition newPart,
    Table tbl,
    EnvironmentContext environmentContext) {
  return MetaStoreUtils.requireCalStats(conf, oldPart, newPart, tbl, environmentContext);
}
 
Example 10
@Override
public boolean updateTableStatsFast(
    Database db,
    Table tbl,
    Warehouse wh,
    boolean madeDir,
    boolean forceRecompute,
    EnvironmentContext environmentContext
) throws MetaException {
  return MetaStoreUtils.updateTableStatsFast(db, tbl, wh, madeDir, forceRecompute, environmentContext);
}
 
Example 11
@Override
public boolean requireCalStats(
    Configuration conf,
    Partition oldPart,
    Partition newPart,
    Table tbl,
    EnvironmentContext environmentContext) {
  return MetaStoreUtils.requireCalStats(conf, oldPart, newPart, tbl);
}
 
Example 12
@Override
public boolean updateTableStatsFast(
    Database db,
    Table tbl,
    Warehouse wh,
    boolean madeDir,
    boolean forceRecompute,
    EnvironmentContext environmentContext
) throws MetaException {
  return MetaStoreUtils.updateUnpartitionedTableStatsFast(db, tbl, wh, madeDir, forceRecompute);
}
 
Example 13
@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 14
@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 15
@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 16
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 create_table_with_environment_context(Table tbl, EnvironmentContext environment_context)
    throws AlreadyExistsException, InvalidObjectException, MetaException, NoSuchObjectException, TException {
  DatabaseMapping mapping = checkWritePermissions(tbl.getDbName());
  mapping.getClient().create_table_with_environment_context(mapping.transformInboundTable(tbl), environment_context);
}
 
Example 17
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 18
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 Partition add_partition_with_environment_context(Partition new_part, EnvironmentContext environment_context)
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
  DatabaseMapping mapping = checkWritePermissions(new_part.getDbName());
  Partition result = mapping
      .getClient()
      .add_partition_with_environment_context(mapping.transformInboundPartition(new_part), environment_context);
  return mapping.transformOutboundPartition(result);
}
 
Example 19
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 Partition append_partition_with_environment_context(
    String db_name,
    String tbl_name,
    List<String> part_vals,
    EnvironmentContext environment_context)
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
  DatabaseMapping mapping = checkWritePermissions(db_name);
  Partition partition = mapping
      .getClient()
      .append_partition_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals,
          environment_context);
  return mapping.transformOutboundPartition(partition);
}
 
Example 20
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 Partition append_partition_by_name_with_environment_context(
    String db_name,
    String tbl_name,
    String part_name,
    EnvironmentContext environment_context)
    throws InvalidObjectException, AlreadyExistsException, MetaException, TException {
  DatabaseMapping mapping = checkWritePermissions(db_name);
  Partition partition = mapping
      .getClient()
      .append_partition_by_name_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name,
          part_name, environment_context);
  return mapping.transformOutboundPartition(partition);
}
 
Example 21
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 boolean drop_partition_with_environment_context(
    String db_name,
    String tbl_name,
    List<String> part_vals,
    boolean deleteData,
    EnvironmentContext environment_context)
    throws NoSuchObjectException, MetaException, TException {
  DatabaseMapping mapping = checkWritePermissions(db_name);
  return mapping
      .getClient()
      .drop_partition_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name, part_vals,
          deleteData, environment_context);
}
 
Example 22
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 boolean drop_partition_by_name_with_environment_context(
    String db_name,
    String tbl_name,
    String part_name,
    boolean deleteData,
    EnvironmentContext environment_context)
    throws NoSuchObjectException, MetaException, TException {
  DatabaseMapping mapping = checkWritePermissions(db_name);
  return mapping
      .getClient()
      .drop_partition_by_name_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name,
          part_name, deleteData, environment_context);
}
 
Example 23
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);
}
 
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 void alter_partitions_with_environment_context(
    String db_name,
    String tbl_name,
    List<Partition> new_parts,
    EnvironmentContext environment_context)
    throws InvalidOperationException, MetaException, TException {
  DatabaseMapping mapping = checkWritePermissions(db_name);
  mapping
      .getClient()
      .alter_partitions_with_environment_context(mapping.transformInboundDatabaseName(db_name), tbl_name, new_parts,
          environment_context);
}
 
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<FieldSchema> get_fields_with_environment_context(
    String db_name,
    String table_name,
    EnvironmentContext environment_context)
    throws MetaException, UnknownTableException, UnknownDBException, TException {
  DatabaseMapping mapping = databaseMappingService.databaseMapping(db_name);
  return mapping
      .getClient()
      .get_fields_with_environment_context(mapping.transformInboundDatabaseName(db_name), table_name,
          environment_context);
}
 
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 List<FieldSchema> get_schema_with_environment_context(
    String db_name,
    String table_name,
    EnvironmentContext environment_context)
    throws MetaException, UnknownTableException, UnknownDBException, TException {
  DatabaseMapping mapping = databaseMappingService.databaseMapping(db_name);
  return mapping
      .getClient()
      .get_schema_with_environment_context(mapping.transformInboundDatabaseName(db_name), table_name,
          environment_context);
}
 
Example 27
Source Project: waggle-dance   Source File: FederatedHMSHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void create_table_with_environment_context() throws TException {
  EnvironmentContext environmentContext = new EnvironmentContext();
  Table table = new Table();
  table.setDbName(DB_P);
  Table inboundTable = new Table();
  inboundTable.setDbName("inbound");
  when(primaryMapping.transformInboundTable(table)).thenReturn(inboundTable);
  handler.create_table_with_environment_context(table, environmentContext);
  verify(primaryMapping).checkWritePermissions(DB_P);
  verify(primaryClient).create_table_with_environment_context(inboundTable, environmentContext);
}
 
Example 28
Source Project: waggle-dance   Source File: FederatedHMSHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void drop_table_with_environment_context() throws TException {
  EnvironmentContext environmentContext = new EnvironmentContext();
  when(primaryMapping.transformInboundDatabaseName(DB_P)).thenReturn("inbound");
  handler.drop_table_with_environment_context(DB_P, "table", false, environmentContext);
  verify(primaryMapping).checkWritePermissions(DB_P);
  verify(primaryClient).drop_table_with_environment_context("inbound", "table", false, environmentContext);
}
 
Example 29
Source Project: waggle-dance   Source File: FederatedHMSHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void alter_table_with_environment_context() throws TException {
  EnvironmentContext environmentContext = new EnvironmentContext();
  Table table = new Table();
  table.setDbName(DB_P);
  Table inbound = new Table();
  when(primaryMapping.transformInboundDatabaseName(DB_P)).thenReturn("inbound");
  when(primaryMapping.transformInboundTable(table)).thenReturn(inbound);
  handler.alter_table_with_environment_context(DB_P, "table", table, environmentContext);
  verify(primaryMapping, times(2)).checkWritePermissions(DB_P);
  verify(primaryClient).alter_table_with_environment_context("inbound", "table", inbound, environmentContext);
}
 
Example 30
Source Project: waggle-dance   Source File: FederatedHMSHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void add_partition_with_environment_context() throws TException {
  EnvironmentContext environmentContext = new EnvironmentContext();
  Partition newPartition = new Partition();
  newPartition.setDbName(DB_P);
  Partition inbound = new Partition();
  Partition outbound = new Partition();
  when(primaryMapping.transformInboundPartition(newPartition)).thenReturn(inbound);
  when(primaryClient.add_partition_with_environment_context(inbound, environmentContext)).thenReturn(inbound);
  when(primaryMapping.transformOutboundPartition(inbound)).thenReturn(outbound);
  Partition result = handler.add_partition_with_environment_context(newPartition, environmentContext);
  assertThat(result, is(outbound));
  verify(primaryMapping).checkWritePermissions(DB_P);
}