Search in sources :

Example 1 with IHMSHandler

use of org.apache.hadoop.hive.metastore.IHMSHandler in project hive by apache.

the class MetaDataExportListener method export_meta_data.

/**
 * Export the metadata to a given path, and then move it to the user's trash
 */
private void export_meta_data(PreDropTableEvent tableEvent) throws MetaException {
    FileSystem fs = null;
    Table tbl = tableEvent.getTable();
    String name = tbl.getTableName();
    org.apache.hadoop.hive.ql.metadata.Table mTbl = new org.apache.hadoop.hive.ql.metadata.Table(tbl);
    IHMSHandler handler = tableEvent.getHandler();
    Configuration conf = handler.getConf();
    Warehouse wh = new Warehouse(conf);
    Path tblPath = new Path(tbl.getSd().getLocation());
    fs = wh.getFs(tblPath);
    Date now = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    String dateString = sdf.format(now);
    String exportPathString = MetastoreConf.getVar(conf, MetastoreConf.ConfVars.METADATA_EXPORT_LOCATION);
    boolean moveMetadataToTrash = MetastoreConf.getBoolVar(conf, MetastoreConf.ConfVars.MOVE_EXPORTED_METADATA_TO_TRASH);
    Path exportPath = null;
    if (exportPathString != null && exportPathString.length() == 0) {
        exportPath = fs.getHomeDirectory();
    } else {
        exportPath = new Path(exportPathString);
    }
    Path metaPath = new Path(exportPath, name + "." + dateString);
    LOG.info("Exporting the metadata of table " + tbl.toString() + " to path " + metaPath.toString());
    try {
        fs.mkdirs(metaPath);
    } catch (IOException e) {
        throw new MetaException(e.getMessage());
    }
    Path outFile = new Path(metaPath, name + EximUtil.METADATA_NAME);
    try {
        SessionState.getConsole().printInfo("Beginning metadata export");
        EximUtil.createExportDump(fs, outFile, mTbl, null, null, new HiveConf(conf, MetaDataExportListener.class));
        if (moveMetadataToTrash == true) {
            wh.deleteDir(metaPath, true);
        }
    } catch (IOException e) {
        throw new MetaException(e.getMessage());
    } catch (SemanticException e) {
        throw new MetaException(e.getMessage());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Warehouse(org.apache.hadoop.hive.metastore.Warehouse) Table(org.apache.hadoop.hive.metastore.api.Table) Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException) Date(java.util.Date) FileSystem(org.apache.hadoop.fs.FileSystem) HiveConf(org.apache.hadoop.hive.conf.HiveConf) IHMSHandler(org.apache.hadoop.hive.metastore.IHMSHandler) SimpleDateFormat(java.text.SimpleDateFormat) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 2 with IHMSHandler

use of org.apache.hadoop.hive.metastore.IHMSHandler in project hive by apache.

the class NotificationListener method onCreateTable.

@Override
public void onCreateTable(CreateTableEvent tableEvent) throws MetaException {
    // as "HCAT_EVENT = HCAT_ADD_TABLE"
    if (tableEvent.getStatus()) {
        Table tbl = tableEvent.getTable();
        IHMSHandler handler = tableEvent.getIHMSHandler();
        Configuration conf = handler.getConf();
        Table newTbl;
        try {
            newTbl = handler.get_table_core(tbl.getDbName(), tbl.getTableName()).deepCopy();
            newTbl.getParameters().put(HCatConstants.HCAT_MSGBUS_TOPIC_NAME, getTopicPrefix(conf) + "." + newTbl.getDbName().toLowerCase() + "." + newTbl.getTableName().toLowerCase());
            handler.alter_table(newTbl.getDbName(), newTbl.getTableName(), newTbl);
        } catch (TException e) {
            MetaException me = new MetaException(e.toString());
            me.initCause(e);
            throw me;
        }
        String topicName = getTopicPrefix(conf) + "." + newTbl.getDbName().toLowerCase();
        send(messageFactory.buildCreateTableMessage(newTbl), topicName);
    }
}
Also used : TException(org.apache.thrift.TException) Table(org.apache.hadoop.hive.metastore.api.Table) Configuration(org.apache.hadoop.conf.Configuration) IHMSHandler(org.apache.hadoop.hive.metastore.IHMSHandler) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)2 IHMSHandler (org.apache.hadoop.hive.metastore.IHMSHandler)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 Table (org.apache.hadoop.hive.metastore.api.Table)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 Warehouse (org.apache.hadoop.hive.metastore.Warehouse)1 TException (org.apache.thrift.TException)1