Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drop down for replace, remove Column_Selector #7295

Merged
merged 14 commits into from
Jul 14, 2023
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@
- [Improving date/time support in Table - added `date_diff`, `date_add`,
`date_part` and some shorthands. Extended `Time_Period` with milli-, micro-
and nanosecond periods.][7221]
- [Retire `Column_Selector` and allow regex based selection of columns.][7295]

[debug-shortcuts]:
https://github.com/enso-org/enso/blob/develop/app/gui/docs/product/shortcuts.md#debug
Expand Down Expand Up @@ -749,6 +750,7 @@
[7223]: https://github.com/enso-org/enso/pull/7223
[7234]: https://github.com/enso-org/enso/pull/7234
[7221]: https://github.com/enso-org/enso/pull/7221
[7295]: https://github.com/enso-org/enso/pull/7295

#### Enso Compiler

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,3 @@ type Case_Sensitivity
to_explicit_sensitivity_in_memory self = case self of
Case_Sensitivity.Default -> Case_Sensitivity.Sensitive
_ -> self

## PRIVATE
Create matcher function
create_match_function : Boolean -> (Text -> Text -> Boolean)
create_match_function self use_regex=False = case use_regex of
True -> (name-> pattern-> Regex.compile pattern case_insensitive=self.is_case_insensitive_in_memory . matches name)
False -> case self of
Case_Sensitivity.Default -> (==)
Case_Sensitivity.Sensitive -> (==)
Case_Sensitivity.Insensitive locale -> (name-> criterion-> name.equals_ignore_case criterion locale)
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ from project.Data.Boolean import Boolean, False, True
from project.Data.Json import Invalid_JSON, JS_Object, Json
from project.Data.Numbers import Decimal, Integer, Number, Number_Parse_Error
from project.Data.Range.Extensions import all
from project.Widget_Helpers import make_date_format_selector, make_date_time_format_selector, make_delimiter_selector, make_time_format_selector
from project.Widget_Helpers import make_date_format_selector, make_date_time_format_selector, make_delimiter_selector, make_regex_text_widget, make_time_format_selector

polyglot java import com.ibm.icu.lang.UCharacter
polyglot java import com.ibm.icu.text.BreakIterator
Expand Down Expand Up @@ -477,8 +477,9 @@ Text.tokenize self pattern="." case_sensitivity=Case_Sensitivity.Sensitive =
Regexp replace.

'<a href="url">content</a>'.replace '<a href="(.*?)">(.*?)</a>'.to_regex '$2 is at $1'== 'content is at url'
Text.replace : Text | Regex -> Text-> Case_Sensitivity -> Boolean -> Text ! Illegal_Argument
Text.replace self term replacement case_sensitivity=Case_Sensitivity.Default only_first=False =
@term make_regex_text_widget
Text.replace : Text | Regex -> Text -> Case_Sensitivity -> Boolean -> Text ! Illegal_Argument
jdunkerley marked this conversation as resolved.
Show resolved Hide resolved
Text.replace self term:(Text | Regex) replacement:Text (case_sensitivity:Case_Sensitivity=Case_Sensitivity.Default) only_first:Boolean=False =
case term of
_ : Text -> if term.is_empty then self else
array_from_single_result result = case result of
Expand All @@ -496,11 +497,7 @@ Text.replace self term replacement case_sensitivity=Case_Sensitivity.Default onl
Text_Utils.span_of_case_insensitive self term locale.java_locale False
Text_Utils.replace_spans self spans_array replacement
_ : Regex ->
updated_regex = case case_sensitivity of
Case_Sensitivity.Default -> term
_ ->
case_insensitive = case_sensitivity.is_case_insensitive_in_memory
term.recompile case_insensitive
updated_regex = term.recompile case_sensitivity
updated_regex.replace self replacement only_first

## ALIAS Get Words
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import project.Data.Filter_Condition.Filter_Condition
import project.Data.Map.Map
import project.Data.Numbers.Integer
import project.Data.Range.Range
import project.Data.Text.Case_Sensitivity.Case_Sensitivity
import project.Data.Text.Helpers
import project.Data.Text.Prim_Text_Helper
import project.Data.Text.Regex.Internal.Match_Iterator.Match_Iterator
Expand Down Expand Up @@ -370,11 +371,14 @@ type Regex

