Extracts
Read from various data sources.
Transforms
Shape and optimize for your needs.
Loads
Store and secure in one of many available data sinks.
Examples:
composer.json
{
"name": "flow-php/examples",
"description": "Flow PHP - Examples",
"license": "MIT",
"type": "library",
"require": {
"flow-php/etl": "1.x-dev",
"symfony/dotenv": "^7.2",
"flow-php/filesystem-azure-bridge": "1.x-dev",
"flow-php/etl-adapter-parquet": "1.x-dev",
"flow-php/filesystem": "1.x-dev",
"flow-php/snappy": "1.x-dev",
"flow-php/parquet": "1.x-dev",
"nyholm/psr7": "^1.8",
"php-http/curl-client": "^2.3"
},
"config": {
"allow-plugins": {
"php-http/discovery": false
}
}
}
code.php
<?php
declare(strict_types=1);
use function Flow\Azure\SDK\DSL\{azure_blob_service, azure_blob_service_config, azure_shared_key_authorization_factory};
use function Flow\ETL\Adapter\Parquet\{from_parquet, to_parquet};
use function Flow\ETL\DSL\{config_builder, data_frame, from_array, overwrite, to_stream};
use function Flow\Filesystem\Bridge\Azure\DSL\azure_filesystem;
use function Flow\Filesystem\DSL\path;
use Symfony\Component\Dotenv\Dotenv;
require __DIR__ . '/vendor/autoload.php';
if (!\file_exists(__DIR__ . '/.env')) {
print 'Example skipped. Please create .env file with Azure Storage Account credentials.' . PHP_EOL;
return;
}
$dotenv = new Dotenv();
$dotenv->load(__DIR__ . '/.env');
$config = config_builder()
->mount(
azure_filesystem(
azure_blob_service(
azure_blob_service_config(
$_ENV['AZURE_ACCOUNT'],
$_ENV['AZURE_CONTAINER']
),
azure_shared_key_authorization_factory(
$_ENV['AZURE_ACCOUNT'],
$_ENV['AZURE_ACCOUNT_KEY']
),
)
)
);
data_frame($config)
->read(from_array([
['id' => 1, 'name' => 'test'],
['id' => 2, 'name' => 'test'],
['id' => 3, 'name' => 'test'],
['id' => 4, 'name' => 'test'],
]))
->saveMode(overwrite())
->write(to_parquet(path('azure-blob://test.parquet')))
->run();
data_frame($config)
->read(from_parquet(path('azure-blob://test.parquet')))
->write(to_stream(__DIR__ . '/output.txt', truncate: false))
->run();
Output
+----+------+
| id | name |
+----+------+
| 1 | test |
+----+------+
1 rows
+----+------+
| id | name |
+----+------+
| 2 | test |
+----+------+
1 rows
+----+------+
| id | name |
+----+------+
| 3 | test |
+----+------+
1 rows
+----+------+
| id | name |
+----+------+
| 4 | test |
+----+------+
1 rows