druid-io / pydruid

A Python connector for Druid
Other
506 stars 194 forks source link

Cant use a variable for intervals, but hard coded strings work #237

Closed bencleary closed 3 years ago

bencleary commented 3 years ago

I am working on a project which allows a user to specify a given interval range and query. I am experiencing a problem whereby I cannot pass a generated interval into the query builder.

query = PyDruid("http://51.104.48.48:8888", "druid/v2")

start = datetime.datetime.now() - datetime.timedelta(hours=1)
end = datetime.datetime.now()
interval = f"{start.isoformat()}/{end.isoformat()}"

sc = query.scan(
    datasource="my-table-name",
    intervals=interval,
    filter=Dimension("device_id") == "30325",
    limit=100,
)

print(sc) # results in []

If I execute the generated native query against the druid endpoint it works as expected and returns the results I am expecting.

{
    "dataSource": "my-table-name",
    "filter": {
        "dimension": "device_id",
        "type": "selector",
        "value": "30325"
    },
    "intervals": "2020-10-06T13:10:09.500371/2020-10-06T14:10:09.500433",
    "limit": 100,
    "queryType": "scan"
}

The same outcome is present if I copy the requested interval in as a string, I only loose results when I try and use a variable for the interval.

Any ideas?

Thanks

bencleary commented 3 years ago

I have resolved this, it was my environment, still unsure what exactly it was but closing