use of org.apache.hadoop.hive.metastore.messaging.AddPrimaryKeyMessage in project hive by apache.
the class LoadConstraint method isPrimaryKeysAlreadyLoaded.
private boolean isPrimaryKeysAlreadyLoaded(String pksMsgString) throws Exception {
AddPrimaryKeyMessage msg = deserializer.getAddPrimaryKeyMessage(pksMsgString);
List<SQLPrimaryKey> pksInMsg = msg.getPrimaryKeys();
if (pksInMsg.isEmpty()) {
return true;
}
String dbName = StringUtils.isBlank(dbNameToLoadIn) ? pksInMsg.get(0).getTable_db() : dbNameToLoadIn;
List<SQLPrimaryKey> pks;
try {
pks = context.hiveDb.getPrimaryKeyList(dbName, pksInMsg.get(0).getTable_name());
} catch (NoSuchObjectException e) {
return false;
}
return CollectionUtils.isNotEmpty(pks);
}
use of org.apache.hadoop.hive.metastore.messaging.AddPrimaryKeyMessage in project hive by apache.
the class AddPrimaryKeyHandler method handle.
@Override
public List<Task<?>> handle(Context context) throws SemanticException {
AddPrimaryKeyMessage msg = deserializer.getAddPrimaryKeyMessage(context.dmd.getPayload());
List<SQLPrimaryKey> pks;
try {
pks = msg.getPrimaryKeys();
} catch (Exception e) {
if (!(e instanceof SemanticException)) {
throw new SemanticException("Error reading message members", e);
} else {
throw (SemanticException) e;
}
}
List<Task<?>> tasks = new ArrayList<Task<?>>();
if (pks.isEmpty()) {
return tasks;
}
final String actualDbName = context.isDbNameEmpty() ? pks.get(0).getTable_db() : context.dbName;
final String actualTblName = pks.get(0).getTable_name();
final TableName tName = TableName.fromString(actualTblName, null, actualDbName);
for (SQLPrimaryKey pk : pks) {
pk.setTable_db(actualDbName);
pk.setTable_name(actualTblName);
}
Constraints constraints = new Constraints(pks, null, null, null, null, null);
AlterTableAddConstraintDesc addConstraintsDesc = new AlterTableAddConstraintDesc(tName, context.eventOnlyReplicationSpec(), constraints);
Task<DDLWork> addConstraintsTask = TaskFactory.get(new DDLWork(readEntitySet, writeEntitySet, addConstraintsDesc, true, context.getDumpDirectory(), context.getMetricCollector()), context.hiveConf);
tasks.add(addConstraintsTask);
context.log.debug("Added add constrains task : {}:{}", addConstraintsTask.getId(), actualTblName);
updatedMetadata.set(context.dmd.getEventTo().toString(), actualDbName, actualTblName, null);
return Collections.singletonList(addConstraintsTask);
}
use of org.apache.hadoop.hive.metastore.messaging.AddPrimaryKeyMessage in project hive by apache.
the class DbNotificationListener method onAddPrimaryKey.
/**
* @param addPrimaryKeyEvent add primary key event
* @throws MetaException
*/
@Override
public void onAddPrimaryKey(AddPrimaryKeyEvent addPrimaryKeyEvent) throws MetaException {
List<SQLPrimaryKey> cols = addPrimaryKeyEvent.getPrimaryKeyCols();
if (cols.size() > 0) {
AddPrimaryKeyMessage msg = MessageBuilder.getInstance().buildAddPrimaryKeyMessage(addPrimaryKeyEvent.getPrimaryKeyCols());
NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_PRIMARYKEY.toString(), msgEncoder.getSerializer().serialize(msg));
event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME);
event.setDbName(cols.get(0).getTable_db());
event.setTableName(cols.get(0).getTable_name());
process(event, addPrimaryKeyEvent);
}
}
Aggregations