Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AdRiley committed Jul 23, 2024
1 parent 2c1d818 commit 191983f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Standard.Database.Internal.Common.Database_Join_Helper
import Standard.Database.Internal.Error_Mapper.Error_Mapper
import Standard.Database.Internal.Internals_Access
import Standard.Database.Internal.IR.Context.Context
import Standard.Database.Internal.IR.Context.Context_Extension
import Standard.Database.Internal.IR.From_Spec.From_Spec
import Standard.Database.Internal.IR.Internal_Column.Internal_Column
import Standard.Database.Internal.IR.Nulls_Order.Nulls_Order
Expand Down Expand Up @@ -124,18 +125,18 @@ type SQLSever_Dialect
Prepares a distinct operation.
prepare_distinct : DB_Table -> Vector -> Case_Sensitivity -> Problem_Builder -> DB_Table
prepare_distinct self table key_columns case_sensitivity problem_builder =
table_name_deduplicator = (Internals_Access.get_connection table).base_connection.table_naming_helper.create_unique_name_strategy
table_name_deduplicator = table.connection.base_connection.table_naming_helper.create_unique_name_strategy
table_name_deduplicator.mark_used table.name
inner_table_alias = table_name_deduplicator.make_unique table.name+"_inner"
setup = (Internals_Access.get_context table).as_subquery inner_table_alias [Internals_Access.internal_columns table]
setup = table.context.as_subquery inner_table_alias [table.internal_columns]
new_columns = setup.new_columns.first
column_mapping = Dictionary.from_vector <| new_columns.map c-> [c.name, c]
new_key_columns = key_columns.map c-> column_mapping.at c.name
type_mapping = self.get_type_mapping
distinct_expressions = new_key_columns.map column->
value_type = type_mapping.sql_type_to_value_type column.sql_type_reference.get
Database_Distinct_Helper.make_distinct_expression case_sensitivity problem_builder column value_type
new_context = Context.for_subquery setup.subquery . set_distinct_on distinct_expressions
new_context = Context.for_subquery setup.subquery . add_extension (make_distinct_extension distinct_expressions)
table.updated_context_and_columns new_context new_columns subquery=True

## PRIVATE
Expand Down Expand Up @@ -709,5 +710,11 @@ make_runtime_error_op arguments =

SQL_Builder.code "CAST('[ENSO INVARIANT VIOLATED: '||" ++ error_message ++ "||'] '||COALESCE(" ++ variable_to_defer ++ "::TEXT,'NULL') AS BOOLEAN)"

## PRIVATE
make_distinct_extension expressions =
run_generator sql_expressions =
SQL_Builder.code "DISTINCT ON (" ++ (SQL_Builder.join ", " sql_expressions) ++ ") "
Context_Extension.Value position=120 expressions=expressions run_generator=run_generator

## PRIVATE
sqlserver_dialect_name = "SQL Server"
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ type SQLServer_Type_Mapping
_ = [source_type, target_type]
False

## PRIVATE
should_warn_on_materialize (db_type : Value_Type) (in_memory_type : Value_Type) -> Boolean =
SQL_Type_Mapping.default_should_warn_on_materialize db_type in_memory_type

## PRIVATE
complex_types_map = Dictionary.from_vector <|
make_decimal sql_type =
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft_Tests/src/SQLServer_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ create_connection_builder =
add_specs suite_builder =
case create_connection_builder of
Nothing ->
message = "PostgreSQL test database is not configured. See README.md for instructions."
suite_builder.group "[PostgreSQL] Database tests" pending=message (_-> Nothing)
message = "SQLServer test database is not configured. See README.md for instructions."
suite_builder.group "[SQLServer] Database tests" pending=message (_-> Nothing)
connection_builder ->
suite_builder.group "[SQLServer] Small" group_builder->
group_builder.specify "debugtest" <|
Expand Down

0 comments on commit 191983f

Please sign in to comment.