rocuinneagain
Forum Replies Created
-
rocuinneagain
MemberMay 24, 2022 at 12:00 am in reply to: What is the role played by key columns in a keyed table [ query join/performance ] ?You can see the speed improvement if you index rather than query using qsql:
q)select from t1 where Name=`Anand Name Age Salary ---------------- Anand 10 1000 q)select from t2 where Name=`Anand Name | Age Salary -----| ---------- Anand| 10 1000 q)t2`Anand Age | 10 Salary| 1000 q)\ts do[100000;select from t1 where Name=`Anand] 164 1808 q)\ts do[100000;select from t2 where Name=`Anand] 174 1808 q)\ts do[100000;t2`Anand] 71 960
-
rocuinneagain
MemberMay 24, 2022 at 12:00 am in reply to: What is the role played by key columns in a keyed table [ query join/performance ] ?For optimisations in qsql queries you should look to attributes.
Here applying the unique attribute to the Name column:
q)t3:update `u#Name from t1 q)\ts do[100000;select from t3 where Name=`Anand] 64 1808
-
This becomes easier by splitting the problem in 2 parts.
- Finding the indexes where needed number of 1b is hit
- Finding the indexes where needed number of 0b is hit
These are the only indexes that matter. Then a prototype list can be populated with nulls before having the important indexes overlaid. Then the prevailing values are carried forward by fills.
q)f:{o:count[z]#0N;o:@[o;where x=x msum z;:;1];y:y+1;"b"$0^fills @[o;where y=y msum not z;:;0]} q)f[3;2] 00001111000111001101000b 00000011110001111111110b q)f[3;2] 110010111001111b 000000001111111b
-
Is the
/
for ofdo
what you are looking for?https://code.kx.com/q/ref/accumulators/#do
q)750 +/2 2 754
-
Something more like:
q)750{(x[0]+1;x[1]+x[2];x[2])}/0
0 2 750 1500 2
Or use a dictionary for readability:
q)750{x[`ID]+:1;x[`y]:sum x`y`z;x}/`ID`y`z!0 0 2
ID| 750
y | 1500
z | 2
-
Are you on Windows/Linux/Mac?
Esc
works in Windows (PowerShell + CMD)- In Linux (Bash)
Ctrl
+E
,Ctrl
+U
https://stackoverflow.com/a/16687377/4256419
On Linux/Mac rlwrap is suggested.
-
rocuinneagain
MemberMay 5, 2022 at 12:00 am in reply to: Creating q code block with syntax highlighting in a messageInstructions now also added for adding inline code to your questions & messages.
-
rocuinneagain
MemberApril 29, 2022 at 12:00 am in reply to: [checkHost.sh] Failed error when installing Platform on Ubuntu 20.04https://code.kx.com/platform/deployment/lin_prerequisites/#host-configuration
Kdb+ licenses (
k4.lic
) are tied to the hostname of a machine and specifically the hostname in FQDN (<HOSTNAME>.<DOMAINNAME>
) format.The installer expects the hostname to be the the required FQDN format .i.e
server1.company.com
-
rocuinneagain
MemberApril 29, 2022 at 12:00 am in reply to: Question about query that stuck the KDB processhttps://code.kx.com/q4m3/6_Functions/#677-more-over-iteration
The final overload of
/
is equivalent to a while loop in imperative programming. It provides a declarative way to specify a test to end the iteration. Thinking functionally, we provide a predicate function that is applied to the result at each step. The iteration continues as long as the predicate result is1b
and stops otherwise. For example, we stop the computation of the Fibonacci sequence once it exceeds 1000 as follows.q)fib:{x,sum -2#x} q)fib/[{1000>last x}; 1 1] 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
Your code accidentally boiled down to an infinite loop as the result never moves to 0b
1 1/[sums;1]
/Each iteration it runs 1 1[1] / Which returns 1 /Then sums 1 /This returns 1 /This is a non zero value which gets treated as 1b so the loop starts again /Infinite loop
-
rocuinneagain
MemberApril 29, 2022 at 12:00 am in reply to: Question about query that stuck the KDB processUsing parse helps to see what is happening.
Parsing a simplified version of your query helped to show the order of execution in the parse tree:
q)-1 .Q.s1 last value last parse "select sums(size)/sum(size) from tab"; ((/;`size);+;(sum;`size))
The q equivalent can then be shown to have the same parse tree
q)-1 .Q.s1 parse"size/[sums;sum size]"; ((/;`size);+;(sum;`size))
-
rocuinneagain
MemberApril 22, 2022 at 12:00 am in reply to: Insert a not matching dictionary to a tableq){k:key y;x upsert enlist (k where k in cols x)#y}[x;td2] a b c ------- 1 I 10 2 J 20 3 K 30 99 a
-
rocuinneagain
MemberApril 17, 2022 at 12:00 am in reply to: Putting CSV data into a chart & other questionsThis is likely close to how qsql would be used based on your example
//Read CSV and store in memory table myCSV:("PFFFFF";enlist csv) 0: `$":/q/spy.csv" //Only retain lines where Line and close do not equal 0 myCSV:select from myCSV where Line<>0, close<>0 //Add deltas other extra columns myCSV:update dc:deltas Line, dclose:deltas close, dc2:1+til count i, dclose2:1+til count i from myCSV //Display the table myCSV
If you run those lines in Developer then you can use
myCSV
in your Dashboard widget to display it as the data is stored in an in memory table.set stores data in kdb+ binary files (not human readable).
If you wish to save as CSV either of these should work for you:
`:myCSV.csv 0: csv 0: myCSV save `myCSV.csv
-
rocuinneagain
MemberApril 17, 2022 at 12:00 am in reply to: apply the function, pass the return value to the function again, multiple roundsYou can so this using over
q)tab:([] A:1 2 3;B:4 5 6;C:7 8 9) // Sample table q)tab A B C ----- 1 4 7 2 5 8 3 6 9 q)func:{![x;();0b;enlist[y]!enlist (+;y;1)]} //Function I want to run q)func[tab;`A] // Same as: update A:A+1 from tab A B C ----- 2 4 7 3 5 8 4 6 9 q)func over enlist[tab],`A`B`C // Using over accumulator A B C ------ 2 5 8 3 6 9 4 7 10
-
-
Another Github user recently created a new Go interface: jshinonome/geek: golang interface for kdb+/q (github.com)