Question about saving to files

145 views
Skip to first unread message

Sahasranaman M S

unread,
Apr 15, 2013, 7:28:11 PM4/15/13
to kona...@googlegroups.com
Hi,

I cloned the Kona code a couple of days back and built it,  and noticed that it is not able to save tables and dictionaries to files.


For example,

  
  d: ("test"; "data")
  save `:/home/sahasranaman/d
()
  `:/home/sahasranaman/d.csv 0: d
  `:/home/sahasranaman/d.csv 0: ("So";"Long")
  `:/home/sahasranaman/d 0: ("So";"Long")
  save `:/home/sahasranaman/d.csv
()

The commands are not failing with error,  but the files are not getting generated either.  I downloaded the free version of q from kx.com,  and the same commands are generating files there.  Is this a recent bug/not implemented yet/or is it supposed to be done differently?  I haven't tried to explore the code yet,  thought I could do that based on your suggestions here.

Thanks,
Sahas

Kevin Lawler

unread,
Apr 15, 2013, 7:56:04 PM4/15/13
to kona...@googlegroups.com
Sahas,

Those are Q/K4 commands. Kona is based on K3. Try

`file 1: data

https://github.com/kevinlawler/kona/wiki#inputoutput-verbs

Cheers,
Kevin
> --
> You received this message because you are subscribed to the Google Groups
> "Kona Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to kona-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Sahasranaman M S

unread,
Apr 16, 2013, 10:01:11 AM4/16/13
to kona...@googlegroups.com
Hi Kevin,

Thanks for the reply and the link, but that doesn't help. 1: is not
creating a file either, just like 0: wasn't creating earlier. I see
from the wiki that 0: in dyadic form is supposed to create a text
file, and 1: is supposed to create a binary file.

d: ("test"; "data")
("test"
"data")
`:/home/sahasranaman/d 1: d

No error, but no file again. I tried with the latest code. Could
you please test in your local version, just in case and let me know?
I will see if I'm able to debug it.

Thanks,
Sahas

Scott Vokes

unread,
Apr 16, 2013, 12:10:24 PM4/16/13
to kona...@googlegroups.com
It appears to be a problem with your file path. This works for me, and you should see a file called "filename.K" appear:

  d: ("test"; "data")
("test"
 "data")
  `"filename" 1: d
  `0: 1: `filename
test
data

Whether the symbol needs quotes or not depends on the symbol. In this case, either form is valid.

HTH,
Scott / silentbicycle

Sahasranaman M S

unread,
Apr 17, 2013, 2:22:40 PM4/17/13
to kona...@googlegroups.com
Thanks Scott, that worked! I'm assuming K3 and K4 Kevin mentioned
earlier are standards. I was wondering if I could find a page listing
the differences between the two?

Thanks,
Sahas

Scott Vokes

unread,
Apr 17, 2013, 2:45:29 PM4/17/13
to kona...@googlegroups.com
k3 and k4 are different, incompatible versions of the (proprietary) k language. According to Kevin, kona is close to k3, though I haven't used either and don't know of any good references offhand. Håkan Kjellerstrand has some links to k2 references on his k/kona page[hk], FWIW.

(Arthur Whitney seems to re-implement k from scratch every couple years [1], changing the language each time. The current version, 'q', seems to be a layer on k4.)


Scott

Sahasranaman M S

unread,
Apr 24, 2013, 1:08:15 PM4/24/13
to kona...@googlegroups.com
Thanks Scott,

I need some more help: I tried saving a table (flipped dictionary) to
a file, and it fails with a type error.

d:("test";"data")
("test"
"data")
`"/tmp/d.test" 0: d //
works, saves simple list

d:(("test";"data");("rain";"fall"))
(("test"
"data")
("rain"
"fall"))
`"/tmp/d.test" 0: d // fails
to save list of lists
type error

