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

Support SELECT * EXCEPT (col1, col2)-style functionality #90

Merged
merged 3 commits into from
Apr 15, 2024

Conversation

KingMob
Copy link
Contributor

@KingMob KingMob commented Mar 22, 2024

This adds SELECT * EXCEPT (col-i-dont-want, col-that-annoys-me) ... functionality to GenSQL.

Adding * EXCEPT to other areas (conditioning, generation) will come in future PRs.

@KingMob KingMob changed the base branch from main to add-caching March 22, 2024 15:16
@KingMob KingMob force-pushed the feature/star-except branch from d279cba to 7963631 Compare March 22, 2024 16:13
@KingMob KingMob force-pushed the feature/star-except branch from 7963631 to 09de192 Compare March 22, 2024 16:22
@KingMob KingMob force-pushed the add-caching branch 3 times, most recently from a97735c to 68000ea Compare April 2, 2024 14:49
@KingMob KingMob force-pushed the feature/star-except branch from 09de192 to 1b3c992 Compare April 2, 2024 14:49
Base automatically changed from add-caching to added-shadow-cljs April 3, 2024 10:09
Base automatically changed from added-shadow-cljs to main April 3, 2024 10:24
@KingMob KingMob force-pushed the feature/star-except branch 4 times, most recently from a602a0b to 23eaeaf Compare April 8, 2024 11:03
@KingMob KingMob marked this pull request as ready for review April 8, 2024 11:04
@KingMob KingMob force-pushed the feature/star-except branch 3 times, most recently from 1d1adf1 to eb5771e Compare April 10, 2024 13:46
@KingMob KingMob changed the title Support * EXCEPT (col1, col2)-style functionality Support SELECT * EXCEPT (col1, col2)-style functionality Apr 10, 2024
@@ -22,14 +22,14 @@
- parse - a parsing function"
[s db parse]
(let [node-or-failure (parse s)]
(tap> #:base.query{:node node-or-failure})
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting, do you recommend leaving this in for production code? I like the idea of more logging via tap>, I just don't know good practices yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Zane requested this. The nice thing about tap> is it's very lightweight if no taps are added.

The less nice thing about tap> is well, everything else, IMO. :P I've tried REBL and Portal, and have yet to find a tap/datafy visualizer I actually think is worth using over logs. They're just so slow to navigate in.

For now, I've taken to running:

(do
  (when (ns-resolve 'user 'log-tap)
    (remove-tap user/log-tap))
  (intern 'user 'log-tap #(do (prn %) (println)))
  (add-tap user/log-tap))

so I get some semblance of logs.

Copy link
Contributor

@zane zane Apr 12, 2024

Choose a reason for hiding this comment

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

I’m happy to be overruled here if you two align on a different solution for logging!

Copy link
Contributor

Choose a reason for hiding this comment

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

@sritchie What, if anything, is OpenGen using for logging?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing now... in Emmy I have used Timbre but I'm not doing anything special to consume the logs.

Copy link
Contributor Author

@KingMob KingMob Apr 12, 2024

Choose a reason for hiding this comment

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

I guess the question is, what problem are we trying to solve? Is this for us, in our debugging efforts? Is this for debugging some eventually-deployed cloud system? Is this for 3rd-party users to get more insight into debugging their own queries? Some weighted combination of all of the above? We can't choose a solution when we haven't articulated the problem.

FWIW, I'm a fan of mulog, and other structured logging libs like pedestal.log. Timbre's not structured, iiuc, but it's already cross-platform, and it eliminates much of the need to fiddle with Java logging backend config files, which are both major pluses, especially for downstream users.

For now, I think it's fine to leave the tap>'s in, but I might add a logging helper for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't choose a solution when we haven't articulated the problem.

For me, I find it help for debugging, since I can see all output at once, and search the REPL if necessary. Cloud servers are a future problem, imo. And I feel I don't know enough about third-party users yet to offer an opinion.

(star? (first selections)))
op
plan (cond (star? (first selections))
(select-star-plan (first selections) op)
Copy link
Contributor

Choose a reason for hiding this comment

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

can this ever fail? Can we get an empty selections input?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I checked, but all my attempts result in parse errors. I don't think we can reach this code without something in the selections.


;; FIXME?: Can't currently combine GROUP BY and SELECT *, which some dbs allow
Copy link
Contributor

Choose a reason for hiding this comment

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

do you want to handle this, or make a ticket to track this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the next step wasn't very clear. I thought Zane might be the person to ask, but he's not around. I suspect Ulli won't care much.

I dug around a bit to see which dbs do this, and the behavior I'm thinking of is an old, nonstandard default of MySQL's (what I cut my teeth on). In that light, it's probably better to delete this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@@ -24,7 +24,7 @@
(defn select-attrs
"Retrives tuple `tup` with only the attributes in `attrs`."
[tup attrs]
(let [names (into #{} (map name) attrs)]
(let [names (into #{} (map name) attrs)] ; FIXME: should this be clojure.core/name?
Copy link
Contributor

Choose a reason for hiding this comment

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

let's get this one resolved. Reviewing this sort of PR is where I miss types, I can't see what attrs should be...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm 99% certain it's a vec of keys (which should be strings these days), based on the attribute code I see elsewhere. In that case, it should almost certainly be clojure.core/name here.

I think the reason nobody's noticed the error is because the select-attrs fn is only called in i.q.relation/project, which is never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's it:

(-> (strict/q "SELECT * FROM tbl LIMIT 1" db)
    first
    (tuple/select-attrs #{"Launch_Site" "Contractor"}))
=> {}

(defn select-attrs
  "Retrives tuple `tup` with only the attributes in `attrs`."
  [tup attrs]
  (let [names (into #{} (map clojure.core/name) attrs)]               
    (medley/filter-keys (comp names clojure.core/name)
                        tup)))
=> #'inferenceql.query.tuple/select-attrs

(-> (strict/q "SELECT * FROM tbl LIMIT 1" db)
    first
    (tuple/select-attrs #{"Launch_Site" "Contractor"}))
=> {"Launch_Site" "Cape Canaveral", "Contractor" "Lockheed Martin"}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@KingMob KingMob force-pushed the feature/star-except branch 2 times, most recently from 6e8700b to 90cfd70 Compare April 11, 2024 10:32
@KingMob KingMob requested a review from sritchie April 11, 2024 10:34
@KingMob KingMob force-pushed the feature/star-except branch from 90cfd70 to f7adbed Compare April 12, 2024 09:06
@KingMob
Copy link
Contributor Author

KingMob commented Apr 12, 2024

@sritchie Got time for a re-review? I think I addressed everything.

Copy link
Contributor

@sritchie sritchie left a comment

Choose a reason for hiding this comment

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

Great work, :shipit: !

@KingMob KingMob force-pushed the feature/star-except branch from f7adbed to 3823297 Compare April 15, 2024 15:07
Copy link

codecov bot commented Apr 15, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 15 lines in your changes are missing coverage. Please review.

Project coverage is 75.87%. Comparing base (931aae4) to head (3823297).

Files Patch % Lines
src/inferenceql/query/plan.cljc 38.09% 3 Missing and 10 partials ⚠️
src/inferenceql/query/tuple.cljc 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #90      +/-   ##
==========================================
- Coverage   76.26%   75.87%   -0.39%     
==========================================
  Files          30       30              
  Lines        1462     1484      +22     
  Branches       52       60       +8     
==========================================
+ Hits         1115     1126      +11     
- Misses        295      298       +3     
- Partials       52       60       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@KingMob KingMob merged commit 95352b2 into main Apr 15, 2024
4 of 6 checks passed
@KingMob KingMob deleted the feature/star-except branch April 15, 2024 15:19
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