Recompile the underlying regex string; used to change the
case-sensitivity of a compiled Regex.
recompile : Boolean | Nothing -> Regex ! Regex_Syntax_Error | Illegal_Argument
recompile self case_insensitive=False =
should_recompile = self.case_insensitive != case_insensitive
if should_recompile.not then self else
Regex.compile self.internal_regex_object.pattern case_insensitive
recompile : Case_Sensitivity -> Regex ! Regex_Syntax_Error | Illegal_Argument
recompile self case_sensitivity:Case_Sensitivity = case case_sensitivity of
Case_Sensitivity.Default -> self
_ ->
case_insensitive = case_sensitivity.is_case_insensitive_in_memory
should_recompile = self.case_insensitive != case_insensitive
if should_recompile.not then self else
Regex.compile self.internal_regex_object.pattern case_insensitive

## PRIVATE
Convert the polyglot map to a Map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ polyglot java import java.time.temporal.ChronoUnit
polyglot java import java.time.temporal.TemporalAdjuster
polyglot java import java.time.temporal.TemporalAdjusters
polyglot java import java.time.temporal.TemporalUnit
polyglot java import org.enso.base.Time_Utils
polyglot java import org.enso.base.time.Date_Period_Utils
polyglot java import org.enso.base.time.CustomTemporalUnits
polyglot java import org.enso.base.time.Date_Period_Utils
polyglot java import org.enso.base.Time_Utils

## Represents a unit of time longer on the scale of days (longer than a day).
type Date_Period
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ from project.Data.Boolean import Boolean, False, True

polyglot java import java.time.temporal.ChronoUnit
polyglot java import java.time.temporal.TemporalUnit
polyglot java import org.enso.base.Time_Utils
polyglot java import org.enso.base.time.CustomTemporalUnits
polyglot java import org.enso.base.Time_Utils

## Represents a unit of time of a day or shorter.
type Time_Period
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import project.Data.Time.Time_Of_Day.Time_Of_Day
import project.Metadata.Widget
from project.Metadata import make_single_choice

## PRIVATE
Creates a Regex / Text Widget for search and replace.
make_regex_text_widget : Widget
make_regex_text_widget =
make_single_choice [["Text", '""'], ["Regular Expression", '(Regex.compile "^$")']]

## PRIVATE
Creates a Single_Choice Widget for delimiters.
make_delimiter_selector : Widget
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from Standard.Base import all

import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
import Standard.Base.Errors.Illegal_State.Illegal_State
import Standard.Base.Internal.Rounding_Helpers
from Standard.Base.Widget_Helpers import make_regex_text_widget

import Standard.Table.Data.Column.Column as Materialized_Column
import Standard.Table.Data.Type.Enso_Types
Expand Down Expand Up @@ -1124,7 +1124,6 @@ type Column
- case_sensitivity: Specifies if the text values should be compared case
sensitively.
- only_first: If True, only replace the first match.
- use_regex: If true, the term is used as a regular expression.

> Example
Replace dashes with underscores.
Expand All @@ -1140,7 +1139,8 @@ type Column
Replace texts in quotes with parentheses.

column.replace '"(.*?)"'.to_regex '($1)'
replace : Text | Column | Regex -> Text | Column -> Case_Sensitivity -> Boolean -> Column
@term make_regex_text_widget
replace : Text | Regex | Column -> Text | Column -> Case_Sensitivity -> Boolean -> Column
replace self term="" new_text="" case_sensitivity=Case_Sensitivity.Sensitive only_first=False =
_ = [term, new_text, case_sensitivity, only_first]
msg = "`Column.replace` is not yet implemented."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Standard.Base.Errors.Unimplemented.Unimplemented

import Standard.Table.Internal.Naming_Helpers.Naming_Helpers
import Standard.Table.Internal.Problem_Builder.Problem_Builder
from Standard.Table import Aggregate_Column, Column_Selector, Join_Kind, Value_Type
from Standard.Table import Aggregate_Column, Join_Kind, Value_Type

import project.Connection.Connection.Connection
import project.Data.SQL.Builder
Expand Down Expand Up @@ -255,6 +255,6 @@ default_fetch_primary_key connection table_name =
rs = metadata.getPrimaryKeys Nothing Nothing table_name
keys_table = result_set_to_table rs connection.dialect.make_column_fetcher_for_type
# The names of the columns are sometimes lowercase and sometimes uppercase, so we do a case insensitive select first.
selected = keys_table.select_columns [Column_Selector.By_Name "COLUMN_NAME", Column_Selector.By_Name "KEY_SEQ"] reorder=True
selected = keys_table.select_columns ["COLUMN_NAME", "KEY_SEQ"] case_sensitivity=Case_Sensitivity.Insensitive reorder=True
key_column_names = selected.order_by 1 . at 0 . to_vector
if key_column_names.is_empty then Nothing else key_column_names
Loading
Loading