The TableScanRule is the only planner rule that for a logical node(e.g. the table scan), its function is to pass along the cluster object and invoke the RelOptTable#toRel which is very trivial because it supplies only a simple ToRelContext that does not support expanding view/passing table hints.
For rels that come from the sql-to-rel conversion, there is already a table conversion logic. This code gives a more powerful ToRelContext that has the complete functionality.
The only reason that I saw the meaning of existing TableScanRule is for the TableScan that comes from the RelBuilder#scan.
So I would suggest to deprecate the TableScanRule, instead, we support translating the table directly in RelBuilder#scan,
We also add a new interface RelBuilder#scan(Iterable<String> tableNames, ToRelContext context), so that user can pass in a more powerful ToRelContext explicitly. User can customize a TableScanFactory in the RelBuilder to do this.