### Execute Asynchronous TopN Query with AsyncPyDruid Source: https://pythonhosted.org/pydruid/index.html Demonstrates initializing the AsyncPyDruid client and executing a topN query. Includes examples of printing the query dictionary, raw results, and exporting to a pandas DataFrame. ```python >>> from pydruid.async_client import * >>> query = AsyncPyDruid('http://localhost:8083', 'druid/v2/') >>> top = yield query.topn( datasource='twitterstream', granularity='all', intervals='2013-10-04/pt1h', aggregations={"count": doublesum("count")}, dimension='user_name', filter = Dimension('user_lang') == 'en', metric='count', threshold=2 ) >>> print json.dumps(top.query_dict, indent=2) >>> { "metric": "count", "aggregations": [ { "type": "doubleSum", "fieldName": "count", "name": "count" } ], "dimension": "user_name", "filter": { "type": "selector", "dimension": "user_lang", "value": "en" }, "intervals": "2013-10-04/pt1h", "dataSource": "twitterstream", "granularity": "all", "threshold": 2, "queryType": "topN" } >>> print top.result >>> [{'timestamp': '2013-10-04T00:00:00.000Z', 'result': [{'count': 7.0, 'user_name': 'user_1'}, {'count': 6.0, 'user_name': 'user_2'}]}] >>> df = top.export_pandas() >>> print df >>> count timestamp user_name 0 7 2013-10-04T00:00:00.000Z user_1 1 6 2013-10-04T00:00:00.000Z user_2 ``` -------------------------------- ### topn query example with client.topn Source: https://pythonhosted.org/pydruid/index.html Example of using the topn method to query a datasource with a dimension filter, metric, and threshold. The query returns a list of results with the top items sorted by the specified metric. ```python >>> top = client.topn( datasource='twitterstream', granularity='all', intervals='2013-06-14/pt1h', aggregations={"count": doublesum("count")}, dimension='user_name', metric='count', filter=Dimension('user_lang') == 'en', threshold=1, context={"timeout": 1000} ) >>> print top >>> [{'timestamp': '2013-06-14T00:00:00.000Z', 'result': [{'count': 22.0, 'user': "cool_user"}}]}] ``` -------------------------------- ### PyDruid client usage with topn query and export_pandas Source: https://pythonhosted.org/pydruid/index.html Complete example of creating a PyDruid client, running a topn query, printing the query dictionary and result, and exporting the result to a pandas DataFrame. Shows the full workflow from client instantiation to data export. ```python >>> from pydruid.client import * >>> query = PyDruid('http://localhost:8083', 'druid/v2/') >>> top = query.topn( datasource='twitterstream', granularity='all', intervals='2013-10-04/pt1h', aggregations={"count": doublesum("count")}, dimension='user_name', filter = Dimension('user_lang') == 'en', metric='count', threshold=2 ) >>> print json.dumps(top.query_dict, indent=2) >>> { "metric": "count", "aggregations": [ { "type": "doubleSum", "fieldName": "count", "name": "count" } ], "dimension": "user_name", "filter": { "type": "selector", "dimension": "user_lang", "value": "en" }, "intervals": "2013-10-04/pt1h", "dataSource": "twitterstream", "granularity": "all", "threshold": 2, "queryType": "topN" } >>> print top.result >>> [{'timestamp': '2013-10-04T00:00:00.000Z', 'result': [{'count': 7.0, 'user_name': 'user_1'}, {'count': 6.0, 'user_name': 'user_2'}]}] >>> df = top.export_pandas() >>> print df >>> count timestamp user_name 0 7 2013-10-04T00:00:00.000Z user_1 1 6 2013-10-04T00:00:00.000Z user_2 ``` -------------------------------- ### topn(**kwargs) Source: https://pythonhosted.org/pydruid/index.html Executes a topN query asynchronously. Accepts keyword arguments for the query parameters. Example usage is provided in the documentation. ```APIDOC ## topn(**kwargs) ### Description Executes a topN query asynchronously. Accepts keyword arguments for the query parameters. ### Parameters - **kwargs** - Required - Query parameters for the topN query. ### Example ```python >>> top = yield query.topn( datasource='twitterstream', granularity='all', intervals='2013-10-04/pt1h', aggregations={"count": doublesum("count")}, dimension='user_name', filter = Dimension('user_lang') == 'en', metric='count', threshold=2 )``` ``` -------------------------------- ### QueryBuilder.select(args) Source: https://pythonhosted.org/pydruid/index.html Builds a select query that returns raw Druid rows and supports pagination. Returns a Query object. ```APIDOC ## select(args) ### Description A select query returns raw Druid rows and supports pagination. ### Method N/A (Python method) ### Endpoint N/A ### Parameters - **args** (dict) - Required - dict of args ### Returns - **Query** - select query ### Example N/A ``` -------------------------------- ### Execute a select query with pydruid Source: https://pythonhosted.org/pydruid/index.html Demonstrates how to perform a select query on a datasource with specified granularity, intervals, paging specifications, and context timeout. ```python >>> raw_data = client.select( datasource=twitterstream, granularity='all', intervals='2013-06-14/pt1h', paging_spec={'pagingIdentifies': {}, 'threshold': 1}, context={"timeout": 1000} ) >>> print raw_data >>> [{'timestamp': '2013-06-14T00:00:00.000Z', 'result': {'pagingIdentifiers': {'twitterstream_2013-06-14T00:00:00.000Z_2013-06-15T00:00:00.000Z_2013-06-15T08:00:00.000Z_v1': 1, 'events': [{'segmentId': 'twitterstream_2013-06-14T00:00:00.000Z_2013-06-15T00:00:00.000Z_2013-06-15T08:00:00.000Z_v1', 'offset': 0, 'event': {'timestamp': '2013-06-14T00:00:00.000Z', 'dim': 'value'}}]}}}] ``` -------------------------------- ### select(**kwargs) Source: https://pythonhosted.org/pydruid/index.html Performs a select query on a Druid data source, returning raw rows of data. It supports paging and context options. ```APIDOC ## select(**kwargs) ### Description Performs a select query on a Druid data source, returning raw rows of data. It supports paging and context options. ### Method select ### Parameters #### Required Key/Value Pairs - **datasource** (str) - Required - Data source to query - **granularity** (str) - Required - Time bucket to aggregate data by hour, day, minute, etc. - **intervals** (str or list) - Required - ISO-8601 intervals for which to run the query on #### Optional Key/Value Pairs - **filter** (pydruid.utils.filters.Filter) - Optional - Indicates which rows of data to include in the query - **dimensions** (list) - Optional - The list of dimensions to select. If left empty, all dimensions are returned - **metrics** (list) - Optional - The list of metrics to select. If left empty, all metrics are returned - **context** (dict) - Optional - A dict of query context options ### Returns The query result ### Return Type Query ### Request Example ```python raw_data = client.select( datasource=twitterstream, granularity='all', intervals='2013-06-14/pt1h', paging_spec={'pagingIdentifies': {}, 'threshold': 1}, context={"timeout": 1000} ) ``` ### Response Example ```python [{'timestamp': '2013-06-14T00:00:00.000Z', 'result': {'pagingIdentifiers': {'twitterstream_2013-06-14T00:00:00.000Z_2013-06-15T00:00:00.000Z_2013-06-15T08:00:00.000Z_v1': 1, 'events': [{'segmentId': 'twitterstream_2013-06-14T00:00:00.000Z_2013-06-15T00:00:00.000Z_2013-06-15T08:00:00.000Z_v1', 'offset': 0, 'event': {'timestamp': '2013-06-14T00:00:00.000Z', 'dim': 'value'}}]}}] ``` ``` -------------------------------- ### select(**kwargs) Source: https://pythonhosted.org/pydruid/index.html Executes a select query asynchronously. Accepts keyword arguments for the query parameters. ```APIDOC ## select(**kwargs) ### Description Executes a select query asynchronously. Accepts keyword arguments for the query parameters. ### Parameters - **kwargs** - Required - Query parameters for the select query. ``` -------------------------------- ### Export query results to a TSV file Source: https://pythonhosted.org/pydruid/index.html Demonstrates using the export_tsv method to write query results to a file path. ```python >>> top = client.topn( datasource='twitterstream', granularity='all', intervals='2013-10-04/pt1h', aggregations={"count": doublesum("count")}, dimension='user_name', filter = Dimension('user_lang') == 'en', metric='count', threshold=2 ) >>> top.export_tsv('top.tsv') >>> !cat top.tsv >>> count user_name timestamp 7.0 user_1 2013-10-04T00:00:00.000Z 6.0 user_2 2013-10-04T00:00:00.000Z ``` -------------------------------- ### Execute a time_boundary query Source: https://pythonhosted.org/pydruid/index.html Retrieves the minimum and maximum timestamps for a specified datasource. ```python >>> bound = client.time_boundary(datasource='twitterstream') >>> print bound >>> [{'timestamp': '2011-09-14T15:00:00.000Z', 'result': {'minTime': '2011-09-14T15:00:00.000Z', 'maxTime': '2014-03-04T23:44:00.000Z'}}] ``` -------------------------------- ### AsyncPyDruid(url, endpoint) Source: https://pythonhosted.org/pydruid/index.html Constructor for the asynchronous PyDruid client. It initializes the client with the URL of the Druid Broker node and the endpoint that the Broker listens for queries on. ```APIDOC ## AsyncPyDruid(url, endpoint) ### Description Asynchronous PyDruid client which mirrors functionality of the synchronous PyDruid, but it executes queries asynchronously (using an asynchronous http client from Tornado framework). Returns Query objects that can be used for exporting query results into TSV files or pandas.DataFrame objects for subsequent analysis. ### Parameters - **url** (str) - Required - URL of Broker node in the Druid cluster - **endpoint** (str) - Required - Endpoint that Broker listens for queries on ### Example ```python >>> from pydruid.async_client import * >>> query = AsyncPyDruid('http://localhost:8083', 'druid/v2/') ``` ``` -------------------------------- ### topn(**kwargs) Source: https://pythonhosted.org/pydruid/index.html Executes a TopN query against the Druid datasource. Returns a Query object containing the results. ```APIDOC ## topn(**kwargs) ### Description A TopN query returns a set of the values in a given dimension, sorted by a specified metric. Conceptually, a topN can be thought of as an approximate GroupByQuery over a single dimension with an Ordering spec. TopNs are faster and more resource efficient than GroupBy for this use case. ### Parameters #### Required Parameters - **datasource** (str) - Required - Data source to query - **granularity** (str) - Required - Aggregate data by hour, day, minute, etc. - **intervals** (str or list) - Required - ISO-8601 intervals of data to query - **aggregations** (dict) - Required - A map from aggregator name to one of the pydruid.utils.aggregators e.g., doublesum - **dimension** (str) - Required - Dimension to run the query against - **metric** (str) - Required - Metric over which to sort the specified dimension by - **threshold** (int) - Required - How many of the top items to return #### Optional Parameters - **filter** (pydruid.utils.filters.Filter) - Optional - Indicates which rows of data to include in the query - **post_aggregations** - Optional - A dict with string key = 'post_aggregator_name', and value pydruid.utils.PostAggregator - **context** (dict) - Optional - A dict of query context options ### Returns - **Query** - The query result ### Example ```python >>> top = client.topn( datasource='twitterstream', granularity='all', intervals='2013-06-14/pt1h', aggregations={"count": doublesum("count")}, dimension='user_name', metric='count', filter=Dimension('user_lang') == 'en', threshold=1, context={"timeout": 1000} ) >>> print top >>> [{'timestamp': '2013-06-14T00:00:00.000Z', 'result': [{'count': 22.0, 'user': "cool_user"}}]}] ``` ``` -------------------------------- ### Execute a timeseries query with aggregations Source: https://pythonhosted.org/pydruid/index.html Performs a timeseries query with defined aggregations, post-aggregations, and context settings. ```python >>> counts = client.timeseries( datasource=twitterstream, granularity='hour', intervals='2013-06-14/pt1h', aggregations={"count": doublesum("count"), "rows": count("rows")}, post_aggregations={'percent': (Field('count') / Field('rows')) * Const(100))}, context={"timeout": 1000} ) >>> print counts >>> [{'timestamp': '2013-06-14T00:00:00.000Z', 'result': {'count': 9619.0, 'rows': 8007, 'percent': 120.13238416385663}}] ``` -------------------------------- ### QueryBuilder.time_boundary(args) Source: https://pythonhosted.org/pydruid/index.html Builds a time boundary query that returns the min and max timestamps in a data source. Returns a Query object. ```APIDOC ## time_boundary(args) ### Description A time boundary query returns the min and max timestamps present in a data source. ### Method N/A (Python method) ### Endpoint N/A ### Parameters - **args** (dict) - Required - dict of args ### Returns - **Query** - time boundary query ### Example N/A ``` -------------------------------- ### PyDruid(url, endpoint) Source: https://pythonhosted.org/pydruid/index.html Constructor for the PyDruid class. Initializes a client to connect to a Druid Broker node and execute queries. ```APIDOC ## PyDruid(url, endpoint) ### Description Initializes a PyDruid client for creating and executing Druid queries. Returns Query objects that can be used for exporting query results into TSV files or pandas.DataFrame objects. ### Parameters - **url** (str) - Required - URL of Broker node in the Druid cluster - **endpoint** (str) - Required - Endpoint that Broker listens for queries on ### Example ```python >>> from pydruid.client import * >>> query = PyDruid('http://localhost:8083', 'druid/v2/') ``` ``` -------------------------------- ### Execute a GroupBy Query Source: https://pythonhosted.org/pydruid/index.html Performs a groupby query on the 'twitterstream' datasource, grouping by user names with specific filters, aggregations, and a limit specification. ```python >>> group = client.groupby( datasource='twitterstream', granularity='hour', intervals='2013-10-04/pt1h', dimensions=["user_name", "reply_to_name"], filter=~(Dimension("reply_to_name") == "Not A Reply"), aggregations={"count": doublesum("count")}, context={"timeout": 1000} limit_spec={ "type": "default", "limit": 50, "columns" : ["count"] } ) >>> for k in range(2): ... print group[k] >>> {'timestamp': '2013-10-04T00:00:00.000Z', 'version': 'v1', 'event': {'count': 1.0, 'user_name': 'user_1', 'reply_to_name': 'user_2'}} >>> {'timestamp': '2013-10-04T00:00:00.000Z', 'version': 'v1', 'event': {'count': 1.0, 'user_name': 'user_2', 'reply_to_name': 'user_3'}} ``` -------------------------------- ### QueryBuilder.topn(args) Source: https://pythonhosted.org/pydruid/index.html Builds a TopN query that returns a set of dimension values sorted by a specified metric. Returns a Query object. ```APIDOC ## topn(args) ### Description A TopN query returns a set of the values in a given dimension, sorted by a specified metric. Conceptually, a topN can be thought of as an approximate GroupByQuery over a single dimension with an Ordering spec. TopNs are faster and more resource efficient than GroupBy for this use case. ### Method N/A (Python method) ### Endpoint N/A ### Parameters - **args** (dict) - Required - dict of arguments ### Returns - **Query** - topn query ### Example N/A ``` -------------------------------- ### Export query results to a Pandas DataFrame Source: https://pythonhosted.org/pydruid/index.html Demonstrates using the export_pandas method on a topN query result to convert it into a Pandas DataFrame. ```python >>> top = client.topn( datasource='twitterstream', granularity='all', intervals='2013-10-04/pt1h', aggregations={"count": doublesum("count")}, dimension='user_name', filter = Dimension('user_lang') == 'en', metric='count', threshold=2 ) >>> df = top.export_pandas() >>> print df >>> count timestamp user_name 0 7 2013-10-04T00:00:00.000Z user_1 1 6 2013-10-04T00:00:00.000Z user_2 ``` -------------------------------- ### QueryBuilder.search(args) Source: https://pythonhosted.org/pydruid/index.html Builds a search query that returns dimension values matching the search specification. Returns a Query object. ```APIDOC ## search(args) ### Description A search query returns dimension values that match the search specification. ### Method N/A (Python method) ### Endpoint N/A ### Parameters - **args** (dict) - Required - dict of args ### Returns - **Query** - search query ### Example N/A ``` -------------------------------- ### BaseDruidClient.select Source: https://pythonhosted.org/pydruid/index.html Executes a select query that returns raw Druid rows and supports pagination. Requires datasource, granularity, paging_spec, and intervals. ```APIDOC ## select(**kwargs) ### Description A select query returns raw Druid rows and supports pagination. ### Method N/A (Python method) ### Parameters #### Required Parameters - **datasource** (str) - Required - Data source to query - **granularity** (str) - Required - Time bucket to aggregate data by hour, day, minute, etc. - **paging_spec** (dict) - Required - Indicates offsets into different scanned segments - **intervals** (str or list) - Required - ISO-8601 intervals for which to run the query on ### Returns - **Query** - The query result ``` -------------------------------- ### QueryBuilder.timeseries(args) Source: https://pythonhosted.org/pydruid/index.html Builds a timeseries query that returns aggregated metric values for each timestamp. Returns a Query object. ```APIDOC ## timeseries(args) ### Description A timeseries query returns the values of the requested metrics (in aggregate) for each timestamp. ### Method N/A (Python method) ### Endpoint N/A ### Parameters - **args** (dict) - Required - dict of args ### Returns - **Query** - timeseries query ### Example N/A ``` -------------------------------- ### QueryBuilder.build_query(query_type, args) Source: https://pythonhosted.org/pydruid/index.html Builds a query based on the given query type and arguments. Returns a Query object. ```APIDOC ## build_query(query_type, args) ### Description Build query based on given query type and arguments. ### Method N/A (Python method) ### Endpoint N/A ### Parameters - **query_type** (string) - Required - a type of query - **args** (dict) - Required - the dict of args to be sent ### Returns - **Query** - the resulting query ### Example N/A ``` -------------------------------- ### time_boundary(**kwargs) Source: https://pythonhosted.org/pydruid/index.html Returns the minimum and maximum timestamps present in a data source. This is useful for determining the time range of data. ```APIDOC ## time_boundary(**kwargs) ### Description Returns the minimum and maximum timestamps present in a data source. This is useful for determining the time range of data. ### Method time_boundary ### Parameters #### Required Key/Value Pairs - **datasource** (str) - Required - Data source to query #### Optional Key/Value Pairs - **context** (dict) - Optional - A dict of query context options ### Returns The query result ### Return Type Query ### Request Example ```python bound = client.time_boundary(datasource='twitterstream') ``` ### Response Example ```python [{'timestamp': '2011-09-14T15:00:00.000Z', 'result': {'minTime': '2011-09-14T15:00:00.000Z', 'maxTime': '2014-03-04T23:44:00.000Z'}}] ``` ``` -------------------------------- ### time_boundary(**kwargs) Source: https://pythonhosted.org/pydruid/index.html Executes a timeBoundary query asynchronously. Accepts keyword arguments for the query parameters. ```APIDOC ## time_boundary(**kwargs) ### Description Executes a timeBoundary query asynchronously. Accepts keyword arguments for the query parameters. ### Parameters - **kwargs** - Required - Query parameters for the timeBoundary query. ``` -------------------------------- ### Query.export_tsv(dest_path) Source: https://pythonhosted.org/pydruid/index.html Exports the current query result to a TSV file. Takes a destination path as a parameter. ```APIDOC ## export_tsv(dest_path) ### Description Export the current query result to a tsv file. ### Method N/A (Python method) ### Endpoint N/A ### Parameters - **dest_path** (str) - Required - file to write query results to ### Returns None ### Raises - **NotImplementedError** - If the export is not implemented for the query type ### Example ```python >>> top = client.topn( datasource='twitterstream', granularity='all', intervals='2013-10-04/pt1h', aggregations={"count": doublesum("count")}, dimension='user_name', filter = Dimension('user_lang') == 'en', metric='count', threshold=2 ) >>> top.export_tsv('top.tsv') >>> !cat top.tsv >>> count user_name timestamp 7.0 user_1 2013-10-04T00:00:00.000Z 6.0 user_2 2013-10-04T00:00:00.000Z ``` ``` -------------------------------- ### pydruid.utils.having.Having Source: https://pythonhosted.org/pydruid/index.html Base class for having clauses. Provides static method build_having(having_obj) and instance method show(). ```APIDOC ## Having(**args) ### Description Base class for having clauses. ### Methods - **build_having(having_obj)** (static) - Builds a having clause from a having object. - **show()** - Returns the having representation. ``` -------------------------------- ### groupby(**kwargs) Source: https://pythonhosted.org/pydruid/index.html Executes a groupBy query asynchronously. Accepts keyword arguments for the query parameters. ```APIDOC ## groupby(**kwargs) ### Description Executes a groupBy query asynchronously. Accepts keyword arguments for the query parameters. ### Parameters - **kwargs** - Required - Query parameters for the groupBy query. ``` -------------------------------- ### pydruid.utils.aggregators module Source: https://pythonhosted.org/pydruid/index.html Provides functions to build various Druid aggregators. ```APIDOC ## pydruid.utils.aggregators module ### Functions #### build_aggregators(agg_input) Builds aggregators from input. #### cardinality(raw_column, by_row=False) Creates a cardinality aggregator. #### count(raw_metric) Creates a count aggregator. #### doublesum(raw_metric) Creates a double sum aggregator. #### filtered(filter, agg) Creates a filtered aggregator. #### hyperunique(raw_metric) Creates a hyperUnique aggregator. #### javascript(columns_list, fn_aggregate, fn_combine, fn_reset) Creates a JavaScript aggregator. #### longsum(raw_metric) Creates a long sum aggregator. #### max(raw_metric) Creates a max aggregator. #### min(raw_metric) Creates a min aggregator. ``` -------------------------------- ### QueryBuilder.groupby(args) Source: https://pythonhosted.org/pydruid/index.html Builds a group-by query that groups results by specified dimensions. Returns a Query object. ```APIDOC ## groupby(args) ### Description A group-by query groups a results set (the requested aggregate metrics) by the specified dimension(s). ### Method N/A (Python method) ### Endpoint N/A ### Parameters - **args** (dict) - Required - dict of args ### Returns - **Query** - group by query ### Example N/A ``` -------------------------------- ### pydruid.utils.dimensions module Source: https://pythonhosted.org/pydruid/index.html Provides classes for building dimension specifications and extraction functions. ```APIDOC ## pydruid.utils.dimensions module ### Classes #### BaseRegexExtraction(expr) Builds a regex extraction function. #### DimensionSpec(dimension, output_name, extraction_function=None) Builds a dimension specification. #### ExtractionFunction Base class for extraction functions. #### JavascriptExtraction(func, injective=False) Builds a JavaScript extraction function. #### LookupExtraction(retain_missing_values=False, replace_missing_values=None, injective=False) Builds a lookup extraction function. #### MapLookupExtraction(mapping, **kwargs) Builds a map lookup extraction function. #### NamespaceLookupExtraction(namespace, **kwargs) Builds a namespace lookup extraction function. #### PartialExtraction(expr) Builds a partial extraction function. #### RegexExtraction(expr) Builds a regex extraction function. #### TimeFormatExtraction(format, locale=None, time_zone=None) Builds a time format extraction function. ### Functions #### build_dimension(dim) Builds a dimension from input. ``` -------------------------------- ### timeseries(**kwargs) Source: https://pythonhosted.org/pydruid/index.html Executes a timeseries query asynchronously. Accepts keyword arguments for the query parameters. ```APIDOC ## timeseries(**kwargs) ### Description Executes a timeseries query asynchronously. Accepts keyword arguments for the query parameters. ### Parameters - **kwargs** - Required - Query parameters for the timeseries query. ``` -------------------------------- ### pydruid.utils.filters.Filter Source: https://pythonhosted.org/pydruid/index.html Base class for filters. Provides static method build_filter(filter_obj) and instance method show(). ```APIDOC ## Filter(**args) ### Description Base class for filter objects. ### Methods - **build_filter(filter_obj)** (static) - Builds a filter from a filter object. - **show()** - Returns the filter representation. ``` -------------------------------- ### pydruid.utils.postaggregator.Quantiles Source: https://pythonhosted.org/pydruid/index.html Postaggregator that computes multiple quantiles. ```APIDOC ## Quantiles(name, probabilities) ### Description Postaggregator that computes multiple quantiles. ### Constructor Parameters - **name** - The field name. - **probabilities** - A list of quantile probabilities. ``` -------------------------------- ### QueryBuilder.segment_metadata(args) Source: https://pythonhosted.org/pydruid/index.html Builds a segment metadata query that returns column type, estimated size, interval, and segment ID. Returns a Query object. ```APIDOC ## segment_metadata(args) ### Description A segment metadata query returns information about segments including column type, estimated size, interval, and segment ID. ### Method N/A (Python method) ### Endpoint N/A ### Parameters - **args** (dict) - Required - dict of args ### Returns - **Query** - segment metadata query ### Example N/A ``` -------------------------------- ### pydruid.utils.postaggregator.Const Source: https://pythonhosted.org/pydruid/index.html Postaggregator that returns a constant value. ```APIDOC ## Const(value, output_name=None) ### Description Postaggregator that returns a constant value. ### Constructor Parameters - **value** - The constant value. - **output_name** (optional) - The output name for the postaggregator. ``` -------------------------------- ### pydruid.utils.postaggregator.Quantile Source: https://pythonhosted.org/pydruid/index.html Postaggregator that computes a quantile. ```APIDOC ## Quantile(name, probability) ### Description Postaggregator that computes a quantile. ### Constructor Parameters - **name** - The field name. - **probability** - The quantile probability. ``` -------------------------------- ### validate_query(query_type, valid_parts, args) Source: https://pythonhosted.org/pydruid/index.html Validates the query parts so only allowed objects are sent. Each query type can have an optional 'context' object attached which is used to set certain query context settings, etc. timeout or priority. ```APIDOC ## validate_query(query_type, valid_parts, args) ### Description Validates the query parts so only allowed objects are sent. Each query type can have an optional 'context' object attached which is used to set certain query context settings, etc. timeout or priority. ### Parameters - **query_type** (string) - Required - a type of query - **valid_parts** (list) - Required - a list of valid object names - **args** (dict) - Required - the dict of args to be sent ### Raises - **ValueError** - if an invalid object is given ``` -------------------------------- ### segment_metadata(**kwargs) Source: https://pythonhosted.org/pydruid/index.html Executes a segmentMetadata query asynchronously. Accepts keyword arguments for the query parameters. ```APIDOC ## segment_metadata(**kwargs) ### Description Executes a segmentMetadata query asynchronously. Accepts keyword arguments for the query parameters. ### Parameters - **kwargs** - Required - Query parameters for the segmentMetadata query. ``` -------------------------------- ### timeseries(**kwargs) Source: https://pythonhosted.org/pydruid/index.html Returns aggregated metric values for each timestamp in the specified intervals. Supports aggregations, post-aggregations, and filtering. ```APIDOC ## timeseries(**kwargs) ### Description Returns aggregated metric values for each timestamp in the specified intervals. Supports aggregations, post-aggregations, and filtering. ### Method timeseries ### Parameters #### Required Key/Value Pairs - **datasource** (str) - Required - Data source to query - **granularity** (str) - Required - Time bucket to aggregate data by hour, day, minute, etc. - **intervals** (str or list) - Required - ISO-8601 intervals for which to run the query on - **aggregations** (dict) - Required - A map from aggregator name to one of the pydruid.utils.aggregators e.g., doublesum #### Optional Key/Value Pairs - **filter** (pydruid.utils.filters.Filter) - Optional - Indicates which rows of data to include in the query - **post_aggregations** - Optional - A dict with string key = 'post_aggregator_name', and value pydruid.utils.PostAggregator - **context** (dict) - Optional - A dict of query context options ### Returns The query result ### Return Type Query ### Request Example ```python counts = client.timeseries( datasource=twitterstream, granularity='hour', n intervals='2013-06-14/pt1h', n aggregations={"count": doublesum("count"), "rows": count("rows")}, post_aggregations={'percent': (Field('count') / Field('rows')) * Const(100))}, context={"timeout": 1000} ) ``` n ### Response Example ```python [{'timestamp': '2013-06-14T00:00:00.000Z', 'result': {'count': 9619.0, 'rows': 8007, 'percent': 120.13238416385663}}] ``` ``` -------------------------------- ### pydruid.utils.postaggregator.Field Source: https://pythonhosted.org/pydruid/index.html Postaggregator that references a field. ```APIDOC ## Field(name) ### Description Postaggregator that references a field. ### Constructor Parameters - **name** - The field name. ``` -------------------------------- ### BaseDruidClient.export_tsv Source: https://pythonhosted.org/pydruid/index.html Exports the current query result to a TSV file. Deprecated; use Query.export_tsv() instead. ```APIDOC ## export_tsv(dest_path) ### Description Export the current query result to a tsv file. ### Parameters - **dest_path** - Required - Destination path for the TSV file ### Deprecation Deprecated since version: Use Query.export_tsv() method instead. ``` -------------------------------- ### pydruid.utils.postaggregator.Postaggregator Source: https://pythonhosted.org/pydruid/index.html Base class for postaggregators. Provides static method build_post_aggregators(postaggs) and instance method fields(other). ```APIDOC ## Postaggregator(fn, fields, name) ### Description Base class for postaggregators. ### Constructor Parameters - **fn** - The function to apply. - **fields** - The fields to use. - **name** - The output name. ### Methods - **build_post_aggregators(postaggs)** (static) - Builds post-aggregators from a list of post-aggregator objects. - **fields(other)** - Combines fields with another postaggregator. ``` -------------------------------- ### BaseDruidClient.groupby Source: https://pythonhosted.org/pydruid/index.html Executes a group-by query that groups a result set by specified dimensions. Required parameters include datasource, granularity, intervals, aggregations, and dimensions; optional parameters include filter, having, post_aggregations, context, and limit_spec. ```APIDOC ## groupby(**kwargs) ### Description A group-by query groups a results set (the requested aggregate metrics) by the specified dimension(s). ### Method N/A (Python method) ### Parameters #### Required Parameters - **datasource** (str) - Required - Data source to query - **granularity** (str) - Required - Time bucket to aggregate data by hour, day, minute, etc. - **intervals** (str or list) - Required - ISO-8601 intervals for which to run the query on - **aggregations** (dict) - Required - A map from aggregator name to one of the pydruid.utils.aggregators e.g., doublesum - **dimensions** (list) - Required - The dimensions to group by #### Optional Parameters - **filter** (pydruid.utils.filters.Filter) - Optional - Indicates which rows of data to include in the query - **having** (pydruid.utils.having.Having) - Optional - Indicates which groups in results set of query to keep - **post_aggregations** - Optional - A dict with string key = 'post_aggregator_name', and value pydruid.utils.PostAggregator - **context** (dict) - Optional - A dict of query context options - **limit_spec** (dict) - Optional - A dict of parameters defining how to limit the rows returned, as specified in the Druid api documentation ### Returns - **Query** - The query result ### Example ```python >>> group = client.groupby( datasource='twitterstream', granularity='hour', intervals='2013-10-04/pt1h', dimensions=["user_name", "reply_to_name"], filter=~(Dimension("reply_to_name") == "Not A Reply"), aggregations={"count": doublesum("count")}, context={"timeout": 1000} limit_spec={ "type": "default", "limit": 50, "columns" : ["count"] } ) >>> for k in range(2): ... print group[k] >>> {'timestamp': '2013-10-04T00:00:00.000Z', 'version': 'v1', 'event': {'count': 1.0, 'user_name': 'user_1', 'reply_to_name': 'user_2'}} >>> {'timestamp': '2013-10-04T00:00:00.000Z', 'version': 'v1', 'event': {'count': 1.0, 'user_name': 'user_2', 'reply_to_name': 'user_3'}} ``` ``` -------------------------------- ### pydruid.utils.having.Aggregation Source: https://pythonhosted.org/pydruid/index.html Class representing an aggregation for having clauses. ```APIDOC ## Aggregation(agg) ### Description Class representing an aggregation for having clauses. ### Constructor Parameters - **agg** - The aggregation object. ``` -------------------------------- ### pydruid.utils.filters.JavaScript Source: https://pythonhosted.org/pydruid/index.html Class representing a JavaScript filter. ```APIDOC ## JavaScript(dim) ### Description Class representing a JavaScript filter. ### Constructor Parameters - **dim** - The dimension name. ``` -------------------------------- ### Retrieve Segment Metadata Source: https://pythonhosted.org/pydruid/index.html Queries segment metadata for the 'twitterstream' datasource and displays column information. ```python >>> meta = client.segment_metadata(datasource='twitterstream', intervals = '2013-10-04/pt1h') >>> print meta[0].keys() >>> ['intervals', 'id', 'columns', 'size'] >>> print meta[0]['columns']['tweet_length'] >>> {'errorMessage': None, 'cardinality': None, 'type': 'FLOAT', 'size': 30908008} ``` -------------------------------- ### BaseDruidClient.export_pandas Source: https://pythonhosted.org/pydruid/index.html Exports the current query result to a Pandas DataFrame object. Deprecated; use Query.export_pandas() instead. ```APIDOC ## export_pandas() ### Description Export the current query result to a Pandas DataFrame object. ### Deprecation Deprecated since version: Use Query.export_pandas() method instead. ``` -------------------------------- ### Query.export_pandas() Source: https://pythonhosted.org/pydruid/index.html Exports the current query result to a Pandas DataFrame object. Returns a DataFrame representing the query result. ```APIDOC ## export_pandas() ### Description Export the current query result to a Pandas DataFrame object. ### Method N/A (Python method) ### Endpoint N/A ### Parameters None ### Returns - **DataFrame** - The DataFrame representing the query result ### Raises - **NotImplementedError** - If the export is not implemented for the query type ### Example ```python >>> top = client.topn( datasource='twitterstream', granularity='all', intervals='2013-10-04/pt1h', aggregations={"count": doublesum("count")}, dimension='user_name', filter = Dimension('user_lang') == 'en', metric='count', threshold=2 ) >>> df = top.export_pandas() >>> print df >>> count timestamp user_name 0 7 2013-10-04T00:00:00.000Z user_1 1 6 2013-10-04T00:00:00.000Z user_2 ``` ``` -------------------------------- ### BaseDruidClient.segment_metadata Source: https://pythonhosted.org/pydruid/index.html Executes a segment metadata query that returns per segment information about column cardinality, column type, estimated sizes, interval, and segment ID. Requires datasource and intervals; optional context parameter. ```APIDOC ## segment_metadata(**kwargs) ### Description A segment meta-data query returns per segment information about: - Cardinality of all the columns present - Column type - Estimated size in bytes - Estimated size in bytes of each column - Interval the segment covers - Segment ID ### Method N/A (Python method) ### Parameters #### Required Parameters - **datasource** (str) - Required - Data source to query - **intervals** (str or list) - Required - ISO-8601 intervals for which to run the query on #### Optional Parameters - **context** (dict) - Optional - A dict of query context options ### Returns - **Query** - The query result ### Example ```python >>> meta = client.segment_metadata(datasource='twitterstream', intervals = '2013-10-04/pt1h') >>> print meta[0].keys() >>> ['intervals', 'id', 'columns', 'size'] >>> print meta[0]['columns']['tweet_length'] >>> {'errorMessage': None, 'cardinality': None, 'type': 'FLOAT', 'size': 30908008} ``` ``` -------------------------------- ### pydruid.utils.filters.Bound Source: https://pythonhosted.org/pydruid/index.html Bound filter to filter by comparing dimension values to an upper and/or lower value. Constructor parameters: dimension (str), lower (str), upper (str), lowerStrict (bool, default False), upperStrict (bool, default False), alphaNumeric (bool, default False). ```APIDOC ## Bound(dimension, lower, upper, lowerStrict=False, upperStrict=False, alphaNumeric=False) ### Description Bound filter can be used to filter by comparing dimension values to an upper value or/and a lower value. ### Constructor Parameters - **dimension** (str) - Required - Dimension to filter on. - **lower** (str) - Required - Lower bound. - **upper** (str) - Required - Upper bound. - **lowerStrict** (bool) - Optional - Strict lower inclusion. Initial value: False - **upperStrict** (bool) - Optional - Strict upper inclusion. Initial value: False - **alphaNumeric** (bool) - Optional - Numeric comparison. Initial value: False ``` -------------------------------- ### pydruid.utils.postaggregator.HyperUniqueCardinality Source: https://pythonhosted.org/pydruid/index.html Postaggregator that computes the cardinality of a hyperUnique field. ```APIDOC ## HyperUniqueCardinality(name) ### Description Postaggregator that computes the cardinality of a hyperUnique field. ### Constructor Parameters - **name** - The field name. ``` -------------------------------- ### pydruid.utils.filters.Dimension Source: https://pythonhosted.org/pydruid/index.html Class representing a dimension for filtering. ```APIDOC ## Dimension(dim) ### Description Class representing a dimension for filtering. ### Constructor Parameters - **dim** - The dimension name. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.