libenchao commented on code in PR #3410:
URL: https://github.com/apache/calcite/pull/3410#discussion_r1337019127


##########
core/src/main/java/org/apache/calcite/rel/rules/CoreRules.java:
##########
@@ -745,6 +746,10 @@ private CoreRules() {}
   public static final UnionToDistinctRule UNION_TO_DISTINCT =
       UnionToDistinctRule.Config.DEFAULT.toRule();
 
+  /** Rule that rewrite {@link Sample} which is bernoulli to the {@link 
Filter}. */
+  public static final RewriteSampleToFilterRule SAMPLE_TO_FILTER =

Review Comment:
   We can add this rule the the default rule sets, e.g., in `BASE_RULES`?



##########
core/src/main/java/org/apache/calcite/rel/rules/RewriteSampleToFilterRule.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.core.Sample;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+
+import org.immutables.value.Value;
+
+/**
+ * This rule rewrite {@link Sample} which is bernoulli to the {@link Filter}.
+ *
+ * <p> For example:
+ * <blockquote><pre>{@code
+ *    select deptno from "scott".dept tablesample bernoulli(50);
+ * }</pre></blockquote>
+ *
+ * <p> will convert to:
+ * <blockquote><pre>{@code
+ *    select deptno from "scott".dept where rand() < 0.5;
+ * }</pre></blockquote>
+ *
+ * <p> The sql:
+ * <blockquote><pre>{@code
+ *    select deptno from "scott".dept tablesample bernoulli(50) REPEATABLE(10);
+ * }</pre></blockquote>
+ *
+ * <p> will convert to:
+ * <blockquote><pre>{@code
+ *    select deptno from "scott".dept where rand(10) < 0.5;
+ * }</pre></blockquote>
+ *
+ * @see CoreRules#SAMPLE_TO_FILTER
+ */
[email protected]
+public class RewriteSampleToFilterRule

Review Comment:
   How about naming it `SampleToFilterRule`, it's precise enough. (We have 
similar rules such as `JoinToCorrelateRule`, `FilterToCalcRule`)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to