-
Notifications
You must be signed in to change notification settings - Fork 321
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
Add Is_Empty
, Not_Empty
, Like
and Not_Like
to Filter_Condition
#3775
Changes from all commits
9906bbf
b082949
6ea5061
6ab3f08
9d5e271
eeb02d3
28f0542
d3ec514
a28b63e
72458e0
777fa28
50b7828
1bbece0
4a184a5
593ef02
6711066
78906f0
07be26a
0cbf8d1
7388c49
f0a82e0
7a91fd1
18b9bdd
fa3e2c1
4264689
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,34 @@ type Column | |
to_sql : SQL_Statement | ||
to_sql self = self.to_table.to_sql | ||
|
||
## PRIVATE | ||
Sets up an operation of arbitrary arity. | ||
|
||
Arguments: | ||
- op_kind: The kind of the operation | ||
- operands: A vector of additional operation arguments (the column itself | ||
is always passed as the first argument). | ||
- new_type: The type of the SQL column that results from applying the | ||
operator. If not specified, the type of this column is used. | ||
- operand_types: The SQL types of the additional arguments. They are used | ||
if additional arguments are constants (and if not provided, the type of | ||
this column is used). If the other argument is a column, its type is | ||
used. | ||
make_op self op_kind operands new_type=Nothing operand_types=Nothing = | ||
prepare_operand operand operand_type = case operand of | ||
other_column : Column -> | ||
if Helpers.check_integrity self other_column then other_column.expression else | ||
Error.throw <| Unsupported_Database_Operation_Error "Cannot use columns coming from different contexts in one expression without a join." | ||
constant -> | ||
actual_operand_type = operand_type.if_nothing self.sql_type | ||
Expression.Constant actual_operand_type constant | ||
actual_operand_types = operand_types.if_nothing (Vector.fill operands.length Nothing) | ||
expressions = operands.zip actual_operand_types prepare_operand | ||
|
||
actual_new_type = new_type.if_nothing self.sql_type | ||
new_expr = Expression.Operation op_kind ([self.expression] + expressions) | ||
Column.Value self.name self.connection actual_new_type new_expr self.context | ||
|
||
## PRIVATE | ||
|
||
Creates a binary operation with given kind and operand. | ||
|
@@ -129,20 +157,7 @@ type Column | |
defaults to the current type if not provided. | ||
make_binary_op : Text -> Text -> (Column | Any) -> (SQL_Type | Nothing) -> (SQL_Type | Nothing) -> Column | ||
make_binary_op self op_kind operand new_type=Nothing operand_type=Nothing = | ||
actual_new_type = new_type.if_nothing self.sql_type | ||
case operand of | ||
Column.Value _ _ _ other_expr _ -> | ||
case Helpers.check_integrity self operand of | ||
False -> | ||
Error.throw <| Unsupported_Database_Operation_Error "Cannot compare columns coming from different contexts. Only columns of a single table can be compared." | ||
True -> | ||
new_expr = Expression.Operation op_kind [self.expression, other_expr] | ||
Column.Value self.name self.connection actual_new_type new_expr self.context | ||
_ -> | ||
actual_operand_type = operand_type.if_nothing self.sql_type | ||
other = Expression.Constant actual_operand_type operand | ||
new_expr = Expression.Operation op_kind [self.expression, other] | ||
Column.Value self.name self.connection actual_new_type new_expr self.context | ||
self.make_op op_kind [operand] new_type [operand_type] | ||
|
||
## PRIVATE | ||
|
||
|
@@ -153,10 +168,7 @@ type Column | |
- new_type: The type of the SQL column that results from applying the | ||
operator. | ||
make_unary_op : Text -> Text -> (SQL_Type | Nothing) -> Column | ||
make_unary_op self op_kind new_type=Nothing = | ||
actual_new_type = new_type.if_nothing self.sql_type | ||
new_expr = Expression.Operation op_kind [self.expression] | ||
Column.Value self.name self.connection actual_new_type new_expr self.context | ||
make_unary_op self op_kind new_type=Nothing = self.make_op op_kind [] new_type | ||
|
||
## UNSTABLE | ||
|
||
|
@@ -314,6 +326,22 @@ type Column | |
< : Column | Any -> Column | ||
< self other = self.make_binary_op "<" other new_type=SQL_Type.boolean | ||
|
||
## Element-wise inclusive bounds check. | ||
|
||
Arguments: | ||
- lower: The lower bound to compare elements of `self` against. If | ||
`lower` is a column, the comparison is performed pairwise between | ||
corresponding elements of `self` and `lower`. | ||
- upper: The upper bound to compare elements of `self` against. If | ||
`upper` is a column, the comparison is performed pairwise between | ||
corresponding elements of `self` and `upper`. | ||
|
||
Returns a column with boolean values indicating whether values of this | ||
column fit between the lower and upper bounds (both ends inclusive). | ||
between : (Column | Any) -> (Column | Any) -> Column | ||
between self lower upper = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: maybe we could think of adding a parameter if it shouldn't be inclusive by default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The SQL BETWEEN this is more or less supposed to emulate is always inclusive. So if we added an option, we'd have to make it unsupported on Database backend or emulate it using regular comparison operators. But we already can always just apply two filters: Greater+Less to get an exclusive between. So I'm not sure if it is necessary to add it, I guess it's mostly a question to @jdunkerley who designed the original set of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was aiming to keep BETWEEN simple and just match SQLs behavior with a view that is what our users would expect. |
||
self.make_op "BETWEEN" [lower, upper] new_type=SQL_Type.boolean | ||
|
||
## UNSTABLE | ||
|
||
Element-wise addition. | ||
|
@@ -407,6 +435,12 @@ type Column | |
is_missing : Column | ||
is_missing self = self.make_unary_op "ISNULL" new_type=SQL_Type.boolean | ||
|
||
## PRIVATE | ||
Returns a column of booleans, with `True` items at the positions where | ||
this column contains an empty string or `Nothing`. | ||
is_empty : Column | ||
is_empty self = self.make_unary_op "ISEMPTY" new_type=SQL_Type.boolean | ||
|
||
## UNSTABLE | ||
|
||
Returns a new column where missing values have been replaced with the | ||
|
@@ -517,6 +551,11 @@ type Column | |
contains : Column | Text -> Column | ||
contains self other = self.make_binary_op "contains" other new_type=SQL_Type.boolean | ||
|
||
## PRIVATE | ||
Checks for each element of the column if it matches an SQL-like pattern. | ||
like : Column | Text -> Column | ||
like self other = self.make_binary_op "LIKE" other new_type=SQL_Type.boolean | ||
|
||
## PRIVATE | ||
as_internal : Internal_Column | ||
as_internal self = Internal_Column.Value self.name self.sql_type self.expression | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly it is not possible to skip the suffix so
buildStdLibAll
looks good!