use of com.ibm.streams.operator.meta.OptionalType in project streamsx.kafka by IBMStreams.
the class AbstractKafkaProducerOperator method checkErrorPortSchema.
@ContextCheck(compile = true)
public static void checkErrorPortSchema(OperatorContextChecker checker) {
final OperatorContext opCtx = checker.getOperatorContext();
final int nOPorts = opCtx.getNumberOfStreamingOutputs();
if (nOPorts == 0)
return;
StreamSchema inPortSchema = opCtx.getStreamingInputs().get(0).getStreamSchema();
StreamSchema outSchema = opCtx.getStreamingOutputs().get(0).getStreamSchema();
if (outSchema.getAttributeCount() > 2) {
// $NON-NLS-1$
checker.setInvalidContext(Messages.getString("PRODUCER_INVALID_OPORT_SCHEMA", opCtx.getKind()), new Object[0]);
}
// check attribute types
int nTupleAttrs = 0;
int nStringAttrs = 0;
for (String outAttrName : outSchema.getAttributeNames()) {
Attribute attr = outSchema.getAttribute(outAttrName);
Type attrType = attr.getType();
MetaType metaType = attrType.getMetaType();
switch(metaType) {
case TUPLE:
++nTupleAttrs;
TupleType tupleType = (TupleType) attr.getType();
StreamSchema tupleSchema = tupleType.getTupleSchema();
if (!tupleSchema.equals(inPortSchema)) {
// $NON-NLS-1$
checker.setInvalidContext(Messages.getString("PRODUCER_INVALID_OPORT_SCHEMA", opCtx.getKind()), new Object[0]);
}
break;
case RSTRING:
case USTRING:
++nStringAttrs;
break;
case OPTIONAL:
MetaType optionalValueMeta = ((OptionalType) attrType).getValueType().getMetaType();
switch(optionalValueMeta) {
case RSTRING:
case USTRING:
++nStringAttrs;
break;
default:
// $NON-NLS-1$
checker.setInvalidContext(Messages.getString("PRODUCER_INVALID_OPORT_SCHEMA", opCtx.getKind()), new Object[0]);
}
break;
default:
// $NON-NLS-1$
checker.setInvalidContext(Messages.getString("PRODUCER_INVALID_OPORT_SCHEMA", opCtx.getKind()), new Object[0]);
}
}
if (nTupleAttrs > 1 || nStringAttrs > 1)
// $NON-NLS-1$
checker.setInvalidContext(Messages.getString("PRODUCER_INVALID_OPORT_SCHEMA", opCtx.getKind()), new Object[0]);
}
Aggregations