Forum Replies Created

Page 4 of 4
  • Can you provide more details such as what you are trying to achieve and what the value of x is?

    A projection is created whenever there is an elided argument in the argument list, no matter what the argument list is being applied to. In fact this allows you to create projections that have no useful purpose such as f:{x}[;;2] which will always either return another projection or throw a ‘rank error.

  • This has to do with the behavior of the ‘ operator (which is each is a wrapper for).

    If we have p:.[;();:;] , p is a binary function, as it is a projection with two elided arguments. The ‘ operator modifies a function to go elementwise on its arguments – and the resulting function has the same arity as the original one. So p’ is also a binary function. Applying p’ to a single object (in this case a two-element list) only gives it one argument, the other is still missing, so the result is a projection.

    In fact each is a wrapper that only works with unary functions. You get the same behavior whenever you try to use each with a non-unary function on the left side. You can only make non-unary functions behave elementwise by directly using the apostrophe and passing the necessary number of arguments.

    If we add a dot after the projection: p2:.[;();:;] . , this changes the structure of the expression. The main operator is now the dot, and it is projected with the left argument p. Since the dot is a binary function, projecting it with one argument creates a unary function. Now you can use each with the unary function and a list. And then the dot will do what you would expect – invoke the function on the left (which is p) with the elements on the list on the right as arguments, and since we are iterating over the original list, those arguments will be a table name and an empty table. The original projection p is a fancy way of overwriting a variable. It would work just as well with set:

    .[set]each x

    has the same effect of assigning the empty table values to the respective tables.

     

  • gyorokpeter-kx

    Member
    February 20, 2023 at 12:00 am in reply to: How the sym file reads data from partition table?

    Why do you have  `$dbpath, “;” ? If dbpath is “db” then that would explain why you are seeing a “db;” directory.

    This way, the sym file from this operation is created in the “db;” directory, and the symbol indices in the table will point to this new sym file. You can’t swap in and out sym files with each other if there are existing symbol references to it, because then they will point to the wrong symbol. Instead you could load the “wrong” sym file, de-enumerate the symbol columns, and then call .Q.en again but this time with the correct database path.

  • gyorokpeter-kx

    Member
    February 17, 2023 at 12:00 am in reply to: Qt QWebSockets with kdb+

    There should be no difference between opening a connection from different clients. Can you compare the HTTP output in both the working and non-working cases?

    When using -u, HTTP connections must be authenticated using basic authentication. If you are connecting from a browser, this will result in a small popup window asking for a user name and password. If you are using a non-browser client, you must make sure to pass the “Authorization” header correctly. This also applies to JavaScript and kdb+ clients – if you didn’t take care of passing the header, those should not be working either. (Although in the JavaScript case, if the JavaScript code is served by the same server as the one you are trying to connect to, you will have to have entered the user/password to fetch the JS so the credentials from there could get reused for the websocket connection).

  • gyorokpeter-kx

    Member
    February 3, 2023 at 12:00 am in reply to: How to re-subscription automatically in kdb-tick?

    It can be done using the built-in handlers .z.pc  (connection close) and .z.ts (timer). When the connection closes, you could set up a periodic timer that tries to reopen the connection.

    Because doing this at the low level is cumbersome and is kind of reinventing the wheel, there are open source implementations that allow setting timers and auto-reconnecting connections, such as this one:

    kdb/q/conn at main finos/kdb (github.com)

    This allows you to set up a connection that is automatically reopened using a timer. You could put the subscription code in the connect callback.

  • gyorokpeter-kx

    Member
    January 30, 2023 at 12:00 am in reply to: Why are feedhandlers not usually kdb?

    Sometimes the only way to interact with the upstream data source is to use a library provided by the vendor. To use a library like that from q you need to write a plugin, and these plugins have a chance to crash unlike pure q code. Also you can’t just reimplement/reverse engineer the network protocol because as of 4.0 q still doesn’t have native raw TCP support. So even if the feed handler is a q app with a plugin, it is best kept as its own process to isolate the impact of a crash.

  • gyorokpeter-kx

    Member
    January 30, 2023 at 12:00 am in reply to: Why does @ need :: and why does . need () in amend?

    The binary form of . is not exactly the same as the 3 or 4 parameter version. The handling of () is special, as it’s equivalent to list[] instead of list . ().

    For list @ :: , this is not the correct syntax for what you want to do as :: is being parsed as a binary operator missing its right argument. If you write it as list @ (::) it works.

    list @ enlist[::] is something else: note that here the index is a list, not a single element, therefore the result will be a list as well, meaning it’s actually enlist[list] – while this looks like the original list in the printout, if you check the type of the result you will notice that they are different.

  • gyorokpeter-kx

    Member
    January 17, 2023 at 11:00 am in reply to: Underneath q is k

    I have written a utility that converts k code to q (not necessarily the prettiest version) by parsing it and then rebuilding the code from the parse tree in q format. It can be found here:

    https://github.com/gyorokpeter/qutils/blob/master/q/k2q.q

  • gyorokpeter-kx

    Member
    December 13, 2022 at 12:00 am in reply to: Why regular expression doesn’t work with bracket?

    The patterns used by like are not actual regular expressions, so they don’t support this {n} syntax. I think the naming is unfortunate.

    Regular expressions in q | Basics | q and kdb+ documentation – Kdb+ and q documentation (kx.com)

  • gyorokpeter-kx

    Member
    December 8, 2022 at 12:00 am in reply to: Parsing with fixed length

    The 0: operator cannot handle filler between records. You either have to explicitly include the spaces as a field:

    (“SSSSS “;3 3 2 2 4 66)0:`:file1.txt

    or find another way to get rid of the spaces.

  • gyorokpeter-kx

    Member
    December 6, 2022 at 12:00 am in reply to: Why Q SQL doesn’t work with "in"?

    The parameters to functional select are parse trees. These have a special rule for symbols and lists because a symbol can also represent a variable/column name, and a list can mean function invocation.

    The rule is that enlisting a value acts as an “escape” so the symbol or list is taken at face value and not evaluated. In your 3rd example, you are enlisting the symbol so it acts as a literal symbol and not a column named “a”. In the 4rd example, there is no enlist, so the list `a`b is taken as a function application, which then looks for variables or columns named a and b to perform the application. It works if you enlist the symbol list.

    ?[t;enlist (in;`c1;enlist`a`b);0b;()]

  • gyorokpeter-kx

    Member
    November 3, 2022 at 12:00 am in reply to: Execute async on self?

    Not directly, but the .z.ts callback can only run during idle time, and you can set it up such that it will run very soon after your function finishes. It is also possible to use a timer library such as this one that takes care of handling the callback and timeout, so you can set up a relative timer to run in zero milliseconds which has the effect of running your function during idle time.

  • gyorokpeter-kx

    Member
    October 12, 2022 at 12:00 am in reply to: rotate function differences between k and q

    Your “q version” is actually a hybrid between k and q. A more q-native interpretation would look like:

    rotate2:{$[0h>type y;'`rank;98h<type y;'`type;count y;raze reverse(0;x mod count y)_y;y]}

    The whole function is a conditional with multiple branches. The part you crossed out is just a check if the list is empty, in which case we don’t bother with calculating the rotated version, we just return the original empty list. You seem to have broken up the conditional in your “q” version even though it is still possible to use the multi-branch version.

  • The queries are the functional equivalents of:

    select from t where c3<44 select from t where c3>={y-x}
    [min 15 25 35 45;44] 
    select from t where c3>={y-x}
    [min 35 45;44]

    In the 2nd example, min 15 25 35 45 evaluates to 15, {y-x}[15;44] is 29, and the condition c3>=29 is true for 4 rows.

    In the 3rd example, min 35 45 is 35, {y-x}[35;44] is 9 and all rows satisfy c3>=9.

    In the functional form, (‘;~;<) is just the representation of >=. If you type >= at the console, you can see it comes back as ~<, which is the composition of the operators ~ (not) and < (less than). The functional form includes the ‘ (composition) operator.

     

     

     

     

     

     

  • gyorokpeter-kx

    Member
    October 11, 2022 at 12:00 am in reply to: Why sometimes the amend/index doesn’t work?

    It’s because the dot operator always requires a list as the index. 1 2 1, 1 2 and () are lists, 1 is not. It works if you enlist it.

    a1:.[myObj; enlist 1; {count x}];
Page 4 of 4