我正在使用Hadoop2.7.3。当您运行hiveql命令并在其中包含“and”和“或”的where子句时,它是如何分配条件的?
例如,假设我有以下查询:
... where A and B or C and D.它是否返回下列内容之一:
A or B or C or D
((A and B) or C) and D
(A and B and D) or C
A and (B or C) and D我知道我可以使用括号来指定上面使用的确切内容,但是默认情况下它会做什么呢?
发布于 2018-07-25 19:52:55
@GordonLinoff的答案是正确的。您可以通过使用以下查询构造真值表来验证这一点:
SELECT *, A and B or C and D AS result
FROM
(SELECT TRUE AS a
UNION ALL SELECT FALSE AS a) A
CROSS JOIN
(SELECT TRUE AS b
UNION ALL SELECT FALSE AS b) B
CROSS JOIN
(SELECT TRUE AS c
UNION ALL SELECT FALSE AS c) C
CROSS JOIN
(SELECT TRUE AS d
UNION ALL SELECT FALSE AS d) D哪个产出:
+-----+-----+-----+-----+-------+
| a.a| b.b| c.c| d.d| result|
+-----+-----+-----+-----+-------+
| true| true| true|false| true|
| true| true| true| true| true|
| true| true|false|false| true|
| true| true|false| true| true|
|false| true| true|false| false|
|false| true| true| true| true|
|false| true|false|false| false|
|false| true|false| true| false|
| true|false| true|false| false|
| true|false| true| true| true|
| true|false|false|false| false|
| true|false|false| true| false|
|false|false| true|false| false|
|false|false| true| true| true|
|false|false|false|false| false|
|false|false|false| true| false|
+-----+-----+-----+-----+-------+因此,我们可以从经验上得出这样的结论,即这确实是(A and B) or (C and D)的结果。
发布于 2018-07-25 19:42:24
这是操作的优先级。AND比OR绑定得更紧密,因此:
A and B or C and D解释为:
(A and B) or (C and D)https://stackoverflow.com/questions/51526491
复制相似问题