Download the PHP package automattic/php-thrift-sql without Composer
On this page you can find all versions of the php package automattic/php-thrift-sql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download automattic/php-thrift-sql
More information about automattic/php-thrift-sql
Files in automattic/php-thrift-sql
Package php-thrift-sql
Short Description A PHP library for connecting to Hive or Impala over Thrift
License GPL-2.0-or-later
Homepage https://github.com/Automattic/php-thrift-sql
Informations about the package php-thrift-sql
PHP ThriftSQL
The ThriftSQL.phar
archive aims to provide access to SQL-on-Hadoop frameworks for PHP. It bundles Thrift and various service packages together and exposes a common interface for running queries over the various frameworks.
Currently the following engines are supported:
- Hive -- Over the HiveServer2 Thrift interface, SASL is enabled by default so username and password must be provided however this can be turned off with the
setSasl()
method before callingconnect()
. - Impala -- Over the Impala Service Thrift interface which extends the Beeswax protocol.
Version Compatibility
This library is currently compiled against the Thrift definitions of the following database versions:
Using the compiler and base PHP classes of:
- Apache Thrift
0.12.0
(Oct 2018)
Usage Example
The recommended way to use this library is to get results from Hive/Impala via the memory efficient iterator which will keep the connection open and scroll through the results a couple rows at a time. This allows the processing of large result datasets one record at a time minimizing PHP's memory consumption.
The downside to using the memory efficient iterator is that we can only iterate over the result set once. If a second foreach
is called on the same iterator object an exception is thrown by default to prevent the same query from executing on Hive/Impala again as results are not cached within the PHP client. This can be turned off however be aware iterating over the same iterator object may produce different results as the query is rerun.
Consider the following example:
Which will output something like:
If the result set is small and it would be easier to load all of it into PHP memory the queryAndFetchAll()
method can be used which will return a plain numeric multidimensional array of the full result set.
Developing & Contributing
In order to rebuild this library you will need Composer to install dev dependencies and Apache Thrift to compile client libraries from the Thrift interface definition files.
Once dev tools are installed, make sure you get all git submodules:
And then the phar can be rebuilt using make
:
NOTE: If you get a BadMethodCallException
, it may come from any of the reasons mentioned in the PHP doc, or even a low soft limit on open file descriptors since Phar::compressfiles
keeps all files opened until it writes the compressed phar.