Skip to content

Conversation

@norberttech
Copy link
Member

@norberttech norberttech commented Nov 29, 2023

Change Log

Added

  • Possibility to filter partitions using scalar functions
  • DSL functions for maps/structs/list/types

Fixed

Changed

  • Deprecated all DSL static classes in favor of functions
  • Moved whole DSL to ETL functions.php

Removed

Deprecated

Security


Description

Example of new DSL

<?php

declare(strict_types=1);

use function Flow\ETL\DSL\average;
use function Flow\ETL\DSL\bar_chart;
use function Flow\ETL\DSL\concat;
use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_csv;
use function Flow\ETL\DSL\lit;
use function Flow\ETL\DSL\max;
use function Flow\ETL\DSL\min;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\sum;
use function Flow\ETL\DSL\to_chartjs_file;

require __DIR__ . '/../../bootstrap.php';

$df = df()
    ->read(from_csv(__FLOW_DATA__ . '/power-plant-daily.csv', delimiter: ';'))
    ->withEntry('production_kwh', ref('Produkcja(kWh)'))
    ->withEntry('consumption_kwh', ref('Zużycie(kWh)'))
    ->withEntry('date', ref('Zaktualizowany czas')->toDate('Y/m/d')->dateFormat('Y/m'))
    ->select('date', 'production_kwh', 'consumption_kwh')
    ->groupBy(ref('date'))
    ->aggregate(
        average(ref('production_kwh')),
        average(ref('consumption_kwh')),
        min(ref('production_kwh')),
        min(ref('consumption_kwh')),
        max(ref('production_kwh')),
        max(ref('consumption_kwh')),
        sum(ref('production_kwh')),
        sum(ref('consumption_kwh'))
    )

    ->withEntry('production_kwh_avg', ref('production_kwh_avg')->round(lit(2)))
    ->withEntry('consumption_kwh_avg', ref('consumption_kwh_avg')->round(lit(2)))
    ->withEntry('production_kwh_min', ref('production_kwh_min')->round(lit(2)))
    ->withEntry('consumption_kwh_min', ref('consumption_kwh_min')->round(lit(2)))
    ->withEntry('production_kwh_max', ref('production_kwh_max')->round(lit(2)))
    ->withEntry('consumption_kwh_max', ref('consumption_kwh_max')->round(lit(2)))
    ->withEntry('production_kwh_sum', ref('production_kwh_sum')->round(lit(2)))
    ->withEntry('consumption_kwh_sum', ref('consumption_kwh_sum')->round(lit(2)))
    ->withEntry('consumption', ref('consumption_kwh_sum')->divide(ref('production_kwh_sum')))
    ->withEntry('consumption', ref('consumption')->multiply(lit(100))->round(lit(2)))
    ->withEntry('consumption', concat(ref('consumption'), lit('%')))
    ->write(
        to_chartjs_file(
            bar_chart(label: ref('date'), datasets: [ref('production_kwh_avg'), ref('consumption_kwh_avg')])
                ->setOptions(['indexAxis' => 'y']),
            output: __FLOW_OUTPUT__ . '/power_plant_bar_chart.html'
        )
    );

if ($_ENV['FLOW_PHAR_APP'] ?? false) {
    return $df;
}

$df->run();

@github-actions
Copy link
Contributor

github-actions bot commented Nov 29, 2023

Flow PHP - Benchmarks

Results of the benchmarks from this PR are compared with the results from 1.x branch.

