@@ -54,8 +54,10 @@ class SqlConverter {
54
54
converters[BinCompPred][Equal] = [](auto n, auto c) -> std::string {
55
55
return c.at (0 ) + " = " + c.at (1 );
56
56
};
57
- converters[Function][NullOp] = [](const AstNodePtr n, auto c) -> std::string {
58
- return std::get<std::string>(n->children ().front ()->origin_value ()) + " (" + c.at (1 ) + " )" ;
57
+ converters[Function][NullOp] = [](const AstNodePtr n,
58
+ auto c) -> std::string {
59
+ return std::get<std::string>(n->children ().front ()->origin_value ()) +
60
+ " (" + c.at (1 ) + " )" ;
59
61
};
60
62
converters[ArgumentList][NullOp] = [](auto n, auto c) -> std::string {
61
63
std::stringstream ss;
@@ -197,6 +199,83 @@ class SqlConverter {
197
199
converters[IsBetweenPred][NotBetween] = [](auto n, auto c) -> std::string {
198
200
return c.at (0 ) + " NOT BETWEEN " + c.at (1 ) + " AND " + c.at (2 );
199
201
};
202
+ converters[Array][NullOp] = [](auto n, auto c) -> std::string {
203
+ std::stringstream ss;
204
+ ss << " VALUES " ;
205
+ for (size_t i = 0 ; i < c.size (); i++) {
206
+ ss << " (" << c.at (i) << " )" ;
207
+ if (i != c.size () - 1 ) ss << " ," ;
208
+ }
209
+ return ss.str ();
210
+ };
211
+ converters[ArrayPred][A_Equals] = [](auto n, auto c) -> std::string {
212
+ std::string lhs = c.at (0 );
213
+ std::string rhs = c.at (1 );
214
+ std::string not_null = " " ;
215
+
216
+ if (n->children ().at (0 )->type () == NodeType::PropertyName) {
217
+ not_null += lhs + " NOT NULL" ;
218
+ lhs = " SELECT value FROM json_each(" + lhs + " )" ;
219
+ }
220
+ if (n->children ().at (1 )->type () == NodeType::PropertyName) {
221
+ if (not not_null.empty ()) not_null += " AND " ;
222
+ not_null += rhs + " NOT NULL" ;
223
+ rhs = " SELECT value FROM json_each(" + rhs + " )" ;
224
+ }
225
+
226
+ if (not not_null.empty ()) not_null += " AND" ;
227
+
228
+ return not_null + " NOT EXISTS (" + lhs + " EXCEPT " + rhs + " )" +
229
+ " AND NOT EXISTS (" + rhs + " EXCEPT " + lhs + " )" ;
230
+ };
231
+ converters[ArrayPred][A_Contains] = [](auto n, auto c) -> std::string {
232
+ std::string lhs = c.at (1 );
233
+ std::string rhs = c.at (0 );
234
+ std::string not_null = " " ;
235
+
236
+ if (n->children ().at (1 )->type () == NodeType::PropertyName) {
237
+ not_null += lhs + " NOT NULL" ;
238
+ lhs = " SELECT value FROM json_each(" + lhs + " )" ;
239
+ }
240
+ if (n->children ().at (0 )->type () == NodeType::PropertyName) {
241
+ if (not not_null.empty ()) not_null += " AND " ;
242
+ not_null += rhs + " NOT NULL" ;
243
+ rhs = " SELECT value FROM json_each(" + rhs + " )" ;
244
+ }
245
+
246
+ if (not not_null.empty ()) not_null += " AND" ;
247
+
248
+ return not_null + " NOT EXISTS (" + lhs + " EXCEPT " + rhs + " )" ;
249
+ };
250
+ converters[ArrayPred][A_ContainedBy] = [](auto n, auto c) -> std::string {
251
+ std::string lhs = c.at (0 );
252
+ std::string rhs = c.at (1 );
253
+ std::string not_null = " " ;
254
+
255
+ if (n->children ().at (0 )->type () == NodeType::PropertyName) {
256
+ not_null += lhs + " NOT NULL" ;
257
+ lhs = " SELECT value FROM json_each(" + lhs + " )" ;
258
+ }
259
+ if (n->children ().at (1 )->type () == NodeType::PropertyName) {
260
+ if (not not_null.empty ()) not_null += " AND " ;
261
+ not_null += rhs + " NOT NULL" ;
262
+ rhs = " SELECT value FROM json_each(" + rhs + " )" ;
263
+ }
264
+
265
+ if (not not_null.empty ()) not_null += " AND" ;
266
+
267
+ return not_null + " NOT EXISTS (" + lhs + " EXCEPT " + rhs + " )" ;
268
+ };
269
+ converters[ArrayPred][A_Overlaps] = [](const AstNodePtr n,
270
+ auto c) -> std::string {
271
+ std::string lhs = c.at (0 );
272
+ std::string rhs = c.at (1 );
273
+ if (n->children ().at (0 )->type () == NodeType::PropertyName)
274
+ lhs = " SELECT value FROM json_each(" + lhs + " )" ;
275
+ if (n->children ().at (1 )->type () == NodeType::PropertyName)
276
+ rhs = " SELECT value FROM json_each(" + rhs + " )" ;
277
+ return " EXISTS (" + lhs + " INTERSECT " + rhs + " )" ;
278
+ };
200
279
}
201
280
202
281
void Register (
0 commit comments