Search in sources :

Example 1 with PrimaryKeyType

use of com.aliyun.openservices.ots.model.PrimaryKeyType in project DataX by alibaba.

the class ParamChecker method checkInputPrimaryKeyAndGet.

public static RowPrimaryKey checkInputPrimaryKeyAndGet(TableMeta meta, List<PrimaryKeyValue> range) {
    if (meta.getPrimaryKey().size() != range.size()) {
        throw new IllegalArgumentException(String.format("Input size of values not equal size of primary key. input size:%d, primary key size:%d .", range.size(), meta.getPrimaryKey().size()));
    }
    RowPrimaryKey pk = new RowPrimaryKey();
    int i = 0;
    for (Entry<String, PrimaryKeyType> e : meta.getPrimaryKey().entrySet()) {
        PrimaryKeyValue value = range.get(i);
        if (e.getValue() != value.getType() && value != PrimaryKeyValue.INF_MIN && value != PrimaryKeyValue.INF_MAX) {
            throw new IllegalArgumentException("Input range type not match primary key. Input type:" + value.getType() + ", Primary Key Type:" + e.getValue() + ", Index:" + i);
        } else {
            pk.addPrimaryKeyColumn(e.getKey(), value);
        }
        i++;
    }
    return pk;
}
Also used : RowPrimaryKey(com.aliyun.openservices.ots.model.RowPrimaryKey) PrimaryKeyValue(com.aliyun.openservices.ots.model.PrimaryKeyValue) PrimaryKeyType(com.aliyun.openservices.ots.model.PrimaryKeyType)

Example 2 with PrimaryKeyType

use of com.aliyun.openservices.ots.model.PrimaryKeyType in project DataX by alibaba.

the class PrimaryKeyValueAdaptor method deserialize.

@Override
public PrimaryKeyValue deserialize(JsonElement ele, Type t, JsonDeserializationContext c) throws JsonParseException {
    JsonObject obj = ele.getAsJsonObject();
    String strType = obj.getAsJsonPrimitive(TYPE).getAsString();
    JsonPrimitive jsonValue = obj.getAsJsonPrimitive(VALUE);
    if (strType.equals(INF_MIN)) {
        return PrimaryKeyValue.INF_MIN;
    }
    if (strType.equals(INF_MAX)) {
        return PrimaryKeyValue.INF_MAX;
    }
    PrimaryKeyValue value = null;
    PrimaryKeyType type = PrimaryKeyType.valueOf(strType);
    switch(type) {
        case STRING:
            value = PrimaryKeyValue.fromString(jsonValue.getAsString());
            break;
        case INTEGER:
            value = PrimaryKeyValue.fromLong(jsonValue.getAsLong());
            break;
        default:
            throw new IllegalArgumentException("Unsupport deserialize the type : " + type + "");
    }
    return value;
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) PrimaryKeyValue(com.aliyun.openservices.ots.model.PrimaryKeyValue) JsonObject(com.google.gson.JsonObject) PrimaryKeyType(com.aliyun.openservices.ots.model.PrimaryKeyType)

Example 3 with PrimaryKeyType

use of com.aliyun.openservices.ots.model.PrimaryKeyType 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)

Example 4 with PrimaryKeyType

use of com.aliyun.openservices.ots.model.PrimaryKeyType in project DataX by alibaba.

the class GetFirstRowPrimaryKeyCallable method call.

@Override
public RowPrimaryKey call() throws Exception {
    RowPrimaryKey ret = new RowPrimaryKey();
    GetRangeRequest request = new GetRangeRequest();
    request.setRangeRowQueryCriteria(criteria);
    GetRangeResult result = ots.getRange(request);
    List<Row> rows = result.getRows();
    if (rows.isEmpty()) {
        // no data
        return null;
    }
    Row row = rows.get(0);
    Map<String, PrimaryKeyType> pk = meta.getPrimaryKey();
    for (String key : pk.keySet()) {
        ColumnValue v = row.getColumns().get(key);
        if (v.getType() == ColumnType.INTEGER) {
            ret.addPrimaryKeyColumn(key, PrimaryKeyValue.fromLong(v.asLong()));
        } else {
            ret.addPrimaryKeyColumn(key, PrimaryKeyValue.fromString(v.asString()));
        }
    }
    return ret;
}
Also used : GetRangeResult(com.aliyun.openservices.ots.model.GetRangeResult) RowPrimaryKey(com.aliyun.openservices.ots.model.RowPrimaryKey) GetRangeRequest(com.aliyun.openservices.ots.model.GetRangeRequest) PrimaryKeyType(com.aliyun.openservices.ots.model.PrimaryKeyType) ColumnValue(com.aliyun.openservices.ots.model.ColumnValue) Row(com.aliyun.openservices.ots.model.Row)

Aggregations

PrimaryKeyType (com.aliyun.openservices.ots.model.PrimaryKeyType)4 PrimaryKeyValue (com.aliyun.openservices.ots.model.PrimaryKeyValue)2 RowPrimaryKey (com.aliyun.openservices.ots.model.RowPrimaryKey)2 OTSPKColumn (com.alibaba.datax.plugin.writer.otswriter.model.OTSPKColumn)1 ColumnValue (com.aliyun.openservices.ots.model.ColumnValue)1 GetRangeRequest (com.aliyun.openservices.ots.model.GetRangeRequest)1 GetRangeResult (com.aliyun.openservices.ots.model.GetRangeResult)1 Row (com.aliyun.openservices.ots.model.Row)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 HashMap (java.util.HashMap)1