KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Academy Issue with flip in Table Joins

  • Issue with flip in Table Joins

    Posted by mn_12 on July 8, 2023 at 12:00 am

    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.

    mn_12 replied 9 months, 3 weeks ago 2 Members · 2 Replies
  • 2 Replies
  • gyorokpeter-kx

    Member
    July 10, 2023 at 12:00 am

    This is hinted at in the docs of flip: the 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

    Member
    July 11, 2023 at 12:00 am

    Hi,

     

    Thanks for the clarification! I understand it now.

Log in to reply.