Search in sources :

Example 1 with MissingValueBehavior

use of com.linkedin.databus2.relay.config.ReplicationBitSetterStaticConfig.MissingValueBehavior in project databus by linkedin.

the class ReplicationBitSetterConfig method build.

@Override
public ReplicationBitSetterStaticConfig build() throws InvalidConfigException {
    SourceType type = null;
    try {
        type = SourceType.valueOf(_sourceType);
    } catch (IllegalArgumentException iae) {
        throw new InvalidConfigException("Source Types should be one of (" + Arrays.asList(SourceType.values()) + ") but is (" + _sourceType + ")");
    }
    MissingValueBehavior missingValueForDelete = null;
    try {
        missingValueForDelete = MissingValueBehavior.valueOf(_missingValueBehavior);
    } catch (IllegalArgumentException iae) {
        throw new InvalidConfigException("Missing Value For Delete Behavior should be one of (" + Arrays.asList(MissingValueBehavior.values()) + ") but is (" + _missingValueBehavior + ")");
    }
    return new ReplicationBitSetterStaticConfig(type, _fieldName, _remoteUpdateValueRegex, missingValueForDelete);
}
Also used : SourceType(com.linkedin.databus2.relay.config.ReplicationBitSetterStaticConfig.SourceType) MissingValueBehavior(com.linkedin.databus2.relay.config.ReplicationBitSetterStaticConfig.MissingValueBehavior) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException)

Example 2 with MissingValueBehavior

use of com.linkedin.databus2.relay.config.ReplicationBitSetterStaticConfig.MissingValueBehavior in project databus by linkedin.

the class ColumnsState method checkNullSafety.

/**
 * Checks if the given field can be null.
 * 1. Primary keys cannot be null
 * 2. Replication fields cannot be null
 * 3. If the errorOnMissing field config is null, then this method will throw an exception
 * @param eventFields Map containing dbFieldName => fieldValue
 * @param pk The primary key object stored as an class object
 * @param field The current field being processed(Avro)
 * @param databaseFieldName Field being processed(oracle name)
 * @throws DatabusException
 */
private void checkNullSafety(HashMap<String, ColumnState.EventField> eventFields, PrimaryKey pk, Schema.Field field, String databaseFieldName, ReplicationBitSetterStaticConfig replicationBitConfig) throws DatabusException {
    if (eventFields.get(databaseFieldName) == null) {
        LOG.error("Missing field " + databaseFieldName + " in event from the xml trail for table " + _currentTable);
        if (// Are we ok to accept null fields ?
        !_errorOnMissingFields) {
            // We cannot tolerate empty primary key fields, so we'll throw exception if key is null
            if (pk.isPartOfPrimaryKey(field))
                throw new DatabusException("Skip errors on missing DB Fields is true, but cannot proceed because primary key not found: " + field.name());
            // We also need the replication field, it's not optional if MissingValueBehavior == STOP_WITH_ERROR
            if (replicationBitConfig.getSourceType() == ReplicationBitSetterStaticConfig.SourceType.COLUMN && isReplicationField(databaseFieldName, replicationBitConfig) && replicationBitConfig.getMissingValueBehavior() == MissingValueBehavior.STOP_WITH_ERROR) {
                throw new DatabusException("Skip errors on missing DB Fields is true, but the replication field is missing, this is mandatory, cannot proceed with  " + field.name() + " field missing");
            }
            setSeenMissingFields(true);
            // If not primary key, we create fake hash entry with a null eventfield entry
            ColumnState.EventField emptyEventField = new ColumnState.EventField(false, null, true);
            eventFields.put(databaseFieldName, emptyEventField);
        } else
            throw new DatabusException("Unable to find a required field " + databaseFieldName + " in the xml trail file");
    }
}
Also used : DatabusException(com.linkedin.databus2.core.DatabusException)

Aggregations

InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)1 DatabusException (com.linkedin.databus2.core.DatabusException)1 MissingValueBehavior (com.linkedin.databus2.relay.config.ReplicationBitSetterStaticConfig.MissingValueBehavior)1 SourceType (com.linkedin.databus2.relay.config.ReplicationBitSetterStaticConfig.SourceType)1