com.ibm.streams.operator

Interface StreamSchema

  • All Superinterfaces:
    java.lang.Iterable<Attribute>


    public interface StreamSchema
    extends java.lang.Iterable<Attribute>
    An immutable object representing the schema of a port or an attribute of type TUPLE. A StreamSchema consists of one or more ordered attributes, each with a name and a type. StreamSchema implements Iterable with the iteration returning the schema's attributes in attribute index order from zero to the last attribute.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      StreamSchema extend(java.lang.String languageType, java.lang.String name)
      Create an extension of this schema with an additional attribute.
      StreamSchema extend(Type type, java.lang.String name)
      Create an extension of this schema with an additional attribute.
      StreamSchema extendByAttributes(Attribute... attributes)
      Create an extension of this schema with additional attributes.
      StreamSchema extendBySchemas(StreamSchema... extension)
      Create an extension of this schema from another schema.
      Attribute getAttribute(int attributeIndex)
      Get the meta-data for the attribute at the given index.
      Attribute getAttribute(java.lang.String attributeName)
      Get the meta-data for the attribute at the given name.
      int getAttributeCount()
      Returns the number of attributes in this schema.
      int getAttributeIndex(java.lang.String attributeName)
      For a given attribute name, find its index.
      java.util.Set<java.lang.String> getAttributeNames()
      Return an unmodifiable set of attribute names in this schema.
      java.util.Comparator<Tuple> getAttributesComparator(boolean ascending, java.lang.String... attributeNames)
      Return a comparator for this schema ordering by a sub-set of the attributes.
      java.lang.String getLanguageType()
      Return the tuple definition for this schema.
      Tuple getTuple()
      Return a Tuple for this schema with all attributes set to the default value.
      Tuple getTuple(java.util.List<?> list)
      Return a Tuple for this schema with any attributes set from the supplied list by position.
      Tuple getTuple(java.util.Map<java.lang.String,?> map)
      Return a Tuple for this schema with any attributes set from the supplied map based upon the attribute name being the key in the map.
      Tuple getTuple(java.lang.Object[] array)
      Return a Tuple for this schema with any attributes set from the supplied array by position.
      Tuple getTuple(Tuple other)
      Return a Tuple for this schema with any matching attributes set from the supplied tuple.
      XML getXMLTupleType()
      Return the tuple definition for this schema as document containing the XML tuple type model.
      XML getXMLTupleType(java.lang.String namespacePrefix)
      Return the tuple definition for this schema as document containing the XML tuple type model using namespacePrefix as the prefix for elements.
      org.w3c.dom.Element getXMLTupleTypeElement(org.w3c.dom.Document doc, java.lang.String namespacePrefix)
      Return the tuple definition for this schema as an Element for the XML document doc The caller must add the returned Element as a child to an existing Node in the document.
      java.util.Iterator<Attribute> iterator()
      Returns an iterator of the attributes in this schema.
      CharacterEncoding newCharacterEncoding()
      Create a CharacterEncoding instance that implements SPL character encoding for this schema.
      BinaryEncoding newNativeBinaryEncoding()
      Create a BinaryEncoding instance that implements SPL non-NBF, native binary encoding.
      StreamSchema remove(java.lang.String... names)
      Create a schema that is a based upon this schema with the named attributes removed.
    • Method Detail

      • getAttribute

        Attribute getAttribute(int attributeIndex)
        Get the meta-data for the attribute at the given index. The zero-based index corresponds to the order in the application source.
        Parameters:
        attributeIndex - Zero-based index of the attribute.
        Returns:
        The attribute in the schema with index attributeIndex.
      • getAttribute

        Attribute getAttribute(java.lang.String attributeName)
        Get the meta-data for the attribute at the given name.
        Parameters:
        attributeName - Name of the attribute.
        Returns:
        The attribute in the schema with name attributeName or null if no such attribute exists.
      • getAttributeIndex

        int getAttributeIndex(java.lang.String attributeName)
        For a given attribute name, find its index.
        Returns:
        The index (zero-based) of the attribute with name attributeName or -1 if no such attribute exists.
      • getAttributeCount

        int getAttributeCount()
        Returns the number of attributes in this schema.
        Returns:
        number of attributes in this schema.
      • iterator

        java.util.Iterator<Attribute> iterator()
        Returns an iterator of the attributes in this schema.
        Specified by:
        iterator in interface java.lang.Iterable<Attribute>
        Returns:
        an iterator of the attributes in this schema.
      • getTuple

        Tuple getTuple()
        Return a Tuple for this schema with all attributes set to the default value.
      • getTuple

        Tuple getTuple(Tuple other)
        Return a Tuple for this schema with any matching attributes set from the supplied tuple. Any non-matched attributes for this schema will be set to the default value. Attributes match if their name and type are equal, regardless of index within the schemas.
        Parameters:
        other - Tuple to assign values from.
        Returns:
        Tuple set from the passed in tuple.
        See Also:
        OutputTuple.assign(Tuple)
      • getTuple

        Tuple getTuple(java.util.Map<java.lang.String,?> map)
        Return a Tuple for this schema with any attributes set from the supplied map based upon the attribute name being the key in the map. Any attributes not contained in map will be set to the default value.
        Parameters:
        map - Map to set values from.
        Returns:
        Tuple set from the map.
      • getTuple

        Tuple getTuple(java.util.List<?> list)
        Return a Tuple for this schema with any attributes set from the supplied list by position. If the size of the list is smaller than the number of attributes in this schema then any remaining attributes will be set to the default value.
        Parameters:
        list - List to set values from.
        Returns:
        Tuple set from the list.
      • getTuple

        Tuple getTuple(java.lang.Object[] array)
        Return a Tuple for this schema with any attributes set from the supplied array by position. If the size of the array is smaller than the number of attributes in this schema then any remaining attributes will be set to the default value.
        Parameters:
        array - Array to set values from.
        Returns:
        Tuple set from the array.
      • getAttributesComparator

        java.util.Comparator<Tuple> getAttributesComparator(boolean ascending,
                                                          java.lang.String... attributeNames)
        Return a comparator for this schema ordering by a sub-set of the attributes. Each attribute that is to be ordered must have an object type that implements Comparator.
        Parameters:
        ascending - True if the comparator is to order from low to high, false for high to low.
        attributeNames - Names of attributes to be included in the ordering. If no names are supplied then the ordering will be across all attributes that are comparable.
        Returns:
        A comparator for tuples of this schema.
        See Also:
        Attribute.getType(), Type.getObjectType()
      • newNativeBinaryEncoding

        BinaryEncoding newNativeBinaryEncoding()
        Create a BinaryEncoding instance that implements SPL non-NBF, native binary encoding. This binary encoding is described in the SPL Binary Encoding section of the SPL Compiler Usage Reference.
        Native byte order is defined by java.nio.ByteOrder.nativeOrder(). The returned BinaryEncoding instance will always call ByteBuffer.order(ByteOrder.nativeOrder()) on the supplied buffer before encoding or decoding tuples .

        The byte representation of encoded tuples is compatible with the encoding provided by the C++ SPL Operator API SPL::Tuple functions serialize(NativeByteBuffer) and deserialize(NativeByteBuffer).
        The byte representation of encoded tuples is not compatible with standard Java serialization.

        Returns:
        A new BinaryEncoding instance for native byte encoding.
        Since:
        InfoSphere® Streams Version 3.0
      • getLanguageType

        java.lang.String getLanguageType()
        Return the tuple definition for this schema.
        Returns:
        The SPL tuple type definition for this schema.
        Since:
        InfoSphere® Streams Version 3.0
      • getXMLTupleType

        XML getXMLTupleType()
        Return the tuple definition for this schema as document containing the XML tuple type model. The tuple type model XML schema definition is in $STREAMS_INSTALL/etc/xsd/SPL/tupleTypeModel.xsd.
        Returns:
        An XML document with a tuple root element representing this tuple schema.
        Since:
        InfoSphere® Streams Version 3.0
      • getXMLTupleType

        XML getXMLTupleType(java.lang.String namespacePrefix)
        Return the tuple definition for this schema as document containing the XML tuple type model using namespacePrefix as the prefix for elements. The tuple type model XML schema definition is in $STREAMS_INSTALL/etc/xsd/SPL/tupleTypeModel.xsd.
        Parameters:
        namespacePrefix - Namespace prefix for elements representing the schema, if null then no prefix is used.
        Returns:
        An XML document with a tuple root element representing this tuple schema.
        Since:
        InfoSphere® Streams Version 3.0
      • getXMLTupleTypeElement

        org.w3c.dom.Element getXMLTupleTypeElement(org.w3c.dom.Document doc,
                                                 java.lang.String namespacePrefix)
        Return the tuple definition for this schema as an Element for the XML document doc The caller must add the returned Element as a child to an existing Node in the document. element. The tuple type model XML schema definition is in $STREAMS_INSTALL/etc/xsd/SPL/tupleTypeModel.xsd.
        Parameters:
        doc - XML document the tuple
        namespacePrefix - Namespace prefix for elements representing the schema, if null then no prefix is used.
        Returns:
        An Element representing this tuple schema.
        Since:
        InfoSphere® Streams Version 3.0
      • getAttributeNames

        java.util.Set<java.lang.String> getAttributeNames()
        Return an unmodifiable set of attribute names in this schema.
        Returns:
        The set of attribute names in this schema
        Since:
        InfoSphere® Streams Version 3.2
      • extendBySchemas

        StreamSchema extendBySchemas(StreamSchema... extension)
        Create an extension of this schema from another schema. A new schema is created taking all attributes from this schema, and then extending it with attributes from extension. If extension has an attribute with the same name and type as this schema, the resulting schema contains that attribute just once, in the position of its left-most occurrence. It is an error for extension to have attributes with the same name but different types.
        Parameters:
        extension - Schemas to extend this schema with.
        Returns:
        The extended schema
        Since:
        InfoSphere® Streams Version 3.2
        See Also:
        Extend by a number of attributes, Extend by a single attribute, Extend by a single attribute, Remove attributes
      • extendByAttributes

        StreamSchema extendByAttributes(Attribute... attributes)
        Create an extension of this schema with additional attributes. If attributes has an attribute with the same name and type as this schema or contains multiple identical attributes, the resulting schema contains that attribute just once, in the position of its left-most occurrence. It is an error for extension to have attributes with the same name but different types.
        Parameters:
        attributes - Attributes to extend this schema with.
        Returns:
        The extended schema.
        Since:
        InfoSphere® Streams Version 3.2
        See Also:
        extendBySchemas(StreamSchema...)
      • extend

        StreamSchema extend(Type type,
                          java.lang.String name)
        Create an extension of this schema with an additional attribute. If this schema already contains an attribute matching type and name then no extension is performed and this is returned. It is an error for extension to have attributes with the same name but different types.
        Parameters:
        type - Type of the attribute
        name - Name of the attribute to be added
        Returns:
        The extended schema.
        Since:
        InfoSphere® Streams Version 3.2
        See Also:
        extendBySchemas(StreamSchema...)
      • extend

        StreamSchema extend(java.lang.String languageType,
                          java.lang.String name)
        Create an extension of this schema with an additional attribute. If this schema already contains an attribute matching metaType and name then no extension is performed and this is returned. It is an error for extension to have attributes with the same name but different types.
        Parameters:
        languageType - Type of the attribute
        name - Name of the attribute to be added
        Returns:
        The extended schema.
        Since:
        InfoSphere® Streams Version 3.2
        See Also:
        extendBySchemas(StreamSchema...)
      • remove

        StreamSchema remove(java.lang.String... names)
        Create a schema that is a based upon this schema with the named attributes removed. Any attribute with its name in names will be removed. If names contains values that do not match attribute names that those values are ignored. If no attributes are removed then this is returned.
        Parameters:
        names - Names of attributes to be removed
        Returns:
        Schema without any attributes named in names
        Throws:
        java.lang.IllegalArgumentException - names includes all attribute names in this schema.
        Since:
        InfoSphere® Streams Version 3.2
        See Also:
        Extending schemas
      • newCharacterEncoding

        CharacterEncoding newCharacterEncoding()
        Create a CharacterEncoding instance that implements SPL character encoding for this schema. This character encoding is described in the SPL Character Encoding section of the Compiling Streams Application documentation.

        The character representation of encoded tuples is compatible with the encoding provided by the C++ SPL Operator API SPL::Tuple functions serialize(std::ostream) and deserialize(std::istream).

        Returns:
        A new CharacterEncoding instance for SPL character encoding.
        Since:
        InfoSphere® Streams Version 4.0