[ 
https://issues.apache.org/jira/browse/TAJO-928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14085686#comment-14085686
 ] 

ASF GitHub Bot commented on TAJO-928:
-------------------------------------

Github user blrunner commented on a diff in the pull request:

    https://github.com/apache/tajo/pull/98#discussion_r15792495
  
    --- Diff: tajo-common/src/main/java/org/apache/tajo/OverridableConf.java ---
    @@ -0,0 +1,239 @@
    +/*
    + * 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.tajo;
    +
    +import com.google.common.base.Preconditions;
    +import org.apache.commons.logging.Log;
    +import org.apache.commons.logging.LogFactory;
    +import org.apache.tajo.conf.TajoConf;
    +import org.apache.tajo.util.KeyValueSet;
    +
    +import java.lang.ref.WeakReference;
    +import java.util.Map;
    +import java.util.WeakHashMap;
    +
    +import static org.apache.tajo.ConfigKey.ConfigType;
    +import static 
org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueSetProto;
    +
    +/**
    + * QueryContext provides a consolidated config system for a query instant.
    + *
    + * In Tajo, there are three configurable layers:
    + * <ul>
    + *   <li>
    + *    <ul>System Config - it comes from Hadoop's Configuration class. by 
tajo-site, catalog-site,
    + *    catalog-default and TajoConf.</ul>
    + *    <ul>Session variables - they are instantly configured by users.
    + *    Each client session has it own set of session variables.</ul>
    + *    <ul>Query config - it is internally used for meta information of a 
query instance.</ul>
    + *   </li>
    + * </ul>
    + *
    + * System configs and session variables can set the same config in the 
same time. System configs are usually used to set
    + * default configs, and session variables is user-specified configs. So, 
session variables can override system configs.
    + *
    + * QueryContent provides a query with a uniform way to access various 
configs without considering their priorities.
    + */
    +public class OverridableConf extends KeyValueSet {
    +  private static final Log LOG = LogFactory.getLog(OverridableConf.class);
    +  private ConfigType [] configTypes;
    +
    +  private static final Map<ClassLoader, Map<String, 
WeakReference<Class<?>>>>
    +      CACHE_CLASSES = new WeakHashMap<ClassLoader, Map<String, 
WeakReference<Class<?>>>>();
    +
    +  private TajoConf conf;
    +
    +  public OverridableConf(final TajoConf conf, ConfigType...configTypes) {
    +    this.conf = conf;
    +    this.configTypes = configTypes;
    +  }
    +
    +  public OverridableConf(final TajoConf conf, KeyValueSetProto proto, 
ConfigType...configTypes) {
    +    super(proto);
    +    this.conf = conf;
    +    this.configTypes = configTypes;
    +  }
    +
    +  public void setConf(TajoConf conf) {
    +    this.conf = conf;
    +  }
    +
    +  public TajoConf getConf() {
    +    return conf;
    +  }
    +
    +  public void setBool(ConfigKey key, boolean val) {
    +    setBool(key.keyname(), val);
    +  }
    +
    +  public boolean getBool(ConfigKey key, Boolean defaultVal) {
    +    assertRegisteredEnum(key);
    +
    +    switch (key.type()) {
    +    case QUERY:
    +      return getBool(key.keyname());
    +    case SESSION:
    +      return getBool(key.keyname(), conf.getBoolVar(((SessionVars) 
key).getConfVars()));
    +    case SYSTEM:
    +      return conf.getBoolVar((TajoConf.ConfVars) key);
    +    default:
    +      return getBool(key.keyname(), defaultVal);
    +    }
    +  }
    +
    +  public boolean getBool(ConfigKey key) {
    +    return getBool(key, null);
    +  }
    +
    +  public int getInt(ConfigKey key, Integer defaultVal) {
    +    assertRegisteredEnum(key);
    +
    +    if (key.type() != ConfigType.SESSION && key.type() != 
ConfigType.SYSTEM) {
    +      return getInt(key.keyname());
    +    } else {
    +      switch (key.type()) {
    +      case SESSION:
    +        return getInt(key.keyname(), conf.getIntVar(((SessionVars) 
key).getConfVars()));
    +      case SYSTEM:
    +        return conf.getIntVar((TajoConf.ConfVars) key);
    +      default:
    +        throw new IllegalStateException("key does not belong to Session 
and System config sets");
    +      }
    +    }
    +  }
    +
    +  public int getInt(ConfigKey key) {
    +    return getInt(key, null);
    +  }
    +
    +  public long getLong(ConfigKey key, Long defaultVal) {
    +    assertRegisteredEnum(key);
    +
    +    if (key.type() != ConfigType.SESSION && key.type() != 
ConfigType.SYSTEM) {
    +      return getLong(key.keyname());
    +    } else {
    +      switch (key.type()) {
    +      case SESSION:
    +        return getLong(key.keyname(), conf.getLongVar(((SessionVars) 
key).getConfVars()));
    +      case SYSTEM:
    +        return conf.getLongVar((TajoConf.ConfVars) key);
    +      default:
    +        throw new IllegalStateException("key does not belong to Session 
and System config sets");
    +      }
    +    }
    +  }
    +
    +  public long getLong(ConfigKey key) {
    +    return getLong(key, null);
    +  }
    +
    +  public float getFloat(ConfigKey key, Float defaultVal) {
    +    assertRegisteredEnum(key);
    +
    +    if (key.type() != ConfigType.SESSION && key.type() != 
ConfigType.SYSTEM) {
    +      return getFloat(key.keyname());
    +    } else {
    +      switch (key.type()) {
    +      case SESSION:
    +        return getFloat(key.keyname(), conf.getFloatVar(((SessionVars) 
key).getConfVars()));
    +      case SYSTEM:
    +        return conf.getFloatVar((TajoConf.ConfVars) key);
    +      default:
    +        throw new IllegalStateException("key does not belong to Session 
and System config sets");
    +      }
    +    }
    +  }
    +
    +  public float getFloat(ConfigKey key) {
    +    return getLong(key, null);
    +  }
    +
    +  public void put(ConfigKey key, String val) {
    +    set(key.keyname(), val);
    +  }
    +
    +  private void assertRegisteredEnum(ConfigKey key) {
    +    boolean registered = false;
    +
    +    for (ConfigType c : configTypes) {
    +      registered = key.type() == c;
    +    }
    +
    +    registered |= key.type() == ConfigType.SESSION || key.type() != 
ConfigType.SYSTEM;
    +
    +    Preconditions.checkArgument(registered, key.keyname() + " (" + 
key.type() + ") is not allowed in " +
    +      getClass().getSimpleName());
    +  }
    +
    +  public String get(ConfigKey key, String defaultVal) {
    +    assertRegisteredEnum(key);
    +
    +    if (key.type() != ConfigType.SESSION && key.type() != 
ConfigType.SYSTEM) {
    +      return get(key.keyname(), defaultVal);
    +    } else {
    +      switch (key.type()) {
    +      case SESSION:
    +        return get(key.keyname(), conf.getVar(((SessionVars) 
key).getConfVars()));
    +      case SYSTEM:
    +        return conf.getVar((TajoConf.ConfVars) key);
    +      default:
    +        throw new IllegalStateException("key does not belong to Session 
and System config sets");
    +      }
    +    }
    +  }
    +
    +  public String get(ConfigKey key) {
    +    return get(key, null);
    +  }
    +
    +  public Class<?> getClass(ConfigKey key) {
    +//    if (containsKey(key)) {
    --- End diff --
    
    Is this a comment? 


> Session variables should override query configs in TajoConf.
> ------------------------------------------------------------
>
>                 Key: TAJO-928
>                 URL: https://issues.apache.org/jira/browse/TAJO-928
>             Project: Tajo
>          Issue Type: Improvement
>          Components: distributed query plan, planner/optimizer
>            Reporter: Hyunsik Choi
>            Assignee: Hyunsik Choi
>             Fix For: 0.9.0
>
>
> Currently, we should use tajo-site in order to change the configurations 
> related queries, such as optimization option or some parameters. It is never 
> practical because we need to restart a Tajo cluster in order to change the 
> config.
> The main purpose of this issue is to refactor the system of session variable 
> and some part to recognize query configs to accept the session variables. 
> Also, when there are duplicated configs in session and TajoConf, session 
> variables should override the existing config of TajoConf.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to