use of org.apache.hadoop.hive.metastore.messaging.AddDefaultConstraintMessage in project hive by apache.
the class LoadConstraint method isDefaultConstraintsAlreadyLoaded.
private boolean isDefaultConstraintsAlreadyLoaded(String dksMsgString) throws Exception {
AddDefaultConstraintMessage msg = deserializer.getAddDefaultConstraintMessage(dksMsgString);
List<SQLDefaultConstraint> dksInMsg = msg.getDefaultConstraints();
if (dksInMsg.isEmpty()) {
return true;
}
String dbName = StringUtils.isBlank(dbNameToLoadIn) ? dksInMsg.get(0).getTable_db() : dbNameToLoadIn;
List<SQLDefaultConstraint> dks;
try {
dks = context.hiveDb.getDefaultConstraintList(dbName, dksInMsg.get(0).getTable_name());
} catch (NoSuchObjectException e) {
return false;
}
return ((dks != null) && !dks.isEmpty());
}
use of org.apache.hadoop.hive.metastore.messaging.AddDefaultConstraintMessage in project hive by apache.
the class AddDefaultConstraintHandler method handle.
@Override
public List<Task<?>> handle(Context context) throws SemanticException {
AddDefaultConstraintMessage msg = deserializer.getAddDefaultConstraintMessage(context.dmd.getPayload());
List<SQLDefaultConstraint> dcs;
try {
dcs = msg.getDefaultConstraints();
} 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 (dcs.isEmpty()) {
return tasks;
}
final String actualDbName = context.isDbNameEmpty() ? dcs.get(0).getTable_db() : context.dbName;
final String actualTblName = dcs.get(0).getTable_name();
final TableName tName = TableName.fromString(actualTblName, null, actualDbName);
for (SQLDefaultConstraint dc : dcs) {
dc.setTable_db(actualDbName);
dc.setTable_name(actualTblName);
}
Constraints constraints = new Constraints(null, null, null, null, dcs, 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.AddDefaultConstraintMessage in project hive by apache.
the class DbNotificationListener method onAddDefaultConstraint.
/**
* @param addDefaultConstraintEvent add default constraint event
* @throws MetaException
*/
@Override
public void onAddDefaultConstraint(AddDefaultConstraintEvent addDefaultConstraintEvent) throws MetaException {
List<SQLDefaultConstraint> cols = addDefaultConstraintEvent.getDefaultConstraintCols();
if (cols.size() > 0) {
AddDefaultConstraintMessage colsInMsg = MessageBuilder.getInstance().buildAddDefaultConstraintMessage(cols);
NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_DEFAULTCONSTRAINT.toString(), msgEncoder.getSerializer().serialize(colsInMsg));
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, addDefaultConstraintEvent);
}
}
Aggregations