mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix(elasticsearch): time_zone setting does not work for cast datetime expressions (#17048)
* fix(elasticsearch): cast does not take effect for time zone settings * test(elasticsearch): add test * fix(test): fix typo * docs(elasticsearch): add annotation * docs(elasticsearch): add time_zone desc * docs(elasticsearch): fix typo * refactor(db_engine): change convert_dttm signature * fix(test): fix test * fix(es): add try catch * fix(test): fix caplog * fix(test): fix typo
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
# under the License.
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import column
|
||||
|
||||
from superset.db_engine_specs.elasticsearch import (
|
||||
@@ -26,14 +27,47 @@ from tests.integration_tests.db_engine_specs.base_tests import TestDbEngineSpec
|
||||
|
||||
|
||||
class TestElasticSearchDbEngineSpec(TestDbEngineSpec):
|
||||
@pytest.fixture(autouse=True)
|
||||
def inject_fixtures(self, caplog):
|
||||
self._caplog = caplog
|
||||
|
||||
def test_convert_dttm(self):
|
||||
dttm = self.get_dttm()
|
||||
|
||||
self.assertEqual(
|
||||
ElasticSearchEngineSpec.convert_dttm("DATETIME", dttm),
|
||||
ElasticSearchEngineSpec.convert_dttm("DATETIME", dttm, db_extra=None),
|
||||
"CAST('2019-01-02T03:04:05' AS DATETIME)",
|
||||
)
|
||||
|
||||
def test_convert_dttm2(self):
|
||||
"""
|
||||
ES 7.8 and above versions need to use the DATETIME_PARSE function to
|
||||
solve the time zone problem
|
||||
"""
|
||||
dttm = self.get_dttm()
|
||||
db_extra = {"version": "7.8"}
|
||||
|
||||
self.assertEqual(
|
||||
ElasticSearchEngineSpec.convert_dttm("DATETIME", dttm, db_extra=db_extra),
|
||||
"DATETIME_PARSE('2019-01-02 03:04:05', 'yyyy-MM-dd HH:mm:ss')",
|
||||
)
|
||||
|
||||
def test_convert_dttm3(self):
|
||||
dttm = self.get_dttm()
|
||||
db_extra = {"version": 7.8}
|
||||
|
||||
self.assertEqual(
|
||||
ElasticSearchEngineSpec.convert_dttm("DATETIME", dttm, db_extra=db_extra),
|
||||
"CAST('2019-01-02T03:04:05' AS DATETIME)",
|
||||
)
|
||||
|
||||
self.assertNotEqual(
|
||||
ElasticSearchEngineSpec.convert_dttm("DATETIME", dttm, db_extra=db_extra),
|
||||
"DATETIME_PARSE('2019-01-02 03:04:05', 'yyyy-MM-dd HH:mm:ss')",
|
||||
)
|
||||
|
||||
self.assertIn("Unexpected error while convert es_version", self._caplog.text)
|
||||
|
||||
def test_opendistro_convert_dttm(self):
|
||||
"""
|
||||
DB Eng Specs (opendistro): Test convert_dttm
|
||||
@@ -41,7 +75,7 @@ class TestElasticSearchDbEngineSpec(TestDbEngineSpec):
|
||||
dttm = self.get_dttm()
|
||||
|
||||
self.assertEqual(
|
||||
OpenDistroEngineSpec.convert_dttm("DATETIME", dttm),
|
||||
OpenDistroEngineSpec.convert_dttm("DATETIME", dttm, db_extra=None),
|
||||
"'2019-01-02T03:04:05'",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user