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

Any chance for ORM/pandas-like interface to augment the sql-like interface? #495

Open
FishmanL opened this issue Oct 21, 2022 · 2 comments

Comments

@FishmanL
Copy link
Contributor

eg supporting filter/groupby methods on the returned data object
should just be a matter of converting to AST under the hood?

@joshua-oss
Copy link
Contributor

Hmm, good question. The way the SQL layer works is to:

  1. Intercept a query request that is formatted as a string
  2. Parse to AST and validate the SQL to ensure it's a query that can be safely done in a private way
  3. Rewrite the query in the AST to ensure privacy. For example, add reservoir sampling or bounds clipping
  4. Convert the rewritten query to a string
  5. Execute the rewritten query string against the database connection

Steps 2-4 need to be handled by SmartNoise to make sure we don't violate privacy. But it should be straightforward to feed step 1 with the output from an ORM-style query. As long as the ORM layer doesn't generate queries which are inconsistent with privacy, it will work. I believe SQLAlchemy allows you to grab a SQL query string from the ORM query, so it should "just work". I will try to whip up a sample later next week. I don't know if it's possible to do that from Pandas, though. If there is a way from Pandas to grab the SQL generated from the filter/groupby methods, it would presumably work.

@FishmanL
Copy link
Contributor Author

Something like https://github.com/AmirPupko/pandas-to-sql looks helpful here!

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

No branches or pull requests

2 participants