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
ef4170a7
Unverified
Commit
ef4170a7
authored
7 years ago
by
Cam Saul
Browse files
Options
Downloads
Plain Diff
Merge branch 'hyperunique' [ci drivers]
parents
55b7665c
2e1c6e1f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/driver/druid.clj
+26
-13
26 additions, 13 deletions
src/metabase/driver/druid.clj
src/metabase/driver/druid/query_processor.clj
+15
-6
15 additions, 6 deletions
src/metabase/driver/druid/query_processor.clj
src/metabase/types.clj
+1
-0
1 addition, 0 deletions
src/metabase/types.clj
with
42 additions
and
19 deletions
src/metabase/driver/druid.clj
+
26
−
13
View file @
ef4170a7
...
...
@@ -70,27 +70,40 @@
;;; ### Sync
(
defn-
describe-table-field
[
druid-field-type
field-name
]
(
defn-
do-segment-metadata-query
[
details
datasource
]
(
do-query
details
{
"queryType"
"segmentMetadata"
"dataSource"
datasource
"intervals"
[
"1999-01-01/2114-01-01"
]
"analysisTypes"
[]
"merge"
true
}))
(
defn-
druid-type->base-type
[
field-type
]
(
case
field-type
"STRING"
:type/Text
"FLOAT"
:type/Float
"LONG"
:type/Float
"hyperUnique"
:type/DruidHyperUnique
:type/Float
))
(
defn-
describe-table-field
[[
field-kw
{
:keys
[
type
]}]]
;; all dimensions are Strings, and all metrics as JS Numbers, I think (?)
;; string-encoded booleans + dates are treated as strings (!)
(
assoc
(
case
druid-field-type
:metric
{
:database-type
"metric"
,
:base-type
:type/Float
}
:dimension
{
:database-type
"dimension"
,
:base-type
:type/Text
})
:name
field-name
))
{
:name
(
name
field-kw
)
:base-type
(
druid-type->base-type
type
)
:database-type
type
})
(
defn-
describe-table
[
database
table
]
(
ssh/with-ssh-tunnel
[
details-with-tunnel
(
:details
database
)]
(
let
[{
:keys
[
dimensions
metrics
]}
(
GET
(
details->url
details-with-tunnel
"/druid/v2/datasources/"
(
:name
table
)
"?interval=1900-01-01/2100-01-01"
))]
(
let
[{
:keys
[
columns
]}
(
first
(
do-segment-metadata-query
details-with-tunnel
(
:name
table
)
))]
{
:schema
nil
:name
(
:name
table
)
:fields
(
set
(
concat
;; every Druid table is an event stream w/ a timestamp field
[{
:name
"timestamp"
:database-type
"timestamp"
:base-type
:type/DateTime
:pk?
true
}]
(
map
(
partial
describe-table-field
:dimension
)
dimensions
)
(
map
(
partial
describe-table-field
:metric
)
metrics
)))})))
;; every Druid table is an event stream w/ a timestamp field
[{
:name
"timestamp"
:database-type
"timestamp"
:base-type
:type/DateTime
:pk?
true
}]
(
map
describe-table-field
(
dissoc
columns
:__time
))))})))
(
defn-
describe-database
[
database
]
{
:pre
[(
map?
(
:details
database
))]}
...
...
This diff is collapsed.
Click to expand it.
src/metabase/driver/druid/query_processor.clj
+
15
−
6
View file @
ef4170a7
...
...
@@ -73,9 +73,10 @@
(
extend-protocol
IDimensionOrMetric
Field
(
dimension-or-metric?
[{
:keys
[
base-type
]}]
(
cond
(
isa?
base-type
:type/Text
)
:dimension
(
isa?
base-type
:type/Float
)
:metric
(
isa?
base-type
:type/Integer
)
:metric
))
(
isa?
base-type
:type/Text
)
:dimension
(
isa?
base-type
:type/Float
)
:metric
(
isa?
base-type
:type/Integer
)
:metric
(
isa?
base-type
:type/DruidHyperUnique
)
:metric
))
DateTimeField
(
dimension-or-metric?
[
this
]
(
dimension-or-metric?
(
:field
this
))))
...
...
@@ -217,6 +218,16 @@
(
defn-
ag
:filtered
[
filtr
aggregator
]
{
:type
:filtered,
:filter
filtr,
:aggregator
aggregator
})
(
defn-
ag
:distinct
[
field
output-name
]
(
if
(
=
(
:base-type
field
)
:type/DruidHyperUnique
)
{
:type
:hyperUnique
:name
output-name
:fieldName
(
->rvalue
field
)}
{
:type
:cardinality
:name
output-name
:fieldNames
[(
->rvalue
field
)]}))
(
defn-
ag
:count
([
output-name
]
{
:type
:count,
:name
output-name
})
([
field
output-name
]
(
ag
:filtered
(
filter
:not
(
filter
:nil?
field
))
...
...
@@ -243,9 +254,7 @@
:fields
[{
:type
:fieldAccess,
:fieldName
sum-name
}
{
:type
:fieldAccess,
:fieldName
count-name
}]}]}])
[
:distinct
_
]
[[(
or
output-name-kwd
:distinct___count
)]
{
:aggregations
[{
:type
:cardinality
:name
(
or
output-name
:distinct___count
)
:fieldNames
[(
->rvalue
ag-field
)]}]}]
{
:aggregations
[(
ag
:distinct
ag-field
(
or
output-name
:distinct___count
))]}]
[
:sum
_
]
[[(
or
output-name-kwd
:sum
)]
{
:aggregations
[(
ag
:doubleSum
ag-field
(
or
output-name
:sum
))]}]
[
:min
_
]
[[(
or
output-name-kwd
:min
)]
{
:aggregations
[(
ag
:doubleMin
ag-field
(
or
output-name
:min
))]}]
[
:max
_
]
[[(
or
output-name-kwd
:max
)]
{
:aggregations
[(
ag
:doubleMax
ag-field
(
or
output-name
:max
))]}])))
...
...
This diff is collapsed.
Click to expand it.
src/metabase/types.clj
+
1
−
0
View file @
ef4170a7
...
...
@@ -67,6 +67,7 @@
(
derive
:type/Boolean
:type/*
)
(
derive
:type/Enum
:type/*
)
(
derive
:type/DruidHyperUnique
:type/*
)
;;; Text-Like Types: Things that should be displayed as text for most purposes but that *shouldn't* support advanced
;;; filter options like starts with / contains
...
...
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