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

Rename order_by to sort for Table and DB_Table. #10372

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
37 changes: 24 additions & 13 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 @@ -735,7 +735,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 +767,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 +877,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 +906,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 +1219,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 +1264,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
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
Loading