Skip to content

Commit

Permalink
Green
Browse files Browse the repository at this point in the history
  • Loading branch information
AdRiley committed Jan 31, 2025
1 parent 7ac65e7 commit 921f56a
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 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 @@ -3183,37 +3183,36 @@ type DB_Table
@order_by Widget_Helpers.make_order_by_selector
offset self columns:(Vector (Integer | Text | Regex | By_Type))=(Missing_Argument.throw "columns") n:Integer=-1 fill_with:Fill_With=..Nothing (group_by:(Vector | Text | Integer | Regex)=[]) (order_by:(Vector | Text)=[]) (set_mode:Set_Mode=..Add) (on_problems:Problem_Behavior=..Report_Warning) -> DB_Table =
Feature.Offset.if_supported_else_throw self.connection.dialect "offset" <|
if columns.is_empty then self else
problem_builder = Problem_Builder.new error_on_missing_columns=True
grouping_columns = self.columns_helper.select_columns_helper group_by Case_Sensitivity.Default True problem_builder
grouping_columns.each column->
if column.value_type.is_floating_point then
problem_builder.report_other_warning (Floating_Point_Equality.Error column.name)
ordering = Table_Helpers.resolve_order_by self.columns order_by problem_builder
problem_builder.attach_problems_before on_problems <|
order_descriptors = case ordering.is_empty of
False -> ordering.map element->
column = element.column
associated_selector = element.associated_selector
self.connection.dialect.prepare_order_descriptor column associated_selector.direction text_ordering=Nothing
True -> case self.default_ordering of
Nothing -> Error.throw (Illegal_Argument.Error "The table has no existing ordering (e.g. from a `sort` operation or primary key). `offset` requires an ordering in database.")
descriptors -> descriptors
grouping_expressions = (grouping_columns.map _.as_internal).map .expression
resolved_columns = self.columns_helper.select_columns_helper columns Case_Sensitivity.Default True problem_builder
new_exprs = resolved_columns.map c->(Offset_Helpers.make_offset n (c.as_internal) order_descriptors grouping_expressions)

type_mapping = self.connection.dialect.get_type_mapping
infer_from_database_callback expression =
SQL_Type_Reference.new self.connection self.context expression
new_type_refs = new_exprs.map expr->(type_mapping.infer_return_type infer_from_database_callback "OFFSET" [] expr)

new_names = resolved_columns.map c->(if set_mode==Set_Mode.Add then self.column_naming_helper.function_name "offset" [c, n, fill_with] else c.name)
new_columns = (new_names.zip new_type_refs).zip new_exprs a->b->(Internal_Column.Value a.first a.second b)

updated_table = new_columns.fold self t-> col->
t.set (self.make_column col)
updated_table.as_subquery
problem_builder = Problem_Builder.new error_on_missing_columns=True
grouping_columns = self.columns_helper.select_columns_helper group_by Case_Sensitivity.Default True problem_builder
grouping_columns.each column->
if column.value_type.is_floating_point then
problem_builder.report_other_warning (Floating_Point_Equality.Error column.name)
ordering = Table_Helpers.resolve_order_by self.columns order_by problem_builder
resolved_columns = self.columns_helper.select_columns_helper columns Case_Sensitivity.Default True problem_builder
problem_builder.attach_problems_before on_problems <| if columns.is_empty then self else
order_descriptors = case ordering.is_empty of
False -> ordering.map element->
column = element.column
associated_selector = element.associated_selector
self.connection.dialect.prepare_order_descriptor column associated_selector.direction text_ordering=Nothing
True -> case self.default_ordering of
Nothing -> Error.throw (Illegal_Argument.Error "The table has no existing ordering (e.g. from a `sort` operation or primary key). `offset` requires an ordering in database.")
descriptors -> descriptors
grouping_expressions = (grouping_columns.map _.as_internal).map .expression
new_exprs = resolved_columns.map c->(Offset_Helpers.make_offset n (c.as_internal) order_descriptors grouping_expressions)

type_mapping = self.connection.dialect.get_type_mapping
infer_from_database_callback expression =
SQL_Type_Reference.new self.connection self.context expression
new_type_refs = new_exprs.map expr->(type_mapping.infer_return_type infer_from_database_callback "OFFSET" [] expr)

new_names = resolved_columns.map c->(if set_mode==Set_Mode.Add then self.column_naming_helper.function_name "offset" [c, n, fill_with] else c.name)
new_columns = (new_names.zip new_type_refs).zip new_exprs a->b->(Internal_Column.Value a.first a.second b)

updated_table = new_columns.fold self t-> col->
t.set (self.make_column col)
updated_table.as_subquery

## PRIVATE

Expand Down

0 comments on commit 921f56a

Please sign in to comment.