64 lines
1.3 KiB
Python
64 lines
1.3 KiB
Python
import os
|
|
import pyarrow
|
|
import sys
|
|
import logging
|
|
from datetime import date, timedelta
|
|
import polars as pl
|
|
from sqlalchemy import create_engine, text
|
|
from sqlalchemy.engine import Engine, URL
|
|
import clickhouse_connect
|
|
from dotenv import load_dotenv
|
|
|
|
from log import log
|
|
from clickhouse_task.create_table import create_clickhouse_table , check
|
|
from db_con.connection import *
|
|
from mids import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_mapping_store_visibility(
|
|
engine: Engine,
|
|
run_date: date
|
|
) -> pl.DataFrame:
|
|
|
|
sql = f"""
|
|
SELECT DISTINCT
|
|
40148 AS project_id,
|
|
Z.StoreId AS store_id,
|
|
Z.VisibilityDefinitionId AS visibility_definition_id,
|
|
Z.FromDate AS from_date,
|
|
Z.ToDate AS to_date
|
|
|
|
FROM OneApp_KelloggsMT.dbo.Mapping_StoreVisibility Z
|
|
|
|
WHERE CAST(Z.FromDate AS DATE) <= '{run_date}'
|
|
AND CAST(Z.ToDate AS DATE) >= '{run_date}'
|
|
|
|
AND Z.VisibilityDefinitionId IN
|
|
(
|
|
SELECT DISTINCT VisibilityDefinitionId
|
|
FROM OneApp_KelloggsMT.dbo.Master_VisibilityDefinition
|
|
WHERE MenuId = 22
|
|
)
|
|
"""
|
|
|
|
log.info(
|
|
f"Fetching Mapping Store Visibility for {run_date}"
|
|
)
|
|
|
|
df = pl.read_database(
|
|
query=sql,
|
|
connection=engine
|
|
)
|
|
|
|
log.info(
|
|
f"Fetched {len(df):,} Mapping Store Visibility records"
|
|
)
|
|
|
|
return df |