@@ -82,11 +82,13 @@ impl RegexpInstrFunc {
82
82
#[ allow(
83
83
clippy:: cast_possible_truncation,
84
84
clippy:: cast_sign_loss,
85
- clippy:: as_conversions
85
+ clippy:: as_conversions,
86
+ clippy:: too_many_lines,
87
+ clippy:: unwrap_used
86
88
) ]
87
89
fn take_args_values ( args : & [ ColumnarValue ] ) -> DFResult < ( usize , usize , usize , & str , usize ) > {
88
90
let position = args. get ( 2 ) . map_or_else (
89
- || Ok ( 0 ) , // Default value of 0 if the index is out of bounds
91
+ || Ok ( 0 ) ,
90
92
|value| match value {
91
93
ColumnarValue :: Scalar ( ScalarValue :: Int64 ( Some ( value) ) ) if 0 <= * value => {
92
94
Ok ( * value as usize - 1 )
@@ -102,12 +104,12 @@ impl RegexpInstrFunc {
102
104
data_type : other. data_type ( ) ,
103
105
position : 3usize ,
104
106
}
105
- . fail ( ) , // Construct the error
107
+ . fail ( ) ,
106
108
} ,
107
109
) ?;
108
110
109
111
let occurrence = args. get ( 3 ) . map_or_else (
110
- || Ok ( 0 ) , // Default value of 0 if the index is out of bounds
112
+ || Ok ( 0 ) ,
111
113
|value| match value {
112
114
ColumnarValue :: Scalar ( ScalarValue :: Int64 ( Some ( value) ) ) if 0 <= * value => {
113
115
Ok ( * value as usize - 1 )
@@ -123,7 +125,7 @@ impl RegexpInstrFunc {
123
125
data_type : other. data_type ( ) ,
124
126
position : 4usize ,
125
127
}
126
- . fail ( ) , // Construct the error
128
+ . fail ( ) ,
127
129
} ,
128
130
) ?;
129
131
@@ -135,9 +137,7 @@ impl RegexpInstrFunc {
135
137
{
136
138
Ok ( * value as usize )
137
139
}
138
- ColumnarValue :: Scalar ( ScalarValue :: Int64 ( Some ( value) ) )
139
- if !( 0 ..=1 ) . contains ( value) =>
140
- {
140
+ ColumnarValue :: Scalar ( ScalarValue :: Int64 ( Some ( value) ) ) => {
141
141
regexp_errors:: WrongArgValueSnafu {
142
142
got : value. to_string ( ) ,
143
143
reason : "Return option must be 0, 1, or NULL" . to_string ( ) ,
@@ -148,23 +148,37 @@ impl RegexpInstrFunc {
148
148
data_type : other. data_type ( ) ,
149
149
position : 5usize ,
150
150
}
151
- . fail ( ) , // Construct the error
151
+ . fail ( ) ,
152
152
} ,
153
153
) ?;
154
154
155
155
let regexp_parameters = args. get ( 5 ) . map_or_else (
156
- || Ok ( "" ) , // Default value of 0 if the index is out of bounds
156
+ || Ok ( "c " ) ,
157
157
|value| match value {
158
158
ColumnarValue :: Scalar (
159
159
ScalarValue :: Utf8 ( Some ( value) )
160
160
| ScalarValue :: Utf8View ( Some ( value) )
161
161
| ScalarValue :: LargeUtf8 ( Some ( value) ) ,
162
- ) => Ok ( value) ,
162
+ ) if value. contains ( [ 'c' , 'i' , 'm' , 'e' , 's' ] ) => Ok ( value) ,
163
+ ColumnarValue :: Scalar (
164
+ ScalarValue :: Utf8 ( Some ( value) )
165
+ | ScalarValue :: Utf8View ( Some ( value) )
166
+ | ScalarValue :: LargeUtf8 ( Some ( value) ) ,
167
+ ) if value. is_empty ( ) => Ok ( "c" ) ,
168
+ ColumnarValue :: Scalar (
169
+ ScalarValue :: Utf8 ( Some ( value) )
170
+ | ScalarValue :: Utf8View ( Some ( value) )
171
+ | ScalarValue :: LargeUtf8 ( Some ( value) ) ,
172
+ ) => regexp_errors:: WrongArgValueSnafu {
173
+ got : value. to_string ( ) ,
174
+ reason : format ! ( "Unknown parameter: '{}'" , value. get( 0 ..1 ) . unwrap( ) ) ,
175
+ }
176
+ . fail ( ) ,
163
177
other => regexp_errors:: UnsupportedInputTypeWithPositionSnafu {
164
178
data_type : other. data_type ( ) ,
165
179
position : 6usize ,
166
180
}
167
- . fail ( ) , // Construct the error
181
+ . fail ( ) ,
168
182
} ,
169
183
) ?;
170
184
@@ -175,7 +189,7 @@ impl RegexpInstrFunc {
175
189
} else {
176
190
Ok ( 0 )
177
191
}
178
- } , // Default value of 0 if the index is out of bounds
192
+ } ,
179
193
|value| match value {
180
194
ColumnarValue :: Scalar ( ScalarValue :: Int64 ( Some ( value) ) ) if 0 <= * value => {
181
195
Ok ( * value as usize )
@@ -191,7 +205,7 @@ impl RegexpInstrFunc {
191
205
data_type : other. data_type ( ) ,
192
206
position : 6usize ,
193
207
}
194
- . fail ( ) , // Construct the error
208
+ . fail ( ) ,
195
209
} ,
196
210
) ?;
197
211
0 commit comments