Skip to content

Commit

Permalink
Approach for relevance of tables on extended models in GPKG
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Jul 16, 2023
1 parent 6afd7d6 commit cddc71c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions modelbaker/dataobjects/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(
is_basket_table=False,
is_dataset_table=False,
ili_name=None,
is_relevant=True,
definitionfile=None,
qmlstylefile=None,
styles={},
Expand Down
1 change: 1 addition & 0 deletions modelbaker/dbconnector/db_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def get_tables_info(self):
extent [a string: "xmin;ymin;xmax;ymax"]
table_alias
model
relevance
"""
return []

Expand Down
40 changes: 38 additions & 2 deletions modelbaker/dbconnector/gpkg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,44 @@ def _get_tables_info(self):
GROUP BY tablename
) as coord_decimals,
substr(c.iliname, 0, instr(c.iliname, '.')) AS model,
attrs.sqlname as attribute_name, """
attrs.sqlname as attribute_name,
{relevance_field},""".format(
relevance_field="""CASE WHEN c.iliname IN (
-- used to get the class names from the full names
WITH names AS (
WITH class_level_name AS(
WITH topic_level_name AS (
SELECT
thisClass as fullname,
substr(thisClass, 0, instr(thisClass, '.')) as model,
substr(ltrim(thisClass,substr(thisClass, 0, instr(thisClass, '.'))),2) as topicclass
FROM T_ILI2DB_INHERITANCE
)
SELECT *, ltrim(topicclass,substr(topicclass, 0, instr(topicclass, '.'))) as class_with_dot
FROM topic_level_name
) select fullname, model, topicclass, substr(class_with_dot, instr(class_with_dot,'.')+1) as class
FROM class_level_name
)
SELECT i.baseClass as base
FROM T_ILI2DB_INHERITANCE i
LEFT JOIN names extend_names
ON thisClass = extend_names.fullname
LEFT JOIN names base_names
ON baseClass = base_names.fullname
-- it's extended
WHERE baseClass IS NOT NULL
-- in a different model
AND base_names.model != extend_names.model
AND (
-- with the same name
base_names.class = extend_names.class
OR
-- multiple times in the same extended model
(SELECT COUNT(baseClass) FROM T_ILI2DB_INHERITANCE JOIN names extend_names ON thisClass = extend_names.fullname WHERE baseClass = i.baseClass GROUP BY baseClass, extend_names.model)>1
)
)
THEN FALSE ELSE TRUE END AS relevance"""
)
interlis_joins = """LEFT JOIN T_ILI2DB_TABLE_PROP p
ON p.tablename = s.name
AND p.tag = 'ch.ehi.ili2db.tableKind'
Expand All @@ -151,7 +188,6 @@ def _get_tables_info(self):
ON s.name == c.sqlname
LEFT JOIN t_ili2db_attrname attrs
ON c.iliname = attrs.iliname """

try:
cursor.execute(
"""
Expand Down
7 changes: 6 additions & 1 deletion modelbaker/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(
parent=None,
mgmt_uri=None,
consider_basket_handling=False,
optimize_extended=True #TRUE for-relevance-tests: should be false after
):
"""
Creates a new Generator objects.
Expand All @@ -68,6 +69,7 @@ def __init__(
self._db_connector.stdout.connect(self.print_info)
self._db_connector.new_message.connect(self.append_print_message)
self.basket_handling = consider_basket_handling and self.get_basket_handling()
self.optimize_extended = optimize_extended

self._additional_ignored_layers = (
[]
Expand Down Expand Up @@ -137,6 +139,8 @@ def layers(self, filter_layer_list=[]):
record.get("tablename") == self._db_connector.dataset_table_name
)

is_relevant = bool(record.get("relevance")) if self.optimize_extended else True

alias = record["table_alias"] if "table_alias" in record else None
if not alias:
short_name = None
Expand Down Expand Up @@ -185,7 +189,7 @@ def layers(self, filter_layer_list=[]):
+ match.group(1).split(".")[-1]
+ ")"
)
alias = short_name
alias = short_name if is_relevant else f"{short_name} !IRRELEVANT!" #for-relevance-tests

display_expression = ""
if is_basket_table:
Expand Down Expand Up @@ -224,6 +228,7 @@ def layers(self, filter_layer_list=[]):
is_basket_table,
is_dataset_table,
record.get("ili_name"),
is_relevant
)

# Configure fields for current table
Expand Down

0 comments on commit cddc71c

Please sign in to comment.