Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/729#discussion_r102874862
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/statistics/MergedStatisticFactory.java
 ---
    @@ -0,0 +1,46 @@
    +/*
    + * 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
    + * <p/>
    + * http://www.apache.org/licenses/LICENSE-2.0
    + * <p/>
    + * 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.physical.impl.statistics;
    +
    +public class MergedStatisticFactory {
    +  /*
    +   * Creates the appropriate statistics object given the name of the 
statistics and the input statistic
    +   */
    +  public static MergedStatistic getMergedStatistic(String outputStatName, 
String inputStatName) {
    +    if (outputStatName == null || inputStatName == null) {
    +      return null;
    +    } else if (outputStatName.equals(Statistic.COLNAME)) {
    +      return new ColumnMergedStatistic(outputStatName, inputStatName);
    +    } else if (outputStatName.equals(Statistic.COLTYPE)) {
    +      return new ColTypeMergedStatistic(outputStatName, inputStatName);
    +    } else if (outputStatName.equals(Statistic.STATCOUNT)) {
    +      return new StatCountMergedStatistic(outputStatName, inputStatName);
    +    } else if (outputStatName.equals(Statistic.NNSTATCOUNT)) {
    +      return new NNStatCountMergedStatistic(outputStatName, inputStatName);
    +    } else if (outputStatName.equals(Statistic.AVG_WIDTH)) {
    +      return new AvgWidthMergedStatistic(outputStatName, inputStatName);
    +    } else if (outputStatName.equals(Statistic.HLL_MERGE)) {
    +      return new HLLMergedStatistic(outputStatName, inputStatName);
    +    } else if (outputStatName.equals(Statistic.NDV)) {
    +      return new NDVMergedStatistic(outputStatName, inputStatName);
    --- End diff --
    
    Consider:
    
    ```
    if (outputStatName.equals(Statistic.NDV)) {
      stat = new NDVMergedStatistic();
    }
    ...
    stat.init(outputStatName, inputStatName);
    ```
    How often will this factory be used? If frequently, then consider:
    ```
    class Factory() {
       private Factory instance = new Factory();
       private HashMap<String,Class<? extends MergedStatistic>> statsClasses = 
new HashMap<>( );
    
       private Factory() {
         statsClasses.put(Statistic.NDV, NDVMergedStatistic.class);
         ...
      }
       public MergedStatistic getMergedStatistic(String outputStatName, String 
inputStatName) {
           return instance.newMergedStatistic(outputStatName, inputStatName);
      }
      private MergedStatistic instance.newMergedStatistic(String 
outputStatName, String inputStatName) {
        MergedStatistic stat = statsClasses.get(outputStatName).newInstance();
        stat.init(outputStatName, inputStatName);
        return stat;
      }
    ```
    Lots of ways to do the above; this is just an example.
     


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to