You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2020/10/02 03:55:00 UTC

[jira] [Comment Edited] (CALCITE-4223) Introducing column statistics to RelOptTable

    [ https://issues.apache.org/jira/browse/CALCITE-4223?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17205961#comment-17205961 ] 

Julian Hyde edited comment on CALCITE-4223 at 10/2/20, 3:54 AM:
----------------------------------------------------------------

I started writing a PR, but there is already a perfect example. In CALCITE-1861 I wanted a table to be able to declare its own predicates. So I added 4 lines to {{getAllPredicates}}:
{code:java}
  public RelOptPredicateList getAllPredicates(TableScan scan, RelMetadataQuery mq) {
    final BuiltInMetadata.AllPredicates.Handler handler =
        scan.getTable().unwrap(BuiltInMetadata.AllPredicates.Handler.class);
    if (handler != null) {
      return handler.getAllPredicates(scan, mq);
    }
    return RelOptPredicateList.EMPTY;
  }
{code}
and I made a mock table that called {{addWrap}} to add its own implementation of {{AllPredicates.Handler}}:
{code:java}
    restaurantTable.addWrap(
        new BuiltInMetadata.AllPredicates.Handler() {
          public RelOptPredicateList getAllPredicates(RelNode r,
              RelMetadataQuery mq) {
...
          }
        });
{code}
Put a break-point in {{RelMdAllPredicates.getAllPredicates(TableScan scan, RelMetadataQuery mq)}} and run {{RelOptRulesTest.testSpatialDWithinToHilbert}} and see how your break-point gets hit.

We need add similar lines to all {{RelMdXxx.getXxx(TableScan, RelMdataQuery)}} methods, to check for a handler, and use it if it is not null. If I did it again I'd implement {{interface AllPredicates}} rather than {{interface AllPredicates.Handler}}, but the principle is the same.


was (Author: julianhyde):
I started writing a PR, but there is already a perfect example. In CALCITE-1861 I wanted a table to be able to declare its own predicates. So I added 4 lines to {{getAllPredicates}}:

{code}
  public RelOptPredicateList getAllPredicates(TableScan scan, RelMetadataQuery mq) {
    final BuiltInMetadata.AllPredicates.Handler handler =
        scan.getTable().unwrap(BuiltInMetadata.AllPredicates.Handler.class);
    if (handler != null) {
      return handler.getAllPredicates(scan, mq);
    }
    return RelOptPredicateList.EMPTY;
  }
{code}

and I made a mock table that called {{addWrap}} to add its own implementation of {{AllPredicates.Handler}}:

{code}
    restaurantTable.addWrap(
        new BuiltInMetadata.AllPredicates.Handler() {
          public RelOptPredicateList getAllPredicates(RelNode r,
              RelMetadataQuery mq) {
...
          }
        });
{code}

Put a break-point in {{RelMdAllPredicates.getAllPredicates(TableScan scan, RelMetadataQuery mq)}} and run {{RelOptRulesTest.testSpatialDWithinToHilbert}} and see how your break-point gets hit.

We need to check for handlers in all {{RelMdXxx.getXxx(TableScan, RelMdataQuery)}} methods. If I did it again I'd implement {{interface AllPredicates}} rather than {{interface AllPredicates.Handler}}, but the principle is the same.  

> Introducing column statistics to RelOptTable
> --------------------------------------------
>
>                 Key: CALCITE-4223
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4223
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: Chunwei Lei
>            Assignee: Chunwei Lei
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Many systems depend on column statistics to compute more accurate stats, such as NDV, average column size, and so on. It would be nice if Calcite can provide such an interface.
> Column statistics might include NDV, average/max column length, number of nulls, number of trues, number of falses and so on. 
> What do you think?
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)