-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated README * Added php syntax coloring
- Loading branch information
1 parent
282d713
commit c0a120f
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Flow\ETL\DSL\Parquet; | ||
use Flow\ETL\Filesystem\SaveMode; | ||
use function Flow\ETL\DSL\lit; | ||
use function Flow\ETL\DSL\ref; | ||
use Flow\ETL\DSL\To; | ||
use Flow\ETL\Flow; | ||
use Flow\ETL\GroupBy\Aggregation; | ||
|
||
require __DIR__ . '/../../bootstrap.php'; | ||
|
||
$flow = (new Flow()) | ||
->read(Parquet::from(__FLOW_DATA__ . '/orders_flow.parquet')) | ||
->select('created_at', 'total_price', 'discount') | ||
->withEntry('created_at', ref('created_at')->toDate(\DateTime::RFC3339)->dateFormat('Y/m')) | ||
->withEntry('revenue', ref('total_price')->minus(ref('discount'))) | ||
->select('created_at', 'revenue') | ||
->groupBy('created_at') | ||
->aggregate(Aggregation::sum(ref('revenue'))) | ||
->sortBy(ref('created_at')->desc()) | ||
->withEntry('daily_revenue', ref('revenue_sum')->round(lit(2))) | ||
->drop('revenue_sum') | ||
->withEntry('created_at', ref('created_at')->toDate('Y/m')) | ||
->write(To::output(truncate: false)) | ||
->mode(SaveMode::Overwrite) | ||
->write(Parquet::to(__FLOW_OUTPUT__ . '/daily_revenue.parquet')); | ||
|
||
if ($_ENV['FLOW_PHAR_APP'] ?? false) { | ||
return $flow; | ||
} | ||
|
||
$flow->run(); |