Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
52c7252c
Commit
52c7252c
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
nicer formatting for generic SQL QP SQL logging
parent
7683c2d3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/driver/generic_sql/query_processor.clj
+12
-6
12 additions, 6 deletions
src/metabase/driver/generic_sql/query_processor.clj
with
12 additions
and
6 deletions
src/metabase/driver/generic_sql/query_processor.clj
+
12
−
6
View file @
52c7252c
...
...
@@ -2,6 +2,7 @@
"The Query Processor is responsible for translating the Metabase Query Language into korma SQL forms."
(
:require
[
clojure.core.match
:refer
[
match
]]
[
clojure.tools.logging
:as
log
]
[
clojure.string
:as
s
]
[
clojure.walk
:as
walk
]
[
korma.core
:refer
:all
]
[
metabase.config
:as
config
]
...
...
@@ -202,11 +203,16 @@
[
korma-form
]
(
when-not
qp/*disable-qp-logging*
(
log/debug
(
u/format-color
'green
"\n\nKORMA FORM:\n%s"
(
->>
(
nth
korma-form
2
)
; korma form is wrapped in a let clause. Discard it
(
walk/prewalk
(
fn
[
form
]
; strip korma.core/ qualifications from symbols in the form
(
if-not
(
symbol?
form
)
form
; to remove some of the clutter
(
u/format-color
'green
"\n\nKORMA FORM:\n%s"
(
->>
(
nth
korma-form
2
)
; korma form is wrapped in a let clause. Discard it
(
walk/prewalk
(
fn
[
form
]
; strip korma.core/ qualifications from symbols in the form
(
if-not
(
symbol?
form
)
form
; to remove some of the clutter
(
symbol
(
name
form
)))))
(
u/pprint-to-str
)))
(
u/format-color
'blue
"\nSQL:\n%s\n"
(
eval
(
let
[[
let-form
binding-form
&
body
]
korma-form
]
; wrap the (select ...) form in a sql-only clause
`
(
~
let-form
~
binding-form
; has to go there to work correctly
(
sql-only
~@
body
))))))))
(
u/format-color
'blue
"\nSQL:\n%s\n"
(
->
(
eval
(
let
[[
let-form
binding-form
&
body
]
korma-form
]
; wrap the (select ...) form in a sql-only clause
`
(
~
let-form
~
binding-form
; has to go there to work correctly
(
sql-only
~@
body
))))
(
s/replace
#
"\sFROM"
"\nFROM"
)
; add newlines to the SQL to make it more readable
(
s/replace
#
"\sWHERE"
"\nWHERE"
)
(
s/replace
#
"\sGROUP BY"
"\nGROUP BY"
)
(
s/replace
#
"\sORDER BY"
"\nORDER BY"
)
(
s/replace
#
"\sLIMIT"
"\nLIMIT"
))))))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment