Search in sources :

Example 1 with PrimaryKeyValue

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

the class ParamChecker method checkInputSplitPoints.

/**
     * 1.检测用户的输入类型是否和PartitionKey一致
     * 2.顺序是否和Range一致
     * 3.是否有重复列
     * 4.检查points的范围是否在range内
     * @param meta
     * @param points
     */
public static void checkInputSplitPoints(TableMeta meta, OTSRange range, Direction direction, List<PrimaryKeyValue> points) {
    if (null == points || points.isEmpty()) {
        return;
    }
    OTSPrimaryKeyColumn part = Common.getPartitionKey(meta);
    // 处理第一个
    PrimaryKeyValue item = points.get(0);
    if (item.getType() != part.getType()) {
        throw new IllegalArgumentException("Input type of 'range-split' not match partition key. " + "Item of 'range-split' type:" + item.getType() + ", Partition type:" + part.getType());
    }
    for (int i = 0; i < points.size() - 1; i++) {
        PrimaryKeyValue before = points.get(i);
        PrimaryKeyValue after = points.get(i + 1);
        checkDirection(direction, before, after);
    }
    PrimaryKeyValue begin = range.getBegin().getPrimaryKey().get(part.getName());
    PrimaryKeyValue end = range.getEnd().getPrimaryKey().get(part.getName());
    checkPointsRange(direction, begin, end, points);
}
Also used : PrimaryKeyValue(com.aliyun.openservices.ots.model.PrimaryKeyValue) OTSPrimaryKeyColumn(com.alibaba.datax.plugin.reader.otsreader.model.OTSPrimaryKeyColumn)

Example 2 with PrimaryKeyValue

use of com.aliyun.openservices.ots.model.PrimaryKeyValue 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 3 with PrimaryKeyValue

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

the class RangeSplit method rangeSplitByCount.

public static List<OTSRange> rangeSplitByCount(TableMeta meta, RowPrimaryKey begin, RowPrimaryKey end, int count) {
    List<OTSRange> results = new ArrayList<OTSRange>();
    OTSPrimaryKeyColumn partitionKey = Common.getPartitionKey(meta);
    PrimaryKeyValue beginPartitionKey = begin.getPrimaryKey().get(partitionKey.getName());
    PrimaryKeyValue endPartitionKey = end.getPrimaryKey().get(partitionKey.getName());
    // 第一,先对PartitionKey列进行拆分
    List<PrimaryKeyValue> ranges = RangeSplit.splitRangeByPrimaryKeyType(partitionKey.getType(), beginPartitionKey, endPartitionKey, count);
    if (ranges.isEmpty()) {
        return results;
    }
    int size = ranges.size();
    for (int i = 0; i < size - 1; i++) {
        RowPrimaryKey bPk = new RowPrimaryKey();
        RowPrimaryKey ePk = new RowPrimaryKey();
        bPk.addPrimaryKeyColumn(partitionKey.getName(), ranges.get(i));
        ePk.addPrimaryKeyColumn(partitionKey.getName(), ranges.get(i + 1));
        results.add(new OTSRange(bPk, ePk));
    }
    // 第二,填充非PartitionKey的ParimaryKey列
    // 注意:在填充过程中,需要使用用户给定的Begin和End来替换切分出来的第一个Range
    // 的Begin和最后一个Range的End
    List<String> keys = new ArrayList<String>(meta.getPrimaryKey().size());
    keys.addAll(meta.getPrimaryKey().keySet());
    for (int i = 0; i < results.size(); i++) {
        for (int j = 1; j < keys.size(); j++) {
            OTSRange c = results.get(i);
            RowPrimaryKey beginPK = c.getBegin();
            RowPrimaryKey endPK = c.getEnd();
            String key = keys.get(j);
            if (i == 0) {
                // 第一行
                beginPK.addPrimaryKeyColumn(key, begin.getPrimaryKey().get(key));
                endPK.addPrimaryKeyColumn(key, PrimaryKeyValue.INF_MIN);
            } else if (i == results.size() - 1) {
                // 最后一行
                beginPK.addPrimaryKeyColumn(key, PrimaryKeyValue.INF_MIN);
                endPK.addPrimaryKeyColumn(key, end.getPrimaryKey().get(key));
            } else {
                beginPK.addPrimaryKeyColumn(key, PrimaryKeyValue.INF_MIN);
                endPK.addPrimaryKeyColumn(key, PrimaryKeyValue.INF_MIN);
            }
        }
    }
    return results;
}
Also used : OTSRange(com.alibaba.datax.plugin.reader.otsreader.model.OTSRange) RowPrimaryKey(com.aliyun.openservices.ots.model.RowPrimaryKey) ArrayList(java.util.ArrayList) PrimaryKeyValue(com.aliyun.openservices.ots.model.PrimaryKeyValue) OTSPrimaryKeyColumn(com.alibaba.datax.plugin.reader.otsreader.model.OTSPrimaryKeyColumn)

Example 4 with PrimaryKeyValue

use of com.aliyun.openservices.ots.model.PrimaryKeyValue 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 5 with PrimaryKeyValue

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

the class Common method getPKFromRecord.

public static RowPrimaryKey getPKFromRecord(List<OTSPKColumn> pkColumns, Record r) {
    RowPrimaryKey primaryKey = new RowPrimaryKey();
    int pkCount = pkColumns.size();
    for (int i = 0; i < pkCount; i++) {
        Column col = r.getColumn(i);
        OTSPKColumn expect = pkColumns.get(i);
        if (col.getRawData() == null) {
            throw new IllegalArgumentException(String.format(OTSErrorMessage.PK_COLUMN_VALUE_IS_NULL_ERROR, expect.getName()));
        }
        PrimaryKeyValue pk = ColumnConversion.columnToPrimaryKeyValue(col, expect);
        primaryKey.addPrimaryKeyColumn(expect.getName(), pk);
    }
    return primaryKey;
}
Also used : Column(com.alibaba.datax.common.element.Column) RowPrimaryKey(com.aliyun.openservices.ots.model.RowPrimaryKey) PrimaryKeyValue(com.aliyun.openservices.ots.model.PrimaryKeyValue)

Aggregations

PrimaryKeyValue (com.aliyun.openservices.ots.model.PrimaryKeyValue)9 RowPrimaryKey (com.aliyun.openservices.ots.model.RowPrimaryKey)3 ArrayList (java.util.ArrayList)3 OTSPrimaryKeyColumn (com.alibaba.datax.plugin.reader.otsreader.model.OTSPrimaryKeyColumn)2 OTSRange (com.alibaba.datax.plugin.reader.otsreader.model.OTSRange)2 PrimaryKeyType (com.aliyun.openservices.ots.model.PrimaryKeyType)2 Column (com.alibaba.datax.common.element.Column)1 OTSClient (com.aliyun.openservices.ots.OTSClient)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 Comparator (java.util.Comparator)1