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
e72be01a
Commit
e72be01a
authored
8 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Plain Diff
Merge pull request #2584 from metabase/crate-fixes
Crate fixes
parents
6b220353
82bdf50a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
circle.yml
+2
-3
2 additions, 3 deletions
circle.yml
src/metabase/driver/crate/util.clj
+19
-11
19 additions, 11 deletions
src/metabase/driver/crate/util.clj
src/metabase/driver/generic_sql/query_processor.clj
+4
-1
4 additions, 1 deletion
src/metabase/driver/generic_sql/query_processor.clj
with
25 additions
and
15 deletions
circle.yml
+
2
−
3
View file @
e72be01a
...
...
@@ -32,13 +32,12 @@ test:
override
:
# 0) runs unit tests w/ H2 local DB. Runs against H2, Mongo, MySQL, BigQuery
# 1) runs unit tests w/ Postgres local DB. Runs against H2, SQL Server
# 2) runs unit tests w/ MySQL local DB. Runs against H2, Postgres, SQLite
# 2) runs unit tests w/ MySQL local DB. Runs against H2, Postgres, SQLite
, Crate
# 3) runs unit tests w/ H2 local DB. Runs against H2, Redshift, Druid
# 4) runs Eastwood linter, Bikeshed linter, docstring-checker & ./bin/reflection-linter
# 5) runs JS linter + JS test
# 6) runs lein uberjar. (We don't run bin/build because we're not really concerned about `npm install` (etc) in this test, which runs elsewhere)
# 7) runs unit tests w/ H2 local DB. Runs agains H2, Crate
-
case $CIRCLE_NODE_INDEX in 0) ENGINES=h2,mongo,mysql,bigquery lein test ;; 1) ENGINES=h2,sqlserver MB_DB_TYPE=postgres MB_DB_DBNAME=circle_test MB_DB_PORT=5432 MB_DB_USER=ubuntu MB_DB_HOST=localhost lein test ;; 2) ENGINES=h2,postgres,sqlite MB_DB_TYPE=mysql MB_DB_DBNAME=circle_test MB_DB_PORT=3306 MB_DB_USER=ubuntu MB_DB_HOST=localhost lein test ;; 3) ENGINES=h2,redshift,druid lein test ;; 4) lein eastwood && lein bikeshed && lein docstring-checker && ./bin/reflection-linter ;; 5) npm install && npm run lint && npm run build && npm run test ;; 6) lein uberjar ;; 7) ENGINES=h2,crate lein test ;; esac
:
-
case $CIRCLE_NODE_INDEX in 0) ENGINES=h2,mongo,mysql,bigquery lein test ;; 1) ENGINES=h2,sqlserver MB_DB_TYPE=postgres MB_DB_DBNAME=circle_test MB_DB_PORT=5432 MB_DB_USER=ubuntu MB_DB_HOST=localhost lein test ;; 2) ENGINES=h2,crate,postgres,sqlite MB_DB_TYPE=mysql MB_DB_DBNAME=circle_test MB_DB_PORT=3306 MB_DB_USER=ubuntu MB_DB_HOST=localhost lein test ;; 3) ENGINES=h2,redshift,druid lein test ;; 4) lein eastwood && lein bikeshed && lein docstring-checker && ./bin/reflection-linter ;; 5) npm install && npm run lint && npm run build && npm run test ;; 6) lein uberjar ;; esac
:
parallel
:
true
deployment
:
master
:
...
...
This diff is collapsed.
Click to expand it.
src/metabase/driver/crate/util.clj
+
19
−
11
View file @
e72be01a
(
ns
metabase.driver.crate.util
(
:re
quire
[
metabase.util.korma-extensions
:as
kx
]
[
korma.sql.utils
:as
kutils
]
(
:re
fer-clojure
:exclude
[
second
])
(
:require
[
korma.sql.utils
:as
kutils
]
[
korma.core
:as
k
]
[
metabase.driver.generic-sql.query-processor
:as
qp
]
[
metabase.util
:as
u
]
[
metabase.
driver.generic-sql.query-processor
:as
qp
])
[
metabase.
util.korma-extensions
:as
kx
])
(
:import
(
java.sql
Timestamp
)))
(
defn
unix-timestamp->timestamp
[
_
expr
seconds-or-milliseconds
]
(
defn
unix-timestamp->timestamp
"Converts datetime string to a valid timestamp"
[
_
expr
seconds-or-milliseconds
]
(
case
seconds-or-milliseconds
:seconds
(
recur
nil
(
kx/*
expr
1000
)
:milliseconds
)
:milliseconds
(
kutils/func
(
str
"TRY_CAST(%s as TIMESTAMP)"
)
[
expr
])))
(
defn-
date-trunc
[
unit
expr
]
(
defn-
date-trunc
"date_trunc('interval', timezone, timestamp): truncates a timestamp to a given interval"
[
unit
expr
]
(
let
[
timezone
(
get-in
qp/*query*
[
:settings
:report-timezone
])]
(
if
(
=
(
nil?
timezone
)
true
)
(
k/sqlfn
:DATE_TRUNC
(
kx/literal
unit
)
expr
)
(
k/sqlfn
:DATE_TRUNC
(
kx/literal
unit
)
timezone
expr
))))
(
defn-
date-format
[
format
expr
]
(
defn-
date-format
"date_format('format_string', timezone, timestamp): formats the timestamp as string"
[
fmt
expr
]
(
let
[
timezone
(
get-in
qp/*query*
[
:settings
:report-timezone
])]
(
if
(
nil?
timezone
)
(
k/sqlfn
:DATE_FORMAT
f
orma
t
expr
)
(
k/sqlfn
:DATE_FORMAT
f
orma
t
timezone
expr
))))
(
k/sqlfn
:DATE_FORMAT
f
m
t
expr
)
(
k/sqlfn
:DATE_FORMAT
f
m
t
timezone
expr
))))
(
defn-
extract
[
unit
expr
]
(
defn-
extract
"extract(field from expr): extracts subfields of a timestamp"
[
unit
expr
]
(
case
unit
;; Crate DOW starts with Monday (1) to Sunday (7)
:day_of_week
(
kx/+
(
kx/mod
(
kutils/func
(
format
"EXTRACT(%s FROM %%s)"
(
name
unit
))
[
expr
])
7
)
1
)
...
...
@@ -44,7 +49,9 @@
(
def
^
:private
^
:const
year
(
*
365
day
))
(
def
^
:private
^
:const
month
(
Math/round
(
float
(
/
year
12
))))
(
defn
date
[
_
unit
expr
]
(
defn
date
"ISQLDriver `date` implementation"
[
_
unit
expr
]
(
let
[
v
(
if
(
instance?
Timestamp
expr
)
(
kx/literal
(
u/date->iso-8601
expr
))
expr
)]
...
...
@@ -71,8 +78,9 @@
(
defn-
sql-interval
[
unit
amount
]
(
format
"CURRENT_TIMESTAMP + %d"
(
*
unit
amount
)))
(
defn
date-interval
[
_
unit
amount
]
(
defn
date-interval
"defines the sql command required for date-interval calculation"
[
_
unit
amount
]
(
case
unit
:quarter
(
recur
nil
:month
(
kx/*
amount
3
))
:year
(
k/raw
(
sql-interval
year
amount
))
...
...
This diff is collapsed.
Click to expand it.
src/metabase/driver/generic_sql/query_processor.clj
+
4
−
1
View file @
e72be01a
...
...
@@ -167,7 +167,10 @@
:=
[
'=
(
formatted
value
)]
:!=
[
'not=
(
formatted
value
)])}))
(
defn
filter-clause->predicate
[{
:keys
[
compound-type
subclause
subclauses
]
,
:as
clause
}]
(
defn
filter-clause->predicate
"Given a filter CLAUSE, return a Korma filter predicate form for use in korma `where`. If this is a compound
clause then we call `filter-subclause->predicate` on all of the subclauses."
[{
:keys
[
compound-type
subclause
subclauses
]
,
:as
clause
}]
(
case
compound-type
:and
(
apply
kfns/pred-and
(
map
filter-clause->predicate
subclauses
))
:or
(
apply
kfns/pred-or
(
map
filter-clause->predicate
subclauses
))
...
...
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