mirror of
https://github.com/apache/superset.git
synced 2026-05-09 09:55:19 +00:00
feat(cross-filters): add support for temporal filters (#16139)
* feat(cross-filters): add support for temporal filters
* fix test
* make filter optional
* remove mocks
* fix more tests
* remove unnecessary optionality
* fix even more tests
* bump superset-ui
* add isExtra to schema
* address comments
* fix presto test
(cherry picked from commit 63ace7b288)
This commit is contained in:
committed by
Ville Brofeldt
parent
a38115d517
commit
630b49f4a3
@@ -17,10 +17,10 @@
|
||||
# pylint: disable=no-self-use
|
||||
import pytest
|
||||
|
||||
from superset.utils.core import to_adhoc
|
||||
from superset.utils.core import form_data_to_adhoc, simple_filter_to_adhoc
|
||||
|
||||
|
||||
def test_to_adhoc_generates_deterministic_values():
|
||||
def test_simple_filter_to_adhoc_generates_deterministic_values():
|
||||
input_1 = {
|
||||
"op": "IS NOT NULL",
|
||||
"col": "LATITUDE",
|
||||
@@ -30,25 +30,56 @@ def test_to_adhoc_generates_deterministic_values():
|
||||
input_2 = {**input_1, "col": "LONGITUDE"}
|
||||
|
||||
# The result is the same when given the same input
|
||||
assert to_adhoc(input_1) == to_adhoc(input_1)
|
||||
assert to_adhoc(input_1) == {
|
||||
assert simple_filter_to_adhoc(input_1) == simple_filter_to_adhoc(input_1)
|
||||
assert simple_filter_to_adhoc(input_1) == {
|
||||
"clause": "WHERE",
|
||||
"expressionType": "SIMPLE",
|
||||
"isExtra": False,
|
||||
"comparator": "",
|
||||
"operator": "IS NOT NULL",
|
||||
"subject": "LATITUDE",
|
||||
"filterOptionName": "d0908f77d950131db7a69fdc820cb739",
|
||||
"filterOptionName": "6ac89d498115da22396f80a765cffc70",
|
||||
}
|
||||
|
||||
# The result is different when given different input
|
||||
assert to_adhoc(input_1) != to_adhoc(input_2)
|
||||
assert to_adhoc(input_2) == {
|
||||
assert simple_filter_to_adhoc(input_1) != simple_filter_to_adhoc(input_2)
|
||||
assert simple_filter_to_adhoc(input_2) == {
|
||||
"clause": "WHERE",
|
||||
"expressionType": "SIMPLE",
|
||||
"isExtra": False,
|
||||
"comparator": "",
|
||||
"operator": "IS NOT NULL",
|
||||
"subject": "LONGITUDE",
|
||||
"filterOptionName": "c5f283f727d4dfc6258b351d4a8663bc",
|
||||
"filterOptionName": "9c984bd3714883ca859948354ce26ab9",
|
||||
}
|
||||
|
||||
|
||||
def test_form_data_to_adhoc_generates_deterministic_values():
|
||||
form_data = {"where": "1 = 1", "having": "count(*) > 1"}
|
||||
|
||||
# The result is the same when given the same input
|
||||
assert form_data_to_adhoc(form_data, "where") == form_data_to_adhoc(
|
||||
form_data, "where"
|
||||
)
|
||||
assert form_data_to_adhoc(form_data, "where") == {
|
||||
"clause": "WHERE",
|
||||
"expressionType": "SQL",
|
||||
"sqlExpression": "1 = 1",
|
||||
"filterOptionName": "99fe79985afbddea4492626dc6a87b74",
|
||||
}
|
||||
|
||||
# The result is different when given different input
|
||||
assert form_data_to_adhoc(form_data, "having") == form_data_to_adhoc(
|
||||
form_data, "having"
|
||||
)
|
||||
assert form_data_to_adhoc(form_data, "having") == {
|
||||
"clause": "HAVING",
|
||||
"expressionType": "SQL",
|
||||
"sqlExpression": "count(*) > 1",
|
||||
"filterOptionName": "1da11f6b709c3190daeabb84f77fc8c2",
|
||||
}
|
||||
|
||||
|
||||
def test_form_data_to_adhoc_incorrect_clause_type():
|
||||
form_data = {"where": "1 = 1", "having": "count(*) > 1"}
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
form_data_to_adhoc(form_data, "foobar")
|
||||
|
||||
Reference in New Issue
Block a user