Extractors
+-----------------------+-------------------+------+-----+------------------+------------------+-----------------+
| benchmark             | subject           | revs | its | mem_peak         | mode             | rstdev          |
+-----------------------+-------------------+------+-----+------------------+------------------+-----------------+
| AvroExtractorBench    | bench_extract_10k | 1    | 3   | 34.766mb +0.97%  | 691.245ms +2.13% | ±1.68% -35.00%  |
| CSVExtractorBench     | bench_extract_10k | 1    | 3   | 4.630mb +3.66%   | 303.512ms +2.79% | ±2.19% +223.45% |
| JsonExtractorBench    | bench_extract_10k | 1    | 3   | 4.790mb +2.26%   | 936.080ms +2.42% | ±1.06% +303.67% |
| ParquetExtractorBench | bench_extract_10k | 1    | 3   | 239.499mb +0.04% | 1.102s -0.08%    | ±0.77% +10.41%  |
| TextExtractorBench    | bench_extract_10k | 1    | 3   | 4.571mb +2.35%   | 28.914ms +21.85% | ±3.48% +490.45% |
| XmlExtractorBench     | bench_extract_10k | 1    | 3   | 4.571mb +2.37%   | 403.974ms -0.36% | ±0.06% -97.61%  |
+-----------------------+-------------------+------+-----+------------------+------------------+-----------------+
Transformers
+-----------------------------+--------------------------+------+-----+------------------+-----------------+----------------+
| benchmark                   | subject                  | revs | its | mem_peak         | mode            | rstdev         |
+-----------------------------+--------------------------+------+-----+------------------+-----------------+----------------+
| RenameEntryTransformerBench | bench_transform_10k_rows | 1    | 3   | 110.254mb +0.10% | 63.996ms -1.02% | ±0.54% -16.23% |
+-----------------------------+--------------------------+------+-----+------------------+-----------------+----------------+
Loaders
+--------------------+----------------+------+-----+------------------+------------------+-----------------+
| benchmark          | subject        | revs | its | mem_peak         | mode             | rstdev          |
+--------------------+----------------+------+-----+------------------+------------------+-----------------+
| AvroLoaderBench    | bench_load_10k | 1    | 3   | 94.426mb +0.36%  | 440.374ms -6.23% | ±0.52% -85.54%  |
| CSVLoaderBench     | bench_load_10k | 1    | 3   | 54.736mb +0.19%  | 72.071ms -0.39%  | ±0.83% +171.86% |
| JsonLoaderBench    | bench_load_10k | 1    | 3   | 105.008mb +0.33% | 55.112ms -3.63%  | ±0.56% -46.46%  |
| ParquetLoaderBench | bench_load_10k | 1    | 3   | 320.486mb +0.03% | 1.478s +0.09%    | ±1.80% -46.22%  |
| TextLoaderBench    | bench_load_10k | 1    | 3   | 17.610mb +0.61%  | 41.656ms -1.07%  | ±0.31% -37.59%  |
+--------------------+----------------+------+-----+------------------+------------------+-----------------+
Building Blocks
+-------------------------+----------------------------+------+-----+------------------+------------------+-----------------+
| benchmark               | subject                    | revs | its | mem_peak         | mode             | rstdev          |
+-------------------------+----------------------------+------+-----+------------------+------------------+-----------------+
| RowsBench               | bench_chunk_10_on_10k      | 2    | 3   | 76.303mb +0.15%  | 2.724ms +2.24%   | ±1.39% +12.44%  |
| RowsBench               | bench_diff_left_1k_on_10k  | 2    | 3   | 96.096mb +0.12%  | 188.595ms +4.75% | ±1.06% +279.32% |
| RowsBench               | bench_diff_right_1k_on_10k | 2    | 3   | 74.622mb +0.15%  | 18.525ms +2.83%  | ±1.49% +162.42% |
| RowsBench               | bench_drop_1k_on_10k       | 2    | 3   | 77.543mb +0.14%  | 1.739ms -11.13%  | ±0.94% -64.22%  |
| RowsBench               | bench_drop_right_1k_on_10k | 2    | 3   | 77.543mb +0.14%  | 1.719ms -1.44%   | ±1.96% -1.78%   |
| RowsBench               | bench_entries_on_10k       | 2    | 3   | 74.655mb +0.15%  | 2.764ms +5.92%   | ±2.63% -25.96%  |
| RowsBench               | bench_filter_on_10k        | 2    | 3   | 75.184mb +0.15%  | 14.553ms -0.96%  | ±0.24% -91.88%  |
| RowsBench               | bench_find_on_10k          | 2    | 3   | 75.184mb +0.15%  | 15.165ms +2.60%  | ±1.67% +174.84% |
| RowsBench               | bench_find_one_on_10k      | 10   | 3   | 73.087mb +0.15%  | 1.794μs -10.03%  | ±2.67% +11.32%  |
| RowsBench               | bench_first_on_10k         | 10   | 3   | 73.087mb +0.15%  | 0.400μs 0.00%    | ±0.00% 0.00%    |
| RowsBench               | bench_flat_map_on_1k       | 2    | 3   | 86.644mb +0.13%  | 12.289ms -4.43%  | ±0.22% -93.88%  |
| RowsBench               | bench_map_on_10k           | 2    | 3   | 116.003mb +0.10% | 63.518ms -2.37%  | ±1.51% +60.48%  |
| RowsBench               | bench_merge_1k_on_10k      | 2    | 3   | 75.705mb +0.15%  | 1.830ms -6.22%   | ±0.80% -6.17%   |
| RowsBench               | bench_partition_by_on_10k  | 2    | 3   | 77.978mb +0.14%  | 34.282ms -0.27%  | ±0.75% -63.05%  |
| RowsBench               | bench_remove_on_10k        | 2    | 3   | 77.805mb +0.14%  | 3.828ms -0.97%   | ±0.57% +57.85%  |
| RowsBench               | bench_sort_asc_on_1k       | 2    | 3   | 73.232mb +0.15%  | 39.614ms -1.20%  | ±1.79% +106.20% |
| RowsBench               | bench_sort_by_on_1k        | 2    | 3   | 73.233mb +0.15%  | 39.966ms +0.72%  | ±2.79% +170.82% |
| RowsBench               | bench_sort_desc_on_1k      | 2    | 3   | 73.232mb +0.15%  | 39.712ms -2.32%  | ±1.10% +90.36%  |
| RowsBench               | bench_sort_entries_on_1k   | 2    | 3   | 75.530mb +0.15%  | 7.306ms -1.95%   | ±1.53% +28.54%  |
| RowsBench               | bench_sort_on_1k           | 2    | 3   | 73.087mb +0.15%  | 29.369ms +1.80%  | ±0.81% -29.05%  |
| RowsBench               | bench_take_1k_on_10k       | 10   | 3   | 73.087mb +0.15%  | 13.288μs -11.41% | ±0.71% -56.37%  |
| RowsBench               | bench_take_right_1k_on_10k | 10   | 3   | 73.087mb +0.15%  | 15.934μs -13.62% | ±1.30% -59.62%  |
| RowsBench               | bench_unique_on_1k         | 2    | 3   | 96.097mb +0.12%  | 189.625ms +2.23% | ±1.71% +263.68% |
| TypeDetectorBench       | bench_type_detector        | 1    | 3   | 59.175mb +0.31%  | 330.962ms +3.41% | ±2.29% +178.40% |
| TypeDetectorBench       | bench_type_detector        | 1    | 3   | 14.098mb +1.31%  | 65.452ms +0.75%  | ±0.39% -82.10%  |
| NativeEntryFactoryBench | bench_entry_factory        | 1    | 3   | 115.846mb +0.10% | 394.911ms +9.20% | ±0.50% -49.08%  |
| NativeEntryFactoryBench | bench_entry_factory        | 1    | 3   | 59.564mb +0.19%  | 192.092ms +4.86% | ±3.45% +354.82% |
| NativeEntryFactoryBench | bench_entry_factory        | 1    | 3   | 14.689mb +0.76%  | 40.738ms +6.79%  | ±0.74% -57.48%  |
+-------------------------+----------------------------+------+-----+------------------+------------------+-----------------+

@norberttech norberttech merged commit 591529a into flow-php:1.x Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants