Skip to content

Commit

Permalink
Added better support for XML types into Flow (#474)
Browse files Browse the repository at this point in the history
* Added better support for XML types into Flow

* adjustments after code review
  • Loading branch information
norberttech authored Sep 6, 2023
1 parent 8c704b1 commit 57666bf
Show file tree
Hide file tree
Showing 31 changed files with 1,145 additions and 406 deletions.
Empty file modified .php-cs-fixer.php
100644 → 100755
Empty file.
75 changes: 38 additions & 37 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions examples/data/salaries.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<Salaries>
<Month name="January">
<Department name="HR">
<TotalSalary>71883</TotalSalary>
</Department>
<Department name="Engineering">
<TotalSalary>192644</TotalSalary>
</Department>
<Department name="Finance">
<TotalSalary>174187</TotalSalary>
</Department>
<Department name="Marketing">
<TotalSalary>179932</TotalSalary>
</Department>
<Department name="Sales">
<TotalSalary>52056</TotalSalary>
</Department>
</Month>
<Month name="February">
<Department name="HR">
<TotalSalary>102342</TotalSalary>
</Department>
<Department name="Engineering">
<TotalSalary>111102</TotalSalary>
</Department>
<Department name="Finance">
<TotalSalary>81938</TotalSalary>
</Department>
<Department name="Marketing">
<TotalSalary>132202</TotalSalary>
</Department>
<Department name="Sales">
<TotalSalary>173225</TotalSalary>
</Department>
</Month>
<Month name="March">
<Department name="HR">
<TotalSalary>79619</TotalSalary>
</Department>
<Department name="Engineering">
<TotalSalary>99387</TotalSalary>
</Department>
<Department name="Finance">
<TotalSalary>198847</TotalSalary>
</Department>
<Department name="Marketing">
<TotalSalary>50550</TotalSalary>
</Department>
<Department name="Sales">
<TotalSalary>98212</TotalSalary>
</Department>
</Month>
<Month name="April">
<Department name="HR">
<TotalSalary>69721</TotalSalary>
</Department>
<Department name="Engineering">
<TotalSalary>151826</TotalSalary>
</Department>
<Department name="Finance">
<TotalSalary>158168</TotalSalary>
</Department>
<Department name="Marketing">
<TotalSalary>111872</TotalSalary>
</Department>
<Department name="Sales">
<TotalSalary>172334</TotalSalary>
</Department>
</Month>
<Month name="May">
<Department name="HR">
<TotalSalary>174220</TotalSalary>
</Department>
<Department name="Engineering">
<TotalSalary>164086</TotalSalary>
</Department>
<Department name="Finance">
<TotalSalary>104257</TotalSalary>
</Department>
<Department name="Marketing">
<TotalSalary>105817</TotalSalary>
</Department>
<Department name="Sales">
<TotalSalary>145490</TotalSalary>
</Department>
</Month>
<Month name="June">
<Department name="HR">
<TotalSalary>127383</TotalSalary>
</Department>
<Department name="Engineering">
<TotalSalary>52592</TotalSalary>
</Department>
<Department name="Finance">
<TotalSalary>71732</TotalSalary>
</Department>
<Department name="Marketing">
<TotalSalary>165083</TotalSalary>
</Department>
<Department name="Sales">
<TotalSalary>85138</TotalSalary>
</Department>
</Month>
</Salaries>
10 changes: 10 additions & 0 deletions examples/data/simple_items.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<root>
<items>
<item><id>1</id></item>
<item><id>2</id></item>
<item><id>3</id></item>
<item><id>4</id></item>
<item><id>5</id></item>
<item><id>6</id></item>
</items>
</root>
16 changes: 16 additions & 0 deletions examples/topics/types/xml/reading.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Flow\ETL\DSL\To;
use Flow\ETL\DSL\XML;
use Flow\ETL\Flow;

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

print "Reading XML dataset...\n";

(new Flow())
->read(XML::from(__FLOW_DATA__ . '/simple_items.xml', 'root/items/item'))
->write(To::output(false))
->run();
29 changes: 29 additions & 0 deletions examples/topics/types/xml/salaries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

use function Flow\ETL\DSL\ref;
use Flow\ETL\DSL\To;
use Flow\ETL\DSL\XML;
use Flow\ETL\Flow;
use Flow\ETL\GroupBy\Aggregation;

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

print "Reading XML dataset...\n";

(new Flow())
->read(XML::from(__FLOW_DATA__ . '/salaries.xml'))
->withEntry('months', ref('row')->xpath('/Salaries/Month'))
->withEntry('month', ref('months')->expand())
->withEntry('month_name', ref('month')->domNodeAttribute('name'))
->withEntry('departments', ref('month')->xpath('/Month/Department'))
->withEntry('department', ref('departments')->expand())
->withEntry('department_name', ref('department')->domNodeAttribute('name'))
->withEntry('department_salary', ref('department')->xpath('/Department/TotalSalary')->domNodeValue())
->drop('row', 'months', 'month', 'departments', 'department')
->groupBy(ref('month_name'))
->aggregate(Aggregation::sum(ref('department_salary')))
->rename('department_salary_sum', 'total_monthly_salaries')
->write(To::output(false))
->run();
Loading

0 comments on commit 57666bf

Please sign in to comment.