cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with flip in Table Joins

MN_12
New Contributor III

Hi,

 

I am learning about table joins for the first time and have been working through the Joins, Practical Guidance - Joins and Joins Exercises notebooks in the Fundamentals series.

 

I have not been able to figure out some things even after spending much time thinking about them.

 

In the Joins notebook:

t is:

name     iq 
------------
Harry    98 
Ron      42 
Hermione 126

meta t is:

c   | t f a
----| -----
name| s    
iq  | j 

It is stated that t,flip (`name`iq!(enlist `Bumble;59)) is:

name     iq 
------------
Harry    98 
Ron      42 
Hermione 126
Bumble   59 

meta t,flip (`name`iq!(enlist `Bumble;59)) is:

c   | t f a
----| -----
name| s    
iq  | j    

I am unable to figure out why there is no need for enlist 59 in flip (`name`iq!(enlist `Bumble;59)) i.e. flip (`name``iq!(enlist `Bumble;enlist 59)). From what I understand, in order to flip a dictionary into a table, the values must be lists of equal length (which I believe is the reason why t,flip (`name`iq!(`Bumble;59)) results in evaluation error: rank).

enlist `Bumble is a list but 59 is not.

(show dictOne:(`name`iq!(enlist `Bumble;59)) is:

name| ,`Bumble
iq  | 59

type each dictOne is:

name| 11
iq  | -7

)

 

I noticed that t,flip (`name`iq!( `Bumble;enlist 59)) also works as shown below. However, I am unable to figure out why there is no need for enlist `Bumble.

t,flip (`name`iq!( `Bumble;enlist 59)) is:

name     iq 
------------
Harry    98 
Ron      42 
Hermione 126
Bumble   59 

meta t,flip (`name`iq!( `Bumble;enlist 59)) is:

c   | t f a
----| -----
name| s    
iq  | j   

This time, enlist 59 is a list but `Bumble is not.

(show dictTwo:(`name`iq!(`Bumble;enlist 59)) is:

name| `Bumble
iq  | ,59

type each dictTwo is: 

name| -11
iq  | 7

)

 

From what I understand, there is a need for both enlist `Bumble and enlist 59 in the dictionary i.e. flip (`name``iq!(enlist `Bumble;enlist 59)). 

t,flip (`name``iq!(enlist `Bumble;enlist 59)) is:

name     iq 
------------
Harry    98 
Ron      42 
Hermione 126
Bumble   59 

meta t,flip (`name``iq!(enlist `Bumble;enlist 59)) is:

c   | t f a
----| -----
name| s    
iq  | j  

(show dictThree:(`name``iq!(enlist `Bumble;enlist 59)) is:

name| Bumble
iq  | 59  

type each dictThree is:

name| 11
iq  | 7

 )

 

I would greatly appreciate any assistance with this issue.

 

Thank you very much.

1 ACCEPTED SOLUTION

gyorokpeter-kx
Contributor
Contributor

This is hinted at in the docs of flipthe values are lists of the same count (or atoms). The "(or atoms)" part is relevant here. If any of the values are atoms, they are extended to the same length as the lists. Therefore it is enough to have only one value be a list and the rest can be atoms. But if there are multiple lists, they must have the same length.

View solution in original post

2 REPLIES 2

gyorokpeter-kx
Contributor
Contributor

This is hinted at in the docs of flipthe values are lists of the same count (or atoms). The "(or atoms)" part is relevant here. If any of the values are atoms, they are extended to the same length as the lists. Therefore it is enough to have only one value be a list and the rest can be atoms. But if there are multiple lists, they must have the same length.

MN_12
New Contributor III

Hi,

 

Thanks for the clarification! I understand it now.