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


Java Row.getArity方法代码示例

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

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

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

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

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

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

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

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


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