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

Explicit intervals and datasource #310

Open
wants to merge 1 commit 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
10 changes: 8 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/ambv/black
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
Expand All @@ -21,7 +21,13 @@ repos:
- id: check-yaml
- id: debug-statements

- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
rev: 3.8.2
hooks:
- id: flake8
exclude:
docs
env
tests
.eggs
build
4 changes: 3 additions & 1 deletion pydruid/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def parse_datasource(datasource, query_type):
"dict or list of strings"
)
if isinstance(datasource, str):
return datasource
return {"type": "table", "name": datasource}
else:
return {"type": "union", "dataSources": datasource}

Expand Down Expand Up @@ -310,6 +310,8 @@ def build_query(self, query_type, args):
query_dict[key] = build_dimension(val)
elif key == "dimensions":
query_dict[key] = [build_dimension(v) for v in val]
elif key == "intervals":
query_dict[key] = {"type": "intervals", key: val}
else:
query_dict[key] = val

Expand Down
14 changes: 10 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def test_druid_returns_html_error(self, mock_urlopen):
str(e.value)
== textwrap.dedent(
"""
HTTP Error 500: Internal Server Error
Druid Error: javax.servlet.ServletException: java.lang.OutOfMemoryError: GC overhead limit exceeded
HTTP Error 500: Internal Server Error
Druid Error: javax.servlet.ServletException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Query is: {
"aggregations": [
{
Expand All @@ -102,15 +102,21 @@ def test_druid_returns_html_error(self, mock_urlopen):
"context": {
"timeout": 1000
},
"dataSource": "testdatasource",
"dataSource": {
"name": "testdatasource",
"type": "table"
},
"dimension": "user_name",
"filter": {
"dimension": "user_lang",
"type": "selector",
"value": "en"
},
"granularity": "all",
"intervals": "2015-12-29/pt1h",
"intervals": {
"intervals": "2015-12-29/pt1h",
"type": "intervals"
},
"metric": "count",
"queryType": "topN",
"threshold": 1
Expand Down
12 changes: 7 additions & 5 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#

import csv
import os

import pandas
import pytest
Expand Down Expand Up @@ -62,7 +61,7 @@ def test_build_query(self):
# given
expected_query_dict = {
"queryType": None,
"dataSource": "things",
"dataSource": {"name": "things", "type": "table"},
"aggregations": [{"fieldName": "thing", "name": "count", "type": "count"}],
"postAggregations": [
{
Expand Down Expand Up @@ -106,7 +105,7 @@ def test_build_query_none_type(self):
# given
expected_query_dict = {
"queryType": None,
"dataSource": "things",
"dataSource": {"name": "things", "type": "table"},
"aggregations": [{"fieldName": "thing", "name": "count", "type": "count"}],
"filter": {"dimension": "one", "type": "selector", "value": 1},
"having": {"aggregation": "sum", "type": "greaterThan", "value": 1},
Expand Down Expand Up @@ -153,7 +152,10 @@ def test_validate_query(self):

def test_union_datasource(self):
# Given
expected_query_dict = {"queryType": None, "dataSource": "things"}
expected_query_dict = {
"queryType": None,
"dataSource": {"name": "things", "type": "table"},
}
builder = QueryBuilder()
# when
builder_dict = {"datasource": "things"}
Expand Down Expand Up @@ -187,7 +189,7 @@ def test_build_subquery(self):
expected_query_dict = {
"query": {
"queryType": "groupBy",
"dataSource": "things",
"dataSource": {"name": "things", "type": "table"},
"aggregations": [
{"fieldName": "thing", "name": "count", "type": "count"}
],
Expand Down