Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(data-warehouse): Some minor memory optimisations #28621

Merged
merged 8 commits into from
Feb 13, 2025

Conversation

Gilbert09
Copy link
Member

@Gilbert09 Gilbert09 commented Feb 12, 2025

Changes

  • Some minor optimisations to the pipeline
    • Package updates
    • SQL source settings
    • Clean up pyarrows memory
    • Added pyarrows debug mode

@posthog-bot
Copy link
Contributor

Hey @Gilbert09! 👋
This pull request seems to contain no description. Please add useful context, rationale, and/or any other information that will help make sense of this change now and in the distant Mars-based future.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR updates SQL-related dependencies and improves database connection handling in the data import pipelines.

  • Fixed critical SQLAlchemy engine execution options bug in /posthog/temporal/data_imports/pipelines/sql_database/__init__.py by properly chaining method calls
  • Added memory optimization in /posthog/temporal/data_imports/pipelines/sql_database/helpers.py with max_row_buffer and stream_results settings
  • Updated PostgreSQL connection string to explicitly use psycopg driver with 'postgresql+psycopg://' format
  • Upgraded core SQL packages including SQLAlchemy (2.0.38), psycopg (3.2.4), and related dependencies while maintaining backwards compatibility
  • Reorganized imports and removed redundancies in arrow_helpers.py for better code organization

5 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

engine.execution_options(stream_results=True, max_row_buffer=2 * chunk_size)
engine = engine_from_credentials(credentials, may_dispose_after_use=True).execution_options(
stream_results=True, max_row_buffer=2 * chunk_size
)
metadata = metadata or MetaData(schema=schema)

table_obj: Table | None = metadata.tables.get("table")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: table lookup uses hardcoded string 'table' instead of the table parameter

Suggested change
table_obj: Table | None = metadata.tables.get("table")
table_obj: Table | None = metadata.tables.get(table)

Comment on lines +140 to +142
result = conn.execution_options(
yield_per=self.chunk_size, max_row_buffer=DEFAULT_CHUNK_SIZE * 2, stream_results=True
).execute(query)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Setting max_row_buffer to 2x chunk_size could still cause OOM issues with very large chunk sizes. Consider adding an upper bound or making this configurable.

@Gilbert09 Gilbert09 changed the title [WIP] Updates to sql source and packcages chore(data-warehouse): Some minor memory optimisations Feb 13, 2025
@Gilbert09 Gilbert09 requested a review from a team February 13, 2025 15:09
@Gilbert09 Gilbert09 enabled auto-merge (squash) February 13, 2025 16:00
@Gilbert09 Gilbert09 merged commit b2dd622 into master Feb 13, 2025
95 checks passed
@Gilbert09 Gilbert09 deleted the tom/sqlalchemy-updates branch February 13, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants