Skip to content

Commit

Permalink
SQLServer enable filter (#11471)
Browse files Browse the repository at this point in the history
* checkpoint

* Passing by.integer.comparisons

* More passing tests

* by empty text

* Add flag

* 2 more green

* Back to 6 red

* 5 red

* 2 red

* 1 red

* Green

* Refactor

* refactor

* Refactor

* refactor

* Refactor

* clean up

* Green

* Refactor

* Cleanup

* Refactor

* Clean up

* Cleanup

* Clean up

* Fix tests

* Fix

* Fix

* Code review

* Refactor

* Code review changes

* Add literals

* Code review changes

* Code review changes

* Checkpoint

* checkpoint

* checkpoint

* Cleanup

* Refactor

* Refactor

* refactor

* Fix type name

* Fix
  • Loading branch information
AdRiley authored Nov 7, 2024
1 parent a5ebdf4 commit 676a7d4
Show file tree
Hide file tree
Showing 19 changed files with 257 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ type Redshift_Dialect
## TODO: Check if Redshift supports WITH clauses in nested queries
Dialect_Flag.Supports_Nested_With_Clause -> True
Dialect_Flag.Supports_Case_Sensitive_Columns -> True
Dialect_Flag.Supports_Infinity -> True
Dialect_Flag.Case_Sensitive_Text_Comparison -> True

## PRIVATE
The default table types to use when listing tables.
Expand Down Expand Up @@ -225,8 +227,9 @@ type Redshift_Dialect
False

## PRIVATE
generate_column_for_select self base_gen expr:(SQL_Expression | Order_Descriptor | Query) name:Text -> SQL_Builder =
base_gen.default_generate_column self expr name
generate_expression self base_gen expr:(SQL_Expression | Order_Descriptor | Query) for_select:Boolean -> SQL_Builder =
_ = for_select
base_gen.generate_expression self expr

## PRIVATE
ensure_query_has_no_holes : JDBC_Connection -> Text -> Nothing ! Illegal_Argument
Expand Down
31 changes: 15 additions & 16 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 @@ -1129,22 +1129,21 @@ type DB_Table
Create a constant column from a value.
make_constant_column : Any -> DB_Column ! Illegal_Argument
make_constant_column self value =
Feature.Column_Operations.if_supported_else_throw self.connection.dialect "make_constant_column" <|
if Table_Helpers.is_column value then Error.throw (Illegal_Argument.Error "A constant value may only be created from a scalar, not a DB_Column") else
type_mapping = self.connection.dialect.get_type_mapping
argument_value_type = Value_Type_Helpers.find_argument_type value
sql_type = case argument_value_type of
Nothing -> SQL_Type.null
_ -> type_mapping.value_type_to_sql argument_value_type Problem_Behavior.Ignore
expr = SQL_Expression.Constant value
new_type_ref = SQL_Type_Reference.from_constant sql_type
base_column = Internal_Column.Value value.pretty new_type_ref expr
needs_cast = argument_value_type.is_nothing.not && self.connection.dialect.needs_literal_table_cast argument_value_type
result_internal_column = if needs_cast.not then base_column else
infer_type_from_database new_expression =
SQL_Type_Reference.new self.connection self.context new_expression
self.connection.dialect.make_cast base_column sql_type infer_type_from_database
self.make_column result_internal_column
if Table_Helpers.is_column value then Error.throw (Illegal_Argument.Error "A constant value may only be created from a scalar, not a DB_Column") else
type_mapping = self.connection.dialect.get_type_mapping
argument_value_type = Value_Type_Helpers.find_argument_type value
sql_type = case argument_value_type of
Nothing -> SQL_Type.null
_ -> type_mapping.value_type_to_sql argument_value_type Problem_Behavior.Ignore
expr = SQL_Expression.Constant value
new_type_ref = SQL_Type_Reference.from_constant sql_type
base_column = Internal_Column.Value value.pretty new_type_ref expr
needs_cast = argument_value_type.is_nothing.not && self.connection.dialect.needs_literal_table_cast argument_value_type
result_internal_column = if needs_cast.not then base_column else
infer_type_from_database new_expression =
SQL_Type_Reference.new self.connection self.context new_expression
self.connection.dialect.make_cast base_column sql_type infer_type_from_database
self.make_column result_internal_column

## PRIVATE
Create a unique temporary column name.
Expand Down
6 changes: 3 additions & 3 deletions distribution/lib/Standard/Database/0.0.0-dev/src/Dialect.enso
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ type Dialect
Unimplemented.throw "This is an interface only."

## PRIVATE
Generates a column for the given expression for use in the SELECT clause.
Generates a expression for use in the SELECT OR WHERE clause.
Used for databases where the expression syntax is different in the SELECT clause
to the syntax in the WHERE clause
generate_column_for_select self base_gen expr:(SQL_Expression | Order_Descriptor | Query) name:Text -> SQL_Builder =
_ = [base_gen, expr, name]
generate_expression self base_gen expr:(SQL_Expression | Order_Descriptor | Query) for_select:Boolean -> SQL_Builder =
_ = [base_gen, expr, for_select]
Unimplemented.throw "This is an interface only."

## PRIVATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ type Dialect_Flag
match column names in a case insensitive way, so that "Foo" and "foo" will refer to the
same column.
Supports_Case_Sensitive_Columns
## PRIVATE
Specifies if the backend supports the `Infinity` value for floating point columns.
Supports_Infinity
## PRIVATE
Specifies text comparisons are case sensitive by default.
Case_Sensitive_Text_Comparison
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ type SQL_Generator
SQL_Expression.Operation kind arguments metadata ->
op = dialect.dialect_operations.operations_dict.get kind (Error.throw <| Unsupported_Database_Operation.Error kind)
parsed_args = arguments.map (self.generate_expression dialect)
result = op parsed_args
# If the function expects more arguments, we pass the metadata as the last argument.
case result of
_ : Function -> result metadata
_ -> result
self.apply_op_generator_with_metadata op parsed_args metadata
SQL_Expression.Let _ binder bindee body ->
wrapped_binder = dialect.wrap_identifier binder
bindee_exp = SQL_Builder.code "SELECT " ++ (self.generate_expression dialect bindee).paren ++ " AS " ++ "x"
Expand All @@ -106,6 +102,14 @@ type SQL_Generator
query : Query -> self.generate_sub_query dialect query
descriptor : Order_Descriptor -> self.generate_order dialect descriptor

## PRIVATE
apply_op_generator_with_metadata self op arguments metadata =
result = op arguments
# If the function expects more arguments, we pass the metadata as the last argument.
case result of
_ : Function -> result metadata
_ -> result

## PRIVATE

Builds code for the FROM clause.
Expand Down Expand Up @@ -166,10 +170,6 @@ type SQL_Generator
base_expression = self.generate_expression dialect order_descriptor.expression
base_expression ++ collation ++ order_suffix ++ nulls_suffix

## PRIVATE
default_generate_column self dialect expr:(SQL_Expression | Order_Descriptor | Query) name:Text -> SQL_Builder =
self.generate_expression dialect expr ++ alias dialect name

## PRIVATE
Generates SQL code corresponding to a SELECT statement.

Expand All @@ -178,11 +178,12 @@ type SQL_Generator
- ctx: A description of the SELECT clause.
generate_select_query_sql : Dialect -> Vector (Pair Text SQL_Expression) -> Context -> SQL_Builder
generate_select_query_sql self dialect columns ctx =
gen_exprs exprs = exprs.map (self.generate_expression dialect)
gen_exprs exprs = exprs.map (expr-> dialect.generate_expression self expr for_select=False)
gen_column pair = (dialect.generate_expression self expr=pair.second for_select=True) ++ alias dialect pair.first

generated_columns = case columns of
Nothing -> SQL_Builder.code "*"
_ -> SQL_Builder.join ", " (columns.map (c-> dialect.generate_column_for_select self expr=c.second name=c.first))
_ -> SQL_Builder.join ", " (columns.map gen_column)

from_part = self.generate_from_part dialect ctx.from_spec
where_part = (SQL_Builder.join " AND " (gen_exprs ctx.where_filters)) . prefix_if_present " WHERE "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ type Postgres_Dialect
Dialect_Flag.Supports_Separate_NaN -> True
Dialect_Flag.Supports_Nested_With_Clause -> True
Dialect_Flag.Supports_Case_Sensitive_Columns -> True
Dialect_Flag.Supports_Infinity -> True
Dialect_Flag.Case_Sensitive_Text_Comparison -> True

## PRIVATE
The default table types to use when listing tables.
Expand Down Expand Up @@ -326,8 +328,9 @@ type Postgres_Dialect
False

## PRIVATE
generate_column_for_select self base_gen expr:(SQL_Expression | Order_Descriptor | Query) name:Text -> SQL_Builder =
base_gen.default_generate_column self expr name
generate_expression self base_gen expr:(SQL_Expression | Order_Descriptor | Query) for_select:Boolean -> SQL_Builder =
_ = for_select
base_gen.generate_expression self expr

## PRIVATE
ensure_query_has_no_holes : JDBC_Connection -> Text -> Nothing ! Illegal_Argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ type SQLite_Dialect
Dialect_Flag.Supports_Separate_NaN -> False
Dialect_Flag.Supports_Nested_With_Clause -> True
Dialect_Flag.Supports_Case_Sensitive_Columns -> False
Dialect_Flag.Supports_Infinity -> True
Dialect_Flag.Case_Sensitive_Text_Comparison -> True

## PRIVATE
The default table types to use when listing tables.
Expand Down Expand Up @@ -329,8 +331,9 @@ type SQLite_Dialect
False

## PRIVATE
generate_column_for_select self base_gen expr:(SQL_Expression | Order_Descriptor | Query) name:Text -> SQL_Builder =
base_gen.default_generate_column self expr name
generate_expression self base_gen expr:(SQL_Expression | Order_Descriptor | Query) for_select:Boolean -> SQL_Builder =
_ = for_select
base_gen.generate_expression self expr

## PRIVATE
ensure_query_has_no_holes : JDBC_Connection -> Text -> Nothing ! Illegal_Argument
Expand Down
Loading

0 comments on commit 676a7d4

Please sign in to comment.