company logo

Set operations

Usually, the view source plays a role in traditional SELECT statements, only. Here an explicit source definition is required using the FROM clause.

        FROM(source)

In an operation path, usually the source collection is sufficient, i.e. the operation paths

        FROM(source).Where(..). ... and

        source.Where(..). ...

are identical, as long as the FROM operation refers to only one operand. The source operand might by a simple property name, but also an access path or an inline expression, i.e. any type of syntactic operand, that returns a collection.

Compared with traditional OQL/SQL statements, the source definition in an OSI access path provides a number of additional features. In general, each operation path can be referred to as source, but there are specific operations, that might be referred to as source in particular:

  • external files
  • union collections - result of Union operation
  • join collections - result of Join operations
  • intersect collections - result of Intersect operation
  • minus collections - result of Minus operation
  • product collection - result of From operation
External file source

The ExternExtent operation allows assigning different kinds of external files as source for an operation. External files usually do have an file location and a file definition (file and exchange scheme), which might be part of the file definition.

The ExternExtent operation differs slightly from the FromFile operation, which immediately imports the external file into the collection of the calling property (collection). The FromFile operation returns the calling property, i.e. the collection with the imported instances.

// access file

FileExtent( Path='c:/temp/my_persons.xml', FileType='xml',

            Definition='c:/temp/my_persons.def', Headline = false)

// import file

FromFile( Path='c:/temp/my_persons.xml', FileType='xml',

          Definition='c:/temp/my_persons.def', Headline = false)

Union operation

The union operation allows merging two collections. There are two ways of defining a union operation. Calling Union as

    A.Union(B)

Unites A with B and stores the result in A. Calling union, however, as

    Union(A,B)

Creates a new collection containing the union of A and B.

Minus operation

The minus operation removes instances in the second operand collection from the first operand collection. There are two ways of defining a minus operation. Calling Minus like

    A.Minus(B)

Creates the difference between A and B and stores the result in A. Calling minus, however, as

    Minus(A,B)

Creates a new collection containing the difference of A and B.

Intersect operation

The intersect operation creates a collection containing all instances from the first and from the second collection. Calling Intersect like

    A.intersect(B)

intersects A with B and stores the result in A. Calling Intersect, however, as

    Intersect(A,B)

creates a new collection containing the intersection of A and B.

Join operation

The join operation flattens a path, i.e. it creates an instance containing all collection instances participating in the path. The join operation requires a properties, which are elements of a property path as parameter, i.e. each operand must be a valid operation path for its predecessor.

In order to avoid naming conflicts, join operands can be assigned to target property names. Named parameters must also be used in order to assign expressions or access paths to a join operand. The result instance contains then one attribute instance for each parameter with the property name assigned in the parameter specification.

Passing other collection expressions as an access paths or an extent, the operation will return the collection passed to the operation without operating on it.

The result of a join operation contains all instances by iterating the property path. In the example below, the result contains all grand children, but each instance consists of a three person instances.

Join(Persons, childeren, grand_children=children)

Product operation

There is no specific product operation, but in order to create set products, the From operation can be used by passing any number of collections to the operation.

    From(Persons, Companies)

The product or FROM operation creates a collection that contains any possible combination of instances from its operands. It creates an instance containing all collection instances participating in the operation. Each operand in a From operation must be a valid operand in the context of the calling operand or a static expression.

In order to avoid naming conflicts, From operands can be assigned to target property names. Named parameters must also be used in order to assign expressions or access paths to a From operand. The result instance inherits then from all instances involved in the operation. In case of name ambiguity, you may refer to as instances similar as to embedded attributes since ODABA supports named base structures.

From( men = Person.Where(sex=='male'), woman=Person.Where(sex=='female'))