Skip to content

Overview

Relational operators take relations as input and produce relations as output.

CategoryOperatorDescriptionRubyTS
SelectionrestrictFilter tuples matching a predicate (aka where)
excludeFilter tuples NOT matching a predicate
matchingSemi join (where exists)
not_matchingInverse semi join (where not exists)
ProjectionprojectKeep specified attributes only
allbutRemove specified attributes
JoiningjoinNatural join on a join key
left_joinLeft join with optional default tuple
cross_productCross product (aka cross_join)
Set OperationsunionSet union
minusSet difference
intersectSet intersection
RenamingrenameRename some attributes
prefixAdd prefix to attribute names
suffixAdd suffix to attribute names
ExtensionextendAdd computed attributes
constantsAdd constant attributes
transformTransform attribute values
SummarizationsummarizeRelational summarization (group by + aggregate)
StructuringgroupCreate relation-valued attribute from attributes
ungroupFlatten relation-valued attributes
imageCreate relation-valued attribute from another relation
wrapWrap attributes into tuple-valued attribute
autowrapStructure a flat relation (e.g. split on _)
unwrapMerge tuple-valued attributes into parent tuple
PaginationpagePagination with explicit ordering

Non-relational operators take relations as input but produce other values (tuples, arrays, booleans, objects).

OperatorDescriptionRubyTS
oneExtract single tuple from relation
toArrayConvert relation to array (Ruby: to_a)
isEqualCheck set equality of two relations
yByXCreate mapping object from relation (Ruby: y_by_x)

Some examples for the individual operations available in Bmg use a version of the well-known Suppliers and Parts database. It contains the following four relations:

citycountry
LondonEngland
ParisFrance
AthensGreece
BrusselsBelgium
pidnamecolorweightcity
P1NutRed12.0London
P2BoltGreen17.0Paris
P3ScrewBlue17.0Oslo
P4ScrewRed14.0London
P5CamBlue12.0Paris
P6CogRed19.0London
sidnamestatuscity
S1Smith20London
S2Jones10Paris
S3Blake30Paris
S4Clark20London
S5Adams30Athens
sidpidqty
S1P1300
S1P2200
S1P3400
S1P4200
S1P5100
S1P6100
S2P1300
S2P2400
S3P2200
S4P2200
S4P4300
S4P5400

Here’s are some examples to illustrate what the relations represent:

  • Supplier S1 (Smith) supplies 6 different parts
  • There are 2 types of screw, one which weighs 17.0 and the other 14.0 (grams, let’s say)
  • There are 2 suppliers in London, 2 in Paris, and 1 in Athens
  • Supplier S4 (Clark) has 900 parts in stock, in total
  • For the part P5 (Cam), there are 500 items in stock in total, accross all suppliers

Our examples assume the four relations are referenced by variables by the same names: cities, parts, etc.

Get part numbers for all parts supplied by more than one supplier