Julian Hyde created CALCITE-5916:
------------------------------------

             Summary: In RelBuilder, add sample() method (equivalent to SQL 
TABLESAMPLE clause)
                 Key: CALCITE-5916
                 URL: https://issues.apache.org/jira/browse/CALCITE-5916
             Project: Calcite
          Issue Type: Bug
            Reporter: Julian Hyde


In RelBuilder, add sample() method (equivalent to SQL TABLESAMPLE clause).

In {{SqlToRelConverter}}, the code
{code}
if (tableSampleSpec.getSamplePercentage() == 0f) {
  bb.setRoot(relBuilder.push(bb.root()).empty().build(), true);
} else {
  RelOptSamplingParameters params =
      new RelOptSamplingParameters(
          tableSampleSpec.isBernoulli(),
          tableSampleSpec.getSamplePercentage(),
          tableSampleSpec.isRepeatable(),
          tableSampleSpec.getRepeatableSeed());
  bb.setRoot(new Sample(cluster, bb.root(), params), false);
}
{code}
would become
{code}
relBuilder.push(bb.root());
relBuilder.sample(tableSampleSpec.isBernoulli(),
    tableSampleSpec.getSamplePercentage(),
    tableSampleSpec.isRepeatable(),
    tableSampleSpec.getRepeatableSeed());
bb.setRoot(relBuilder.build(), false);
{code}
Note that {{RelBuilder.sample}} calls {{empty()}} if the rate = 0. It should 
also skip sampling if rate = 1.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to