diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Data/DB_Column.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Data/DB_Column.enso index 6b28940ae361..043b805a5cb2 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Data/DB_Column.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Data/DB_Column.enso @@ -1648,8 +1648,8 @@ type DB_Column can be used. For `Boolean`, it should be two values that represent true and false, separated by a `|`. Alternatively, a `Data_Formatter` can be passed to provide complete customisation of the formatting. If - `Nothing` is provided, the default formatting settings of the backend - will be used. `Nothing` is currently the only setting accepted by the + `""` is provided, the default formatting settings of the backend + will be used. `""` is currently the only setting accepted by the Database backends. - on_problems: Specifies how to handle if a problem occurs, raising as a warning by default. @@ -1665,26 +1665,22 @@ type DB_Column does not support customization, an `Unsupported_Database_Operation` error is reported. @type (Widget_Helpers.parse_type_selector include_auto=False) - parse : Value_Type | Auto -> Text | Data_Formatter | Nothing -> Problem_Behavior -> DB_Column - parse self type format=Nothing on_problems=Report_Warning = - check_parameters = - if type == Auto then Error.throw (Unsupported_Database_Operation.Error "The `Auto` parse type is not supported by the Database backend. Either pick a specific type or materialize the table to memory using `.read`.") else - case format of - Nothing -> Nothing - _ -> Error.throw (Unsupported_Database_Operation.Error "Custom formatting is not supported by the Database backend. Please set the format to `Nothing` to indicate that the default Database settings can be used, or if custom formatting is needed, materialize the table to memory using `.read` first.") - check_parameters.if_not_error <| - Value_Type.expect_text self <| - ## In the future we may have some specific logic, for example - allowing to support formatting settings. For now, the - Database parse just boils down to a simple CAST. - self.internal_do_cast type on_problems + parse : Value_Type | Auto -> Text | Data_Formatter -> Problem_Behavior -> DB_Column + parse self type format:(Text|Data_Formatter)="" on_problems=Report_Warning = + if type == Auto then Error.throw (Unsupported_Database_Operation.Error "The `Auto` parse type is not supported by the Database backend. Either pick a specific type or materialize the table to memory using `.read`.") else + if format != "" then Error.throw (Unsupported_Database_Operation.Error "Custom formatting is not supported by the Database backend. Please set the format to `''` to use the default settings, or if custom formatting is needed, materialize the table to memory using `.read` first.") else + Value_Type.expect_text self <| + ## In the future we may have some specific logic, for example + allowing to support formatting settings. For now, the + Database parse just boils down to a simple CAST. + self.internal_do_cast type on_problems ## GROUP Standard.Base.Conversions ICON convert Formatting values is not supported in database columns. @locale Locale.default_widget format : Text | Date_Time_Formatter | DB_Column | Nothing -> Locale -> DB_Column ! Illegal_Argument - format self format:(Text | Date_Time_Formatter | DB_Column | Nothing)=Nothing locale=Locale.default = + format self format:(Text | Date_Time_Formatter | DB_Column)="" locale=Locale.default = _ = [format, locale] Error.throw <| Unsupported_Database_Operation.Error "`DB_Column.format` is not implemented yet for the Database backends." diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Data/Table.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Data/Table.enso index 991b016f1389..5d99dddd0e39 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Data/Table.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Data/Table.enso @@ -2104,8 +2104,9 @@ type Table table.format @columns Widget_Helpers.make_column_name_vector_selector @locale Locale.default_widget - format : Vector (Text | Integer | Regex) | Text | Integer | Regex -> Text | Date_Time_Formatter | DB_Column | Nothing -> Locale -> Boolean -> Problem_Behavior -> Table ! Date_Time_Format_Parse_Error | Illegal_Argument - format self columns format:(Text | Date_Time_Formatter | DB_Column | Nothing)=Nothing locale=Locale.default error_on_missing_columns=True on_problems=Report_Warning = + @format (make_format_chooser include_number=False) + format : Vector (Text | Integer | Regex) | Text | Integer | Regex -> Text | Date_Time_Formatter | DB_Column -> Locale -> Boolean -> Problem_Behavior -> Table ! Date_Time_Format_Parse_Error | Illegal_Argument + format self columns format:(Text | Date_Time_Formatter | DB_Column)="" locale=Locale.default error_on_missing_columns=True on_problems=Report_Warning = _ = [columns, format, locale, error_on_missing_columns, on_problems] Error.throw (Unsupported_Database_Operation.Error "Table.format is not implemented yet for the Database backends.") diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Column.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Column.enso index 737aab4f0053..5b3dac71ade6 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Column.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Column.enso @@ -1667,8 +1667,8 @@ type Column can be used. For `Boolean`, it should be two values that represent true and false, separated by a `|`. Alternatively, a `Data_Formatter` can be passed to provide complete customisation of the formatting. If - `Nothing` is provided, the default formatting settings of the backend - will be used. `Nothing` is currently the only setting accepted by the + `""` is provided, the default formatting settings of the backend + will be used. `""` is currently the only setting accepted by the Database backends. - on_problems: Specifies how to handle if a problem occurs, raising as a warning by default. @@ -1725,16 +1725,12 @@ type Column example_contains = Examples.text_column_1.parse Boolean 'Yes|No' @type Widget_Helpers.parse_type_selector - parse : Value_Type | Auto -> Text | Data_Formatter | Nothing -> Problem_Behavior -> Column - parse self type=Auto format=Data_Formatter.Value on_problems=Report_Warning = + parse : Value_Type | Auto -> Text | Data_Formatter -> Problem_Behavior -> Column + parse self type=Auto format:(Text|Data_Formatter)="" on_problems=Report_Warning = Value_Type.expect_text self <| formatter = case format of - _ : Text -> - Data_Formatter.Value.with_format type format + _ : Text -> if format == "" then Data_Formatter.Value else Data_Formatter.Value.with_format type format _ : Data_Formatter -> format - Nothing -> Data_Formatter.Value - _ -> Error.throw (Illegal_Argument.Error "Invalid format type. Expected Text or Data_Formatter or Nothing.") - parser = formatter.make_value_type_parser type storage = self.java_column.getStorage @@ -1749,9 +1745,8 @@ type Column Arguments: - format: The type-dependent format string to use to format the values. - If `format` is `""` or `Nothing`, .to_text is used to format the value. - In case of date/time columns, the format can also be a - `Date_Time_Formatter`. + If `format` is `""`, .to_text is used to format the value. + In case of date/time columns, a `Date_Time_Formatter` can be used. - locale: The locale in which the format should be interpreted. If a `Date_Time_Formatter` is provided for `format` and the `locale` is set to anything else than `Locale.default`, then that locale will @@ -1823,8 +1818,8 @@ type Column input.format "#,##0.00" locale=(Locale.new "fr") # ==> ["100 000 000,00", "2 222,00", "3,00"] @locale Locale.default_widget - format : Text | Date_Time_Formatter | Column | Nothing -> Locale -> Column ! Illegal_Argument - format self format:(Text | Date_Time_Formatter | Column | Nothing)=Nothing locale=Locale.default = + format : Text | Date_Time_Formatter | Column -> Locale -> Column ! Illegal_Argument + format self format:(Text | Date_Time_Formatter | Column)="" locale=Locale.default = new_column = case format of format_column : Column -> Value_Type.expect_text format_column <| formatter = make_value_formatter_for_value_type self.value_type locale diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Table.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Table.enso index eef8e3232825..5b0bf3ca2dc0 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Table.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Table.enso @@ -1070,8 +1070,9 @@ type Table table.format @columns Widget_Helpers.make_column_name_vector_selector @locale Locale.default_widget - format : Vector (Text | Integer | Regex) | Text | Integer | Regex -> Text | Date_Time_Formatter | Column | Nothing -> Locale -> Boolean -> Problem_Behavior -> Table ! Date_Time_Format_Parse_Error | Illegal_Argument - format self columns format:(Text | Date_Time_Formatter | Column | Nothing)=Nothing locale=Locale.default error_on_missing_columns=True on_problems=Report_Warning = + @format (make_format_chooser include_number=False) + format : Vector (Text | Integer | Regex) | Text | Integer | Regex -> Text | Date_Time_Formatter | Column -> Locale -> Boolean -> Problem_Behavior -> Table ! Date_Time_Format_Parse_Error | Illegal_Argument + format self columns format:(Text | Date_Time_Formatter | Column)="" locale=Locale.default error_on_missing_columns=True on_problems=Report_Warning = select_problem_builder = Problem_Builder.new error_on_missing_columns=error_on_missing_columns selected_columns = self.columns_helper.select_columns_helper columns Case_Sensitivity.Default True select_problem_builder select_problem_builder.attach_problems_before on_problems <| diff --git a/test/Table_Tests/src/In_Memory/Column_Format_Spec.enso b/test/Table_Tests/src/In_Memory/Column_Format_Spec.enso index 03b3d7692708..a1b5bf589d11 100644 --- a/test/Table_Tests/src/In_Memory/Column_Format_Spec.enso +++ b/test/Table_Tests/src/In_Memory/Column_Format_Spec.enso @@ -32,12 +32,11 @@ add_specs suite_builder = input.format (Date_Time_Formatter.from "d. MMMM yyyy" Locale.uk) . should_equal expected_gb input.format (Date_Time_Formatter.from "d. MMMM yyyy" Locale.france) . should_equal expected_fr - group_builder.specify "Empty/Nothing format" <| + group_builder.specify "Empty format" <| input = Column.from_vector "values" [Date.new 2020 12 21, Date.new 2023 4 25] expected = Column.from_vector "values" ['2020-12-21', '2023-04-25'] input.format . should_equal expected input.format "" . should_equal expected - input.format Nothing . should_equal expected group_builder.specify "Bad format" <| input = Column.from_vector "values" [Date.new 2020 6 21, Date.new 2023 4 25] @@ -106,13 +105,12 @@ add_specs suite_builder = # If I provide a locale argument, it overrides what is already in the formatter: input.format formatter Locale.poland . should_equal expected_pl - group_builder.specify "Empty/Nothing format" <| + group_builder.specify "Empty format" <| zone = Time_Zone.parse "US/Hawaii" input = Column.from_vector "values" [Date_Time.new 2020 12 21 8 10 20 zone=zone, Date_Time.new 2023 4 25 14 25 2 zone=zone] expected = Column.from_vector "values" ['2020-12-21 08:10:20-10:00[US/Hawaii]', '2023-04-25 14:25:02-10:00[US/Hawaii]'] input.format . should_equal expected input.format "" . should_equal expected - input.format Nothing . should_equal expected group_builder.specify "Bad format" <| input = Column.from_vector "values" [Date_Time.new 2020 6 21 8 10 20, Date_Time.new 2023 4 25 14 25 2] @@ -170,12 +168,11 @@ add_specs suite_builder = input.format "HH.mm.ss" (Locale.default) . should_equal expected input.format "HH.mm.ss" (Locale.new "gb") . should_equal expected - group_builder.specify "Empty/Nothing format" <| + group_builder.specify "Empty format" <| input = Column.from_vector "values" [Time_Of_Day.new 8 10 20, Time_Of_Day.new 14 25 2] expected = Column.from_vector "values" ['08:10:20', '14:25:02'] input.format . should_equal expected input.format "" . should_equal expected - input.format Nothing . should_equal expected group_builder.specify "Bad format" <| input = Column.from_vector "values" [Time_Of_Day.new 8 10 20, Time_Of_Day.new 14 25 2] @@ -228,12 +225,11 @@ add_specs suite_builder = actual = input.format "t|f" actual . should_equal expected - group_builder.specify "Empty/Nothing format" <| + group_builder.specify "Empty format" <| input = Column.from_vector "values" [True, False] expected = Column.from_vector "values" ["True", "False"] input.format . should_equal expected input.format "" . should_equal expected - input.format Nothing . should_equal expected group_builder.specify "Bad format" <| input = Column.from_vector "values" [True, False] @@ -267,20 +263,18 @@ add_specs suite_builder = expected = Column.from_vector "values" ["100,000,000.00", "2,222.00", "3.00"] input.format "#,##0.00" . should_equal expected - suite_builder.group "Numeric, empty/Nothing" group_builder-> + suite_builder.group "Numeric format, empty" group_builder-> group_builder.specify "Integer" <| input = Column.from_vector "values" ["100000000", "2222", "3"] . parse (Value_Type.Integer Bits.Bits_64) expected = Column.from_vector "values" ["100000000", "2222", "3"] input.format . should_equal expected input.format "" . should_equal expected - input.format Nothing . should_equal expected group_builder.specify "Float" <| input = Column.from_vector "values" ["100000000", "2222", "3"] . parse (Value_Type.Float Bits.Bits_64) expected = Column.from_vector "values" ['1.0E8', '2222.0', '3.0'] input.format . should_equal expected input.format "" . should_equal expected - input.format Nothing . should_equal expected group_builder.specify "Integer, with format Column" <| input = Column.from_vector "values" ["100000000", "2222", "3"] . parse (Value_Type.Integer Bits.Bits_64)