Search in sources :

Example 1 with ColumnValue

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

the class Common method getAttrFromRecord.

public static List<Pair<String, ColumnValue>> getAttrFromRecord(int pkCount, List<OTSAttrColumn> attrColumns, Record r) {
    List<Pair<String, ColumnValue>> attr = new ArrayList<Pair<String, ColumnValue>>(r.getColumnNumber());
    for (int i = 0; i < attrColumns.size(); i++) {
        Column col = r.getColumn(i + pkCount);
        OTSAttrColumn expect = attrColumns.get(i);
        if (col.getRawData() == null) {
            attr.add(new Pair<String, ColumnValue>(expect.getName(), null));
            continue;
        }
        ColumnValue cv = ColumnConversion.columnToColumnValue(col, expect);
        attr.add(new Pair<String, ColumnValue>(expect.getName(), cv));
    }
    return attr;
}
Also used : Column(com.alibaba.datax.common.element.Column) ArrayList(java.util.ArrayList) ColumnValue(com.aliyun.openservices.ots.model.ColumnValue) Pair(org.apache.commons.math3.util.Pair)

Example 2 with ColumnValue

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

ColumnValue (com.aliyun.openservices.ots.model.ColumnValue)2 Column (com.alibaba.datax.common.element.Column)1 GetRangeRequest (com.aliyun.openservices.ots.model.GetRangeRequest)1 GetRangeResult (com.aliyun.openservices.ots.model.GetRangeResult)1 PrimaryKeyType (com.aliyun.openservices.ots.model.PrimaryKeyType)1 Row (com.aliyun.openservices.ots.model.Row)1 RowPrimaryKey (com.aliyun.openservices.ots.model.RowPrimaryKey)1 ArrayList (java.util.ArrayList)1 Pair (org.apache.commons.math3.util.Pair)1