v.22.5Improvement

Refactor Schema Inference Logic with Improved Error Handling

Refactor code around schema inference with globs. Try next file from glob only if it makes sense (previously we tried next file in case of any error). Also it fixes #36317. #36205 (Kruglov Pavel).
Improved schema inference logic for file globs by attempting the next file only when it makes sense, enhancing reliability and performance.

Why it matters

Previously, the system tried the next file from a glob pattern on any error during schema inference, which could lead to unnecessary retries and inefficiencies. This change refactors the logic to be more selective, reducing redundant file processing and fixing issue #36317.

How to use it

This improvement is applied internally in schema inference when reading files using glob patterns. Users benefit automatically without any configuration changes required.