有效删除包含空值的行

发布于 2025-01-17 00:13:13 字数 308 浏览 1 评论 0原文

对于包含许多行的表,删除包含任何空值的行的最有效方法是什么?

另外,为什么我会收到错误

错误:'时间(尝试使用变量时间而不先定义/分配

即使我在使用功能选择

时没有任何名为'时间'的内容?[ t;{(not;(null;x))} 每个 cols t; ()]

这个 S/O 答案

What is the most efficient way to remove rows containing any null values, for a table with many rows?

Additionally, why do I get the error

ERROR: 'time (attempt to use variable time without defining/assigning first

even though I have nothing named as ‘time’ when using the functional select

?[t;{(not;(null;x))} each cols t; 0b; ()]

given in this S/Oanswer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香橙ぽ 2025-01-24 00:13:13

您的表是在内存中还是在磁盘上?

如果您的表位于内存中,那么简单的表单也可能是最快的。

show t:flip`a`b`c`d`e!(1+til 100)*/:100 cut 500?(1 0N)where 19 1
a  b  c  d  e
--------------
1  1     1  1
2  2  2  2  2
3  3  3  3  3
4  4  4  4  4
5  5  5  5  5
6  6  6  6  6
7  7  7  7  7
8  8  8  8  8
9  9  9  9  9
10 10 10 10 10
11 11 11 11 11
12 12 12 12 12
13    13 13 13
14 14 14 14 14
15 15 15 15 15
16 16    16 16
   17 17 17 17
18 18 18 18 18
..

q)\ts:1000 ?[t;{(not;(null;x))}each cols t;0b;()]
5 7552
q)\ts:1000 t where not any null flip t
2 6768

如果表格在磁盘上展开,游戏就会改变。在展开表中,每一列都存储为一个文件。 Select 运算符的第二个参数是约束列表;每一个都是一棵解析树。上面的 null Flip t 会测试 t 的每个单元格,而 Select 会连续应用约束:仅测试已通过先前约束的行以进行下一个约束。如果没有行满足第一个约束,则可能根本不需要读取后续列文件。

由此遵循以下规则:按限制性降序列出约束 - 如果空值在某些列中更常见,请首先测试它们。

关于内存中测试,请注意,not any 可能比 all not 快很多,具体取决于 null 是否常见。

q)q:null flip t
q)\ts:10000 all not q
9 1168
q)\ts:10000 not any q
6 656

Is your table in memory or splayed on disk?

If your table is in memory, then a simple form might also be the fastest.

show t:flip`a`b`c`d`e!(1+til 100)*/:100 cut 500?(1 0N)where 19 1
a  b  c  d  e
--------------
1  1     1  1
2  2  2  2  2
3  3  3  3  3
4  4  4  4  4
5  5  5  5  5
6  6  6  6  6
7  7  7  7  7
8  8  8  8  8
9  9  9  9  9
10 10 10 10 10
11 11 11 11 11
12 12 12 12 12
13    13 13 13
14 14 14 14 14
15 15 15 15 15
16 16    16 16
   17 17 17 17
18 18 18 18 18
..

q)\ts:1000 ?[t;{(not;(null;x))}each cols t;0b;()]
5 7552
q)\ts:1000 t where not any null flip t
2 6768

If the table is splayed on disk, the game changes. In a splayed table each column is stored as a file. The second argument of the Select operator is a list of constraints; each one a parse tree. Whereas null flip t above tests every cell of t, Select applies is constraints successively: only rows that have passed previous constraints are tested for the next. If no rows satisfy the first constraint/s subsequent column files may never need to be read at all.

From this follows the rule: list your constraints in descending order of restrictiveness – if nulls are more common in certain columns, test them first.

Regarding an in-memory test, note that not any can be a good deal faster than all not, depending on whether nulls are common.

q)q:null flip t
q)\ts:10000 all not q
9 1168
q)\ts:10000 not any q
6 656
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文