当前位置: 首页>>代码示例>>Java>>正文


Java Row.getField方法代码示例

本文整理汇总了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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:JDBCInputFormatTest.java

示例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);
		}
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:RowSerializer.java

示例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;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:27,代码来源:RowSerializer.java

示例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);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:27,代码来源:NullMaskUtils.java

示例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;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:RowComparator.java

示例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;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:RowComparator.java

示例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;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:RowComparator.java

示例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;
	}

}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:RowComparator.java

示例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;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:9,代码来源:CassandraRowSink.java

示例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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:37,代码来源:OrcRowInputFormatTest.java

示例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());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:38,代码来源:OrcRowInputFormatTest.java

示例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]);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:14,代码来源:RowComparator.java

示例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);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:11,代码来源:RowSerializerTest.java

示例14: getRoutingKey

import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
public String getRoutingKey(Row event) {
    return (String) event.getField(keyIndex);
}
 
开发者ID:pravega,项目名称:flink-connectors,代码行数:5,代码来源:FlinkPravegaTableSink.java

示例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;
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:63,代码来源:CassandraRowWriteAheadSink.java


注:本文中的org.apache.flink.types.Row.getField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。