Skip to content

Commit

Permalink
Workaround for IIF issue.
Browse files Browse the repository at this point in the history
Proper solution needed (TODO add task to infer SQLite types locally)
  • Loading branch information
radeusgd committed Apr 5, 2023
1 parent 5d48852 commit ed1e5e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Standard.Base.Errors.Illegal_State.Illegal_State
import Standard.Table.Data.Type.Enso_Types
import Standard.Table.Data.Type.Value_Type.Value_Type
import Standard.Table.Data.Type.Value_Type.Bits
import Standard.Table.Data.Type.Value_Type_Helpers
from Standard.Table.Errors import Inexact_Type_Coercion

import project.Data.Column.Column
Expand Down Expand Up @@ -118,7 +119,11 @@ type SQLite_Type_Mapping
Panic.throw (Illegal_State.Error "Impossible: IIF must have 3 arguments. This is a bug in the Database library.")
inputs_types = arguments.drop 1 . map find_type
if inputs_types.first == inputs_types.second then return inputs_types.first else
infer_default_type
case Value_Type_Helpers.reconcile_types inputs_types.first inputs_types.second of
## Inference failed, fall back to default type.
Ideally, should never happen. To be handled in #6106.
Value_Type.Mixed -> infer_default_type
common -> return common

always_boolean_ops = ["==", "!=", "equals_ignore_case", ">=", "<=", "<", ">", "BETWEEN", "AND", "OR", "NOT", "IS_NULL", "IS_NAN", "IS_EMPTY", "LIKE", "IS_IN", "starts_with", "ends_with", "contains"]
always_text_ops = ["ADD_TEXT", "CONCAT", "CONCAT_QUOTE_IF_NEEDED"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ spec setup =
t = table_builder [["X", [True, False, Nothing, True]]]
t.at "X" . iif 22 33 . to_vector . should_equal [22, 33, Nothing, 22]

Test.specify "iif on Columns" pending="Not implemented yet." Nothing
Test.specify "iif on Columns" <|
t = table_builder [["X", [True, False, Nothing, False]], ["Y", [1, 2, 3, 4]], ["Z", [1.5, 2.5, 3.5, 4.5]]]
c = t.at "X" . iif (t.at "Y") (t.at "Z")
c.value_type . is_floating_point . should_be_true
c.to_vector . should_equal [1, 2.5, Nothing, 4.5]

t2 = table_builder [["x", [1, 4, 5, Nothing]], ["y", [2, 3, 5, Nothing]], ["b", [False, False, True, Nothing]]]
x = t2.at "x"
Expand Down

0 comments on commit ed1e5e7

Please sign in to comment.