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

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project hcatalog, under directory /server-extensions/src/main/java/org/apache/hcatalog/listener/.

Source file: NotificationListener.java

  21 
vote

private static String getTopicName(Partition partition,ListenerEvent partitionEvent) throws MetaException {
  try {
    return partitionEvent.getHandler().get_table(partition.getDbName(),partition.getTableName()).getParameters().get(HCatConstants.HCAT_MSGBUS_TOPIC_NAME);
  }
 catch (  NoSuchObjectException e) {
    throw new MetaException(e.toString());
  }
}
 

Example 2

From project hcatalog, under directory /server-extensions/src/main/java/org/apache/hcatalog/listener/.

Source file: NotificationListener.java

  21 
vote

@Override public void onCreateTable(CreateTableEvent tableEvent) throws MetaException {
  if (tableEvent.getStatus()) {
    Table tbl=tableEvent.getTable();
    HMSHandler handler=tableEvent.getHandler();
    HiveConf conf=handler.getHiveConf();
    Table newTbl;
    try {
      newTbl=handler.get_table(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 (    InvalidOperationException e) {
      MetaException me=new MetaException(e.toString());
      me.initCause(e);
      throw me;
    }
catch (    NoSuchObjectException e) {
      MetaException me=new MetaException(e.toString());
      me.initCause(e);
      throw me;
    }
    send(newTbl,getTopicPrefix(conf) + "." + newTbl.getDbName().toLowerCase(),HCatConstants.HCAT_ADD_TABLE_EVENT);
  }
}
 

Example 3

From project hcatalog, under directory /storage-handlers/hbase/src/java/org/apache/hcatalog/hbase/.

Source file: HBaseHCatStorageHandler.java

  21 
vote

private HBaseAdmin getHBaseAdmin() throws MetaException {
  try {
    if (admin == null) {
      admin=new HBaseAdmin(this.getConf());
    }
    return admin;
  }
 catch (  MasterNotRunningException mnre) {
    throw new MetaException(StringUtils.stringifyException(mnre));
  }
catch (  ZooKeeperConnectionException zkce) {
    throw new MetaException(StringUtils.stringifyException(zkce));
  }
}
 

Example 4

From project culvert, under directory /hive-culvert-handler/src/main/java/com/bah/culvert/hive/.

Source file: CulvertMetaHook.java

  20 
vote

@Override public void preCreateTable(Table table) throws MetaException {
  Map<String,String> params=table.getParameters();
  for (  String param : requiredTableParams) {
    if (!params.containsKey(param)) {
      throw new MetaException("Cannot create table. Missing parameter: " + param);
    }
  }
  if (!MetaStoreUtils.isExternalTable(table)) {
    throw new MetaException("Hive managed tables are not supported. The table must already exist in the datastore");
  }
  String dbAdapterClassName=params.get(CULVERT_DATABASE_ADAPTER);
  Class<DatabaseAdapter> dbAdapterClass;
  DatabaseAdapter databaseAdapter;
  try {
    dbAdapterClass=(Class<DatabaseAdapter>)Class.forName(dbAdapterClassName);
    databaseAdapter=dbAdapterClass.newInstance();
  }
 catch (  ClassNotFoundException e) {
    throw new MetaException("Unknown DatabaseAdapter: " + dbAdapterClassName);
  }
catch (  InstantiationException e) {
    throw new MetaException("Unable to instantiate DatabaseAdapter: " + dbAdapterClassName);
  }
catch (  IllegalAccessException e) {
    throw new MetaException("Unable to access DatabaseAdapter constructor: " + dbAdapterClassName + ". There should be a public no-arg constructor");
  }
  boolean verified=databaseAdapter.verify();
  if (!verified) {
    throw new MetaException("Unable to connect to the database table. Check the connection " + "parameters and if the table exists in the database.");
  }
}
 

Example 5

From project hcatalog, under directory /storage-handlers/hbase/src/java/org/apache/hcatalog/hbase/.

Source file: HBaseHCatStorageHandler.java

  20 
vote

private void checkDeleteTable(Table table) throws MetaException {
  boolean isExternal=MetaStoreUtils.isExternalTable(table);
  String tableName=getFullyQualifiedHBaseTableName(table);
  RevisionManager rm=null;
  try {
    if (!isExternal && getHBaseAdmin().tableExists(tableName)) {
      if (getHBaseAdmin().isTableEnabled(tableName)) {
        getHBaseAdmin().disableTable(tableName);
      }
      getHBaseAdmin().deleteTable(tableName);
      rm=HBaseRevisionManagerUtil.getOpenedRevisionManager(hbaseConf);
      rm.dropTable(tableName);
    }
  }
 catch (  IOException ie) {
    throw new MetaException(StringUtils.stringifyException(ie));
  }
 finally {
    HBaseRevisionManagerUtil.closeRevisionManagerQuietly(rm);
  }
}
 

Example 6

From project hcatalog, under directory /server-extensions/src/main/java/org/apache/hcatalog/listener/.

Source file: NotificationListener.java

  19 
vote

@Override public void onAddPartition(AddPartitionEvent partitionEvent) throws MetaException {
  if (partitionEvent.getStatus()) {
    Partition partition=partitionEvent.getPartition();
    String topicName=getTopicName(partition,partitionEvent);
    if (topicName != null && !topicName.equals("")) {
      send(partition,topicName,HCatConstants.HCAT_ADD_PARTITION_EVENT);
    }
 else {
      LOG.info("Topic name not found in metastore. Suppressing HCatalog notification for " + partition.getDbName() + "."+ partition.getTableName()+ " To enable notifications for this table, please do alter table set properties ("+ HCatConstants.HCAT_MSGBUS_TOPIC_NAME+ "=<dbname>.<tablename>) or whatever you want topic name to be.");
    }
  }
}
 

Example 7

From project hcatalog, under directory /server-extensions/src/main/java/org/apache/hcatalog/listener/.

Source file: NotificationListener.java

  19 
vote

/** 
 * Send dropped partition notifications. Subscribers can receive these notifications for a particular table by listening on a topic named "dbName.tableName" with message selector string  {@value org.apache.hcatalog.common.HCatConstants#HCAT_EVENT} ={@value org.apache.hcatalog.common.HCatConstants#HCAT_DROP_PARTITION_EVENT}. </br> TODO: DataNucleus 2.0.3, currently used by the HiveMetaStore for persistence, has been found to throw NPE when serializing objects that contain null. For this reason we override some fields in the StorageDescriptor of this notification. This should be fixed after HIVE-2084 "Upgrade datanucleus from 2.0.3 to 3.0.1" is resolved.
 */
@Override public void onDropPartition(DropPartitionEvent partitionEvent) throws MetaException {
  if (partitionEvent.getStatus()) {
    Partition partition=partitionEvent.getPartition();
    StorageDescriptor sd=partition.getSd();
    sd.setBucketCols(new ArrayList<String>());
    sd.setSortCols(new ArrayList<Order>());
    sd.setParameters(new HashMap<String,String>());
    sd.getSerdeInfo().setParameters(new HashMap<String,String>());
    sd.getSkewedInfo().setSkewedColNames(new ArrayList<String>());
    String topicName=getTopicName(partition,partitionEvent);
    if (topicName != null && !topicName.equals("")) {
      send(partition,topicName,HCatConstants.HCAT_DROP_PARTITION_EVENT);
    }
 else {
      LOG.info("Topic name not found in metastore. Suppressing HCatalog notification for " + partition.getDbName() + "."+ partition.getTableName()+ " To enable notifications for this table, please do alter table set properties ("+ HCatConstants.HCAT_MSGBUS_TOPIC_NAME+ "=<dbname>.<tablename>) or whatever you want topic name to be.");
    }
  }
}
 

Example 8

From project hcatalog, under directory /server-extensions/src/main/java/org/apache/hcatalog/listener/.

Source file: NotificationListener.java

  19 
vote

/** 
 * Send dropped table notifications. Subscribers can receive these notifications for dropped tables by listening on topic "HCAT" with message selector string {@value org.apache.hcatalog.common.HCatConstants#HCAT_EVENT} ={@value org.apache.hcatalog.common.HCatConstants#HCAT_DROP_TABLE_EVENT}</br> TODO: DataNucleus 2.0.3, currently used by the HiveMetaStore for persistence, has been found to throw NPE when serializing objects that contain null. For this reason we override some fields in the StorageDescriptor of this notification. This should be fixed after HIVE-2084 "Upgrade datanucleus from 2.0.3 to 3.0.1" is resolved.
 */
@Override public void onDropTable(DropTableEvent tableEvent) throws MetaException {
  if (tableEvent.getStatus()) {
    Table table=tableEvent.getTable();
    StorageDescriptor sd=table.getSd();
    sd.setBucketCols(new ArrayList<String>());
    sd.setSortCols(new ArrayList<Order>());
    sd.setParameters(new HashMap<String,String>());
    sd.getSerdeInfo().setParameters(new HashMap<String,String>());
    sd.getSkewedInfo().setSkewedColNames(new ArrayList<String>());
    send(table,getTopicPrefix(tableEvent.getHandler().getHiveConf()) + "." + table.getDbName().toLowerCase(),HCatConstants.HCAT_DROP_TABLE_EVENT);
  }
}
 

Example 9

From project templeton, under directory /src/java/org/apache/hcatalog/templeton/.

Source file: SecureProxySupport.java

  19 
vote

private String buildHcatDelegationToken(String user) throws IOException, InterruptedException, MetaException, TException {
  HiveConf c=new HiveConf();
  final HiveMetaStoreClient client=new HiveMetaStoreClient(c);
  LOG.info("user: " + user + " loginUser: "+ UserGroupInformation.getLoginUser().getUserName());
  final TokenWrapper twrapper=new TokenWrapper();
  final UserGroupInformation ugi=UgiFactory.getUgi(user);
  String s=ugi.doAs(new PrivilegedExceptionAction<String>(){
    public String run() throws IOException, MetaException, TException {
      String u=ugi.getUserName();
      return client.getDelegationToken(u);
    }
  }
);
  return s;
}