Skip to content

Commit

Permalink
Merge pull request #2833 from bonicim/hotfix/sqlhistorian
Browse files Browse the repository at this point in the history
Hotfix - sqlhistorian
  • Loading branch information
craig8 authored Dec 2, 2021
2 parents 10dc132 + 3b9ad14 commit bb7fb49
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 4 deletions.
2 changes: 1 addition & 1 deletion volttron/platform/dbutils/mysqlfuncts.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def get_topic_meta_map(self):
_log.debug("loading metadata from db")
topic_meta_map = dict()
for id, meta in rows:
topic_meta_map[id] = jsonapi.loads(meta)
topic_meta_map[id] = jsonapi.loads(meta) if meta else None
return topic_meta_map

def get_topic_map(self):
Expand Down
2 changes: 1 addition & 1 deletion volttron/platform/dbutils/postgresqlfuncts.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def get_topic_meta_map(self):
'SELECT topic_id, metadata '
'FROM {}').format(Identifier(self.meta_table))
rows = self.select(query)
meta_map = {tid: jsonapi.loads(meta) for tid, meta in rows}
meta_map = {tid: jsonapi.loads(meta) if meta else None for tid, meta in rows}
return meta_map

def get_agg_topics(self):
Expand Down
2 changes: 1 addition & 1 deletion volttron/platform/dbutils/redshiftfuncts.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def get_topic_meta_map(self):
'SELECT topic_id, metadata '
'FROM {}').format(Identifier(self.meta_table))
rows = self.select(query)
meta_map = {tid: jsonapi.loads(meta) for tid, meta in rows}
meta_map = {tid: jsonapi.loads(meta) if meta else None for tid, meta in rows}
return meta_map

def get_agg_topics(self):
Expand Down
2 changes: 1 addition & 1 deletion volttron/platform/dbutils/sqlitefuncts.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def get_topic_meta_map(self):
_log.debug("loading metadata from db")
topic_meta_map = dict()
for id, meta in rows:
topic_meta_map[id] = jsonapi.loads(meta)
topic_meta_map[id] = jsonapi.loads(meta) if meta else None
return topic_meta_map

def get_agg_topics(self):
Expand Down
17 changes: 17 additions & 0 deletions volttrontesting/platform/dbutils/test_mysqlfuncts.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ def test_get_topic_map_should_succeed(get_container_func):
assert actual == expected


def test_get_topic_meta_map_should_succeed(get_container_func):
container, sqlfuncts, connection_port, historian_version = get_container_func
if historian_version == "<4.0.0":
pytest.skip("method applied only to version >=4.0.0")
else:
query = """
INSERT INTO topics (topic_name)
VALUES ('football');
INSERT INTO topics (topic_name, metadata)
VALUES ('baseball', '{"metadata":"value"}');
"""
seed_database(container, query)
expected = {1: None, 2: {"metadata": "value"}}
actual = sqlfuncts.get_topic_meta_map()
assert actual == expected


# fails for image:mysql:8.0.25 historian schema version >=4.0.0
def test_get_agg_topic_map_should_return_dict(get_container_func):
container, sqlfuncts, connection_port, historian_version = get_container_func
Expand Down
16 changes: 16 additions & 0 deletions volttrontesting/platform/dbutils/test_postgresql_timescaledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,22 @@ def test_get_topic_map_should_return_maps(get_container_func):
assert actual == expected


def test_get_topic_meta_map_should_return_maps(get_container_func):
container, sqlfuncts, connection_port, historian_version = get_container_func
if historian_version == "<4.0.0":
pytest.skip("method applied only to version >=4.0.0")
else:
query = """
INSERT INTO topics (topic_name)
VALUES ('football');
INSERT INTO topics (topic_name, metadata)
VALUES ('baseball', '{"meta":"value"}');
"""
seed_database(container, query)
expected = {1: None, 2: {"meta": "value"}}
actual = sqlfuncts.get_topic_meta_map()
assert actual == expected

def test_get_agg_topics_should_return_list(get_container_func):
container, postgresqlfuncts, port_on_host, historian_version = get_container_func
topic = "some_agg_topic"
Expand Down
17 changes: 17 additions & 0 deletions volttrontesting/platform/dbutils/test_postgresqlfuncts.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,23 @@ def test_get_topic_map_should_return_maps(get_container_func):
assert actual == expected


def test_get_topic_meta_map_should_return_maps(get_container_func):
container, sqlfuncts, connection_port, historian_version = get_container_func
if historian_version == "<4.0.0":
pytest.skip("method applied only to version >=4.0.0")
else:
query = """
INSERT INTO topics (topic_name)
VALUES ('football');
INSERT INTO topics (topic_name, metadata)
VALUES ('baseball', '{"meta":"value"}');
"""
seed_database(container, query)
expected = {1: None, 2: {"meta": "value"}}
actual = sqlfuncts.get_topic_meta_map()
assert actual == expected


def test_get_agg_topics_should_return_list(get_container_func):
container, sqlfuncts, connection_port, historian_version = get_container_func

Expand Down
16 changes: 16 additions & 0 deletions volttrontesting/platform/dbutils/test_sqlitefuncts.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,22 @@ def test_get_topic_map(get_sqlitefuncts):
assert actual_topic_map == expected_topic_map


@pytest.mark.sqlitefuncts
@pytest.mark.dbutils
def test_get_topic_meta_map(get_sqlitefuncts):
sqlitefuncts, historian_version = get_sqlitefuncts
if historian_version == "<4.0.0":
pytest.skip("method applied only to version >=4.0.0")
else:
query = "INSERT INTO topics (topic_name) values ('football');" \
"INSERT INTO topics (topic_name, metadata) values ('netball', '{\"meta\":\"value\"}');"
query_db(query)
expected_topic_map = {1: None, 2: {"meta": "value"}}

actual_topic_meta_map = sqlitefuncts.get_topic_meta_map()

assert actual_topic_meta_map == expected_topic_map

@pytest.mark.sqlitefuncts
@pytest.mark.dbutils
def test_get_agg_topics(get_sqlitefuncts):
Expand Down

0 comments on commit bb7fb49

Please sign in to comment.