

eohara
Forum Replies Created
-
9. Queries q-sql – Q for Mortals (kx.com)
“Unlike in SQL, columns in the Select phrase do not actually exist until the final result table is returned. Thus a computed column cannot be used in other column expressions.”
You’ll need two different select statements here, e.g.
select (total+5)%total from select total:a+b from t
-
-
Could you try running this in command line, then starting a new q session?
export PATH="/usr/bin/anaconda3/bin:$PATH"
-
Are you missing something on the left hand side of your = sign?
Also, could you provide a few example rows of the table you’re working with? Thanks
-
eohara
MemberApril 14, 2022 at 12:00 am in reply to: Why does this work: value each {x+y+z}[1;;],’enlist (2;enlist 3)Might be best to deal with this in pieces
q)(2;3)
2 3
q)(2;enlist 3)
2
,3Here, the enlist is to prevent 2 and 3 concatenating into a simple list of longs.
The difference in the final output is an extra level of enlisting:
q)value each{x+y+z}[1;;],’enlist(2;3)
,6
q)value each{x+y+z}[1;;],’enlist(2;enlist 3)
6
q)type value each{x+y+z}[1;;],’enlist(2;enlist 3)
0h
q)type value each{x+y+z}[1;;],’enlist(2;3)
7hWhy the other enlist?
q){x+y+z}[1;;],'(2;enlist 3)
{x+y+z}[1;;] 2
{x+y+z}[1;;] 3
q){x+y+z}[1;;],’enlist(2;enlist 3)
{x+y+z}[1;;] 2 ,3In the first example, each element of the right-hand list (2 and ,3) is joined to the projection, which results in two projections being returned.
With the enlist, the right-hand side is now a one-element list (the element being (2;,3)). This is joined to the projection. -
-
the .z namespace | Reference | kdb+ and q documentation – Kdb+ and q documentation (kx.com) end of this section:
When kdb+ has completed executing a script passed as a command-line argument, and if there are no open sockets nor a console, kdb+ will exit. The timer alone is not enough to stop the process exiting it must have an event source which is a file descriptor (socket, console, or some plugin registering a file descriptor and callback via the C API
sd1
function). -
eohara
MemberApril 1, 2022 at 12:00 am in reply to: Q 4.0 can’t have space in command line argumentMy earlier version of 4.0 handles it differently
ubuntu@LPTP630:~$ q -args '12 34' KDB+ 4.0 2020.05.04 Copyright (C) 1993-2020 Kx Systems l64/ 8()core 12649MB ubuntu lptp630 127.0.1.1 EXPIRE 2022.09.16 #########@#####.com KXCE #____ q).z.x "-args" "12 34" q).Q.opt .z.x args| "12 34"
-
eohara
MemberMarch 23, 2022 at 12:00 am in reply to: How to write data into table from python to kdb+ on Refinery?Hi Ori,
In my experience UDFs are used for reads, not writes. Your problem sounds more suited to PyKX. With that you can convert your python data into kdb+, and publish to the Refinery TP (see Refinery architecture diagram Architecture (kx.com), your python process(es) act as feedhandlers).
Thanks,
Eoghan
-
eohara
MemberFebruary 24, 2022 at 12:00 am in reply to: Can i use hourly and daily partitions together?– Can i use hourly and daily partitions together?
Not in the same HDB, see here:
14. Introduction to Kdb+ – Q for Mortals (kx.com)
If you are looking to change from hourly to daily partitions, you could move your older partitions to a separate database and merge them into dates. You would then have to query this database separately. Or you can look at converting all of your existing database into daily partitions
-
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