You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use several times composite business keys in addition to a surrogate keys. Sample dimensional table:
CREATETABLEvendor
(
id INTEGER IDENTITY(1,1) NOT NULL,
company_num VARCHAR(5) NOT NULL,
account_num VARCHAR(20) NOT NULL,
name TEXT,
street TEXT,
PRIMARY KEY (id),
UNIQUE (company_num, account_num)
)
My fact table often only includes the business key but not the surrogate key:
CREATETABLEpurchase_transaction
(
company_num VARCHAR(5) NOT NULL,
vendor_order_account_num VARCHAR(20) NOT NULL,
vendor_invoice_account_num VARCHAR(20) NOT NULL,
invoice_date DATE,
product_num VARCHAR(20),
net_line_amount_acy DECIMAL(32,5),
net_line_discount_acy DECIMAL(32,5)
)
The mara_schema module currently only supports relationships where the foreign key is related to the primary key (which is unique). So I have to manually add a vendor_order_account_fk to purchase_transaction and use an UPDATE SQL statement to set the foreign key based on the business key connection.
It would be great when mara_schema would support the following use cases:
use the business key instead of the primary key and/or
generate SQL statements to update a foreign key related based on the primary key
Option 1: Using the business key in relations
Required changes:
The entity would need the option to define a business key (bk_column_names in Entity.__init__), `Entity.
The Entity.link_entity method would need a new parameter bk_columns.
The mara_schema.sql_generation.data_set_sql_query would need to use the business key in the LEFT JOIN when the primary key is not defined.
Option 2: Gelerating an update statement
Required changes:
Add a function to generate an SQL statement setting a foreign key property based on the business key. It should generate something similar to:
UPDATE purchase_transaction
SETpurchase_transaction.vendor_order_account_fk=vendor.idFROM purchase_transaction
INNER JOIN vendor ONvendor.company_num=purchase_transaction.company_numANDvendor.account_num=purchase_transaction.vendor_order_account_numWHEREpurchase_transaction.vendor_order_account_fk IS NULL
add a function to generate the SQL statements for all relations for multiple/all defined entities
(option) maybe adding the option to add the foreign key column to the fact table as well.
ALTERTABLE purchase_transaction ADD COLUMN IF NOT EXISTS vendor_order_account_fk INTEGER;
The text was updated successfully, but these errors were encountered:
I use several times composite business keys in addition to a surrogate keys. Sample dimensional table:
My fact table often only includes the business key but not the surrogate key:
The
mara_schema
module currently only supports relationships where the foreign key is related to the primary key (which is unique). So I have to manually add avendor_order_account_fk
topurchase_transaction
and use anUPDATE
SQL statement to set the foreign key based on the business key connection.It would be great when mara_schema would support the following use cases:
Option 1: Using the business key in relations
Required changes:
bk_column_names
inEntity.__init__
), `Entity.Entity.link_entity
method would need a new parameterbk_columns
.mara_schema.sql_generation.data_set_sql_query
would need to use the business key in theLEFT JOIN
when the primary key is not defined.Option 2: Gelerating an update statement
Required changes:
The text was updated successfully, but these errors were encountered: