Search in sources :

Example 1 with OTSPrimaryKeyColumn

use of com.alibaba.datax.plugin.reader.otsreader.model.OTSPrimaryKeyColumn in project DataX by alibaba.

the class Common method getPartitionKey.

public static OTSPrimaryKeyColumn getPartitionKey(TableMeta meta) {
    List<String> keys = new ArrayList<String>();
    keys.addAll(meta.getPrimaryKey().keySet());
    String key = keys.get(0);
    OTSPrimaryKeyColumn col = new OTSPrimaryKeyColumn();
    col.setName(key);
    col.setType(meta.getPrimaryKey().get(key));
    return col;
}
Also used : ArrayList(java.util.ArrayList) OTSPrimaryKeyColumn(com.alibaba.datax.plugin.reader.otsreader.model.OTSPrimaryKeyColumn)

Example 2 with OTSPrimaryKeyColumn

use of com.alibaba.datax.plugin.reader.otsreader.model.OTSPrimaryKeyColumn 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 3 with OTSPrimaryKeyColumn

use of com.alibaba.datax.plugin.reader.otsreader.model.OTSPrimaryKeyColumn 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)

Aggregations

OTSPrimaryKeyColumn (com.alibaba.datax.plugin.reader.otsreader.model.OTSPrimaryKeyColumn)3 PrimaryKeyValue (com.aliyun.openservices.ots.model.PrimaryKeyValue)2 ArrayList (java.util.ArrayList)2 OTSRange (com.alibaba.datax.plugin.reader.otsreader.model.OTSRange)1 RowPrimaryKey (com.aliyun.openservices.ots.model.RowPrimaryKey)1