← cast operator page · general/cast/boolean_to_string/true_and_false

True and false 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

cast(Me_1, string) on a Boolean measure, an implicit conversion written as an explicit cast, whose "behavior remains the same".

Manual:

Type conversion: "From boolean to string: Either one of the string values "true" and "false" is returned, depending on the input."

Expected:

true gives the string true and false gives false, in lower case as the manual writes them; a string is compared exactly.

script.vtl ⇩

DS_r := DS_1[calc Me_2 := cast(Me_1, string)];

input/DS_1.csv ⇩

Id_1Me_1
1true
2false

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Boolean", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Me_1Me_2
1truetrue
2falsefalse

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier"},
        {"name": "Me_1", "type": "Boolean", "role": "Measure"},
        {"name": "Me_2", "type": "String", "role": "Measure"}
      ]
    }
  ]
}