KX Community

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

Home Forums kdb+ What is the need of a flip of splay or partitioned table ?

  • megan_mcp

    Administrator
    June 11, 2024 at 1:15 pm

    Hi @newstudent2017

    This operation is used internally by kdb+ to represent the flip of a memory-mapped splayed table. When loading a database with \l, the tables in the database are added to the root namespace using this operation.

    x!y ![x;y]

    The result must be flipped in order to use it as a table. After doing that, select statements will operate on the on-disk table. Many operations (including certain overloads of select) will throw a par error when used on this table.

    Examples:

    q):db/t/ set ([]a:1 2)<br>:db/t/
    q)\l db
    q).Q.s1 t
    "+(,a)!:./t/"

    It is possible to manually create this representation:

    q)enlist[a]!:./t/
    (,a)!:./t/
    q)flip enlist[a]!:./t/
    a
    -
    1
    2

    The equivalent for a partitioned table:

    q):db/2001.01.01/t/ set ([]a:1 2)<br>:db/2001.01.01/t/
    q):db/2001.01.02/t/ set ([]a:3 4)<br>:db/2001.01.02/t/
    q)\l db
    q).Q.s1 t
    "+(,a)!t"
    q)enlist[a]!t
    (,a)!t
    q)flip enlist[a]!t
    date a
    ------------
    2001.01.01 1
    2001.01.01 2
    2001.01.02 3
    2001.01.02 4

    If the specified table does not exist on disk, the expression remains unresolved and any attempt to select from it fails:

    q)flip enlist[a]!:./s/
    +(,a)!:./s/
    q)select from flip enlist[a]!:./s/
    './s/a. OS reports: No such file or directory
    [0] select from flip enlist[a]!:./s/
    q)flip enlist[a]!s
    +(,a)!s
    q)select from flip enlist[a]!s
    's
    [0] select from flip enlist[a]!s
    ^

    We are adjusting our documentation to make this clearer in future.

    If you have any further questions, please let me know!

    Thanks,

    Megan

Log in to reply.