use of com.ibm.streams.operator.meta.TupleType 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]);
}
use of com.ibm.streams.operator.meta.TupleType in project streamsx.topology by IBMStreams.
the class PythonFunctionalOperatorsTest method testTupleStream.
public static SPLStream testTupleStream(Topology topology, boolean withSets) {
TStream<Long> beacon = BeaconStreams.longBeacon(topology, TUPLE_COUNT);
SPLStream tuples = SPLStreams.convertStream(beacon, new BiFunction<Long, OutputTuple, OutputTuple>() {
private static final long serialVersionUID = 1L;
private transient TupleType type;
private transient Random rand;
@Override
public OutputTuple apply(Long v1, OutputTuple v2) {
if (type == null) {
type = Type.Factory.getTupleType(getPythonTypesSchema(withSets).getLanguageType());
rand = new Random();
}
Tuple randTuple = (Tuple) type.randomValue(rand);
v2.assign(randTuple);
return v2;
}
}, getPythonTypesSchema(withSets));
return tuples;
}
Aggregations