prestodb http protocol client for php
Presto is an open source distributed SQL query engine for running interactive analytic queries against data sources of all sizes ranging from gigabytes to petabytes.
required >= PHP 7.0
$ composer require ytake/php-presto-client
<?php
$client = new \Ytake\PrestoClient\StatementClient(
new \Ytake\PrestoClient\ClientSession('http://localhost:8080/', 'acme'),
'SELECT * FROM acme.acme.acme'
);
// execute http request
$client->execute();
// next call uri
$client->advance();
/** @var \Ytake\PrestoClient\QueryResult $result */
// current result
$result = $client->current();
// request cancel
$client->cancelLeafStage();
<?php
$client = new \Ytake\PrestoClient\StatementClient(
new \Ytake\PrestoClient\ClientSession('http://localhost:8080/', 'acme'),
'SELECT * FROM acme.acme.acme'
);
$resultSession = new \Ytake\PrestoClient\ResultsSession($client);
// yield results instead of returning them. Recommended.
$result = $resultSession->execute()->yieldResults();
// array
$result = $resultSession->execute()->getResults();
<?php
$client = new \Ytake\PrestoClient\StatementClient(
new \Ytake\PrestoClient\ClientSession('http://localhost:8080/', 'acme'),
'SELECT * FROM acme.acme.acme'
);
$resultSession = new \Ytake\PrestoClient\ResultsSession($client);
$result = $resultSession->execute()->yieldResults();
/** @var \Ytake\PrestoClient\QueryResult $row */
foreach ($result as $row) {
foreach ($row->yieldData() as $yieldRow) {
if ($yieldRow instanceof \Ytake\PrestoClient\FixData) {
var_dump($yieldRow->offsetGet('column_name'), $yieldRow['column_name']);
}
}
}
<?php
$client = new \Ytake\PrestoClient\StatementClient(
new \Ytake\PrestoClient\ClientSession('http://localhost:8080/', 'acme'),
'SELECT * FROM acme.acme.acme'
);
$resultSession = new \Ytake\PrestoClient\ResultsSession($client);
$result = $resultSession->execute()->yieldResults();
/** @var \Ytake\PrestoClient\QueryResult $row */
foreach ($result as $row) {
/** @var array $item */
foreach ($row->yieldDataArray() as $item) {
if (!is_null($item)) {
var_dump($item);
}
}
}
<?php
class Testing
{
private $_key;
private $_value;
}
$client = new \Ytake\PrestoClient\StatementClient(
new \Ytake\PrestoClient\ClientSession('http://localhost:8080/', 'acme'),
'SELECT * FROM acme.acme.acme'
);
$resultSession = new \Ytake\PrestoClient\ResultsSession($client);
$result = $resultSession->execute()->yieldResults();
/** @var \Ytake\PrestoClient\QueryResult $row */
foreach ($result as $row) {
foreach($row->yieldObject(Testing::class) as $object) {
if ($object instanceof Testing) {
var_dump($object);
}
}
}