use hahn;
PRAGMA yson.DisableStrict;
PRAGMA yt.InferSchema;
PRAGMA AnsiInForEmptyOrNullableItemsCollections;
PRAGMA OrderedColumns;

$datetime_parse_alt = DateTime::Parse("%Y-%m-%d %H:%M:%S");
$datetime_parse = DateTime::Parse("%Y-%m-%dT%H:%M:%S");
$date_parse = DateTime::Parse("%Y-%m-%dT");
$datetime_format_alt = DateTime::Format("%Y-%m-%d %H:%M:%S");
$datetime_format = DateTime::Format("%Y-%m-%dT%H:%M:%S");
$datetime_format_short = DateTime::Format("%Y-%m-%d");


$fct_order = '//home/taxi-dwh/cdm/marketplace/fct_order';
$fct_start = '2020-01-01';
$delivery_tariff_filter = ['express', 'courier', 'cargo'];
$period_first_day = '2021-03-01';
$appmetrica = '//home/taxi-dwh/ods/appmetrica/taxi';
$user_path = '//home/taxi-dwh/ods/mdb/user/user';

insert into `//home/taxi-delivery/analytics/dev/product/users/users_with_first_delivery_date` with truncate
select yandex_uid
    ,   min(utc_order_created_dt) as first_delivery_order_date
from range($fct_order, $fct_start) as fct_order
where true 
    and tariff_class_code in $delivery_tariff_filter
    and country_name_ru = 'Россия'
    and not corp_order_flg
    and success_order_flg
    and not fake_order_flg
    and not mqc_order_flg
    and yandex_uid is not null
    and yandex_uid <> ""
group by yandex_uid; 
