Join (query directive)

From WandoraWiki
Jump to: navigation, search

Contents

Description

Joins the results of inner directives by performing a cartesian product on the results of them.

Constructor

Join(Directive d1,Directive d2,...)

Notes

This directive is best used using the join method present in every directive. Calling A.join(B) will resolve to new Join(A,B). In many cases you do not need to refer to join specifically at all. Instead you may provide several directives to from method which will implicitly join them.

Joining these two result sets

#A #B
A1 B1
A2 B2
   
#C #D
C1 D1
C2 D2

Will result in this result set.

#A #B #C #D
A1 B1 C1 D1
A1 B1 C2 D2
A2 B2 C1 D1
A2 B2 C2 D2

Note that the number of rows returned by the join operation is the product of the number of rows in the joined results. If all joined results have a single row, the join operation will result in a single row.

Example

importPackage(org.wandora.query2);
importPackage(org.wandora.topicmap);
new Join(
  new Instances().as("#instance"),
  new Players(
    XTMPSI.SUPERCLASS_SUBCLASS,
    XTMPSI.SUBCLASS).whereInputIs(XTMPSI.SUPERCLASS)
).where("#instance","t=",XTMPSI.SUBCLASS)

Above example joins instances and subclasses of input. Typically the results of joins are filtered by comparing some values of the result rows. In this case only rows where the topics with roles "#instance" and XTMPSI.SUBCLASS are the same are selected (see Compare directive). Effectively this query finds out if any of the instances of the input topic are also subclasses of it.

Following example gets variant names of the input topic in various languages and joins the results.

importPackage(org.wandora.query2);
importPackage(org.wandora.topicmap);
new Join(
  new Variant(XTMPSI.DISPLAY,XTMPSI.getLang("en")).as("#en"),
  new Variant(XTMPSI.DISPLAY,XTMPSI.getLang("fi")).as("#fi"),
  new Variant(XTMPSI.DISPLAY,XTMPSI.getLang("se")).as("#se"),
  new Variant(XTMPSI.DISPLAY,XTMPSI.getLang("it")).as("#it")
)
Personal tools