J has relational namespace layout:
locales as tables and names as attributes.


NB. =========================================================

require 'strings'

cocurrent 'T1'

B=: s: ','cut'one,two,three,four,five,six,seven,eight'
C=: 100+(#B)[EMAIL PROTECTED] 5
E=: 'ab'{~(#B) [EMAIL PROTECTED] 2

cocurrent 'T2'

D=: s: ','cut'uno,dos,tres,cuatro,cinco,seis,siete,ocho'
C=: 100+(#D)[EMAIL PROTECTED] 5
E=: 'ab'{~($D) [EMAIL PROTECTED] 2

cocurrent 'base'

jndx=: (0 , [EMAIL PROTECTED]) #: [: I.@, =/
sel=: ,.@:{

0 : 0
B_T1_ (,[EMAIL PROTECTED];]) C_T1_ ;&,. E_T1_
C_T2_ (,[EMAIL PROTECTED];]) D_T2_ ;&,. E_T2_

]'j1 j2'=. |:C_T1_ jndx C_T2_
(j1 sel B_T1_);(j1 sel C_T1_);(j2 sel D_T2_)

]'j1 j2'=. |:(C_T1_ jndx C_T2_) (e.#[) E_T1_ jndx E_T2_
(j1 sel B_T1_);(j1 sel C_T1_);(j1 sel E_T1_);(j2 sel D_T2_)
)

NB. =========================================================

   B_T1_ (,[EMAIL PROTECTED];]) C_T1_ ;&,. E_T1_
+------+---+-+
|`one  |101|a|
|`two  |100|b|
|`three|104|b|
|`four |102|a|
|`five |104|a|
|`six  |104|b|
|`seven|100|a|
|`eight|102|b|
+------+---+-+
   C_T2_ (,[EMAIL PROTECTED];]) D_T2_ ;&,. E_T2_
+---+-------+-+
|101|`uno   |a|
|100|`dos   |b|
|104|`tres  |b|
|102|`cuatro|a|
|104|`cinco |a|
|104|`seis  |b|
|100|`siete |a|
|102|`ocho  |b|
+---+-------+-+
   
   ]'j1 j2'=. |:C_T1_ jndx C_T2_
0 1 1 2 2 2 3 3 4 4 4 5 5 5 6 6 7 7
0 1 6 2 4 5 3 7 2 4 5 2 4 5 1 6 3 7
   (j1 sel B_T1_);(j1 sel C_T1_);(j2 sel D_T2_)
+------+---+-------+
|`one  |101|`uno   |
|`two  |100|`dos   |
|`two  |100|`siete |
|`three|104|`tres  |
|`three|104|`cinco |
|`three|104|`seis  |
|`four |102|`cuatro|
|`four |102|`ocho  |
|`five |104|`tres  |
|`five |104|`cinco |
|`five |104|`seis  |
|`six  |104|`tres  |
|`six  |104|`cinco |
|`six  |104|`seis  |
|`seven|100|`dos   |
|`seven|100|`siete |
|`eight|102|`cuatro|
|`eight|102|`ocho  |
+------+---+-------+
   
   ]'j1 j2'=. |:(C_T1_ jndx C_T2_) (e.#[) E_T1_ jndx E_T2_
0 1 2 2 3 4 5 5 6 7
0 1 2 5 3 4 2 5 6 7
   (j1 sel B_T1_);(j1 sel C_T1_);(j1 sel E_T1_);(j2 sel D_T2_)
+------+---+-+-------+
|`one  |101|a|`uno   |
|`two  |100|b|`dos   |
|`three|104|b|`tres  |
|`three|104|b|`seis  |
|`four |102|a|`cuatro|
|`five |104|a|`cinco |
|`six  |104|b|`tres  |
|`six  |104|b|`seis  |
|`seven|100|a|`siete |
|`eight|102|b|`ocho  |
+------+---+-+-------+
   

--- "Miller, Raul D" <[EMAIL PROTECTED]> wrote:

> Here's an approach that better follows the pattern for join:
> 
> join1=:4 :0
>  bX=. (kX=. {."1 x) </. x
>  bY=. (kY=. {."1 y) </. y
>  j1=. (0 # {.)&.>
>  j2=. ([: ,/ ,"1/)&.>/
>  ;-.&a:,(kX,&~.kY) j2/[EMAIL PROTECTED](2>#)/.bX,bY
> )
> 
> For example:
>    ]'a b'=:<@~."2?.2 5 2$2 9
> +---+---+
> |1 8|0 1|
> |0 2|0 7|
> |1 2|0 2|
> |1 4|   |
> |0 3|   |
> +---+---+
>    a join1 b
> 0 2 0 1
> 0 2 0 7
> 0 2 0 2
> 0 3 0 1
> 0 3 0 7
> 0 3 0 2
> 
> Also, note that here I'm using the first column from both
> arguments as the key column.  If I wanted to parameterize
> that, I could use the m and n conjunction arguments to get
> the key columns.
> 
> Also, if I wanted to suppress the duplication of the key
> column in the result, that's straightforward to implement.
> 
> Finally, if I want a left outer join, I could supplement
> bX with "null values" (whatever they are) for the keys which
> are in Y but not in X.  Right outer join is similar, but
> I'd be modifying bY instead of bX.  And, of course, for a
> full outer join I'd modify both bX and bY.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to