Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1A69A200C16 for ; Thu, 26 Jan 2017 01:24:40 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 19047160B5A; Thu, 26 Jan 2017 00:24:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 61875160B4E for ; Thu, 26 Jan 2017 01:24:39 +0100 (CET) Received: (qmail 93251 invoked by uid 500); 26 Jan 2017 00:24:38 -0000 Mailing-List: contact dev-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list dev@drill.apache.org Received: (qmail 93240 invoked by uid 99); 26 Jan 2017 00:24:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Jan 2017 00:24:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 30AF4DFC12; Thu, 26 Jan 2017 00:24:38 +0000 (UTC) From: amansinha100 To: dev@drill.apache.org Reply-To: dev@drill.apache.org References: In-Reply-To: Subject: [GitHub] drill pull request #729: Drill 1328 r4 Content-Type: text/plain Message-Id: <20170126002438.30AF4DFC12@git1-us-west.apache.org> Date: Thu, 26 Jan 2017 00:24:38 +0000 (UTC) archived-at: Thu, 26 Jan 2017 00:24:40 -0000 Github user amansinha100 commented on a diff in the pull request: https://github.com/apache/drill/pull/729#discussion_r97910777 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/cost/DrillRelMdSelectivity.java --- @@ -0,0 +1,219 @@ +/******************************************************************************* + * 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.drill.exec.planner.cost; + +import org.apache.calcite.plan.RelOptUtil; +import org.apache.calcite.plan.volcano.RelSubset; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.SingleRel; +import org.apache.calcite.rel.core.JoinRelType; +import org.apache.calcite.rel.core.TableScan; +import org.apache.calcite.rel.metadata.ReflectiveRelMetadataProvider; +import org.apache.calcite.rel.metadata.RelMdSelectivity; +import org.apache.calcite.rel.metadata.RelMdUtil; +import org.apache.calcite.rel.metadata.RelMetadataProvider; +import org.apache.calcite.rel.metadata.RelMetadataQuery; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rex.RexBuilder; +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexInputRef; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.rex.RexUtil; +import org.apache.calcite.rex.RexVisitor; +import org.apache.calcite.rex.RexVisitorImpl; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.util.BuiltInMethod; +import org.apache.calcite.util.Util; +import org.apache.drill.exec.planner.common.DrillJoinRelBase; +import org.apache.drill.exec.planner.common.DrillRelOptUtil; +import org.apache.drill.exec.planner.logical.DrillTable; +import org.apache.drill.exec.planner.logical.DrillTranslatableTable; + +import java.util.ArrayList; +import java.util.List; + +public class DrillRelMdSelectivity extends RelMdSelectivity { + private static final org.slf4j.Logger logger = + org.slf4j.LoggerFactory.getLogger(RelMdSelectivity.class); + + private static final DrillRelMdSelectivity INSTANCE = + new DrillRelMdSelectivity(); + + public static final RelMetadataProvider SOURCE = + ReflectiveRelMetadataProvider.reflectiveSource( + BuiltInMethod.SELECTIVITY.method, INSTANCE); + + @Override + public Double getSelectivity(RelNode rel, RexNode predicate) { + if (rel instanceof TableScan) { + return getScanSelectivity((TableScan) rel, predicate); + } else if (rel instanceof DrillJoinRelBase) { + return getJoinSelectivity(((DrillJoinRelBase) rel), predicate); + } else if (rel instanceof SingleRel && !DrillRelOptUtil.guessRows(rel)) { + return RelMetadataQuery.getSelectivity(((SingleRel) rel).getInput(), predicate); + } else if (rel instanceof RelSubset && !DrillRelOptUtil.guessRows(rel)) { + if (((RelSubset) rel).getBest() != null) { + return RelMetadataQuery.getSelectivity(((RelSubset)rel).getBest(), predicate); + } else if (((RelSubset)rel).getOriginal() != null) { + return RelMetadataQuery.getSelectivity(((RelSubset)rel).getOriginal(), predicate); + } else { + return super.getSelectivity(rel, predicate); + } + } else { + return super.getSelectivity(rel, predicate); + } + } + + private Double getJoinSelectivity(DrillJoinRelBase rel, RexNode predicate) { --- End diff -- Let's explore whether this can be done in Calcite instead of Drill since it is a generic function, not Drill specific. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---