本文整理汇总了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;
}