t: + `name`iq!(`Dent`Beeblebrox`Prefect;98 42 126)
.((`name
`Dent `Beeblebrox `Prefect
)
(`iq
98 42 126
))
`"/tmp/t.test" 0: t // fails
to save table
type error


Is it possible to save dictionaries and tables to disk, and read them
directly from disk, or would we have to save/load them using one file
per column and joining outside kona? I'm particularly interested in
saving and loading csv files.


Another question: Because we don't have sql in k3, I'm trying to
prepare a list of equivalent statements.

For example,
select name from t where iq = 42 ==> t[`name;t[`iq]?42]
select name from t where iq > 42 ==> t[`name;&t[`iq]>42]

But when we want multiple where clauses (like select from t where iq >
42, name = `Dent), I'm able to see how to do it in multiple
statements, but unable to think of a way to do it with a single
statement. Are there any ways to do this?


Thanks,
Sahas

Sahasranaman M S

unread,
Apr 26, 2013, 1:04:46 PM4/26/13
to kona...@googlegroups.com
Hi Scott/Kevin,

I think I've managed to solve the querying problem. Could you please
just suggest the best way to load csv data into and out of kona?

Thanks,
Sahas

Sahasranaman M S

unread,
Apr 29, 2013, 6:11:11 PM4/29/13
to kona...@googlegroups.com
Hi,

I had not added my solution to the querying problem in my previous email.  This has not been fully tested and might be buggy.  Just posting here to close the thread.

selectRetrieve:{[t;f;c]
        r:1
        ctr:0
        if[7=4:c[0]; ret:t[f;&c[0][t[c[1]];c[2]]]; :ret]
        do[#cl; d:c[ctr]; ctr:ctr+1; r:r & (d[0][t[d[1]];d[2]])]
        t[f;&r]}

select:{[t;f;c]
        d:selectRetrieve[t;f;c]
        :[1=#f; +f!,(d); +f!d]}

t: + `name`iq`age!(`Dent`Beeblebrox`Prefect;98 42 126;10 20 30)    / test code
select[t;`name;(>;`age;10)]


Thanks,
Sahas
>>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>>
>>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups
>>>>>> "Kona Developers" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send
>>>>>> an
>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>
>>>>>>
>>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>> Groups
>>>>> "Kona Developers" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>
>>>>>
>>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups
>>>> "Kona Developers" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>>
>>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Kona Developers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Kona Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

Kevin Lawler

unread,
Apr 30, 2013, 2:28:01 PM4/30/13
to kona...@googlegroups.com
Interesting take, thanks for sharing
>> >>>>>>> email to kona-dev+u...@googlegroups.com.
>> >>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>> >>>>>>>
>> >>>>>>>
>> >>>>>> --
>> >>>>>> You received this message because you are subscribed to the Google
>> >>>>>> Groups
>> >>>>>> "Kona Developers" group.
>> >>>>>> To unsubscribe from this group and stop receiving emails from it,
>> >>>>>> send
>> >>>>>> an
>> >>>>>> email to kona-dev+u...@googlegroups.com.
>> >>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>> >>>>>>
>> >>>>>>
>> >>>>>>
>> >>>>> --
>> >>>>> You received this message because you are subscribed to the Google
>> >>> Groups
>> >>>>> "Kona Developers" group.
>> >>>>> To unsubscribe from this group and stop receiving emails from it,
>> >>>>> send
>> >>> an
>> >>>>> email to kona-dev+u...@googlegroups.com.
>> >>>>> For more options, visit https://groups.google.com/groups/opt_out.
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>> --
>> >>>> You received this message because you are subscribed to the Google
>> >>>> Groups
>> >>>> "Kona Developers" group.
>> >>>> To unsubscribe from this group and stop receiving emails from it,
>> >>>> send
>> >>>> an
>> >>>> email to kona-dev+u...@googlegroups.com.
>> >>>> For more options, visit https://groups.google.com/groups/opt_out.
>> >>>>
>> >>>>
>> >>>>
>> >>> --
>> >>> You received this message because you are subscribed to the Google
>> >>> Groups
>> >>> "Kona Developers" group.
>> >>> To unsubscribe from this group and stop receiving emails from it, send
>> >>> an
>> >>> email to kona-dev+u...@googlegroups.com.
>> >>> For more options, visit https://groups.google.com/groups/opt_out.
>> >>>
>> >>>
>> >>>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Kona Developers" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an
>> >> email to kona-dev+u...@googlegroups.com.
>> >> For more options, visit https://groups.google.com/groups/opt_out.
>> >>
>> >>
>> >>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Kona Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to kona-dev+u...@googlegroups.com.

Sahasranaman M S

unread,
Apr 30, 2013, 6:21:52 PM4/30/13
to kona...@googlegroups.com
Thanks Kevin.

Here's an improved select, an update function and some examples.  Please let me know if I should put these somewhere in the wiki instead of here.

select:{[t;f;c]
        r:1; i:0
        :[7=4:c[0]; r:c[0][t[c[1]];c[2]];do[#c; d:c[i]; i:i+1; r:(r) & (d[0][t[d[1]];d[2]])]]
        d:t[f;&r]; :[1=#f; +f!,(d); +f!d]}

update:{[t;f;c]
        r:1; i:0
        :[7=4:c[0]; r:c[0][t[c[1]];c[2]];do[#c; d:c[i]; i:i+1; r:(r) & (d[0][t[d[1]];d[2]])]]
        i:0
        :[4=4:f[0]; t[f[0];&r]:f[1]; do[#f; d:f[i]; i:i+1; t[d[0];&r]:d[1]]]; t}

t: + `name`iq`age!(`Dent`Beeblebrox`Prefect;98 42 126;10 20 30)      / sample usage below
select[t;`name`iq;(=; `name; `Beeblebrox)]
update[t; ((`name;`Superman);(`iq;200)); ((>;`age;10);(<;`iq;126))]
update[t; (`age;29); (=;`age;20)]

Thanks,
Sahas

Kevin Lawler

unread,
Apr 30, 2013, 9:43:12 PM4/30/13
to kona...@googlegroups.com
This would be good to have on the wiki. I would create a new page on
replicating SQL or database functionality.

Tom Szczesny

unread,
Aug 2, 2013, 6:08:46 PM8/2/13
to kona...@googlegroups.com
I was looking over the SQL wiki page in more detail and trying out some of the examples,
and I have 2 questions:

1)  Is there any reason to use "flip" ( monadic + ) ?  I get the same result with/without flip.
 t0: + `name`iq`age!(`Dent`Beeblebrox`Prefect;98 42 126;10 20 30)
 t1:  `name`iq`age!(`Dent`Beeblebrox`Prefect;98 42 126;10 20 30) 
t0 ~ t1
1

2)  How did you know that you could use mod/rotate ( dyadic ! ) to create dictionaries in Kona?
 As far as I can tell, this is not documented anywhere in the Kona wiki or Kona issue comments.
 In K3.2, you get an "int error", as specified in the K reference manual.

Bakul Shah

unread,
Aug 2, 2013, 7:58:44 PM8/2/13
to kona...@googlegroups.com
On Aug 2, 2013, at 3:08 PM, Tom Szczesny <tav...@gmail.com> wrote:

I was looking over the SQL wiki page in more detail and trying out some of the examples,
and I have 2 questions:

1)  Is there any reason to use "flip" ( monadic + ) ?  I get the same result with/without flip.
 t0: + `name`iq`age!(`Dent`Beeblebrox`Prefect;98 42 126;10 20 30)
 t1:  `name`iq`age!(`Dent`Beeblebrox`Prefect;98 42 126;10 20 30) 
t0 ~ t1
1

Note that v ~ +v for any vector v. k3 (& kona) seem to treat a dictionary like a vector.
In k4 a `flipped' dictionary is a table.

2)  How did you know that you could use mod/rotate ( dyadic ! ) to create dictionaries in Kona?

See issue 84.

Tom Szczesny

unread,
Aug 3, 2013, 10:33:24 AM8/3/13
to kona...@googlegroups.com
Thanks.  I only looked for this topic in the closed issues.
Seems that while issue 84 is still open, it was at least partially implemented in the code base.
Reply all
Reply to author
Forward
0 new messages