(self, sql, optional=False)
| 234 | return result |
| 235 | |
| 236 | def parse_sql(self, sql, optional=False): |
| 237 | if optional and sql is None: |
| 238 | return None |
| 239 | if self.factorize_sketch == 0: |
| 240 | return filter_nones({ |
| 241 | '_type': 'sql', |
| 242 | 'select': self.parse_select(sql['select']), |
| 243 | 'where': self.parse_cond(sql['where'], optional=True), |
| 244 | 'group_by': [self.parse_col_unit(u) for u in sql['groupBy']], |
| 245 | 'order_by': self.parse_order_by(sql['orderBy']), |
| 246 | 'having': self.parse_cond(sql['having'], optional=True), |
| 247 | 'limit': sql['limit'] if self.include_literals else (sql['limit'] is not None), |
| 248 | 'intersect': self.parse_sql(sql['intersect'], optional=True), |
| 249 | 'except': self.parse_sql(sql['except'], optional=True), |
| 250 | 'union': self.parse_sql(sql['union'], optional=True), |
| 251 | **({ |
| 252 | 'from': self.parse_from(sql['from'], self.infer_from_conditions), |
| 253 | } if self.output_from else {}) |
| 254 | }) |
| 255 | elif self.factorize_sketch == 1: |
| 256 | return filter_nones({ |
| 257 | '_type': 'sql', |
| 258 | 'select': self.parse_select(sql['select']), |
| 259 | **({ |
| 260 | 'from': self.parse_from(sql['from'], self.infer_from_conditions), |
| 261 | } if self.output_from else {}), |
| 262 | 'sql_where': filter_nones({ |
| 263 | '_type': 'sql_where', |
| 264 | 'where': self.parse_cond(sql['where'], optional=True), |
| 265 | 'sql_groupby': filter_nones({ |
| 266 | '_type': 'sql_groupby', |
| 267 | 'group_by': [self.parse_col_unit(u) for u in sql['groupBy']], |
| 268 | 'having': filter_nones({ |
| 269 | '_type': 'having', |
| 270 | 'having': self.parse_cond(sql['having'], optional=True), |
| 271 | }), |
| 272 | 'sql_orderby': filter_nones({ |
| 273 | '_type': 'sql_orderby', |
| 274 | 'order_by': self.parse_order_by(sql['orderBy']), |
| 275 | 'limit': filter_nones({ |
| 276 | '_type': 'limit', |
| 277 | 'limit': sql['limit'] if self.include_literals else (sql['limit'] is not None), |
| 278 | }), |
| 279 | 'sql_ieu': filter_nones({ |
| 280 | '_type': 'sql_ieu', |
| 281 | 'intersect': self.parse_sql(sql['intersect'], optional=True), |
| 282 | 'except': self.parse_sql(sql['except'], optional=True), |
| 283 | 'union': self.parse_sql(sql['union'], optional=True), |
| 284 | }) |
| 285 | }) |
| 286 | }) |
| 287 | }) |
| 288 | }) |
| 289 | elif self.factorize_sketch == 2: |
| 290 | return filter_nones({ |
| 291 | '_type': 'sql', |
| 292 | 'select': self.parse_select(sql['select']), |
| 293 | **({ |
no test coverage detected