From issues-return-187110-archive-asf-public=cust-asf.ponee.io@hive.apache.org Fri Apr 24 07:41:03 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id E5EF518062C for ; Fri, 24 Apr 2020 09:41:02 +0200 (CEST) Received: (qmail 32612 invoked by uid 500); 24 Apr 2020 07:41:02 -0000 Mailing-List: contact issues-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hive.apache.org Delivered-To: mailing list issues@hive.apache.org Received: (qmail 32603 invoked by uid 99); 24 Apr 2020 07:41:02 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Apr 2020 07:41:02 +0000 Received: from jira-he-de.apache.org (static.172.67.40.188.clients.your-server.de [188.40.67.172]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 355A6E01AE for ; Fri, 24 Apr 2020 07:41:00 +0000 (UTC) Received: from jira-he-de.apache.org (localhost.localdomain [127.0.0.1]) by jira-he-de.apache.org (ASF Mail Server at jira-he-de.apache.org) with ESMTP id 4215B78028F for ; Fri, 24 Apr 2020 07:41:00 +0000 (UTC) Date: Fri, 24 Apr 2020 07:41:00 +0000 (UTC) From: "ASF GitHub Bot (Jira)" To: issues@hive.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Work logged] (HIVE-23031) Add option to enable transparent rewrite of count(distinct) into sketch functions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HIVE-23031?focusedWorklogId=426882&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-426882 ] ASF GitHub Bot logged work on HIVE-23031: ----------------------------------------- Author: ASF GitHub Bot Created on: 24/Apr/20 07:40 Start Date: 24/Apr/20 07:40 Worklog Time Spent: 10m Work Description: kgyrtkirk commented on a change in pull request #988: URL: https://github.com/apache/hive/pull/988#discussion_r414363412 ########## File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRewriteCountDistinctToDataSketches.java ########## @@ -0,0 +1,175 @@ +/* + * 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.hadoop.hive.ql.optimizer.calcite.rules; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.apache.calcite.plan.RelOptRule; +import org.apache.calcite.plan.RelOptRuleCall; +import org.apache.calcite.rel.RelCollation; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.core.Aggregate; +import org.apache.calcite.rel.core.AggregateCall; +import org.apache.calcite.rel.core.RelFactories.AggregateFactory; +import org.apache.calcite.rel.core.RelFactories.ProjectFactory; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rex.RexBuilder; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.sql.SqlAggFunction; +import org.apache.calcite.sql.SqlOperator; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.conf.HiveConf.ConfVars; +import org.apache.hadoop.hive.ql.exec.DataSketchesFunctions; +import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelFactories; +import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveAggregate; +import org.apache.hive.plugin.api.HiveUDFPlugin.UDFDescriptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.ImmutableList; + +/** + * This rule could rewrite {@code count(distinct(x))} calls to be calculated using sketch based functions. + */ +public final class HiveRewriteCountDistinctToDataSketches extends RelOptRule { + + protected static final Logger LOG = LoggerFactory.getLogger(HiveRewriteCountDistinctToDataSketches.class); + private String sketchClass; + + public HiveRewriteCountDistinctToDataSketches(HiveConf conf) { + super(operand(HiveAggregate.class, any())); + sketchClass = conf.getVar(ConfVars.HIVE_OPTIMIZE_REWRITE_COUNT_DISTINCT_SKETCHCLASS); + } + + @Override + public void onMatch(RelOptRuleCall call) { + final Aggregate aggregate = call.rel(0); + + if (aggregate.getGroupSets().size() != 1) { + // not yet supported + return; + } + + List newAggCalls = new ArrayList(); + + AggregateFactory f = HiveRelFactories.HIVE_AGGREGATE_FACTORY; Review comment: I just followed the "usual practice" by passing the `HiveConf` :D but since there is nothing else needed - I've removed it... About the factory stuff: I've moved it to the constructor/etc but this is not entirely clear to me: * we the `HiveRelFactories` - to construct things * in the meantime there is also `call.builder()` which could be probably could be used to do the same Other rules seemed to utilize `HiveRelFactories` so I've followed that - but I feel that it would be better to use the builder - and fix the issues we might encounter along the way...what do you think? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: users@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 426882) Time Spent: 40m (was: 0.5h) > Add option to enable transparent rewrite of count(distinct) into sketch functions > --------------------------------------------------------------------------------- > > Key: HIVE-23031 > URL: https://issues.apache.org/jira/browse/HIVE-23031 > Project: Hive > Issue Type: Sub-task > Reporter: Zoltan Haindrich > Assignee: Zoltan Haindrich > Priority: Major > Attachments: HIVE-23031.01.patch, HIVE-23031.02.patch, HIVE-23031.03.patch, HIVE-23031.03.patch, HIVE-23031.03.patch > > Time Spent: 40m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.4#803005)