Skip to content

feat: join v_ahbesser with newly introduced ahb_expressions table #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3ef80b3
expressions WIP
Apr 15, 2025
d15ce3b
chore: include AHB PK in materialized AHB view
Apr 15, 2025
d8d0779
Merge branch 'ahb-pk' into expressions
Apr 15, 2025
fbbc081
wip
Apr 15, 2025
dab2f6a
Merge remote-tracking branch 'origin/main' into expressions
Apr 15, 2025
7e1d594
wip
Apr 15, 2025
cc2097f
wip
Apr 15, 2025
acce381
wip
Apr 15, 2025
2d68c15
args
Apr 15, 2025
661e862
linter pain
Apr 15, 2025
bdc0a86
Delete src/fundamend/sqlmodels/create_ahb_expressions_table.sql
hf-kklein Apr 15, 2025
1474fd2
isort
Apr 15, 2025
bb10d22
spell check
Apr 15, 2025
c9d9c4a
Merge remote-tracking branch 'origin/expressions' into expressions
Apr 15, 2025
1ec3624
formating linter conflict
Apr 15, 2025
8ccc0e3
Update src/fundamend/sqlmodels/expression_view.py
hf-kklein Apr 15, 2025
a48e75e
enable type checking again
Apr 15, 2025
3f0682d
Merge remote-tracking branch 'origin/expressions' into expressions
Apr 15, 2025
aecfbb2
use order by in snapshot test for reproducible, stable results
Apr 15, 2025
448d068
linters
Apr 15, 2025
4eb020f
wip
Apr 15, 2025
501b4c0
wip
Apr 15, 2025
fe1955e
don't include pruefi, drop empty rows
Apr 15, 2025
e655163
arg. this turned out to be more complicated than i thought ;)
Apr 15, 2025
97c0340
feat: join `v_ahbesser` with newly introduced `ahb_expressions` table
Apr 15, 2025
11668b0
linter
Apr 15, 2025
2b514ef
Merge branch 'expressions' into join
Apr 15, 2025
fb19e42
ooooooooooooooook
Apr 15, 2025
3223c93
Update src/fundamend/sqlmodels/create_ahbtabellen_view.sql
hf-kklein Apr 15, 2025
974c167
Merge branch 'main' into join
hf-kklein Apr 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/fundamend/sqlmodels/ahbtabellen_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pathlib import Path
from uuid import UUID

from efoli import EdifactFormatVersion
from efoli import EdifactFormat, EdifactFormatVersion
from sqlalchemy.sql.functions import func
from sqlmodel import Field, Session, SQLModel, select

Expand Down Expand Up @@ -42,6 +42,7 @@ class AhbTabellenLine(SQLModel, table=True):
__tablename__ = "v_ahbtabellen"
id: UUID = Field(primary_key=True)
format_version: EdifactFormatVersion = Field()
format: EdifactFormat = Field()
pruefidentifikator: str = Field()
path: str = Field()
id_path: str = Field()
Expand All @@ -53,6 +54,8 @@ class AhbTabellenLine(SQLModel, table=True):
qualifier: str | None = Field()
line_ahb_status: str | None = Field()
line_name: str | None = Field()
bedingung: str | None = Field()
bedingungsfehler: str | None = Field()
sort_path: str = Field()


Expand Down
66 changes: 46 additions & 20 deletions src/fundamend/sqlmodels/create_ahbtabellen_view.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,53 @@

DROP TABLE IF EXISTS v_ahbtabellen; -- this is because sqlmodel tries to create a table first... it doesn't know that this is just a view. bit dirty but ok.
DROP VIEW IF EXISTS v_ahbtabellen;
CREATE VIEW v_ahbtabellen as
SELECT id as id,
edifact_format_version as format_version,
pruefidentifikator as pruefidentifikator,
path,
id_path,
kommunikation_von as direction,
beschreibung as description,
'SG' || segmentgroup_id as segmentgroup_key, -- eg 'SG6'
segment_id as segment_code, -- e.g 'NAD'
dataelement_id as data_element, -- e.g 'D_3035'

CREATE VIEW v_ahbtabellen AS
WITH consolidated_ahm AS (SELECT id,
edifact_format_version,
format,
pruefidentifikator,
path,
id_path,
kommunikation_von,
beschreibung,
segmentgroup_id,
segment_id,
dataelement_id,
code_value,
sort_path,
trim(coalesce(code_ahb_status, coalesce(dataelement_ahb_status,
coalesce(segment_ahb_status, segmentgroup_ahb_status)))) AS line_ahb_status,
coalesce(code_name, coalesce(dataelement_name, coalesce(dataelementgroup_name,
coalesce(segment_name, segmentgroup_name)))) AS line_name
FROM ahb_hierarchy_materialized ahm
WHERE ahm.TYPE != 'dataelementgroup'
AND (ahm.TYPE != 'dataelement' OR ahm.dataelement_ahb_status IS NOT NULL))

SELECT c.id as id,
c.edifact_format_version as format_version,
c.format as format,
c.pruefidentifikator as pruefidentifikator,
c.path,
c.id_path,
c.kommunikation_von as direction,
c.beschreibung as description,
'SG' || c.segmentgroup_id as segmentgroup_key, -- eg 'SG6'
c.segment_id as segment_code, -- e.g 'NAD'
c.dataelement_id as data_element, -- e.g 'D_3035'
--CASE
-- WHEN dataelement_id IS NOT NULL THEN SUBSTR(dataelement_id, 3)
-- END AS dataelement_without_leading_d_, -- e.g '3035'
code_value as qualifier,
c.code_value as qualifier,
c.line_ahb_status as line_ahb_status, -- e.g. 'Muss [28] ∧ [64]'
c.line_name as line_name, -- e.g. 'Datums- oder Uhrzeit- oder Zeitspannen-Format, Code' or 'Produkt-Daten für Lieferant relevant'
c.sort_path as sort_path,
NULLIF(ahe.node_texts, '') as bedingung,
NULLIF(ahe.ahbicht_error_message, '') as bedingungsfehler
FROM consolidated_ahm as c
LEFT JOIN ahb_expressions as ahe -- if this table is missing, call create_and_fill_ahb_expression_table(...) first
ON ahe.edifact_format_version = c.edifact_format_version
AND ahe.format = c.format
AND ahe.expression = c.line_ahb_status;


coalesce(code_ahb_status, coalesce(dataelement_ahb_status,
coalesce(segment_ahb_status, segmentgroup_ahb_status))) as line_ahb_status, -- e.g. 'Muss [28] ∧ [64]'
coalesce(code_name, coalesce(dataelement_name, coalesce(dataelementgroup_name,
coalesce(segment_name, segmentgroup_name)))) as line_name, -- e.g. 'Datums- oder Uhrzeit- oder Zeitspannen-Format, Code' or 'Produkt-Daten für Lieferant relevant'
sort_path as sort_path
-- the bedingung column is still missing, but we'll solve this one separately
FROM ahb_hierarchy_materialized
WHERE TYPE != 'dataelementgroup' AND (TYPE != 'dataelement' OR dataelement_ahb_status IS NOT Null) ;
Loading