|
@@ -3,7 +3,7 @@ import textwrap
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
from unittest.mock import patch
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
-from dw_base.datax.partition import compute_partition_dt, execute_ddls, parse_ini_partition
|
|
|
|
|
|
|
+from dw_base.datax.partition import execute_ddls, parse_ini_partition
|
|
|
|
|
|
|
|
|
|
|
|
|
def _write_ini(tmp_path: Path, content: str) -> str:
|
|
def _write_ini(tmp_path: Path, content: str) -> str:
|
|
@@ -12,21 +12,13 @@ def _write_ini(tmp_path: Path, content: str) -> str:
|
|
|
return str(p)
|
|
return str(p)
|
|
|
|
|
|
|
|
|
|
|
|
|
-def test_compute_partition_dt_stop_minus_1():
|
|
|
|
|
- assert compute_partition_dt('20260423') == '20260422'
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-def test_compute_partition_dt_month_boundary():
|
|
|
|
|
- assert compute_partition_dt('20260401') == '20260331'
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
def test_parse_partitioned_writer(tmp_path):
|
|
def test_parse_partitioned_writer(tmp_path):
|
|
|
ini = _write_ini(tmp_path, '''\
|
|
ini = _write_ini(tmp_path, '''\
|
|
|
[writer]
|
|
[writer]
|
|
|
dataSource = hdfs/prd-ha
|
|
dataSource = hdfs/prd-ha
|
|
|
path = /user/hive/warehouse/test.db/raw_usr_app_user_cert_info_inc_d/dt=${dt}/
|
|
path = /user/hive/warehouse/test.db/raw_usr_app_user_cert_info_inc_d/dt=${dt}/
|
|
|
''')
|
|
''')
|
|
|
- ddl = parse_ini_partition(ini, stop_date='20260423')
|
|
|
|
|
|
|
+ ddl = parse_ini_partition(ini, start_date='20260422')
|
|
|
assert ddl == ('ALTER TABLE test.raw_usr_app_user_cert_info_inc_d '
|
|
assert ddl == ('ALTER TABLE test.raw_usr_app_user_cert_info_inc_d '
|
|
|
'ADD IF NOT EXISTS PARTITION(dt=20260422);')
|
|
'ADD IF NOT EXISTS PARTITION(dt=20260422);')
|
|
|
|
|
|
|
@@ -37,7 +29,7 @@ def test_parse_non_partitioned(tmp_path):
|
|
|
dataSource = hdfs/xx
|
|
dataSource = hdfs/xx
|
|
|
path = /user/hive/warehouse/test.db/non_partitioned/
|
|
path = /user/hive/warehouse/test.db/non_partitioned/
|
|
|
''')
|
|
''')
|
|
|
- assert parse_ini_partition(ini, stop_date='20260423') is None
|
|
|
|
|
|
|
+ assert parse_ini_partition(ini, start_date='20260422') is None
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_no_writer_path(tmp_path):
|
|
def test_parse_no_writer_path(tmp_path):
|
|
@@ -45,18 +37,18 @@ def test_parse_no_writer_path(tmp_path):
|
|
|
[writer]
|
|
[writer]
|
|
|
dataSource = mongo/xx
|
|
dataSource = mongo/xx
|
|
|
''')
|
|
''')
|
|
|
- assert parse_ini_partition(ini, stop_date='20260423') is None
|
|
|
|
|
|
|
+ assert parse_ini_partition(ini, start_date='20260422') is None
|
|
|
|
|
|
|
|
|
|
|
|
|
-def test_parse_dt_aligns_with_stop_minus_1_for_multiday(tmp_path):
|
|
|
|
|
- # 多日范围 start=20260401 stop=20260410:dt 应 = stop-1 = 20260409
|
|
|
|
|
- # 避免老脚本 START_DATE=dt 假设引入的多日范围分区错位
|
|
|
|
|
|
|
+def test_parse_dt_aligns_with_start_date_for_multiday(tmp_path):
|
|
|
|
|
+ # 多日范围 start=20260401 stop=20260410:dt 应 = start_date = 20260401(业务日)
|
|
|
|
|
+ # 与 HDFS writer 对齐,分区内允许含 [start, stop) 范围内所有数据
|
|
|
ini = _write_ini(tmp_path, '''\
|
|
ini = _write_ini(tmp_path, '''\
|
|
|
[writer]
|
|
[writer]
|
|
|
path = /user/hive/warehouse/db1.db/t1/dt=${dt}/
|
|
path = /user/hive/warehouse/db1.db/t1/dt=${dt}/
|
|
|
''')
|
|
''')
|
|
|
- ddl = parse_ini_partition(ini, stop_date='20260410')
|
|
|
|
|
- assert 'PARTITION(dt=20260409)' in ddl
|
|
|
|
|
|
|
+ ddl = parse_ini_partition(ini, start_date='20260401')
|
|
|
|
|
+ assert 'PARTITION(dt=20260401)' in ddl
|
|
|
|
|
|
|
|
|
|
|
|
|
@patch('dw_base.datax.partition.subprocess.run')
|
|
@patch('dw_base.datax.partition.subprocess.run')
|