-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align Column_Mapping Add By_Position Separating off the validation for By_Index so can reuse for rename By_Position implemented By_Index implemented Adjusted behaviour following discussion with Ned, so that renames dominate untouched columns. Moving to validation style checks for problems Putting accumulator back Rename work
- Loading branch information
1 parent
c174fcd
commit 481f0f5
Showing
3 changed files
with
173 additions
and
47 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
distribution/lib/Standard/Table/0.0.0-dev/src/Data/Column_Mapping.enso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from Standard.Base import all | ||
|
||
from Standard.Table.Data.Matching import Matching_Strategy, Exact | ||
|
||
## Specifies a selection of columns from the table and the new name for them to | ||
become. | ||
type Column_Mapping | ||
|
||
## Selects columns based on their names. | ||
|
||
The `matching_strategy` can be used to specify if the names should be | ||
matched exactly or should be treated as regular expressions. It also | ||
allows to specify if the matching should be case-sensitive. | ||
type By_Name (names : Map Text Text) (matching_strategy : Matching_Strategy = Exact True) | ||
|
||
## Selects columns by their index. | ||
|
||
The index of the first column in the table is 0. If the provided index is | ||
negative, it counts from the end of the table (e.g. -1 refers to the last | ||
column in the table). | ||
type By_Index (indexes : Map Number Text) | ||
|
||
## Selects columns having exactly the same names as the columns provided in | ||
the input. | ||
|
||
The input columns do not necessarily have to come from the same table, so | ||
this approach can be used to match columns with the same names as a set | ||
of columns of some other table, for example, when preparing for a join. | ||
type By_Column (columns : Map Column Text) | ||
|
||
## Selects columns by position starting at the first column until the | ||
new_names is exhausted. | ||
type By_Position (new_names : Vector Text) | ||
|
||
## UNSTABLE | ||
A temporary workaround to allow the By_Name constructor to work with default arguments. | ||
By_Name.new : Map Text Text -> Matching_Strategy -> By_Name | ||
By_Name.new names (matching_strategy = Exact.new) = By_Name names matching_strategy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Unique_Name_Strategy.enso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from Standard.Base import all | ||
|
||
new : Unique_Name_Strategy | ||
new = Unique_Name_Strategy.new | ||
|
||
type Unique_Name_Strategy | ||
type Unique_Name_Strategy store | ||
|
||
new : Unique_Name_Strategy | ||
new = Unique_Name_Strategy Map.empty | ||
|
||
make_unique : Text -> Text | ||
make_unique name = this.internal_unique name 0 | ||
|
||
internal_unique : Text -> Integer -> Text | ||
internal_unique name shift = | ||
inner_name = if shift == 0 then name else (name + "_"+ shift.to_text) | ||
case this.store.get_or_else inner_name False of | ||
False -> | ||
new_store = this.store.insert inner_name True | ||
Unsafe.set_atom_field this 0 new_store | ||
inner_name | ||
True -> | ||
@Tail_Call this.internal_unique name (shift+1) |