| 215 | |
| 216 | @dataclass(frozen=True) |
| 217 | class ExplainFile: |
| 218 | database: str |
| 219 | schema: str |
| 220 | name: str |
| 221 | suffix: str | None |
| 222 | item_type: ItemType |
| 223 | explainee_type: ExplaineeType |
| 224 | stage: ExplainStage |
| 225 | ext: str |
| 226 | |
| 227 | def file_name(self) -> str: |
| 228 | return ".".join( |
| 229 | str(part) |
| 230 | for part in [ |
| 231 | self.name, |
| 232 | self.explainee_type, |
| 233 | self.stage.name.lower(), |
| 234 | self.suffix, |
| 235 | "json" if self.stage == ExplainStage.OPTIMIZER_TRACE else self.ext, |
| 236 | ] |
| 237 | if part |
| 238 | ) |
| 239 | |
| 240 | def folder(self) -> Path: |
| 241 | return Path(self.item_type.value, self.database, self.schema) |
| 242 | |
| 243 | def path(self) -> Path: |
| 244 | return self.folder() / self.file_name() |
| 245 | |
| 246 | def __str__(self) -> str: |
| 247 | return str(self.path()) |
| 248 | |
| 249 | def skip(self) -> bool: |
| 250 | # Skip items with database, schema, or item names that contain a `/` |
| 251 | # (not a valid UNIX folder character). |
| 252 | if "/" in self.database: |
| 253 | warn(f"Skip processing of item with bad database name: `{self.database}`") |
| 254 | return True |
| 255 | elif "/" in self.schema: |
| 256 | warn(f"Skip processing of item with bad schema name: `{self.schema}`") |
| 257 | return True |
| 258 | elif "/" in self.name: |
| 259 | warn(f"Skip processing of item with bad item name: `{self.name}`") |
| 260 | return True |
| 261 | # All good! |
| 262 | else: |
| 263 | return False |
| 264 | |
| 265 | |
| 266 | def explain_file(path: Path) -> ExplainFile | None: |
no outgoing calls
no test coverage detected