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;
}
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;
}
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()));
}
}
}
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;
}
Aggregations