本文整理汇总了Java中org.apache.flink.types.Row.getField方法的典型用法代码示例。如果您正苦于以下问题:Java Row.getField方法的具体用法?Java Row.getField怎么用?Java Row.getField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.types.Row
的用法示例。
在下文中一共展示了Row.getField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifySplit
import org.apache.flink.types.Row; //导入方法依赖的package包/类
private void verifySplit(InputSplit split, int expectedIDSum) throws IOException {
int sum = 0;
Row row = new Row(5);
jdbcInputFormat.open(split);
while (!jdbcInputFormat.reachedEnd()) {
row = jdbcInputFormat.nextRecord(row);
int id = ((int) row.getField(0));
int testDataIndex = id - 1001;
assertEquals(TEST_DATA[testDataIndex], row);
sum += id;
}
Assert.assertEquals(expectedIDSum, sum);
}
示例2: serialize
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
public void serialize(Row record, DataOutputView target) throws IOException {
int len = fieldSerializers.length;
if (record.getArity() != len) {
throw new RuntimeException("Row arity of from does not match serializers.");
}
// write a null mask
writeNullMask(len, record, target);
// serialize non-null fields
for (int i = 0; i < len; i++) {
Object o = record.getField(i);
if (o != null) {
fieldSerializers[i].serialize(o, target);
}
}
}
示例3: deserialize
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
public Row deserialize(Row reuse, DataInputView source) throws IOException {
int len = fieldSerializers.length;
if (reuse.getArity() != len) {
throw new RuntimeException("Row arity of from does not match serializers.");
}
// read null mask
readIntoNullMask(len, source, nullMask);
for (int i = 0; i < len; i++) {
if (nullMask[i]) {
reuse.setField(i, null);
} else {
Object reuseField = reuse.getField(i);
if (reuseField != null) {
reuse.setField(i, fieldSerializers[i].deserialize(reuseField, source));
} else {
reuse.setField(i, fieldSerializers[i].deserialize(source));
}
}
}
return reuse;
}
示例4: writeNullMask
import org.apache.flink.types.Row; //导入方法依赖的package包/类
public static void writeNullMask(int len, Row value, DataOutputView target) throws IOException {
int b = 0x00;
int bytePos = 0;
int fieldPos = 0;
int numPos = 0;
while (fieldPos < len) {
b = 0x00;
// set bits in byte
bytePos = 0;
numPos = Math.min(8, len - fieldPos);
while (bytePos < numPos) {
b = b << 1;
// set bit if field is null
if (value.getField(fieldPos + bytePos) == null) {
b |= 0x01;
}
bytePos += 1;
}
fieldPos += numPos;
// shift bits if last byte is not completely filled
b <<= (8 - bytePos);
// write byte
target.writeByte(b);
}
}
示例5: hash
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
public int hash(Row record) {
int code = 0;
int i = 0;
try {
for (; i < keyPositions.length; i++) {
code *= TupleComparatorBase.HASH_SALT[i & 0x1F];
Object element = record.getField(keyPositions[i]); // element can be null
code += comparators[i].hash(element);
}
} catch (IndexOutOfBoundsException e) {
throw new KeyFieldOutOfBoundsException(keyPositions[i]);
}
return code;
}
示例6: equalToReference
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
public boolean equalToReference(Row candidate) {
int i = 0;
try {
for (; i < keyPositions.length; i++) {
TypeComparator<Object> comparator = comparators[i];
Object element = candidate.getField(keyPositions[i]); // element can be null
// check if reference is not equal
if (!comparator.equalToReference(element)) {
return false;
}
}
} catch (IndexOutOfBoundsException e) {
throw new KeyFieldOutOfBoundsException(keyPositions[i]);
}
return true;
}
示例7: compare
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
public int compare(Row first, Row second) {
int i = 0;
try {
for (; i < keyPositions.length; i++) {
int keyPos = keyPositions[i];
TypeComparator<Object> comparator = comparators[i];
Object firstElement = first.getField(keyPos); // element can be null
Object secondElement = second.getField(keyPos); // element can be null
int cmp = comparator.compare(firstElement, secondElement);
if (cmp != 0) {
return cmp;
}
}
} catch (IndexOutOfBoundsException e) {
throw new KeyFieldOutOfBoundsException(keyPositions[i]);
}
return 0;
}
示例8: putNormalizedKey
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
public void putNormalizedKey(Row record, MemorySegment target, int offset, int numBytes) {
int bytesLeft = numBytes;
int currentOffset = offset;
for (int i = 0; i < numLeadingNormalizableKeys && bytesLeft > 0; i++) {
int len = normalizedKeyLengths[i];
len = bytesLeft >= len ? len : bytesLeft;
TypeComparator<Object> comparator = comparators[i];
Object element = record.getField(keyPositions[i]); // element can be null
// write key
comparator.putNormalizedKey(element, target, currentOffset, len);
bytesLeft -= len;
currentOffset += len;
}
}
示例9: extract
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
protected Object[] extract(Row record) {
Object[] al = new Object[rowArity];
for (int i = 0; i < rowArity; i++) {
al[i] = record.getField(i);
}
return al;
}
示例10: testReadNestedListFile
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Test
public void testReadNestedListFile() throws Exception {
rowOrcInputFormat = new OrcRowInputFormat(getPath(TEST_FILE_NESTEDLIST), TEST_SCHEMA_NESTEDLIST, new Configuration());
FileInputSplit[] splits = rowOrcInputFormat.createInputSplits(1);
assertEquals(1, splits.length);
rowOrcInputFormat.openInputFormat();
rowOrcInputFormat.open(splits[0]);
assertFalse(rowOrcInputFormat.reachedEnd());
Row row = null;
long cnt = 0;
// read all rows
while (!rowOrcInputFormat.reachedEnd()) {
row = rowOrcInputFormat.nextRecord(row);
assertEquals(1, row.getArity());
// outer list
Object[] list = (Object[]) row.getField(0);
assertEquals(1, list.length);
// nested list of rows
Row[] nestedRows = (Row[]) list[0];
assertEquals(1, nestedRows.length);
assertEquals(1, nestedRows[0].getArity());
// verify list value
assertEquals(cnt, nestedRows[0].getField(0));
cnt++;
}
// number of rows in file
assertEquals(100, cnt);
}
示例11: testReadWithProjection
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Test
public void testReadWithProjection() throws IOException{
rowOrcInputFormat = new OrcRowInputFormat(getPath(TEST_FILE_NESTED), TEST_SCHEMA_NESTED, new Configuration());
rowOrcInputFormat.selectFields(7, 0, 10, 8);
FileInputSplit[] splits = rowOrcInputFormat.createInputSplits(1);
assertEquals(1, splits.length);
rowOrcInputFormat.openInputFormat();
rowOrcInputFormat.open(splits[0]);
assertFalse(rowOrcInputFormat.reachedEnd());
Row row = rowOrcInputFormat.nextRecord(null);
// validate first row
assertNotNull(row);
assertEquals(4, row.getArity());
// check binary
assertArrayEquals(new byte[]{0, 1, 2, 3, 4}, (byte[]) row.getField(0));
// check boolean
assertEquals(false, row.getField(1));
// check list
assertTrue(row.getField(2) instanceof Object[]);
Object[] list1 = (Object[]) row.getField(2);
assertEquals(2, list1.length);
assertEquals(Row.of(3, "good"), list1[0]);
assertEquals(Row.of(4, "bad"), list1[1]);
// check string
assertEquals("hi", row.getField(3));
// check that there is a second row with four fields
assertFalse(rowOrcInputFormat.reachedEnd());
row = rowOrcInputFormat.nextRecord(null);
assertNotNull(row);
assertEquals(4, row.getArity());
assertTrue(rowOrcInputFormat.reachedEnd());
}
示例12: setReference
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
public void setReference(Row toCompare) {
int i = 0;
try {
for (; i < keyPositions.length; i++) {
TypeComparator<Object> comparator = comparators[i];
Object element = toCompare.getField(keyPositions[i]);
comparator.setReference(element); // element can be null
}
} catch (IndexOutOfBoundsException e) {
throw new KeyFieldOutOfBoundsException(keyPositions[i]);
}
}
示例13: deepEquals
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
protected void deepEquals(String message, Row should, Row is) {
int arity = should.getArity();
assertEquals(message, arity, is.getArity());
for (int i = 0; i < arity; i++) {
Object copiedValue = should.getField(i);
Object element = is.getField(i);
assertEquals(message, element, copiedValue);
}
}
示例14: getRoutingKey
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
public String getRoutingKey(Row event) {
return (String) event.getField(keyIndex);
}
示例15: sendValues
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
protected boolean sendValues(Iterable<Row> values, long checkpointId, long timestamp) throws Exception {
final AtomicInteger updatesCount = new AtomicInteger(0);
final AtomicInteger updatesConfirmed = new AtomicInteger(0);
final AtomicReference<Throwable> exception = new AtomicReference<>();
FutureCallback<ResultSet> callback = new FutureCallback<ResultSet>() {
@Override
public void onSuccess(ResultSet resultSet) {
updatesConfirmed.incrementAndGet();
if (updatesCount.get() > 0) { // only set if all updates have been sent
if (updatesCount.get() == updatesConfirmed.get()) {
synchronized (updatesConfirmed) {
updatesConfirmed.notifyAll();
}
}
}
}
@Override
public void onFailure(Throwable throwable) {
if (exception.compareAndSet(null, throwable)) {
LOG.error("Error while sending value.", throwable);
synchronized (updatesConfirmed) {
updatesConfirmed.notifyAll();
}
}
}
};
//set values for prepared statement
int updatesSent = 0;
for (Row value : values) {
for (int x = 0; x < arity; x++) {
fields[x] = value.getField(x);
}
//insert values and send to cassandra
BoundStatement s = preparedStatement.bind(fields);
s.setDefaultTimestamp(timestamp);
ResultSetFuture result = session.executeAsync(s);
updatesSent++;
if (result != null) {
//add callback to detect errors
Futures.addCallback(result, callback);
}
}
updatesCount.set(updatesSent);
synchronized (updatesConfirmed) {
while (exception.get() == null && updatesSent != updatesConfirmed.get()) {
updatesConfirmed.wait();
}
}
if (exception.get() != null) {
LOG.warn("Sending a value failed.", exception.get());
return false;
} else {
return true;
}
}