Search in sources :

Example 1 with OTSPKColumn

use of com.alibaba.datax.plugin.writer.otswriter.model.OTSPKColumn in project DataX by alibaba.

the class ParamChecker method checkPrimaryKey.

public static void checkPrimaryKey(TableMeta meta, List<OTSPKColumn> pk) {
    Map<String, PrimaryKeyType> types = meta.getPrimaryKey();
    // 个数是否相等
    if (types.size() != pk.size()) {
        throw new IllegalArgumentException(String.format(OTSErrorMessage.INPUT_PK_COUNT_NOT_EQUAL_META_ERROR, pk.size(), types.size()));
    }
    // 名字类型是否相等
    Map<String, PrimaryKeyType> inputTypes = new HashMap<String, PrimaryKeyType>();
    for (OTSPKColumn col : pk) {
        inputTypes.put(col.getName(), col.getType());
    }
    for (Entry<String, PrimaryKeyType> e : types.entrySet()) {
        if (!inputTypes.containsKey(e.getKey())) {
            throw new IllegalArgumentException(String.format(OTSErrorMessage.PK_COLUMN_MISSING_ERROR, e.getKey()));
        }
        PrimaryKeyType type = inputTypes.get(e.getKey());
        if (type != e.getValue()) {
            throw new IllegalArgumentException(String.format(OTSErrorMessage.INPUT_PK_TYPE_NOT_MATCH_META_ERROR, e.getKey(), type, e.getValue()));
        }
    }
}
Also used : HashMap(java.util.HashMap) PrimaryKeyType(com.aliyun.openservices.ots.model.PrimaryKeyType) OTSPKColumn(com.alibaba.datax.plugin.writer.otswriter.model.OTSPKColumn)

Aggregations

OTSPKColumn (com.alibaba.datax.plugin.writer.otswriter.model.OTSPKColumn)1 PrimaryKeyType (com.aliyun.openservices.ots.model.PrimaryKeyType)1 HashMap (java.util.HashMap)1