ytake/php-presto-client

php prestodb client

Fund package maintenance!
ytake

0.1.4 2017-09-19 18:36 UTC

This package is auto-updated.

Last update: 2024-11-20 01:41:58 UTC


README

Build Status Coverage Status Scrutinizer Code Quality

License Latest Version Total Downloads StyleCI

SensioLabsInsight

prestodb http protocol client for php

prestodb

What is Presto

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.

Install

required >= PHP 7.0

$ composer require ytake/php-presto-client

Usage

Standard

<?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();

bulk operations

<?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();

Fetch Styles

FixData Object

<?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']);
        }
    }
}

Array Keys

<?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);
        }
    }
}

Mapping Class

<?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);
        }
    }
}