本文整理汇总了Java中org.apache.flink.types.Row.getArity方法的典型用法代码示例。如果您正苦于以下问题:Java Row.getArity方法的具体用法?Java Row.getArity怎么用?Java Row.getArity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.types.Row
的用法示例。
在下文中一共展示了Row.getArity方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
public byte[] serialize(Row row) {
if (row.getArity() != fieldNames.length) {
throw new IllegalStateException(String.format(
"Number of elements in the row %s is different from number of field names: %d", row, fieldNames.length));
}
ObjectNode objectNode = mapper.createObjectNode();
for (int i = 0; i < row.getArity(); i++) {
JsonNode node = mapper.valueToTree(row.getField(i));
objectNode.set(fieldNames[i], node);
}
try {
return mapper.writeValueAsBytes(objectNode);
} catch (Exception e) {
throw new RuntimeException("Failed to serialize row", e);
}
}
示例2: nextRecord
import org.apache.flink.types.Row; //导入方法依赖的package包/类
/**
* Stores the next resultSet row in a tuple.
*
* @param row row to be reused.
* @return row containing next {@link Row}
* @throws java.io.IOException
*/
@Override
public Row nextRecord(Row row) throws IOException {
try {
if (!hasNext) {
return null;
}
for (int pos = 0; pos < row.getArity(); pos++) {
row.setField(pos, resultSet.getObject(pos + 1));
}
//update hasNext after we've read the record
hasNext = resultSet.next();
return row;
} catch (SQLException se) {
throw new IOException("Couldn't read data - " + se.getMessage(), se);
} catch (NullPointerException npe) {
throw new IOException("Couldn't access resultSet", npe);
}
}
示例3: 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);
}
}
}
示例4: 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;
}
示例5: serialize
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@Override
public byte[] serialize(Row row) {
if (row.getArity() != fieldNames.length) {
throw new IllegalStateException(String.format(
"Number of elements in the row %s is different from number of field names: %d", row, fieldNames.length));
}
ObjectNode objectNode = MAPPER.createObjectNode();
for (int i = 0; i < row.getArity(); i++) {
JsonNode node = MAPPER.valueToTree(row.getField(i));
objectNode.set(fieldNames[i], node);
}
try {
return MAPPER.writeValueAsBytes(objectNode);
} catch (Exception e) {
throw new RuntimeException("Failed to serialize row", e);
}
}
示例6: assertEqualRows
import org.apache.flink.types.Row; //导入方法依赖的package包/类
private void assertEqualRows(Row expectedRow, Row resultRow) {
assertEquals("Deserialized row should have expected number of fields",
expectedRow.getArity(), resultRow.getArity());
for (int i = 0; i < expectedRow.getArity(); i++) {
assertEquals(String.format("Field number %d should be as in the original row", i),
expectedRow.getField(i), resultRow.getField(i));
}
}
示例7: 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);
}
}
示例8: privateGetForObject
import org.apache.flink.types.Row; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private <X> TypeInformation<X> privateGetForObject(X value) {
checkNotNull(value);
// check if type information can be produced using a factory
final ArrayList<Type> typeHierarchy = new ArrayList<>();
typeHierarchy.add(value.getClass());
final TypeInformation<X> typeFromFactory = createTypeInfoFromFactory(value.getClass(), typeHierarchy, null, null);
if (typeFromFactory != null) {
return typeFromFactory;
}
// check if we can extract the types from tuples, otherwise work with the class
if (value instanceof Tuple) {
Tuple t = (Tuple) value;
int numFields = t.getArity();
if(numFields != countFieldsInClass(value.getClass())) {
// not a tuple since it has more fields.
return analyzePojo((Class<X>) value.getClass(), new ArrayList<Type>(), null, null, null); // we immediately call analyze Pojo here, because
// there is currently no other type that can handle such a class.
}
TypeInformation<?>[] infos = new TypeInformation[numFields];
for (int i = 0; i < numFields; i++) {
Object field = t.getField(i);
if (field == null) {
throw new InvalidTypesException("Automatic type extraction is not possible on candidates with null values. "
+ "Please specify the types directly.");
}
infos[i] = privateGetForObject(field);
}
return new TupleTypeInfo(value.getClass(), infos);
}
else if (value instanceof Row) {
Row row = (Row) value;
int arity = row.getArity();
for (int i = 0; i < arity; i++) {
if (row.getField(i) == null) {
LOG.warn("Cannot extract type of Row field, because of Row field[" + i + "] is null. " +
"Should define RowTypeInfo explicitly.");
return privateGetForClass((Class<X>) value.getClass(), new ArrayList<Type>());
}
}
TypeInformation<?>[] typeArray = new TypeInformation<?>[arity];
for (int i = 0; i < arity; i++) {
typeArray[i] = TypeExtractor.getForObject(row.getField(i));
}
return (TypeInformation<X>) new RowTypeInfo(typeArray);
}
else {
return privateGetForClass((Class<X>) value.getClass(), new ArrayList<Type>());
}
}