Skip to content

Commit 11b76ab

Browse files
committed
fix: anchor partition aging to server date for v0.4.2
1 parent 60eef26 commit 11b76ab

4 files changed

Lines changed: 28 additions & 20 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pg-workload"
7-
version = "0.4.1"
7+
version = "0.4.2"
88
description = "PostgreSQL workload emulator for diagnostic and observability testing"
99
readme = "README.md"
1010
requires-python = ">=3.10"
1111
license = "MIT"
1212
license-files = ["LICENSE", "THIRD_PARTY_NOTICES.md"]
1313
authors = [
14-
{ name = "O2eg", email = "oleg.ispu@yandex.ru" }
14+
{ name = "O2eg", email = "oleg.ispu@gmail.com" }
1515
]
1616
keywords = ["postgresql", "workload", "emulation", "diagnostics", "observability"]
1717
dependencies = [

src/pg_workload/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""PostgreSQL workload generation and scheduling tools."""
22

3-
__version__ = "0.4.1"
3+
__version__ = "0.4.2"
44

55
from pg_workload.assets import bundled_profiles_root, initialize_project
66
from pg_workload.cli import build_parser

src/pg_workload/bundled/profiles/partition_aging/generator.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import math
55
import os
66
import subprocess
7-
from datetime import date, timedelta
87

98
DAYS_BACK = 30
109
DAYS_AHEAD = 2
@@ -23,20 +22,25 @@ def main() -> None:
2322

2423
row_count = scaled(200_000, args.scale, 2_000)
2524

26-
today = date.today()
27-
partitions = []
28-
for offset in range(-DAYS_BACK, DAYS_AHEAD + 1):
29-
day = today + timedelta(days=offset)
30-
nxt = day + timedelta(days=1)
31-
partitions.append(
32-
f"CREATE TABLE partition_aging.events_{day:%Y_%m_%d} "
33-
"PARTITION OF partition_aging.events "
34-
f"FOR VALUES FROM ('{day.isoformat()}') TO ('{nxt.isoformat()}');"
35-
)
36-
37-
sql = (
38-
"\n".join(partitions)
39-
+ f"""
25+
partition_count = DAYS_BACK + DAYS_AHEAD + 1
26+
sql = f"""
27+
DO $partition_setup$
28+
DECLARE
29+
partition_day date;
30+
BEGIN
31+
FOR day_offset IN -{DAYS_BACK}..{DAYS_AHEAD} LOOP
32+
partition_day := current_date + day_offset;
33+
EXECUTE format(
34+
'CREATE TABLE partition_aging.%I '
35+
'PARTITION OF partition_aging.events '
36+
'FOR VALUES FROM (%L) TO (%L)',
37+
'events_' || to_char(partition_day, 'YYYY_MM_DD'),
38+
partition_day,
39+
partition_day + 1
40+
);
41+
END LOOP;
42+
END
43+
$partition_setup$;
4044
4145
SELECT setseed(0.55083122);
4246
@@ -49,15 +53,14 @@ def main() -> None:
4953
'event ' || g || ' session=' || floor(power(random(), 2) * 100000)::integer
5054
FROM generate_series(1, {row_count}) AS g;
5155
"""
52-
)
5356
subprocess.run(
5457
[os.environ.get("PG_WORKLOAD_PSQL", "psql"), "-X", "-q", "-v", "ON_ERROR_STOP=1"],
5558
input=sql,
5659
text=True,
5760
check=True,
5861
)
5962

60-
print(f"Generated partition_aging: partitions={len(partitions)}, events={row_count}")
63+
print(f"Generated partition_aging: partitions={partition_count}, events={row_count}")
6164

6265

6366
if __name__ == "__main__":

tests/test_workload.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ def test_all_profile_manifests_are_valid(self):
4848
self.assertEqual(errors, [])
4949
imdb_generator = Path(tmpdir) / "data" / "imdb" / "generator.py"
5050
self.assertIn("g::bigint * 104729", imdb_generator.read_text(encoding="utf-8"))
51+
partition_generator = (Path(tmpdir) / "data" / "partition_aging" / "generator.py").read_text(
52+
encoding="utf-8"
53+
)
54+
self.assertIn("partition_day := current_date + day_offset", partition_generator)
55+
self.assertNotIn("date.today()", partition_generator)
5156

5257
def test_default_pg_major_is_18(self):
5358
parser = self.workload.build_parser()

0 commit comments

Comments
 (0)