Search in sources :

Example 1 with TupleType

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]);
}
Also used : MetaType(com.ibm.streams.operator.Type.MetaType) OptionalType(com.ibm.streams.operator.meta.OptionalType) TupleType(com.ibm.streams.operator.meta.TupleType) Type(com.ibm.streams.operator.Type) Attribute(com.ibm.streams.operator.Attribute) DefaultAttribute(com.ibm.streams.operator.model.DefaultAttribute) TupleAttribute(com.ibm.streams.operator.TupleAttribute) OperatorContext(com.ibm.streams.operator.OperatorContext) TupleType(com.ibm.streams.operator.meta.TupleType) StreamSchema(com.ibm.streams.operator.StreamSchema) Checkpoint(com.ibm.streams.operator.state.Checkpoint) MetaType(com.ibm.streams.operator.Type.MetaType) ContextCheck(com.ibm.streams.operator.OperatorContext.ContextCheck)

Example 2 with TupleType

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;
}
Also used : Random(java.util.Random) TupleType(com.ibm.streams.operator.meta.TupleType) OutputTuple(com.ibm.streams.operator.OutputTuple) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple)

Aggregations

TupleType (com.ibm.streams.operator.meta.TupleType)2 Attribute (com.ibm.streams.operator.Attribute)1 OperatorContext (com.ibm.streams.operator.OperatorContext)1 ContextCheck (com.ibm.streams.operator.OperatorContext.ContextCheck)1 OutputTuple (com.ibm.streams.operator.OutputTuple)1 StreamSchema (com.ibm.streams.operator.StreamSchema)1 Tuple (com.ibm.streams.operator.Tuple)1 TupleAttribute (com.ibm.streams.operator.TupleAttribute)1 Type (com.ibm.streams.operator.Type)1 MetaType (com.ibm.streams.operator.Type.MetaType)1 OptionalType (com.ibm.streams.operator.meta.OptionalType)1 DefaultAttribute (com.ibm.streams.operator.model.DefaultAttribute)1 Checkpoint (com.ibm.streams.operator.state.Checkpoint)1 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)1 Random (java.util.Random)1