Search in sources :

Example 1 with AddCheckConstraintMessage

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

the class LoadConstraint method isCheckConstraintsAlreadyLoaded.

private boolean isCheckConstraintsAlreadyLoaded(String cksMsgString) throws Exception {
    AddCheckConstraintMessage msg = deserializer.getAddCheckConstraintMessage(cksMsgString);
    List<SQLCheckConstraint> cksInMsg = msg.getCheckConstraints();
    if (cksInMsg.isEmpty()) {
        return true;
    }
    String dbName = StringUtils.isBlank(dbNameToLoadIn) ? cksInMsg.get(0).getTable_db() : dbNameToLoadIn;
    List<SQLCheckConstraint> cks;
    try {
        cks = context.hiveDb.getCheckConstraintList(dbName, cksInMsg.get(0).getTable_name());
    } catch (NoSuchObjectException e) {
        return false;
    }
    return ((cks != null) && !cks.isEmpty());
}
Also used : SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) AddCheckConstraintMessage(org.apache.hadoop.hive.metastore.messaging.AddCheckConstraintMessage)

Example 2 with AddCheckConstraintMessage

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

the class AddCheckConstraintHandler method handle.

@Override
public List<Task<?>> handle(Context context) throws SemanticException {
    AddCheckConstraintMessage msg = deserializer.getAddCheckConstraintMessage(context.dmd.getPayload());
    List<SQLCheckConstraint> ccs;
    try {
        ccs = msg.getCheckConstraints();
    } 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 (ccs.isEmpty()) {
        return tasks;
    }
    final String actualDbName = context.isDbNameEmpty() ? ccs.get(0).getTable_db() : context.dbName;
    final String actualTblName = ccs.get(0).getTable_name();
    final TableName tName = TableName.fromString(actualTblName, null, actualDbName);
    for (SQLCheckConstraint ck : ccs) {
        ck.setTable_db(actualDbName);
        ck.setTable_name(actualTblName);
    }
    Constraints constraints = new Constraints(null, null, null, null, null, ccs);
    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) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) ArrayList(java.util.ArrayList) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) AddCheckConstraintMessage(org.apache.hadoop.hive.metastore.messaging.AddCheckConstraintMessage) 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 AddCheckConstraintMessage

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

the class DbNotificationListener method onAddCheckConstraint.

/**
 * @param addCheckConstraintEvent add check constraint event
 * @throws MetaException
 */
@Override
public void onAddCheckConstraint(AddCheckConstraintEvent addCheckConstraintEvent) throws MetaException {
    LOG.info("Inside DBNotification listener for check constraint.");
    List<SQLCheckConstraint> cols = addCheckConstraintEvent.getCheckConstraintCols();
    if (cols.size() > 0) {
        AddCheckConstraintMessage colsInMsg = MessageBuilder.getInstance().buildAddCheckConstraintMessage(cols);
        NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_CHECKCONSTRAINT.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, addCheckConstraintEvent);
    }
}
Also used : SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) NotificationEvent(org.apache.hadoop.hive.metastore.api.NotificationEvent) AddCheckConstraintMessage(org.apache.hadoop.hive.metastore.messaging.AddCheckConstraintMessage)

Aggregations

SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)3 AddCheckConstraintMessage (org.apache.hadoop.hive.metastore.messaging.AddCheckConstraintMessage)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