Closed e3krisztian closed 11 years ago
You have right I fixed this. The boolean conversion is worked for Integers. So if you want to work the correct solution was the following:
name: boolean_variable
finalType: Boolean
transforms:
- transform: Map
values:
t: 1
f: 0
- transform: ConvertType
fieldType: Integer
- transform: ConvertType
fieldType: Boolean
It was not good enough so added more rule for strings at version 0.1.6.12:
:+1: It was really fast!
I confirm the following is working now:
name: boolean_variable
type: Boolean
There is a postgres export in .csv. Postgres exports boolean values as
t
andf
for true and false respectively.This file is to be reimported into postgres, with the fields defined as
boolean
in the target table.How can I define a field that converts the string values
f
andt
in source toBoolean
values true and false in target?I have tried these variants:
It actually works, however this is not clean: the field type is defined as
String
, the values are python booleans (True
andFalse
), so there is a type mismatch, it works by chance: all parties are dynamic enough to get over the type mismatch. Note, thatfinalType
is commented out - the pythonbool
s are still erroneously stored in aString
field internally!So let's try to do it properly - it turns out that we can not:
It does not work,
ConvertType
converts 'false' toTrue
as well - in fact it I do not know if is possible at all to get aFalse
out - the bool value of every non-empty string isTrue
, the empty string however gets converted toNULL
!Finally the simplest:
Works! Types are consistent within mETL config (String), but it is the database that does the work: the postgres database implicitly converts
t
andf
strings to booleans - we are dependending on postgresql, probably fails with any other db!