Search in sources :

Example 1 with GetRangeResult

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

the class OtsReaderSlaveProxy method generateRequestItem.

private RequestItem generateRequestItem(OTSClientAsync ots, OTSConf conf, RowPrimaryKey begin, RowPrimaryKey end, Direction direction, List<String> columns) throws Exception {
    RangeRowQueryCriteria criteria = generateRangeRowQueryCriteria(conf.getTableName(), begin, end, direction, columns);
    GetRangeRequest request = new GetRangeRequest();
    request.setRangeRowQueryCriteria(criteria);
    OTSFuture<GetRangeResult> future = ots.getRange(request);
    return new RequestItem(criteria, future);
}
Also used : GetRangeResult(com.aliyun.openservices.ots.model.GetRangeResult) GetRangeRequest(com.aliyun.openservices.ots.model.GetRangeRequest) RangeRowQueryCriteria(com.aliyun.openservices.ots.model.RangeRowQueryCriteria)

Example 2 with GetRangeResult

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

the class OtsReaderSlaveProxy method read.

public void read(RecordSender sender, Configuration configuration) throws Exception {
    LOG.info("read begin.");
    OTSConf conf = GsonParser.jsonToConf(configuration.getString(OTSConst.OTS_CONF));
    OTSRange range = GsonParser.jsonToRange(configuration.getString(OTSConst.OTS_RANGE));
    Direction direction = GsonParser.jsonToDirection(configuration.getString(OTSConst.OTS_DIRECTION));
    OTSServiceConfiguration configure = new OTSServiceConfiguration();
    configure.setRetryStrategy(new DefaultNoRetry());
    OTSClientAsync ots = new OTSClientAsync(conf.getEndpoint(), conf.getAccessId(), conf.getAccesskey(), conf.getInstanceName(), null, configure, null);
    RowPrimaryKey token = range.getBegin();
    List<String> columns = Common.getNormalColumnNameList(conf.getColumns());
    RequestItem request = null;
    do {
        LOG.debug("Next token : {}", GsonParser.rowPrimaryKeyToJson(token));
        if (request == null) {
            request = generateRequestItem(ots, conf, token, range.getEnd(), direction, columns);
        } else {
            RequestItem req = request;
            GetRangeResult result = RetryHelper.executeWithRetry(new GetRangeCallable(ots, req.getCriteria(), req.getFuture()), conf.getRetry(), conf.getSleepInMilliSecond());
            if ((token = result.getNextStartPrimaryKey()) != null) {
                request = generateRequestItem(ots, conf, token, range.getEnd(), direction, columns);
            }
            rowsToSender(result.getRows(), sender, conf.getColumns());
        }
    } while (token != null);
    ots.shutdown();
    LOG.info("read end.");
}
Also used : OTSServiceConfiguration(com.aliyun.openservices.ots.OTSServiceConfiguration) DefaultNoRetry(com.alibaba.datax.plugin.reader.otsreader.utils.DefaultNoRetry) OTSClientAsync(com.aliyun.openservices.ots.OTSClientAsync) OTSRange(com.alibaba.datax.plugin.reader.otsreader.model.OTSRange) GetRangeResult(com.aliyun.openservices.ots.model.GetRangeResult) RowPrimaryKey(com.aliyun.openservices.ots.model.RowPrimaryKey) OTSConf(com.alibaba.datax.plugin.reader.otsreader.model.OTSConf) GetRangeCallable(com.alibaba.datax.plugin.reader.otsreader.callable.GetRangeCallable) Direction(com.aliyun.openservices.ots.model.Direction)

Example 3 with GetRangeResult

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

GetRangeResult (com.aliyun.openservices.ots.model.GetRangeResult)3 GetRangeRequest (com.aliyun.openservices.ots.model.GetRangeRequest)2 RowPrimaryKey (com.aliyun.openservices.ots.model.RowPrimaryKey)2 GetRangeCallable (com.alibaba.datax.plugin.reader.otsreader.callable.GetRangeCallable)1 OTSConf (com.alibaba.datax.plugin.reader.otsreader.model.OTSConf)1 OTSRange (com.alibaba.datax.plugin.reader.otsreader.model.OTSRange)1 DefaultNoRetry (com.alibaba.datax.plugin.reader.otsreader.utils.DefaultNoRetry)1 OTSClientAsync (com.aliyun.openservices.ots.OTSClientAsync)1 OTSServiceConfiguration (com.aliyun.openservices.ots.OTSServiceConfiguration)1 ColumnValue (com.aliyun.openservices.ots.model.ColumnValue)1 Direction (com.aliyun.openservices.ots.model.Direction)1 PrimaryKeyType (com.aliyun.openservices.ots.model.PrimaryKeyType)1 RangeRowQueryCriteria (com.aliyun.openservices.ots.model.RangeRowQueryCriteria)1 Row (com.aliyun.openservices.ots.model.Row)1