Skip to content

Commit

Permalink
Rename order_by to sort for Table and DB_Table. (#10372)
Browse files Browse the repository at this point in the history
- Rename `order_by` to `sort` for `Table` and `DB_Table`.
- Added deprecated placeholder.
- Fixed a couple of minor deprecated mistakes.

![image](https://github.com/enso-org/enso/assets/4699705/96c32fa7-33e5-400a-9d3a-ebf330886911)
  • Loading branch information
jdunkerley authored Jun 26, 2024
1 parent 0039c4d commit d920784
Show file tree
Hide file tree
Showing 47 changed files with 385 additions and 350 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
database.][10206]
- [Implemented fallback to Windows-1252 encoding for `Encoding.Default`.][10190]
- [Added Table.duplicates component][10323]
- [Renamed `Table.order_by` to `Table.sort`][10372]

[debug-shortcuts]:

Expand All @@ -55,6 +56,7 @@
[10206]: https://github.com/enso-org/enso/pull/10206
[10190]: https://github.com/enso-org/enso/pull/10190
[10323]: https://github.com/enso-org/enso/pull/10323
[10372]: https://github.com/enso-org/enso/pull/10372

<br/>![Release Notes](/docs/assets/tags/release_notes.svg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Vector.running self statistic:Statistic=..Count =
- statistics: Set of statistics to calculate.
@statistics Statistic.bulk_widget
Vector.running_bulk : Vector Statistic -> Vector Any
Vector.running_bulk self statistics:Statistic=[..Count, ..Sum] =
Vector.running_bulk self (statistics:(Vector Statistic)=[..Count, ..Sum]) =
Statistic.running_bulk self statistics

## GROUP Statistics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ 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.CustomTemporalUnits
polyglot java import org.enso.base.time.Date_Utils
polyglot java import org.enso.base.time.Date_Period_Utils
polyglot java import org.enso.base.time.Date_Time_Utils
polyglot java import org.enso.base.time.Date_Utils
polyglot java import org.enso.base.time.Time_Of_Day_Utils
polyglot java import org.enso.base.Time_Utils

Expand Down
4 changes: 2 additions & 2 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/XML.enso
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ polyglot java import org.enso.base.XML_Utils
polyglot java import org.w3c.dom.Attr
polyglot java import org.w3c.dom.Document
polyglot java import org.w3c.dom.Element
polyglot java import org.w3c.dom.NamedNodeMap
polyglot java import org.w3c.dom.Node
polyglot java import org.w3c.dom.NodeList
polyglot java import org.w3c.dom.NamedNodeMap
polyglot java import org.w3c.dom.Text as Java_Text
polyglot java import org.xml.sax.SAXException
polyglot java import org.xml.sax.SAXParseException
Expand Down Expand Up @@ -99,9 +99,9 @@ type XML_Document
Wrap Java's Document to XML_Document
new doc:Document = XML_Document.Value doc

## PRIVATE
private Value (java_document:Document)


## GROUP Metadata
ICON metadata
Get the root element of the document.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ from project.Metadata import make_single_choice

polyglot java import org.enso.base.enso_cloud.EnsoSecretHelper
polyglot java import org.enso.base.enso_cloud.HideableValue
polyglot java import org.enso.base.enso_cloud.HideableValue.Base64EncodeValue
polyglot java import org.enso.base.enso_cloud.HideableValue.ConcatValues
polyglot java import org.enso.base.enso_cloud.HideableValue.PlainValue
polyglot java import org.enso.base.enso_cloud.HideableValue.SecretValue
polyglot java import org.enso.base.enso_cloud.HideableValue.ConcatValues
polyglot java import org.enso.base.enso_cloud.HideableValue.Base64EncodeValue

## A reference to a secret stored in the Enso Cloud.
type Enso_Secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ from project.Data.Json.Extensions import all

polyglot java import java.lang.Exception as JException
polyglot java import java.net.http.HttpClient
polyglot java import java.net.http.HttpClient.Builder as ClientBuilder
polyglot java import java.net.http.HttpClient.Redirect
polyglot java import java.net.http.HttpClient.Version
polyglot java import java.net.http.HttpClient.Builder as ClientBuilder
polyglot java import java.net.http.HttpRequest
polyglot java import java.net.http.HttpRequest.BodyPublisher
polyglot java import java.net.http.HttpRequest.BodyPublishers
polyglot java import java.net.http.HttpRequest.Builder
polyglot java import java.net.InetSocketAddress
polyglot java import java.net.ProxySelector
polyglot java import javax.net.ssl.SSLContext
polyglot java import org.enso.base.file_system.File_Utils
polyglot java import org.enso.base.enso_cloud.EnsoSecretHelper
polyglot java import org.enso.base.file_system.File_Utils
polyglot java import org.enso.base.net.http.MultipartBodyBuilder
polyglot java import org.enso.base.net.http.UrlencodedBodyBuilder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ from project.Metadata import Display, Widget
from project.Network.HTTP.Response_Body import decode_format_selector

polyglot java import java.net.http.HttpHeaders
polyglot java import org.enso.base.enso_cloud.EnsoHttpResponse
polyglot java import java.util.Optional
polyglot java import org.enso.base.enso_cloud.EnsoHttpResponse

type Response
## PRIVATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ polyglot java import java.nio.file.StandardCopyOption
polyglot java import java.nio.file.StandardOpenOption
polyglot java import java.time.ZonedDateTime
polyglot java import org.enso.base.DryRunFileManager
polyglot java import org.enso.base.file_system.FileSystemSPI
polyglot java import org.enso.base.file_system.File_Utils
polyglot java import org.enso.base.file_system.FileSystemSPI

## PRIVATE
file_types : Vector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import project.System.Input_Stream.Input_Stream
from project.Data.Boolean import Boolean, False, True
from project.Runtime import assert

polyglot java import org.enso.base.encoding.DecodingProblemAggregator
polyglot java import org.enso.base.encoding.DecodingProblem
polyglot java import org.enso.base.encoding.DecodingProblemAggregator
polyglot java import org.enso.base.encoding.Encoding_Utils
polyglot java import org.enso.base.encoding.ReportingStreamDecoder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ from project.System.Input_Stream import close_stream
polyglot java import java.io.ByteArrayOutputStream
polyglot java import java.io.OutputStream as Java_Output_Stream
polyglot java import org.enso.base.encoding.Encoding_Utils

polyglot java import org.enso.base.encoding.ReportingStreamEncoder
polyglot java import org.enso.base.Stream_Utils
polyglot java import org.enso.base.Stream_Utils.OutputStreamLike
polyglot java import org.enso.base.encoding.ReportingStreamEncoder

## PRIVATE
An output stream, allowing for interactive writing of contents.
Expand Down
15 changes: 15 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Widget_Helpers.enso
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,18 @@ make_data_cleanse_vector_selector display:Display=Display.Always =
patterns = ['Leading_Whitespace', 'Trailing_Whitespace', 'Duplicate_Whitespace', 'All_Whitespace', 'Leading_Numbers', 'Trailing_Numbers', 'Non_ASCII', 'Tabs', 'Letters', 'Numbers', 'Punctuation', 'Symbols']
options = patterns.map f-> Option f (".." + f)
Multiple_Choice values=options display=display

## PRIVATE
Make a single value selector
make_any_selector : Display -> Boolean -> Boolean -> Boolean -> Boolean -> Boolean -> Boolean -> Widget
make_any_selector display:Display=..Always add_text:Boolean=False add_regex:Boolean=False add_number:Boolean=False add_boolean:Boolean=False add_named_pattern:Boolean=False add_nothing:Boolean=False =
text = if add_text then [Option "<Text Value>" "''"] else []
regex = if add_regex then [Option "<Regular Expression>" "(regex '')"] else []
number = if add_number then [Option "<Number Value>" "0"] else []
boolean = if add_boolean then [Option "<True/False>" "True"] else []
named_pattern = if add_named_pattern.not then [] else
patterns = ["Leading_Whitespace", "Trailing_Whitespace", "All_Whitespace", "Leading_Numbers", "Trailing_Numbers", "Non_ASCII", "Tabs", "Letters", "Numbers", "Punctuation", "Symbols"]
## Can't use auto-scoping as Named_Patterns are materialised into Regex.
patterns.map p-> Option "<"+p+">" "Named_Pattern."+p
nothing = if add_nothing then [Option "<Nothing>" "Nothing"] else []
make_single_choice (text + regex + number + boolean + named_pattern + nothing) display=display
10 changes: 5 additions & 5 deletions distribution/lib/Standard/Database/0.0.0-dev/src/DB_Column.enso
Original file line number Diff line number Diff line change
Expand Up @@ -1196,9 +1196,9 @@ type DB_Column
column.sort Sort_Direction.Descending
sort : Sort_Direction -> DB_Column
sort self order=Sort_Direction.Ascending =
self.to_table.order_by [Sort_Column.Index 0 order] . at 0
self.to_table.sort [..Index 0 order] . at 0

## ALIAS first, head, last, limit, sample, slice, tail, top, keep
## ALIAS first, head, keep, last, limit, sample, slice, tail, top
GROUP Standard.Base.Selections
ICON parse3
Creates a new Column with the specified range of rows from the input
Expand All @@ -1210,7 +1210,7 @@ type DB_Column
take : (Index_Sub_Range | Range | Integer) -> DB_Column
take self range=(First 1) = self.to_table.take range . at 0

## ALIAS skip, remove
## ALIAS remove, skip
GROUP Standard.Base.Selections
ICON parse3
Creates a new column from the input with the specified range of rows
Expand Down Expand Up @@ -1805,9 +1805,9 @@ type DB_Column
check_cast_compatibility self.value_type value_type <|
self.internal_do_cast value_type on_problems

## GROUP Standard.Base.Conversions
## ALIAS auto_value_type
GROUP Standard.Base.Conversions
ICON convert
ALIAS auto_value_type
Change the value type of the column to a more specific one, based on its
contents.

Expand Down
43 changes: 28 additions & 15 deletions distribution/lib/Standard/Database/0.0.0-dev/src/DB_Table.enso
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Standard.Base.Errors.Unimplemented.Unimplemented
import Standard.Base.System.File.Generic.Writable_File.Writable_File
from Standard.Base.Metadata import Display, make_single_choice, Widget
from Standard.Base.Runtime import assert
from Standard.Base.Widget_Helpers import make_data_cleanse_vector_selector, make_delimiter_selector, make_format_chooser
from Standard.Base.Widget_Helpers import make_any_selector, make_data_cleanse_vector_selector, make_delimiter_selector, make_format_chooser

import Standard.Table.Column_Operation.Column_Operation
import Standard.Table.Columns_To_Add.Columns_To_Add
Expand Down Expand Up @@ -167,6 +167,7 @@ type DB_Table
- if_missing: The value to use if the selector isn't present.
@selector Widget_Helpers.make_column_name_selector
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.row_count-1)
@if_missing (make_any_selector add_text=True add_regex=True add_number=True add_boolean=True add_named_pattern=True add_nothing=True)
get_value : Text | Integer -> Integer -> Any -> Any
get_value self selector:(Text | Integer)=0 index:Integer=0 ~if_missing=Nothing =
col = self.get selector if_missing=Nothing
Expand Down Expand Up @@ -735,7 +736,7 @@ type DB_Table
result = self.filter column Filter_Condition.Is_True
Warning.attach (Deprecated.Warning "Standard.Database.DB_Table.DB_Table" "filter_by_expression" "Deprecated: use `filter` with an `Expression` instead.") result

## ALIAS first, head, last, limit, sample, slice, tail, top, keep
## ALIAS first, head, keep, last, limit, sample, slice, tail, top
GROUP Standard.Base.Selections
ICON select_row
Creates a new Table with the specified range of rows from the input
Expand Down Expand Up @@ -767,7 +768,7 @@ type DB_Table
take self range:(Index_Sub_Range | Range | Integer)=(..First 1) =
Take_Drop_Helpers.take_drop_helper Take_Drop.Take self range

## ALIAS skip, remove
## ALIAS remove, skip
GROUP Standard.Base.Selections
ICON select_row
Creates a new Table from the input with the specified range of rows
Expand Down Expand Up @@ -877,7 +878,7 @@ type DB_Table
updated_table.as_subquery


## UNSTABLE
## ALIAS order_by
GROUP Standard.Base.Selections
ICON select_row

Expand Down Expand Up @@ -906,8 +907,9 @@ type DB_Table
In the call below, assuming that the table of `t1` contains rows for
numbers 1, 2, ..., 10, will return rows starting from 6 and not an empty
result as one could expect if the limit was applied before the filters.
t1 = table.order_by [Sort_Column.Name "A"] . limit 5
t2 = t1.filter 'A' (Greater than=5)

t1 = table.sort [..Name "A"] . limit 5
t2 = t1.filter 'A' (..Greater than=5)
t2.read
limit : Integer -> DB_Table
limit self max_rows:Integer=1000 =
Expand Down Expand Up @@ -1218,40 +1220,40 @@ type DB_Table
> Example
Sorting `table` in ascending order by the value in column `'Quantity'`.

table.order_by ['Quantity']
table.sort ['Quantity']

> Example
Sorting `table` in descending order by the value in column `'Quantity'`.

table.order_by [Sort_Column.Name 'Quantity' Sort_Direction.Descending]
table.sort [..Name 'Quantity' ..Descending]

> Example
Sorting `table` in ascending order by the value in column `'Quantity'`,
using the value in column `'Rating'` for breaking ties.

table.order_by ['Quantity', 'Rating']
table.sort ['Quantity', 'Rating']

> Example
Sorting `table` in ascending order by the value in column `'Quantity'`,
using the value in column `'Rating'` in descending order for breaking
ties.

table.order_by [Sort_Column.Name 'Quantity', Sort_Column.Name 'Rating' Sort_Direction.Descending]
table.sort [..Name 'Quantity', ..Name 'Rating' ..Descending]

> Example
Order the table by the second column in ascending order. In case of any
ties, break them based on the 7th column from the end of the table in
descending order.

table.order_by [1, Sort_Column.Index -7 Sort_Direction.Descending]
table.sort [1, ..Index -7 ..Descending]

> Example
Sort the table by columns whose names start with letter `a`.

table.order_by [(Sort_Column.Select_By_Name "a.*".to_regex case_sensitivity=Case_Sensitivity.Insensitive)]
table.sort [(..Select_By_Name "a.*".to_regex case_sensitivity=..Insensitive)]
@columns Widget_Helpers.make_order_by_selector
order_by : Vector (Text | Sort_Column) | Text -> Text_Ordering -> Boolean -> Problem_Behavior -> DB_Table ! Incomparable_Values | No_Input_Columns_Selected | Missing_Input_Columns
order_by self (columns = ([(Sort_Column.Name (self.columns.at 0 . name))])) text_ordering:Text_Ordering=..Default error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning =
sort : Vector (Text | Sort_Column) | Text -> Text_Ordering -> Boolean -> Problem_Behavior -> DB_Table ! Incomparable_Values | No_Input_Columns_Selected | Missing_Input_Columns
sort self (columns = ([(Sort_Column.Name (self.columns.at 0 . name))])) text_ordering:Text_Ordering=..Default error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning =
problem_builder = Problem_Builder.new error_on_missing_columns=error_on_missing_columns types_to_always_throw=[No_Input_Columns_Selected]
columns_for_ordering = Table_Helpers.prepare_order_by self.columns columns problem_builder
problem_builder.attach_problems_before on_problems <|
Expand All @@ -1263,6 +1265,16 @@ type DB_Table
new_ctx = self.context.add_orders new_order_descriptors
self.updated_context new_ctx

## PRIVATE
GROUP Standard.Base.Selections
ICON order
Deprecated - use `Table.sort` instead.
@columns Widget_Helpers.make_order_by_selector
order_by : Vector (Text | Sort_Column) | Text -> Text_Ordering -> Boolean -> Problem_Behavior -> DB_Table ! Incomparable_Values | No_Input_Columns_Selected | Missing_Input_Columns
order_by self (columns = ([(Sort_Column.Name (self.columns.at 0 . name))])) text_ordering:Text_Ordering=..Default error_on_missing_columns:Boolean=True on_problems:Problem_Behavior=..Report_Warning =
result = self.sort columns text_ordering error_on_missing_columns on_problems
Warning.attach (Deprecated.Warning "Standard.Database.Table.Table" "order_by" "Deprecated: use `sort` instead.") result

## PRIVATE
Returns the default ordering used for operations like `add_row_number` or
`take`.
Expand Down Expand Up @@ -1331,7 +1343,7 @@ type DB_Table
setting.
@columns Widget_Helpers.make_column_name_multi_selector
distinct : Vector (Integer | Text | Regex) | Text | Integer | Regex -> Case_Sensitivity -> Problem_Behavior -> DB_Table ! No_Output_Columns | Missing_Input_Columns | No_Input_Columns_Selected | Floating_Point_Equality
distinct self columns=self.column_names case_sensitivity:Case_Sensitivity=..Default on_problems:Problem_Behavior=Report_Warning =
distinct self columns=self.column_names case_sensitivity:Case_Sensitivity=..Default on_problems:Problem_Behavior=..Report_Warning =
key_columns = self.columns_helper.select_columns columns Case_Sensitivity.Default reorder=True error_on_missing_columns=True on_problems=on_problems . catch No_Output_Columns _->
Error.throw No_Input_Columns_Selected
problem_builder = Problem_Builder.new
Expand Down Expand Up @@ -1697,6 +1709,7 @@ type DB_Table
# 1 | 20 | b | f
# 2 | 30 | c | g
# 3 | 40 | d | h
@lookup_table Widget_Helpers.make_replace_selector
@columns (Widget_Helpers.make_column_name_multi_selector add_regex=True add_by_type=True)
@from_column Widget.Text_Input
@to_column Widget.Text_Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,5 @@ default_fetch_primary_key connection table_name =
keys_table = result_set_to_table rs connection.dialect.get_type_mapping.make_column_fetcher
# 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_NAME", "KEY_SEQ"] case_sensitivity=Case_Sensitivity.Insensitive reorder=True
key_column_names = selected.order_by 1 . at 0 . to_vector
key_column_names = selected.sort 1 . at 0 . to_vector
if key_column_names.is_empty then Nothing else key_column_names
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ type SQLite_Dialect
## The `pk` field is non-zero if the columns is part of the primary key.
The column value indicates the position in the key.
See: https://www.sqlite.org/pragma.html#pragma_table_info
v = info_table.filter "pk" (>0) . order_by "pk" . at "name" . to_vector
v = info_table.filter "pk" (>0) . sort "pk" . at "name" . to_vector
if v.is_empty then Nothing else v

## PRIVATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

example_sort =
table = Examples.inventory_table
table.order_by [Sort_Column.Name "total_stock", Sort_Column.Name "sold_stock" Sort_Direction.Descending]
table.sort [Sort_Column.Name "total_stock", Sort_Column.Name "sold_stock" Sort_Direction.Descending]

> Example
Compute the number of transactions that each item has participated in, as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

example_sort =
table = Examples.inventory_table
table.order_by [Sort_Column.Name "price" Sort_Direction.Descending]
table.sort [Sort_Column.Name "price" Sort_Direction.Descending]

> Example
Add two columns to each other.
Expand Down
8 changes: 4 additions & 4 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso
Original file line number Diff line number Diff line change
Expand Up @@ -1961,9 +1961,9 @@ type Column
new_storage = self.java_column.getStorage.cast target_storage_type cast_problem_builder
Column.from_storage self.name new_storage

## GROUP Standard.Base.Conversions
## ALIAS auto_value_type
GROUP Standard.Base.Conversions
ICON convert
ALIAS auto_value_type
Change the value type of the column to a more specific one, based on its
contents.

Expand Down Expand Up @@ -2383,7 +2383,7 @@ type Column
sorted = self.to_vector.sort order by=wrapped
Column.from_vector self.name sorted

## ALIAS first, head, last, limit, sample, slice, tail, top, keep
## ALIAS first, head, keep, last, limit, sample, slice, tail, top
GROUP Standard.Base.Selections
ICON parse3
Creates a new Column with the specified range of rows from the input
Expand Down Expand Up @@ -2418,7 +2418,7 @@ type Column
take self range=(First 1) =
Index_Sub_Range_Module.take_helper self.length (self.at _) self.slice (slice_ranges self) range

## ALIAS skip, remove
## ALIAS remove, skip
GROUP Standard.Base.Selections
ICON parse3
Creates a new Column from the input with the specified range of rows
Expand Down
Loading

0 comments on commit d920784

Please sign in to comment.