从q中的表中软删除列 [英] soft deleting a column from a table in q

查看:101
本文介绍了从q中的表中软删除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从表中删除列而不丢失数据,以便可以再次恢复数据,但是当q进程加载表时,将不会显示已删除的列.显然我下面的代码无法正常工作. q是否有特定的功能可以做到这一点? dir是表所在的位置,c是要删除的列.

I am trying to delete a column from a table without the loss of data so the data can be reinstated again but when the table is loaded up by q process the deleted column will not show. Obviously my code below will not work. Is there something specific to q that can do that? dir is where the table is and c is the column to be deleted.

{[dir;t;c] delete c from (` sv (dir,t),`)}

推荐答案

kdb +提供了一种删除"列的简便方法,而无需实际删除列数据.如果查看存储表的目录,则应该能够识别.d文件.这是kdb +存储表列正确顺序的地方.要删除列,只需从此.d文件中删除列名称.例如:

kdb+ has an easy way to "remove" a column without actually deleting the column data. If you look in the directory where your table is stored, you should be able to identify a .d file. This is where kdb+ stores the correct order of your table columns. To remove the column, simply delete the column name from this .d file. For example:

q)get `:test/.d
`sym`time`src`bid`ask`bsize`asize
q)
q)`:test/.d set `sym`time`src`bid`ask`bsize
`:test/.d
q)
q)test
sym  time                          src bid   ask   bsize asize
--------------------------------------------------------------
AAPL 2014.04.21D08:00:00.456000000 L   25.32 25.36 8000  8500
AAPL 2014.04.21D08:00:01.387000000 O   25.32 25.35 9500  2500
AAPL 2014.04.21D08:00:10.348000000 N   25.35 25.35 8000  5000
AAPL 2014.04.21D08:00:10.532000000 L   25.33 25.37 5000  7000
AAPL 2014.04.21D08:00:15.163000000 L   25.34 25.36 10000 8000
AAPL 2014.04.21D08:00:15.847000000 N   25.32 25.36 1500  500
AAPL 2014.04.21D08:00:16.335000000 N   25.33 25.34 8500  5500
AAPL 2014.04.21D08:00:17.017000000 N   25.33 25.34 9000  2500
AAPL 2014.04.21D08:00:17.634000000 N   25.3  25.36 9500  1000
AAPL 2014.04.21D08:00:19.427000000 L   25.33 25.36 9500  5000
AAPL 2014.04.21D08:00:24.629000000 N   25.33 25.37 6000  2000
AAPL 2014.04.21D08:00:25.207000000 L   25.33 25.36 5000  2500
AAPL 2014.04.21D08:00:29.962000000 L   25.32 25.38 3500  5000
AAPL 2014.04.21D08:00:31.998000000 O   25.34 25.36 5500  4000
AAPL 2014.04.21D08:00:33.795000000 N   25.34 25.36 5000  3500
AAPL 2014.04.21D08:00:34.651000000 L   25.35 25.37 7500  6500
AAPL 2014.04.21D08:00:38.843000000 O   25.33 25.36 4000  6500
AAPL 2014.04.21D08:00:40.062000000 L   25.33 25.38 2000  9500
AAPL 2014.04.21D08:00:43.508000000 N   25.35 25.36 6500  10000
AAPL 2014.04.21D08:00:46.823000000 N   25.35 25.38 6000  7500
..
q)\l .
q)test
sym  time                          src bid   ask   bsize
--------------------------------------------------------
AAPL 2014.04.21D08:00:00.456000000 L   25.32 25.36 8000
AAPL 2014.04.21D08:00:01.387000000 O   25.32 25.35 9500
AAPL 2014.04.21D08:00:10.348000000 N   25.35 25.35 8000
AAPL 2014.04.21D08:00:10.532000000 L   25.33 25.37 5000
AAPL 2014.04.21D08:00:15.163000000 L   25.34 25.36 10000
AAPL 2014.04.21D08:00:15.847000000 N   25.32 25.36 1500
AAPL 2014.04.21D08:00:16.335000000 N   25.33 25.34 8500
AAPL 2014.04.21D08:00:17.017000000 N   25.33 25.34 9000

一旦删除,kdb +将不会将该列与您的表关联,并且在调用内存时将不会显示该列.

Once removed, kdb+ will not associate the column with your table and it will not be displayed when called into memory.

希望这会有所帮助.

这篇关于从q中的表中软删除列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