Hi everyone,Recently I started to learn KDB, and I saw some working codes asfollowinghCx:hopen `:eqkdb8p:12000hCx({select cnt:count i from corrTab};::)I tried to run them in q session and they work very well. The firstline is just to connect to KDB host. But the second line is veryconfusing. Especially corrTab is neither a q keyword nor a variable/table defined. Why it works and print outcnt-------9415683Can anyone help?Thanks
charset=us-ascii
X-Mailer: iPhone Mail (8F190)
In-Reply-To: <2195d485-eab1-469b-a976-05febf6114cf@x21g2000prd.googlegroups.com>
Message-Id: <23D30AB2-FA80-4B27-80DA-0E85D33B4C16@gmail.com>
Date: Fri, 2 Sep 2011 06:15:43 -0400
To: “personal-kdbplus@googlegroups.com”
Mime-Version: 1.0 (iPhone Mail 8F190)
For you to understand this you need to read the manuals or q for mortals. In=
particular the sections on ipc, data types (in this case lists) and functio=
ns.
In a nutshell it’s sending a function to the remote host which is simply exe=
cuting the query.
hCx ({select cnt:count i from corrTab};::)
is sending the list ({select cnt:count i from corrTab};::) to the socket referred to by hCx.
({select cnt:count i from corrTab};::)
is a 2 element list, a lambda (anonymous function) and identity (::).
It’s possible to evaluate a single level parse tree as
q)value ({x+y};2;3)
and that’s what is happening here, except ({select cnt:count i from corrTab};::) is being recompiled and evaluated remotely.
Presumably corrTab is defined on the remote system.
In this case, you are connecting to a different kdb process andsending an anonymous function {select cnt:count i from corrTab} andidentity to be executed in that process. So here corrTab is a tabledefined the q process running on eqkdb8p at port 12000. This isequivalent to executing this query on that remote process “selectcnt:count i from corrTab”. Hope this answers your question.Another way to do the same thing would behCx:hopen :eqkdb8p:12000hCx "select cnt:count i from corrTab"On Sep 2, 5:43?am, Wei Li <lavi...> wrote:> Hi everyone,> Recently I started to learn KDB, and I saw some working codes as> following>> hCx:hopen
:eqkdb8p:12000> hCx({select cnt:count i from corrTab};::)>> I tried to run them in q session and they work very well. The first> line is just to connect to KDB host. But the second line is very> confusing. Especially corrTab is neither a q keyword nor a variable/> table defined. Why it works and print out>> cnt> -------> 9415683>> Can anyone help?> Thanks</lavi…>
> Another way to do the same thing would be
>
>
> hCx:hopen `:eqkdb8p:12000
> hCx “select cnt:count i from corrTab”
slightly more precisely,
hCx “{select cnt:count i from corrTab}”
sending (::) as an arg is the equivalent of invoking with
–
Aaron Davies
aaron.davies@gmail.com
Thanks all for help.Now I understand it.On Sep 3, 1:44?am, Aaron Davies <aaron.dav…> wrote:> > Another way to do the same thing would be>> > hCx:hopen `:eqkdb8p:12000> > hCx “select cnt:count i from corrTab”>> slightly more precisely,>> hCx “{select cnt:count i from corrTab}”>> sending (::) as an arg is the equivalent of invoking with >> –> Aaron Davies> aaron.dav...@gmail.com</aaron.dav…>