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

Update crosstab to support more types of input #3

Merged
merged 6 commits into from
Feb 7, 2018

Conversation

proegssilb
Copy link
Contributor

@proegssilb proegssilb commented Jan 26, 2017

I needed crosstab support for generating graphs in a SQL Alchemy ORM project, so I thought I'd share the code.

Major changes:

  • Pytest-based tests file. Not complete, but covers a lot of the common cases for two-argument crosstab.
  • Added support for selectables in general and tuples of Columns in the Return Def. This allows me to use the same crosstab code multiple times in the same Session without having to generate a new table name. Generating a new table for each request could add up over the course of days or months in a web server (ie, memory leak). Depends on details.
  • Remove the result set name from the AS clause. Generic selectables and Query objects don't have a name, and I couldn't find a SQLA way to generate a unique name, so I removed the return value name (in the AS clause) from the compilation. Works on 9.6, and works in CI, so I'm not sure why the docs consistently include a name. Being able to get a compiled name from .alias would be a great way to make this work, if I was smart enough to figure it out. I tried various manipulations of Alias.name, but there's some extra machinery going on there I don't understand.
  • Support for Query objects in stmt and categories arguments. For ORM projects, that's a major source of cleaner code. Still not perfect, but I think the tests show a pretty good way to use the new code.

Less major changes:

  • Added requirements.txt for better dependency control. Just makes life easier.
  • Travis CI configuration. If you decide to enable Travis CI for pull requests against your code, I've got a config file that works. Not sure how to do multiple versions of PostgreSQL, but at least there's multiple versions of Python.
  • Support for envfile.txt in tests. Because Windows doesn't really handle environment variables well, and a file ignored by git is not the worst place to stick a DB Connection String.

- Tests for both SQL Alchemy Core and SQL Alchemy ORM.
- Tests cover getting all data, filtering, and aggregating.
- Some patches to crosstab were required for ORM.
- Added requirements.txt for pip usage.
- Added Travis config for automatically testing on many versions.
* Add psycopg2 to requirements.

* Attempt to add tablefunc extension to Travis CI test DB.

* Attempt #2 to add tablefunc extension to Travis CI test DB.

* Adding name to crosstab because CI wants it.

* Generalize SQLite exception, because it varies between platforms.

* Tweak how matrix was handled, since it seemed to be invalid.

* Remove attempts to use multipl versions of PostgreSQL; it won't work.
@makmanalp
Copy link
Owner

@proegssilb Wow! I'm extremely grateful for this and super touched that you took the time to contribute back! Give me a day or two to review / test this over the weekend. It's been a while since I touched this code!

@makmanalp makmanalp merged commit 6c17093 into makmanalp:master Feb 7, 2018
@makmanalp
Copy link
Owner

@proegssilb 🍰 !!!

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.

2 participants