writing results and temp tables

This commit is contained in:
2026-01-16 14:13:55 +01:00
parent 4ea9d35a91
commit 3b2e0e5773
4 changed files with 247 additions and 72 deletions

View File

@@ -6,6 +6,30 @@ from umbreit.types import PolarsNullValues, PolarsSchema
metadata = sql.MetaData()
class OracleBoolean(sql.types.TypeDecorator):
impl = sql.VARCHAR(1)
cache_ok = True
def process_bind_param(
self,
value: bool | None,
dialect,
) -> str | None:
if value is None:
return None
return "Y" if value else "N"
def process_result_value(
self,
value: sql.VARCHAR | None,
dialect,
) -> bool | None:
if value is None:
return None
return value == "Y"
ext_bedpbed = Table(
"ext_bedpbed",
metadata,
@@ -153,41 +177,7 @@ EXT_AUFPAUF_schema_map: PolarsSchema = {
EXT_AUFPAUF_null_values: PolarsNullValues = {}
csv_tables: tuple[tuple[Table, PolarsSchema, PolarsNullValues], ...] = (
(ext_bedpbed, ext_bedpbed_schema_map, ext_bedpbed_null_values),
(ext_titel_info, ext_titel_info_schema_map, ext_titel_info_null_values),
(EXT_AUFPAUF, EXT_AUFPAUF_schema_map, EXT_AUFPAUF_null_values),
(EXT_BESPBES_INFO, EXT_BESPBES_INFO_schema_map, EXT_BESPBES_INFO_null_values),
)
results = Table(
"results",
metadata,
Column("id", sql.Integer, nullable=False, primary_key=True, autoincrement=True),
Column("bedarf_nr", sql.Integer, nullable=False),
Column("bedarf_sequenz", sql.Integer, nullable=False),
Column("vorlage", sql.Boolean, nullable=False),
Column("wf_id", sql.Integer, nullable=False),
Column("best_menge", sql.Integer, nullable=True),
Column("freigabe_auto", sql.Boolean, nullable=False),
)
results_schema_map: PolarsSchema = {
"id": pl.UInt32,
"bedarf_nr": pl.UInt32,
"bedarf_sequenz": pl.UInt32,
"vorlage": pl.Boolean,
"wf_id": pl.UInt16,
"best_menge": pl.UInt32,
"freigabe_auto": pl.Boolean,
}
map_to_result: dict[str, str] = {
"BEDARFNR": "bedarf_nr",
"BEDP_SEQUENZ": "bedarf_sequenz",
}
# // queries and temp data
raw_data_query_schema_map: PolarsSchema = {
"BEDARFNR": pl.UInt32,
"BEDP_SEQUENZ": pl.UInt32,
@@ -199,3 +189,75 @@ raw_data_query_schema_map: PolarsSchema = {
"MENGE_VORMERKER": pl.UInt32,
"MANDFUEHR": pl.UInt8,
}
tmp_data = Table(
"EXT_TMP_BEDP_TINFO",
metadata,
Column("BEDARFNR", sql.Integer, primary_key=True, autoincrement=False, nullable=False),
Column(
"BEDP_SEQUENZ", sql.Integer, primary_key=True, autoincrement=False, nullable=False
),
Column("BEDP_TITELNR", sql.Integer, nullable=False),
Column("BEDP_MAN", sql.Integer, nullable=False),
Column("BEDP_MENGE_BEDARF_VM", sql.Integer, nullable=True),
Column("MELDENUMMER", sql.Integer, nullable=False),
Column("VERLAGSNR", sql.Integer, nullable=False),
Column("MENGE_VORMERKER", sql.Integer, nullable=True),
Column("MANDFUEHR", sql.Integer, primary_key=True, autoincrement=False, nullable=False),
)
tmp_data_schema_map = raw_data_query_schema_map
csv_tables: tuple[tuple[Table, PolarsSchema, PolarsNullValues], ...] = (
(ext_bedpbed, ext_bedpbed_schema_map, ext_bedpbed_null_values),
(ext_titel_info, ext_titel_info_schema_map, ext_titel_info_null_values),
(EXT_AUFPAUF, EXT_AUFPAUF_schema_map, EXT_AUFPAUF_null_values),
(EXT_BESPBES_INFO, EXT_BESPBES_INFO_schema_map, EXT_BESPBES_INFO_null_values),
)
# ** results
# ** Umbreit
EXT_DOPT_ERGEBNIS = Table(
"EXT_DOPT_ERGEBNIS",
metadata,
Column("ID", sql.Integer, nullable=False, primary_key=True, autoincrement=True),
Column("BEDARF_NR", sql.Integer, nullable=False),
Column("BEDARF_SEQUENZ", sql.Integer, nullable=False),
Column("VORLAGE", OracleBoolean, nullable=False),
Column("WF_ID", sql.Integer, nullable=False),
Column("BEST_MENGE", sql.Integer, nullable=True),
Column("FREIGABE_AUTO", OracleBoolean, nullable=False),
)
results_schema_map: PolarsSchema = {
"ID": pl.UInt64,
"BEDARF_NR": pl.UInt32,
"BEDARF_SEQUENZ": pl.UInt32,
"VORLAGE": pl.Boolean,
"WF_ID": pl.UInt16,
"BEST_MENGE": pl.UInt32,
"FREIGABE_AUTO": pl.Boolean,
}
map_data_to_result: dict[str, str] = {
"BEDARFNR": "BEDARF_NR",
"BEDP_SEQUENZ": "BEDARF_SEQUENZ",
}
# ** local
results_local = Table(
"results",
metadata,
Column("id", sql.Integer, nullable=False, primary_key=True, autoincrement=True),
Column("bedarf_nr", sql.Integer, nullable=False),
Column("bedarf_sequenz", sql.Integer, nullable=False),
Column("vorlage", sql.Boolean, nullable=False),
Column("wf_id", sql.Integer, nullable=False),
Column("best_menge", sql.Integer, nullable=True),
Column("freigabe_auto", sql.Boolean, nullable=False),
)
results_local_schema_map: PolarsSchema = {
k.lower(): v for (k, v) in results_schema_map.items()
}