PHPackages                             level23/druid-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. level23/druid-client

ActiveLibrary[Database &amp; ORM](/categories/database)

level23/druid-client
====================

Druid php client for executing queries and more

v4.1.2(6mo ago)2959.0k↓39.8%71Apache-2.0PHPPHP ^8.2CI passing

Since Aug 12Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/level23/druid-client)[ Packagist](https://packagist.org/packages/level23/druid-client)[ RSS](/packages/level23-druid-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (72)Used By (1)

Druid-Client
============

[](#druid-client)

[![Build](https://github.com/level23/druid-client/actions/workflows/build.yml/badge.svg)](https://github.com/level23/druid-client/actions/workflows/build.yml)[![Coverage Status](https://camo.githubusercontent.com/fd6607ab74c2578c9f474e9e17a45eb46b8e33157316df8497ee1219bbb9885b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6c6576656c32332f64727569642d636c69656e742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/level23/druid-client?branch=master)[![Packagist Version](https://camo.githubusercontent.com/dd0e63aa0b8dfc3af81d854ec90314ad06aeda325f12cb90da493de6241d48f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6576656c32332f64727569642d636c69656e742e737667)](https://packagist.org/packages/level23/druid-client)[![Total Downloads](https://camo.githubusercontent.com/b500abb3a254238df8c85cc6d46cf7955d94f9ff694a8f9722dbf54302276457/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6576656c32332f64727569642d636c69656e742e737667)](https://packagist.org/packages/level23/druid-client)[![Quality Score](https://camo.githubusercontent.com/2e4740e0ee74b83d655447c784db80b2ecc07eac05dcd0f8f644881a95feec9c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6c6576656c32332f64727569642d636c69656e74)](https://scrutinizer-ci.com/g/level23/druid-client)[![Software License](https://camo.githubusercontent.com/51063f60f69f5e439b0e68f3a210e4f0cc4ef15ece8b55967fa1aecaa1fb2dbf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d627269676874677265656e2e737667)](LICENSE.txt)

The goal of this project is to make it easy to select data from druid.

This project gives you an easy query builder to create the complex druid queries.

It also gives you a way to manage dataSources (tables) in druid and import new data from files.

Requirements
------------

[](#requirements)

This package only requires Guzzle as dependency. The PHP and Guzzle version requirements are listed below.

Druid Client VersionPHP RequirementsGuzzle RequirementsDruid Requirements4.\* (current)PHP 8.2 or higherVersion 7.0&gt;= 28.0.03.\*PHP 8.2 or higherVersion 7.02.\*PHP 7.4, 8.0, 8.1 and 8.2.Version 6.2 or 7.\*1.\*PHP version 7.2, 7.4, 8.0, 8.1 and 8.2.Version 6.2 or 7.\*Installation
------------

[](#installation)

To install this package, you can use composer:

```
composer require level23/druid-client

```

You can also download it as a ZIP file and include it in your project, as long as you have Guzzle also in your project.

ChangeLog and Upgrading
-----------------------

[](#changelog-and-upgrading)

See [CHANGELOG](CHANGELOG.md) for changes in the different versions and how to upgrade to the latest version.

Laravel/Lumen support.
----------------------

[](#laravellumen-support)

This package is Laravel/Lumen ready. It can be used in a Laravel/Lumen project, but it's not required.

#### Laravel

[](#laravel)

For Laravel the package will be auto discovered.

#### Lumen

[](#lumen)

If you are using a Lumen project, just include the service provider in `bootstrap/app.php`:

```
// Register the druid-client service provider
$app->register(Level23\Druid\DruidServiceProvider::class);
```

#### Laravel/Lumen Configuration:

[](#laravellumen-configuration)

You should also define the correct endpoint URL's in your `.env` in your Laravel/Lumen project:

```
DRUID_BROKER_URL=http://broker.url:8082
DRUID_COORDINATOR_URL=http://coordinator.url:8081
DRUID_OVERLORD_URL=http://overlord.url:8090
DRUID_RETRIES=2
DRUID_RETRY_DELAY_MS=500
DRUID_TIMEOUT=60
DRUID_CONNECT_TIMEOUT=10
DRUID_POLLING_SLEEP_SECONDS=2

```

If you are using a Druid Router process, you can also just set the router url, which then will be used for the broker, overlord and the coordinator:

```
DRUID_ROUTER_URL=http://druid-router.url:8080

```

Todo's
------

[](#todos)

- Support for building metricSpec and DimensionSpec in CompactTaskBuilder
- Implement hadoop based batch ingestion (indexing)
- Implement Avro Stream and Avro OCF input formats.

Examples
--------

[](#examples)

There are several examples which are written on the single-server tutorial of druid. See [this](examples/README.md) page for more information.

Table of Contents
=================

[](#table-of-contents)

- [DruidClient](#druidclient)
    - [DruidClient::auth()](#druidclientauth)
    - [DruidClient::query()](#druidclientquery)
    - [DruidClient::lookup()](#druidclientlookup)
    - [DruidClient::cancelQuery()](#druidclientcancelquery)
    - [DruidClient::compact()](#druidclientcompact)
    - [DruidClient::reindex()](#druidclientreindex)
    - [DruidClient::pollTaskStatus()](#druidclientpolltaskstatus)
    - [DruidClient::taskStatus()](#druidclienttaskstatus)
    - [DruidClient::metadata()](#druidclientmetadata)
    - [QueryBuilder: Generic Query Methods](#querybuilder-generic-query-methods)
        - [interval()](#interval)
        - [limit()](#limit)
        - [orderBy()](#orderby)
        - [orderByDirection()](#orderbydirection)
        - [pagingIdentifier()](#pagingidentifier)
        - [subtotals()](#subtotals)
        - [metrics()](#metrics)
        - [dimensions()](#dimensions)
        - [toArray()](#toarray)
        - [toJson()](#tojson)
    - [QueryBuilder: Data Sources](#querybuilder-data-sources)
        - [from()](#from)
        - [join()](#join)
        - [leftJoin()](#leftjoin)
        - [innerJoin()](#innerjoin)
        - [joinLookup()](#joinlookup)
        - [union()](#union)
    - [QueryBuilder: Dimension Selections](#querybuilder-dimension-selections)
        - [select()](#select)
        - [lookup()](#lookup)
        - [inlineLookup()](#inlinelookup)
        - [multiValueListSelect()](#multivaluelistselect)
        - [multiValueRegexSelect()](#multivalueregexselect)
        - [multiValuePrefixSelect()](#multivalueprefixselect)
    - [QueryBuilder: Metric Aggregations](#querybuilder-metric-aggregations)
        - [count()](#count)
        - [sum()](#sum)
        - [min()](#min)
        - [max()](#max)
        - [first()](#first)
        - [last()](#last)
        - [any()](#any)
        - [javascript()](#javascript)
        - [hyperUnique()](#hyperunique)
        - [cardinality()](#cardinality)
        - [distinctCount()](#distinctcount)
        - [doublesSketch()](#doublesSketch)
    - [QueryBuilder: Filters](#querybuilder-filters)
        - [where()](#where)
        - [orWhere()](#orwhere)
        - [whereNot()](#wherenot)
        - [orWhereNot()](#orwherenot)
        - [whereNull()](#wherenull)
        - [orWhereNull()](#orwherenull)
        - [whereIn()](#wherein)
        - [orWhereIn()](#orwherein)
        - [whereArrayContains()](#wherearraycontains)
        - [orWhereArrayContains()](#orwherearraycontains)
        - [whereBetween()](#wherebetween)
        - [orWhereBetween()](#orwherebetween)
        - [whereColumn()](#wherecolumn)
        - [orWhereColumn()](#orwherecolumn)
        - [whereInterval()](#whereinterval)
        - [orWhereInterval()](#orwhereinterval)
        - [whereFlags()](#whereflags)
        - [orWhereFlags()](#orwhereflags)
        - [whereExpression()](#whereexpression)
        - [orWhereExpression()](#orwhereexpression)
        - [whereSpatialRectangular()](#wherespatialrectangular)
        - [whereSpatialRadius()](#wherespatialradius)
        - [whereSpatialPolygon()](#wherespatialpolygon)
        - [orWhereSpatialRectangular()](#orwherespatialrectangular)
        - [orWhereSpatialRadius()](#orwherespatialradius)
        - [orWhereSpatialPolygon()](#orwherespatialpolygon)
    - [QueryBuilder: Having Filters](#querybuilder-having-filters)
        - [having()](#having)
        - [orHaving()](#orhaving)
    - [QueryBuilder: Virtual Columns](#querybuilder-virtual-columns)
        - [virtualColumn()](#virtualcolumn)
        - [selectVirtual()](#selectvirtual)
    - [QueryBuilder: Post Aggregations](#querybuilder-post-aggregations)
        - [fieldAccess()](#fieldaccess)
        - [constant()](#constant)
        - [expression](#expression)
        - [divide()](#divide)
        - [multiply()](#multiply)
        - [subtract()](#subtract)
        - [add()](#add)
        - [quotient()](#quotient)
        - [longGreatest() and doubleGreatest()](#longgreatest-and-doublegreatest)
        - [longLeast() and doubleLeast()](#longleast-and-doubleleast)
        - [postJavascript()](#postjavascript)
        - [hyperUniqueCardinality()](#hyperuniquecardinality)
        - [quantile()](#quantile)
        - [quantiles()](#quantiles)
        - [histogram()](#histogram)
        - [rank()](#rank)
        - [cdf()](#cdf)
        - [sketchSummary()](#sketchsummary)
    - [QueryBuilder: Search Filters](#querybuilder-search-filters)
        - [searchContains()](#searchcontains)
        - [searchFragment()](#searchfragment)
        - [searchRegex()](#searchregex)
    - [QueryBuilder: Execute The Query](#querybuilder-execute-the-query)
        - [execute()](#execute)
        - [groupBy()](#groupby)
        - [topN()](#topn)
        - [selectQuery()](#selectquery)
        - [scan()](#scan)
        - [timeseries()](#timeseries)
        - [search()](#search)
    - [LookupBuilder: Generic Methods](#lookupbuilder-generic-methods)
        - [all()](#all)
        - [names()](#names)
        - [introspect()](#introspect)
        - [keys()](#keys)
        - [values()](#values)
        - [tiers()](#tiers)
        - [store()](#store)
        - [delete()](#delete)
    - [LookupBuilder: Building Lookups](#lookupbuilder-building-lookups)
        - [uri()](#uri)
        - [uriPrefix()](#uriprefix)
        - [kafka()](#kafka)
        - [jdbc()](#jdbc)
        - [map()](#map)
        - [maxHeapPercentage()](maxheappercentage)
        - [pollPeriod()](#pollperiod)
        - [injective()](#injective)
        - [firstCacheTimeout()](#firstcachetimeout)
    - [LookupBuilder: Lookup Parse Specifications](#lookupbuilder-lookup-parse-specifications)
        - [tsv()](#tsv)
        - [csv()](#csv)
        - [json()](#json)
        - [customJson()](#customjson)
    - [Metadata](#metadata)
        - [intervals](#metadata-intervals)
        - [interval](#metadata-interval)
        - [structure](#metadata-structure)
        - [timeBoundary](#metadata-timeboundary)
        - [dataSources](#metadata-datasources)
        - [rowCount](#metadata-rowcount)
    - [Reindex/compact data/kill](#reindex--compact-data--kill)
        - [compact()](#compact)
        - [reindex()](#reindex)
        - [kill()](#kill)
    - [Importing data using a batch index job](#importing-data-using-a-batch-index-job)
    - [Input Sources](#input-sources)
        - [AzureInputSource](#azureinputsource)
        - [GoogleCloudInputSource](#googlecloudinputsource)
        - [S3InputSource](#s3inputsource)
        - [HdfsInputSource](#hdfsinputsource)
        - [HttpInputSource](#httpinputsource)
    - [Input Formats](#input-formats)
        - [csvFormat()](#csvformat)
        - [tsvFormat()](#tsvformat)
        - [jsonFormat()](#jsonformat)
        - [orcFormat()](#orcformat)
        - [parquetFormat()](#parquetformat)
        - [protobufFormat()](#protobufformat)

Documentation
=============

[](#documentation)

Here is an example of how you can use this package.

Please see the inline comment for more information / feedback.

Example:

```
