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

Clean up codegen export with quoted symbols #151

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions src/tablecloth/api/lift_operators.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
(format
"Applies the operation %s to the columns selected by
`columns-selector` and returns a new ds with the the result in
`target-col`. %s
`target-col`.

`columns-selector can be:
- name
- sequence of names
- map of names with new names (rename)
- function which filter names (via column metadata)"
columns-selector can be:
- name
- sequence of names
- map of names with new names (rename)
- function which filter names (via column metadata)"
fn-sym
(when (< max-allowed Double/POSITIVE_INFINITY)
(format
Expand All @@ -66,42 +66,40 @@
[fn-sym {:keys [return-ds? make-aggregator?]
:or {return-ds? false
make-aggregator? false}}]
(let [defn (symbol "defn")
let (symbol "let")
arglists (get-arglists fn-sym)
(let [arglists (get-arglists fn-sym)
max-cols (max-cols-allowed arglists)
lifted-arglists (convert-arglists arglists return-ds?)
new-fn-sym (symbol (name fn-sym))
new-docstring (build-docstring fn-sym)]
`(~defn ~new-fn-sym
`(~'defn ~new-fn-sym
~new-docstring
~@(for [args lifted-arglists]
(if make-aggregator?
;; build an aggregator fn
`(~args
(~let [aggregator#
(fn [ds#]
(~let [ds-with-selected-cols#
(~'let [aggregator#
(~'fn [ds#]
Copy link
Member

Choose a reason for hiding this comment

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

ds# -> ~'ds - it will generate more clean code

(~'let [ds-with-selected-cols#
(select-columns ds# ~'columns-selector)
cols-count#
(-> ds-with-selected-cols#
(~'-> ds-with-selected-cols#
column-names
count)
~'count)
selected-cols# (columns ds-with-selected-cols#)]
(if (>= ~max-cols cols-count#)
(apply ~fn-sym (apply vector selected-cols#))
(throw (Exception. (str "Exceeded maximum number of columns allowed for operation."))))))]
(~'if (>= ~max-cols cols-count#)
Copy link
Member

@genmeblog genmeblog May 19, 2024

Choose a reason for hiding this comment

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

>= is missed

(~'apply ~fn-sym (~'apply ~'vector selected-cols#))
(throw (Exception. (~'str "Exceeded maximum number of columns allowed for operation."))))))]
(aggregate ~'ds aggregator#)))
;; build either a fn that returns a dataset or the result of the operation
`(~args
(~let [selected-cols# (apply vector (columns
(~'let [selected-cols# (~'apply ~'vector (columns
(select-columns ~'ds ~'columns-selector)))
args-to-pass# (concat selected-cols# [~@(drop 3 args)])]
(if (>= ~max-cols (count selected-cols#))
(->> args-to-pass#
(apply ~fn-sym)
args-to-pass# (~'concat selected-cols# [~@(drop 3 args)])]
(~'if (>= ~max-cols (~'count selected-cols#))
Copy link
Member

Choose a reason for hiding this comment

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

Also here: >=

(~'->> args-to-pass#
(~'apply ~fn-sym)
~(if return-ds? `(add-or-replace-column ~'ds ~'target-col) `(identity)))
(throw (Exception. (str "Exceeded maximum number of columns allowed for operation.")))))))))))
(throw (Exception. (~'str "Exceeded maximum number of columns allowed for operation.")))))))))))

(def serialized-lift-fn-lookup
{'[distance
Expand Down
Loading
Loading