Search in sources :

Example 6 with RowPrimaryKey

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

Example 7 with RowPrimaryKey

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

RowPrimaryKey (com.aliyun.openservices.ots.model.RowPrimaryKey)7 OTSRange (com.alibaba.datax.plugin.reader.otsreader.model.OTSRange)4 PrimaryKeyValue (com.aliyun.openservices.ots.model.PrimaryKeyValue)3 Direction (com.aliyun.openservices.ots.model.Direction)2 GetRangeResult (com.aliyun.openservices.ots.model.GetRangeResult)2 PrimaryKeyType (com.aliyun.openservices.ots.model.PrimaryKeyType)2 ArrayList (java.util.ArrayList)2 Column (com.alibaba.datax.common.element.Column)1 GetRangeCallable (com.alibaba.datax.plugin.reader.otsreader.callable.GetRangeCallable)1 OTSConf (com.alibaba.datax.plugin.reader.otsreader.model.OTSConf)1 OTSPrimaryKeyColumn (com.alibaba.datax.plugin.reader.otsreader.model.OTSPrimaryKeyColumn)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 GetRangeRequest (com.aliyun.openservices.ots.model.GetRangeRequest)1 Row (com.aliyun.openservices.ots.model.Row)1