@@ -28,18 +28,26 @@ sealed interface BaseGenerator {
28
28
fun buildComparison (
29
29
col : Field <Any >,
30
30
operator : ApplyBinaryComparisonOperator ,
31
- value : Field <Any >
31
+ listVal : List < Field <Any > >
32
32
): Condition {
33
+ if (operator != ApplyBinaryComparisonOperator .IN && listVal.size != 1 ) {
34
+ error(" Only the IN operator supports multiple values" )
35
+ }
36
+
37
+ // unwrap single value for use in all but the IN operator
38
+ // OR return falseCondition if listVal is empty
39
+ val singleVal = listVal.firstOrNull() ? : return DSL .falseCondition()
40
+
33
41
return when (operator ) {
34
- ApplyBinaryComparisonOperator .EQ -> col.eq(value )
35
- ApplyBinaryComparisonOperator .GT -> col.gt(value )
36
- ApplyBinaryComparisonOperator .GTE -> col.ge(value )
37
- ApplyBinaryComparisonOperator .LT -> col.lt(value )
38
- ApplyBinaryComparisonOperator .LTE -> col.le(value )
39
- ApplyBinaryComparisonOperator .IN -> DSL .nullCondition( )
42
+ ApplyBinaryComparisonOperator .EQ -> col.eq(singleVal )
43
+ ApplyBinaryComparisonOperator .GT -> col.gt(singleVal )
44
+ ApplyBinaryComparisonOperator .GTE -> col.ge(singleVal )
45
+ ApplyBinaryComparisonOperator .LT -> col.lt(singleVal )
46
+ ApplyBinaryComparisonOperator .LTE -> col.le(singleVal )
47
+ ApplyBinaryComparisonOperator .IN -> col.` in `(listVal )
40
48
ApplyBinaryComparisonOperator .IS_NULL -> col.isNull
41
- ApplyBinaryComparisonOperator .LIKE -> col.like(value as Field <String >)
42
- ApplyBinaryComparisonOperator .CONTAINS -> col.contains(value as Field <String >)
49
+ ApplyBinaryComparisonOperator .LIKE -> col.like(singleVal as Field <String >)
50
+ ApplyBinaryComparisonOperator .CONTAINS -> col.contains(singleVal as Field <String >)
43
51
}
44
52
}
45
53
@@ -124,15 +132,16 @@ sealed interface BaseGenerator {
124
132
val comparisonValue = when (val v = e.value) {
125
133
is ComparisonValue .ColumnComp -> {
126
134
val col = splitCollectionName(getCollectionForCompCol(v.column, request))
127
- DSL .field(DSL .name(col + v.column.name))
135
+ listOf ( DSL .field(DSL .name(col + v.column.name) ))
128
136
}
129
137
130
138
is ComparisonValue .ScalarComp ->
131
- if (e.operator == ApplyBinaryComparisonOperator .IN )
132
- return handleInComp(column, v)
133
- else DSL .inline(v.value)
139
+ when (val scalarValue = v.value) {
140
+ is List <* > -> (scalarValue as List <Any >).map { DSL .inline(it) }
141
+ else -> listOf (DSL .inline(scalarValue))
142
+ }
134
143
135
- is ComparisonValue .VariableComp -> DSL .field(DSL .name(listOf (" vars" , v.name)))
144
+ is ComparisonValue .VariableComp -> listOf ( DSL .field(DSL .name(listOf (" vars" , v.name) )))
136
145
}
137
146
return buildComparison(column, e.operator , comparisonValue)
138
147
}
@@ -212,17 +221,6 @@ sealed interface BaseGenerator {
212
221
}
213
222
}
214
223
215
- fun handleInComp (column : Field <Any >, value : ComparisonValue .ScalarComp ): Condition {
216
- return when (val scalarValue = value.value) {
217
- is List <* > -> {
218
- if (scalarValue.isEmpty()) DSL .falseCondition()
219
- else column.`in `(scalarValue.map { DSL .inline(it) })
220
- }
221
- // Handle non-array scalar value
222
- else -> column.eq(DSL .inline(scalarValue))
223
- }
224
- }
225
-
226
224
fun splitCollectionName (collectionName : String ): List <String > {
227
225
return collectionName.split(" ." )
228
226
}
0 commit comments