You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Ambud Sharma <as...@gmail.com> on 2017/01/17 01:21:49 UTC

How to implement range scan

Hi,

I am trying use calcite and develop a custom adapter. I have implemented
the SPI and able to get basic enumerator to work with a simple select query
and no where clause.

Trying to understand how to convert operators to range scan and push them
to the underlying data source.

Should it be a rule or a visitor if yes how do you subset the nodes so that
only the range scannable entity is delivered to the converter. A link to a
working example would help.

The data source has range scan capability and I can make a method call to
it.

Thanks and regards,
Ambud

Re: How to implement range scan

Posted by Ambud Sharma <as...@gmail.com>.
Thanks a lot Julian, this is very helpful!

On Tue, Jan 17, 2017 at 10:35 PM, Julian Hyde <jh...@gmail.com>
wrote:

> I think what you’re after is how to convert a predicate, say
>
>   select * from emp
>   where (empno = 100 or empno between 200 and 1000)
>     and empno not between 150 and 400
>
> into a set of ranges
>
>   [100], (400, 1000]
>
> Actually we don’t have that in Calcite, but note that literal values of
> all data types are Comparable and that Guava has an excellent RangeSet
> class.
>
> For the Druid adapter we needed to convert expressions like
>
>   EXTRACT(YEAR FROM t) = 2016
>  AND EXTRACT(MONTH FROM t) BETWEEN 5 and 7
>
> into
>
>   t BETWEEN ‘2016-05-01’ AND ‘2016-07-31’
>
> and for that we created DateRangeRules (see https://issues.apache.org/
> jira/browse/CALCITE-1334 <https://issues.apache.org/
> jira/browse/CALCITE-1334>). You’ll notice that DateRangeRules also makes
> extensive use of RangeSet internally.
>
> Julian
>
>
> > On Jan 16, 2017, at 5:21 PM, Ambud Sharma <as...@gmail.com>
> wrote:
> >
> > Hi,
> >
> > I am trying use calcite and develop a custom adapter. I have implemented
> > the SPI and able to get basic enumerator to work with a simple select
> query
> > and no where clause.
> >
> > Trying to understand how to convert operators to range scan and push them
> > to the underlying data source.
> >
> > Should it be a rule or a visitor if yes how do you subset the nodes so
> that
> > only the range scannable entity is delivered to the converter. A link to
> a
> > working example would help.
> >
> > The data source has range scan capability and I can make a method call to
> > it.
> >
> > Thanks and regards,
> > Ambud
>
>

Re: How to implement range scan

Posted by Julian Hyde <jh...@gmail.com>.
I think what you’re after is how to convert a predicate, say

  select * from emp
  where (empno = 100 or empno between 200 and 1000)
    and empno not between 150 and 400

into a set of ranges

  [100], (400, 1000]

Actually we don’t have that in Calcite, but note that literal values of all data types are Comparable and that Guava has an excellent RangeSet class.

For the Druid adapter we needed to convert expressions like

  EXTRACT(YEAR FROM t) = 2016
 AND EXTRACT(MONTH FROM t) BETWEEN 5 and 7

into

  t BETWEEN ‘2016-05-01’ AND ‘2016-07-31’

and for that we created DateRangeRules (see https://issues.apache.org/jira/browse/CALCITE-1334 <https://issues.apache.org/jira/browse/CALCITE-1334>). You’ll notice that DateRangeRules also makes extensive use of RangeSet internally.

Julian


> On Jan 16, 2017, at 5:21 PM, Ambud Sharma <as...@gmail.com> wrote:
> 
> Hi,
> 
> I am trying use calcite and develop a custom adapter. I have implemented
> the SPI and able to get basic enumerator to work with a simple select query
> and no where clause.
> 
> Trying to understand how to convert operators to range scan and push them
> to the underlying data source.
> 
> Should it be a rule or a visitor if yes how do you subset the nodes so that
> only the range scannable entity is delivered to the converter. A link to a
> working example would help.
> 
> The data source has range scan capability and I can make a method call to
> it.
> 
> Thanks and regards,
> Ambud