Comments (10)
Thank you @tristanbsn we are going to look at it.
from php-etl.
@tristanbsn could you clarify this point please, I am not sure to understand 🙇
... while the $row array take string('true', 't', 'false', 'f') or NULL value to define booleans.
from php-etl.
@ecourtial In my case I use a transformer with a callback that take a date as source and transform it as string 'false'
if date < current_date, 'true'
otherwise :
return (date($row->get($column)) < date('Y-m-d')) ? 'false' : 'true';
This value get stored in a Boolean field in my PostgreSQL database.
from php-etl.
To clarify the issue is mainly caused by the loose comparision in the update(array $row, array $current)
function that cause unwanted behaviors because of thoses cases :
- true == "false" return true
- true == "f" return true
- false == "false" return false
- false == "f" return false
- false == NULL return true
In my case if the value is true in my PostegreSQL database, it cannot be updated to false because this line prevent the update to be triggered :
if ($row == array_intersect_key($current, $row)) { return; }
from php-etl.
Thank you. I will look at it today.
from php-etl.
Thank you, I made a quick patch if it can help you :
/**
* Execute the update statement.
*/
protected function update(array $row, array $current): void
{
if (false === $this->doUpdates) {
return;
}
if (null === $this->update) {
$this->prepareUpdate($row);
}
// CURRENT VERSION
/*
if ($row == array_intersect_key($current, $row)) {
return;
}
*/
// CORRECTED VERSION
$correctedRow = $row;
foreach ($correctedRow as $key => $value) {
if (isset($current[$key]) && gettype($current[$key]) === "boolean" && gettype($value) === "string" && in_array($value, ["true", "t", "false", "f"])) {
$correctedRow[$key] = in_array($value, ["true", "t"]) ? true : false;
}
}
if ($correctedRow == array_intersect_key($current, $row)) {
return;
}
// END CORRECTED VERSION
if ($this->timestamps) {
$row['updated_at'] = $this->time;
}
$this->update->execute($row);
}
from php-etl.
After a quick look, I am still not sure to understand 😅
This section use loose comparison between old values array and new values array :
if ($row == array_intersect_key($current, $row)) { return; }
So here the comparison is between keys of the array.
Hence despite the fact that we should have === instead of == at line 188, we are going to fix that on rigour sake, it won't change anything because as we can see in the documentation of PHP:
The two keys from the key => value pairs are considered equal only if (string) $key1 === (string) $key2 . In other words a strict type check is executed so the string representation must be the same.
So if we would like to really strictly compare keys, we could use a callback. But I am not sure why we should do that, because the keys of the array are supposed to represent columns names, not values.
Let me know if I am missing something, I would be very glad to help you.
from php-etl.
if ($row == array_intersect_key($current, $row)) { return; }
compare not only the keys but also the values of the array.
In my situation,
$row = ["date_naissance" => "1962-06-18", "actif" => "false"]
$current = ["date_naissance" => "1962-06-18", "actif" => true]
the comparison is true because "false" == true
is true and this cause the update to not be triggered.
from php-etl.
My bad indeed. Easily reproduced... after your explanations.
So I created a PR, could you check it is ok for you, and then I will merge and tag a new version.
from php-etl.
It works for me, thank you !
from php-etl.
Related Issues (20)
- An odd idea for a transformer... a progress meter HOT 6
- Tests do not comply with PSR12 HOT 1
- Is it possible to transform a json that has more than one depth? HOT 2
- Insert and InsertUpdate loaders are inconsistent
- Use PHP 7.4 type hints HOT 1
- CSV extractor header option HOT 1
- Conditional in Database\Transaction:shouldBeginTransaction() my have an extra clause HOT 4
- Allow multi-line CSV header HOT 2
- Add Validator Step HOT 9
- Fix tests in UniqueRowsTest
- Aggregator columns messed up HOT 3
- Is it possible to extract a xml that has more than one loop? HOT 1
- Possibility for advanced connection management ?
- Add Constants to Transform HOT 2
- Complete example, with DB connection? HOT 6
- Can we Extract data from MSSQL database and load it into a csv file? HOT 4
- Option to skip insert for InsertUpdate (update only) HOT 8
- JSON Array to PostgreSQL Array error HOT 5
- Syntax error on Load if column is a reserved word (on more recent MariaDB) HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-etl.