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


Java Tuple.getStreamSchema方法代码示例

本文整理汇总了Java中com.ibm.streams.operator.Tuple.getStreamSchema方法的典型用法代码示例。如果您正苦于以下问题:Java Tuple.getStreamSchema方法的具体用法?Java Tuple.getStreamSchema怎么用?Java Tuple.getStreamSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.ibm.streams.operator.Tuple的用法示例。


在下文中一共展示了Tuple.getStreamSchema方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertAttributeToAvro

import com.ibm.streams.operator.Tuple; //导入方法依赖的package包/类
private static Object convertAttributeToAvro(String attributeName, Object tupleAttribute, Type tupleAttributeType,
		Schema avroSchema) {
	Object returnObject = null;
	MetaType metaType = tupleAttributeType.getMetaType();
	switch (metaType) {
	case BOOLEAN:
		returnObject = (Boolean) tupleAttribute;
		break;
	case FLOAT32:
		returnObject = (Float) tupleAttribute;
		break;
	case FLOAT64:
		returnObject = (Double) tupleAttribute;
		break;
	case INT32:
		returnObject = (Integer) tupleAttribute;
		break;
	case INT64:
		returnObject = (Long) tupleAttribute;
		break;
	case RSTRING:
		returnObject = ((RString) tupleAttribute).getString();
		break;
	case USTRING:
		returnObject = tupleAttribute.toString();
		break;
	case TUPLE:
		Tuple subTuple = (Tuple) tupleAttribute;
		StreamSchema subStreamSchema = subTuple.getStreamSchema();
		GenericRecord subDatum = convertTupleToAvro(subTuple, subStreamSchema, avroSchema);
		// Return the Avro record
		returnObject = subDatum;
		break;
	case LIST:
		@SuppressWarnings("unchecked")
		List<Object> subList = (List<Object>) tupleAttribute;
		// Obtain the type of the elements contained in the Streams list
		Type tupleElementType = ((CollectionType) tupleAttributeType).getElementType();
		// Obtain the type of the elements contained in the Avro array
		Schema avroArrayElementType = avroSchema.getElementType();
		// Now loop through all list elements and populate the associated
		// Avro array elements
		GenericArray<Object> subArray = new GenericData.Array<Object>(subList.size(), avroSchema);
		for (Object arrayElement : subList) {
			Object avroElement = convertAttributeToAvro(attributeName, arrayElement, tupleElementType,
					avroArrayElementType);
			subArray.add(avroElement);
		}
		// Return the Avro array
		returnObject = subArray;
		break;
	default:
		LOGGER.log(TraceLevel.WARN,
				"Ignoring attribute " + attributeName + " because of unsupported type " + metaType);
	}
	return returnObject;
}
 
开发者ID:IBMStreams,项目名称:streamsx.avro,代码行数:58,代码来源:TupleToAvroConverter.java


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