本文整理汇总了Java中com.ibm.streams.operator.StreamSchema.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java StreamSchema.getAttribute方法的具体用法?Java StreamSchema.getAttribute怎么用?Java StreamSchema.getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.streams.operator.StreamSchema
的用法示例。
在下文中一共展示了StreamSchema.getAttribute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValidTupleToAvroMapping
import com.ibm.streams.operator.StreamSchema; //导入方法依赖的package包/类
public static boolean isValidTupleToAvroMapping(String tupleSchemaName, StreamSchema tupleSchema, Schema avroSchema)
throws Exception {
boolean validMapping = true;
LOGGER.log(TraceLevel.TRACE,
"Checking attributes in tuple schema " + tupleSchemaName + ": " + tupleSchema.getAttributeNames());
for (String attributeName : tupleSchema.getAttributeNames()) {
Attribute attribute = tupleSchema.getAttribute(attributeName);
Field avroField = avroSchema.getField(attributeName);
if (avroField != null)
validMapping = validMapping
& isValidAttributeToAvroMapping(attributeName, attribute.getType(), avroField.schema());
else
LOGGER.log(TraceLevel.INFO, "Attribute " + attributeName + " in schema " + tupleSchemaName
+ " does not have a corresponding field in the Avro schema. It will not be mapped.");
}
return validMapping;
}
示例2: checkOutputAttributeRuntime
import com.ibm.streams.operator.StreamSchema; //导入方法依赖的package包/类
@ContextCheck(compile=false)
public static void checkOutputAttributeRuntime(OperatorContextChecker checker) {
OperatorContext context = checker.getOperatorContext();
StreamSchema schema = context.getStreamingOutputs().get(0).getStreamSchema();
Attribute resultAttribute = schema.getAttribute(ANALYSISRESULT_ATTRIBUTE);
//make sure that the output attribute is the right type based on the type of analysis
String type = context.getParameterValues("analysisType").get(0);
if(type.equals(AnalysisType.Prediction.name())) {
if( resultAttribute.getType().getMetaType() != MetaType.FLOAT64) {
tracer.log(TraceLevel.ERROR, "TRACE_M_WRONG_TYPE_ALS", new Object[]{"Prediction", "float64", resultAttribute.getType()});
checker.setInvalidContext();
}
}
else if(!isList(resultAttribute, Integer.class)) {
tracer.log(TraceLevel.ERROR, "TRACE_M_WRONG_TYPE_ALS", new Object[]{type, "list<int32>", resultAttribute.getType()});
checker.setInvalidContext();
}
}
示例3: checkControlPortInputAttribute
import com.ibm.streams.operator.StreamSchema; //导入方法依赖的package包/类
@ContextCheck
public static void checkControlPortInputAttribute(OperatorContextChecker checker) {
OperatorContext context = checker.getOperatorContext();
if(context.getNumberOfStreamingInputs() == 2) {
StreamSchema schema = context.getStreamingInputs().get(1).getStreamSchema();
//the first attribute must be of type rstring
Attribute jsonAttr = schema.getAttribute(0);
//check if the output attribute is present where the result will be stored
if(jsonAttr != null && jsonAttr.getType().getMetaType() != MetaType.RSTRING) {
tracer.log(TraceLevel.ERROR, "COMPILE_M_WRONG_TYPE", jsonAttr.getType());
checker.setInvalidContext();
}
}
}
示例4: checkOutputAttribute
import com.ibm.streams.operator.StreamSchema; //导入方法依赖的package包/类
/**
* Compile time to check to ensure that the output schema contains an attribute called
* 'analysisResult'. The type of the attribute depends on the specific type of the
* operator and is handled by the appropriate derived class.
*/
@ContextCheck
public static void checkOutputAttribute(OperatorContextChecker checker) {
OperatorContext context = checker.getOperatorContext();
if(context.getNumberOfStreamingOutputs() == 1) {
StreamSchema schema = context.getStreamingOutputs().get(0).getStreamSchema();
Attribute resultAttribute = schema.getAttribute(ANALYSISRESULT_ATTRIBUTE);
//check if the output attribute is present where the result will be stored
if(resultAttribute == null) {
tracer.log(TraceLevel.ERROR, "COMPILE_M_MISSING_ATTRIBUTE", new Object[]{ ANALYSISRESULT_ATTRIBUTE});
checker.setInvalidContext();
}
}
}
示例5: checkFileAttributeName
import com.ibm.streams.operator.StreamSchema; //导入方法依赖的package包/类
/**
* Check that the fileAttributeName parameter is an attribute of the right
* type.
*
* @param checker
*/
@ContextCheck(compile = false)
public static void checkFileAttributeName(OperatorContextChecker checker) {
StreamSchema inputSchema = checker.getOperatorContext()
.getStreamingInputs().get(0).getStreamSchema();
List<String> fileAttrNameList = checker.getOperatorContext()
.getParameterValues(IHdfsConstants.PARAM_FILE_NAME_ATTR);
if (fileAttrNameList == null || fileAttrNameList.size() == 0) {
// Nothing to check, because the parameter doesn't exist.
return;
}
String fileAttrName = fileAttrNameList.get(0);
Attribute fileAttr = inputSchema.getAttribute(fileAttrName);
if (fileAttr == null) {
checker.setInvalidContext(Messages.getString("HDFS_SINK_NO_ATTRIBUTE"),
new Object[] { fileAttrName });
}
if (MetaType.RSTRING != fileAttr.getType().getMetaType()
&& MetaType.USTRING != fileAttr.getType().getMetaType()) {
checker.setInvalidContext(
Messages.getString("HDFS_SINK_INVALID_ATTR_FILENAME", fileAttr.getType().getMetaType()),
new Object[] {});
}
}
示例6: convertTupleToAvro
import com.ibm.streams.operator.StreamSchema; //导入方法依赖的package包/类
public static GenericRecord convertTupleToAvro(Tuple tuple, StreamSchema streamSchema, Schema avroSchema) {
GenericRecord datum = new GenericData.Record(avroSchema);
for (String attributeName : streamSchema.getAttributeNames()) {
Attribute attribute = streamSchema.getAttribute(attributeName);
Object tupleAttribute = tuple.getObject(attributeName);
Field avroField = avroSchema.getField(attributeName);
// If there is an Avro field associated with this attribute, convert
if (avroField != null)
datum.put(attributeName,
convertAttributeToAvro(attributeName, tupleAttribute, attribute.getType(), avroField.schema()));
}
return datum;
}
示例7: checkOutputAttributeType
import com.ibm.streams.operator.StreamSchema; //导入方法依赖的package包/类
/**
* Check to ensure that an analysisResult attribute of type int32 is present on the output schema
*/
@ContextCheck
public static void checkOutputAttributeType(OperatorContextChecker checker) {
OperatorContext context = checker.getOperatorContext();
StreamSchema schema = context.getStreamingOutputs().get(0).getStreamSchema();
Attribute resultAttribute = schema.getAttribute(ANALYSISRESULT_ATTRIBUTE);
if(resultAttribute != null && resultAttribute.getType().getMetaType() != MetaType.INT32) {
tracer.log(TraceLevel.ERROR, "COMPILE_M_WRONG_TYPE_FULL", new Object[]{ANALYSISRESULT_ATTRIBUTE, "int32", resultAttribute.getType()});
checker.setInvalidContext();
}
}
示例8: checkOutputAttributeType
import com.ibm.streams.operator.StreamSchema; //导入方法依赖的package包/类
/**
* Check to ensure that an analysisResult attribute of type float64 is present on the output schema
*/
@ContextCheck
public static void checkOutputAttributeType(OperatorContextChecker checker) {
OperatorContext context = checker.getOperatorContext();
StreamSchema schema = context.getStreamingOutputs().get(0).getStreamSchema();
Attribute resultAttribute = schema.getAttribute(ANALYSISRESULT_ATTRIBUTE);
if(resultAttribute != null && resultAttribute.getType().getMetaType() != MetaType.FLOAT64) {
tracer.log(TraceLevel.ERROR, "COMPILE_M_WRONG_TYPE_FULL", new Object[]{ANALYSISRESULT_ATTRIBUTE, "float64", resultAttribute.getType()});
checker.setInvalidContext();
}
}
示例9: checkOutputAttributeType
import com.ibm.streams.operator.StreamSchema; //导入方法依赖的package包/类
@ContextCheck (compile = true)
public static void checkOutputAttributeType(OperatorContextChecker checker) {
OperatorContext context = checker.getOperatorContext();
StreamSchema schema = context.getStreamingOutputs().get(0).getStreamSchema();
Attribute resultAttribute = schema.getAttribute(ANALYSISRESULT_ATTRIBUTE);
if(resultAttribute != null && resultAttribute.getType().getMetaType() != MetaType.FLOAT64) {
tracer.log(TraceLevel.ERROR, "COMPILE_M_WRONG_TYPE_FULL", new Object[]{ANALYSISRESULT_ATTRIBUTE, "float64", resultAttribute.getType()});
checker.setInvalidContext();
}
}
示例10: initialize
import com.ibm.streams.operator.StreamSchema; //导入方法依赖的package包/类
/**
* Initialize this operator. Called once before any tuples are processed.
*
* @param operatorContext
* OperatorContext for this operator.
* @throws Exception
* Operator failure, will cause the enclosing PE to terminate.
*/
@Override
public synchronized void initialize(OperatorContext operatorContext) throws Exception {
// Must call super.initialize(context) to correctly setup an operator.
super.initialize(operatorContext);
LOGGER.log(TraceLevel.TRACE, "Operator " + operatorContext.getName() + " initializing in PE: "
+ operatorContext.getPE().getPEId() + " in Job: " + operatorContext.getPE().getJobId());
StreamSchema ssOp0 = getOutput(0).getStreamSchema();
StreamSchema ssIp0 = getInput(0).getStreamSchema();
// If no input Avro message blob attribute specified, use default
if (inputAvroMessage == null) {
if (ssIp0.getAttributeCount() == 1) {
inputAvroMessage = ssIp0.getAttribute(0).getName();
} else {
inputAvroMessage = DEFAULT_INPUT_AVRO_MSG_ATTRIBUTE;
}
}
LOGGER.log(TraceLevel.TRACE, "Input Avro message attribute: " + inputAvroMessage);
// If no Avro key attribute specified, check if optional attribute is
// available in the input tuple
if (inputAvroKey == null) {
if (ssIp0.getAttribute(DEFAULT_INPUT_AVRO_KEY_ATTRIBUTE) != null)
inputAvroKey = DEFAULT_INPUT_AVRO_KEY_ATTRIBUTE;
}
if (inputAvroKey != null)
LOGGER.log(TraceLevel.TRACE, "Input Avro key attribute: " + inputAvroKey);
// If no output JSON message attribute specified, use default
if (outputJsonMessage == null) {
if (ssOp0.getAttributeCount() == 1) {
outputJsonMessage = ssOp0.getAttribute(0).getName();
} else {
outputJsonMessage = DEFAULT_OUTPUT_JSON_MSG_ATTRIBUTE;
}
}
LOGGER.log(TraceLevel.TRACE, "Output JSON message attribute: " + outputJsonMessage);
// If no JSON key attribute specified, check if optional attribute is
// available in the output tuple
if (outputJsonKey == null) {
if (ssIp0.getAttribute(DEFAULT_OUTPUT_JSON_KEY_ATTRIBUTE) != null)
outputJsonKey = DEFAULT_OUTPUT_JSON_KEY_ATTRIBUTE;
}
if (outputJsonKey != null)
LOGGER.log(TraceLevel.TRACE, "Output JSON key attribute: " + outputJsonKey);
// Get the Avro message schema file to parse the Avro messages
if (!avroMessageSchemaFile.isEmpty()) {
LOGGER.log(TraceLevel.TRACE, "Retrieving and parsing Avro message schema file " + avroMessageSchemaFile);
InputStream avscMessageInput = new FileInputStream(avroMessageSchemaFile);
messageSchema = new Schema.Parser().parse(avscMessageInput);
}
// Get the Avro key schema file to parse the Avro messages
if (!avroKeySchemaFile.isEmpty()) {
LOGGER.log(TraceLevel.TRACE, "Retrieving and parsing Avro key schema file " + avroKeySchemaFile);
InputStream avscKeyInput = new FileInputStream(avroKeySchemaFile);
keySchema = new Schema.Parser().parse(avscKeyInput);
}
// If the schema is embedded in the message, the schema file must not be
// specified
if (avroSchemaEmbedded && !avroMessageSchemaFile.isEmpty())
throw new Exception(
"Parameter avroMessageSchema cannot be specified if the schema is embedded in the message.");
LOGGER.log(TraceLevel.TRACE, "AvroToJSON operator initialized, ready to receive tuples");
}