datadistillr / drill-sdk-php
PHP SDK for programmatically connecting to Apache Drill.
Installs: 1 015
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-10-15 18:23:07 UTC
README
PHP SDK Library for Connecting to Apache Drill.
This library allows you to connect to and query Apache Drill programmatically. It is loosely modeled after PHP's mysql interface, so if you are familiar with that, you already pretty much know how to use the Drill connector.
Installing the Library
This library can be installed using Composer by using the following command:
composer require "datadistillr/drill-sdk-php:^0.7.17"
The current pre-release version is: 0.7.17
Using the Connector
The first step is to make a Drill connection handle. The module uses Drill's RESTful interface, so it will not maintain an open connection like a typical JDBC/ODBC connection would.
$drillHandle = new DrillConnection( 'localhost', 8047 );
You can use the is_active()
menthod to verify that your connection is active.
if( $drillHandle->is_active() ) { print( "Connection Active" ); } else { print( "Connection Inactive" ); }
Querying Drill
Now that you've created your Drill connection handle, you can query Drill in a similar fashion as MySQL by calling
the query()
method. Once you've called the query()
method, you can use one of the fetch()
methods to retrieve
the results, in a similar manner as MySQL. Currently, the Drill connector currently has:
fetchAll()
: Returns all query results in an associative array.fetchAssoc()
: Returns a single query row as an associative array.fetchObject()
: Returns a single row as a PHP Object.
You might also find these functions useful:
dataSeek($n)
: Returns the row at index$n
and sets the current row to$n
.numEows()
: Returns the number of rows returned by the query.fieldCount()
: Returns the number of columns returned by the query.
Thus, if you want to execute a query in Drill, you can do so as follows:
$query_result = $drillHandle->query( "SELECT * FROM cp.`employee.json` LIMIT 20" ); while( $row = $query_result->fetch_assoc() ) { print( "Field 1: {$row['field1']}\n" ); print( "Field 2: {$row['field2']}\n" ); }
Interacting with Drill
You can also use the connector to activate/deactivate Drill's storage as well as get information about Drill's plugins.
disablePlugin( $plugin )
Disables the given plugin. Returns true if successful, false if not.enablePlugin( $plugin )
Enables the given plugin. Returns true if successful, false if not.getAllStoragePlugins()
Returns an array of all storage plugins.getDisabledStoragePlugins()
Returns an array of all disabled plugins.getEnabledStoragePlugins()
Returns an array of all enabled plugins.getStoragePlugins()
Returns an associative array of plugins and associated configuration options for all plugins.getStoragePluginInfo( $plugin )
Returns an associative array of configuration options for a given plugin.saveStoragePlugin( $plugin_name, $config )
Creates or edits a storage plugin. Returns true if successful, throws exception if not.deleteStoragePlugin( $plugin_name )
Deletes a storage plugin. Returns true if successful, throws exception if not.