PNixx / clickhouse-activerecord

A Ruby database ActiveRecord driver for ClickHouse
MIT License
198 stars 100 forks source link

Encapsulate format logic within Statement and helper classes #162

Open leboshi opened 1 month ago

leboshi commented 1 month ago

Summary

Handling different I/O formats added a lot of complexity to the codebase: whenever a specific format is needed or requested, that format has to be passed around to whatever handles the response so that it can be parsed correctly. Various methods around parsing responses according to different formats have been growing and collecting within the SchemaStatements module, where they don't really seem to belong. process_response also has nested case statements that are hard to grok.

This PR extracts three helper classes:

The first two are internal to Statement and have no reason to be used directly outside of it.

Breaking Changes

Deprecations

Next Steps

The skip_format? check in the FormatManager really just includes checks that were already being run plus a few more we've found. They are not comprehensive. Ideally, we should go through the documentation to identify exactly which statements do or don't accept a FORMAT clause.

The chain of conditionals is also less than ideal. It's ugly but manageable for now. Whenever the complete list of inclusions/exclusions materializes, it may be better to apply a filter pattern to clean up the checks.

PNixx commented 1 week ago

@leboshi need resolve conflicts