Home › Forums › kdb+ › How can i understand the code below › Re: How can i understand the code below
-
Hi,
The : in :@ is an explicit return (see Function notation Basics kdb+ and q documentation – Kdb+ and q documentation (kx.com)).
The @ is an amend operator (see Amend, Amend At Reference kdb+ and q documentation – Kdb+ and q documentation (kx.com)).
`p# is the parted attribute (see Tables | Q For Mortals | A textbook forkdb+ and the q programming language – Q for Mortals (kx.com)).
` is the first argument of sv here as we wish to build a filepath to a splayed table (see sv scalar from vector | Reference | kdb+ and q documentation – Kdb+ and q documentation (kx.com)).
To bring that altogether, what is happening in your function is:
- get table
- This returns the table data for the given table name
- .Q.en[tabPath] get table
- This enumerates the output of 1) against a sym file in “tabPath”, and returns the enumerated table
- (` sv (tabPath; ` ; table; ` ) ) set .Q.en[tabPath] get table
- Writes the table from 2) to the filepath, and returns the filepath if successful e.g. if tabPath is `:/home/kx/db and table is `trade, then (` sv (tabPath; ` ; table; ` ) ) will return `:/home/kx/db/trade/
- The trailing slash after trade means the table will be saved splayed
- Writes the table from 2) to the filepath, and returns the filepath if successful e.g. if tabPath is `:/home/kx/db and table is `trade, then (` sv (tabPath; ` ; table; ` ) ) will return `:/home/kx/db/trade/
- pvar xasc (` sv (tabPath; ` ; table; ` ) ) set .Q.en[tabPath] get table
- Sorts the written table in 3) on the column in the pvar variable
- :@[;pvar; `p#] pvar xasc (` sv (tabPath; ` ; table; ` ) ) set .Q.en[tabPath] get table
- Amends the sorted table on disk, adding a parted attribute to the column in the pvar variable
- get table