Search in sources :

Example 1 with Type

use of com.ibm.streams.operator.Type 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)

Aggregations

Attribute (com.ibm.streams.operator.Attribute)1 OperatorContext (com.ibm.streams.operator.OperatorContext)1 ContextCheck (com.ibm.streams.operator.OperatorContext.ContextCheck)1 StreamSchema (com.ibm.streams.operator.StreamSchema)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 TupleType (com.ibm.streams.operator.meta.TupleType)1 DefaultAttribute (com.ibm.streams.operator.model.DefaultAttribute)1 Checkpoint (com.ibm.streams.operator.state.Checkpoint)1