Search in sources :

Example 1 with AddNotNullConstraintMessage

use of org.apache.hadoop.hive.metastore.messaging.AddNotNullConstraintMessage in project hive by apache.

the class LoadConstraint method isNotNullConstraintsAlreadyLoaded.

private boolean isNotNullConstraintsAlreadyLoaded(String nnsMsgString) throws Exception {
    AddNotNullConstraintMessage msg = deserializer.getAddNotNullConstraintMessage(nnsMsgString);
    List<SQLNotNullConstraint> nnsInMsg = msg.getNotNullConstraints();
    if (nnsInMsg.isEmpty()) {
        return true;
    }
    String dbName = StringUtils.isBlank(dbNameToLoadIn) ? nnsInMsg.get(0).getTable_db() : dbNameToLoadIn;
    List<SQLNotNullConstraint> nns;
    try {
        nns = context.hiveDb.getNotNullConstraintList(dbName, nnsInMsg.get(0).getTable_name());
    } catch (NoSuchObjectException e) {
        return false;
    }
    return CollectionUtils.isNotEmpty(nns);
}
Also used : SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) AddNotNullConstraintMessage(org.apache.hadoop.hive.metastore.messaging.AddNotNullConstraintMessage)

Example 2 with AddNotNullConstraintMessage

use of org.apache.hadoop.hive.metastore.messaging.AddNotNullConstraintMessage in project hive by apache.

the class AddNotNullConstraintHandler method handle.

@Override
public List<Task<?>> handle(Context context) throws SemanticException {
    AddNotNullConstraintMessage msg = deserializer.getAddNotNullConstraintMessage(context.dmd.getPayload());
    List<SQLNotNullConstraint> nns;
    try {
        nns = msg.getNotNullConstraints();
    } 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 (nns.isEmpty()) {
        return tasks;
    }
    final String actualDbName = context.isDbNameEmpty() ? nns.get(0).getTable_db() : context.dbName;
    final String actualTblName = nns.get(0).getTable_name();
    final TableName tName = TableName.fromString(actualTblName, null, actualDbName);
    for (SQLNotNullConstraint nn : nns) {
        nn.setTable_db(actualDbName);
        nn.setTable_name(actualTblName);
    }
    Constraints constraints = new Constraints(null, null, nns, 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);
}
Also used : Task(org.apache.hadoop.hive.ql.exec.Task) ArrayList(java.util.ArrayList) AddNotNullConstraintMessage(org.apache.hadoop.hive.metastore.messaging.AddNotNullConstraintMessage) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) TableName(org.apache.hadoop.hive.common.TableName) Constraints(org.apache.hadoop.hive.ql.ddl.table.constraint.Constraints) DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) AlterTableAddConstraintDesc(org.apache.hadoop.hive.ql.ddl.table.constraint.add.AlterTableAddConstraintDesc) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 3 with AddNotNullConstraintMessage

use of org.apache.hadoop.hive.metastore.messaging.AddNotNullConstraintMessage in project hive by apache.

the class DbNotificationListener method onAddNotNullConstraint.

/**
 * @param addNotNullConstraintEvent add not null constraint event
 * @throws MetaException
 */
@Override
public void onAddNotNullConstraint(AddNotNullConstraintEvent addNotNullConstraintEvent) throws MetaException {
    List<SQLNotNullConstraint> cols = addNotNullConstraintEvent.getNotNullConstraintCols();
    if (cols.size() > 0) {
        AddNotNullConstraintMessage msg = MessageBuilder.getInstance().buildAddNotNullConstraintMessage(addNotNullConstraintEvent.getNotNullConstraintCols());
        NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_NOTNULLCONSTRAINT.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, addNotNullConstraintEvent);
    }
}
Also used : SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent) AddNotNullConstraintMessage(org.apache.hadoop.hive.metastore.messaging.AddNotNullConstraintMessage)

Aggregations

SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)3 AddNotNullConstraintMessage (org.apache.hadoop.hive.metastore.messaging.AddNotNullConstraintMessage)3 ArrayList (java.util.ArrayList)1 TableName (org.apache.hadoop.hive.common.TableName)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 NotificationEvent (org.apache.hadoop.hive.metastore.api.NotificationEvent)1 DDLWork (org.apache.hadoop.hive.ql.ddl.DDLWork)1 Constraints (org.apache.hadoop.hive.ql.ddl.table.constraint.Constraints)1 AlterTableAddConstraintDesc (org.apache.hadoop.hive.ql.ddl.table.constraint.add.AlterTableAddConstraintDesc)1 Task (org.apache.hadoop.hive.ql.exec.Task)1 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)1