use of org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint in project hive by apache.
the class AddPrimaryKeyHandler method handle.
@Override
public List<Task<? extends Serializable>> handle(Context context) throws SemanticException {
AddPrimaryKeyMessage msg = deserializer.getAddPrimaryKeyMessage(context.dmd.getPayload());
List<SQLPrimaryKey> pks = null;
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<? extends Serializable>> tasks = new ArrayList<Task<? extends Serializable>>();
if (pks.isEmpty()) {
return tasks;
}
String actualDbName = context.isDbNameEmpty() ? pks.get(0).getTable_db() : context.dbName;
String actualTblName = context.isTableNameEmpty() ? pks.get(0).getTable_name() : context.tableName;
for (SQLPrimaryKey pk : pks) {
pk.setTable_db(actualDbName);
pk.setTable_name(actualTblName);
}
AlterTableDesc addConstraintsDesc = new AlterTableDesc(actualDbName + "." + actualTblName, pks, new ArrayList<SQLForeignKey>(), new ArrayList<SQLUniqueConstraint>(), context.eventOnlyReplicationSpec());
Task<DDLWork> addConstraintsTask = TaskFactory.get(new DDLWork(readEntitySet, writeEntitySet, addConstraintsDesc));
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.api.SQLUniqueConstraint in project hive by apache.
the class AddUniqueConstraintHandler method handle.
@Override
public List<Task<? extends Serializable>> handle(Context context) throws SemanticException {
AddUniqueConstraintMessage msg = deserializer.getAddUniqueConstraintMessage(context.dmd.getPayload());
List<SQLUniqueConstraint> uks = null;
try {
uks = msg.getUniqueConstraints();
} catch (Exception e) {
if (!(e instanceof SemanticException)) {
throw new SemanticException("Error reading message members", e);
} else {
throw (SemanticException) e;
}
}
List<Task<? extends Serializable>> tasks = new ArrayList<Task<? extends Serializable>>();
if (uks.isEmpty()) {
return tasks;
}
String actualDbName = context.isDbNameEmpty() ? uks.get(0).getTable_db() : context.dbName;
String actualTblName = context.isTableNameEmpty() ? uks.get(0).getTable_name() : context.tableName;
for (SQLUniqueConstraint uk : uks) {
uk.setTable_db(actualDbName);
uk.setTable_name(actualTblName);
}
AlterTableDesc addConstraintsDesc = new AlterTableDesc(actualDbName + "." + actualTblName, new ArrayList<SQLPrimaryKey>(), new ArrayList<SQLForeignKey>(), uks, context.eventOnlyReplicationSpec());
Task<DDLWork> addConstraintsTask = TaskFactory.get(new DDLWork(readEntitySet, writeEntitySet, addConstraintsDesc));
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);
}
Aggregations