You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by vo...@apache.org on 2018/05/06 19:12:39 UTC

[drill] branch master updated (6cbba28 -> c6c5d27)

This is an automated email from the ASF dual-hosted git repository.

volodymyr pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git.


    from 6cbba28  DRILL-6380: Fix sporadic mongo db hangs.
     new e0727a2  DRILL-6361: Revised typeOf() function versions
     new c6c5d27  DRILL-143: CGroup Support for Drill-on-YARN

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/drill/common/types/Types.java  |  49 ++++-
 distribution/src/resources/drillbit.sh             |  30 ++--
 .../drill/exec/expr/fn/impl/UnionFunctions.java    | 128 +++++++++++--
 .../drill/exec/expr/fn/impl/TestTypeFns.java       | 197 +++++++++++++++++++++
 .../src/test/resources/functions/null.json         |   1 +
 5 files changed, 372 insertions(+), 33 deletions(-)
 create mode 100644 exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestTypeFns.java
 create mode 100644 exec/java-exec/src/test/resources/functions/null.json

-- 
To stop receiving notification emails like this one, please contact
volodymyr@apache.org.

[drill] 01/02: DRILL-6361: Revised typeOf() function versions

Posted by vo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

volodymyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git

commit e0727a20009ea956ef54b338c2310a76cc35e45b
Author: Paul Rogers <pr...@cloudera.com>
AuthorDate: Sat Apr 28 23:04:26 2018 -0700

    DRILL-6361: Revised typeOf() function versions
    
    Added more unit tests.
    
    Updated to handle VARDECIMAL
    The VARDECIMAL type was recently added to Drill. Added support for this type. The sqlTypeOf() function now returns DECIMAL(p, s) for precision p, scale s.
    
    closes #1242
---
 .../java/org/apache/drill/common/types/Types.java  |  49 ++++-
 .../drill/exec/expr/fn/impl/UnionFunctions.java    | 128 +++++++++++--
 .../drill/exec/expr/fn/impl/TestTypeFns.java       | 197 +++++++++++++++++++++
 .../src/test/resources/functions/null.json         |   1 +
 4 files changed, 357 insertions(+), 18 deletions(-)

diff --git a/common/src/main/java/org/apache/drill/common/types/Types.java b/common/src/main/java/org/apache/drill/common/types/Types.java
index 1346f47..21744eb 100644
--- a/common/src/main/java/org/apache/drill/common/types/Types.java
+++ b/common/src/main/java/org/apache/drill/common/types/Types.java
@@ -28,9 +28,9 @@ import org.apache.drill.common.exceptions.DrillRuntimeException;
 import org.apache.drill.common.types.TypeProtos.DataMode;
 import org.apache.drill.common.types.TypeProtos.MajorType;
 import org.apache.drill.common.types.TypeProtos.MinorType;
+import org.apache.drill.common.util.CoreDecimalUtility;
 
 import com.google.protobuf.TextFormat;
-import org.apache.drill.common.util.CoreDecimalUtility;
 
 public class Types {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Types.class);
@@ -107,6 +107,10 @@ public class Types {
     if (type.getMode() == DataMode.REPEATED || type.getMinorType() == MinorType.LIST) {
       return "ARRAY";
     }
+    return getBaseSqlTypeName(type);
+  }
+
+  public static String getBaseSqlTypeName(final MajorType type) {
 
     switch (type.getMinorType()) {
 
@@ -175,6 +179,49 @@ public class Types {
     }
   }
 
+  /**
+   * Extend decimal type with precision and scale.
+   *
+   * @param type major type
+   * @param typeName type converted to a string
+   * @return type name augmented with precision and scale,
+   * if type is a decimal
+   */
+
+  public static String getExtendedSqlTypeName(MajorType type) {
+
+    String typeName = getSqlTypeName(type);
+    switch (type.getMinorType()) {
+    case DECIMAL9:
+    case DECIMAL18:
+    case DECIMAL28SPARSE:
+    case DECIMAL28DENSE:
+    case DECIMAL38SPARSE:
+    case DECIMAL38DENSE:
+    case VARDECIMAL:
+      // Disabled for now. See DRILL-6378
+      if (type.getPrecision() > 0) {
+        typeName += String.format("(%d, %d)",
+            type.getPrecision(), type.getScale());
+      }
+    default:
+    }
+    return typeName;
+  }
+
+  public static String getSqlModeName(final MajorType type) {
+    switch (type.getMode()) {
+    case REQUIRED:
+      return "NOT NULL";
+    case OPTIONAL:
+      return "NULLABLE";
+    case REPEATED:
+      return "ARRAY";
+    default:
+      return "UNKNOWN";
+    }
+  }
+
   /***
    * Gets JDBC type code for given SQL data type name.
    */
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/UnionFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/UnionFunctions.java
index 6b2b7aa..d63d3d6 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/UnionFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/UnionFunctions.java
@@ -17,32 +17,22 @@
  */
 package org.apache.drill.exec.expr.fn.impl;
 
-import com.google.common.collect.Sets;
-import io.netty.buffer.DrillBuf;
+import javax.inject.Inject;
+
 import org.apache.drill.common.types.TypeProtos.MinorType;
-import org.apache.drill.common.types.Types;
 import org.apache.drill.exec.expr.DrillSimpleFunc;
 import org.apache.drill.exec.expr.annotations.FunctionTemplate;
 import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
 import org.apache.drill.exec.expr.annotations.Output;
 import org.apache.drill.exec.expr.annotations.Param;
-import org.apache.drill.exec.expr.holders.BigIntHolder;
 import org.apache.drill.exec.expr.holders.BitHolder;
-import org.apache.drill.exec.expr.holders.NullableIntHolder;
-import org.apache.drill.exec.expr.holders.NullableTinyIntHolder;
-import org.apache.drill.exec.expr.holders.NullableUInt1Holder;
-import org.apache.drill.exec.expr.holders.UnionHolder;
 import org.apache.drill.exec.expr.holders.IntHolder;
+import org.apache.drill.exec.expr.holders.UnionHolder;
 import org.apache.drill.exec.expr.holders.VarCharHolder;
 import org.apache.drill.exec.resolver.TypeCastRules;
-import org.apache.drill.exec.vector.complex.impl.UnionReader;
 import org.apache.drill.exec.vector.complex.reader.FieldReader;
 
-import javax.inject.Inject;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Set;
+import io.netty.buffer.DrillBuf;
 
 /**
  * The class contains additional functions for union types in addition to those in GUnionFunctions
@@ -65,8 +55,10 @@ public class UnionFunctions {
     @Output
     IntHolder out;
 
+    @Override
     public void setup() {}
 
+    @Override
     public void eval() {
       org.apache.drill.common.types.TypeProtos.MinorType type1;
       if (input1.isSet()) {
@@ -147,16 +139,104 @@ public class UnionFunctions {
     @Inject
     DrillBuf buf;
 
+    @Override
     public void setup() {}
 
+    @Override
     public void eval() {
 
-      byte[] type;
+      String typeName;
       if (input.isSet()) {
-         type = input.getType().getMinorType().name().getBytes();
+        typeName = input.getType().getMinorType().name();
       } else {
-        type = org.apache.drill.common.types.TypeProtos.MinorType.NULL.name().getBytes();
+        typeName = org.apache.drill.common.types.TypeProtos.MinorType.NULL.name();
       }
+      byte[] type = typeName.getBytes();
+      buf = buf.reallocIfNeeded(type.length);
+      buf.setBytes(0, type);
+      out.buffer = buf;
+      out.start = 0;
+      out.end = type.length;
+    }
+  }
+
+  @FunctionTemplate(name = "sqlTypeOf",
+          scope = FunctionTemplate.FunctionScope.SIMPLE,
+          nulls = NullHandling.INTERNAL)
+  public static class GetSqlType implements DrillSimpleFunc {
+
+    @Param
+    FieldReader input;
+    @Output
+    VarCharHolder out;
+    @Inject
+    DrillBuf buf;
+
+    @Override
+    public void setup() {}
+
+    @Override
+    public void eval() {
+
+      String typeName = org.apache.drill.common.types.Types.getExtendedSqlTypeName(input.getType());
+      byte[] type = typeName.getBytes();
+      buf = buf.reallocIfNeeded(type.length);
+      buf.setBytes(0, type);
+      out.buffer = buf;
+      out.start = 0;
+      out.end = type.length;
+    }
+  }
+
+  @FunctionTemplate(name = "drillTypeOf",
+          scope = FunctionTemplate.FunctionScope.SIMPLE,
+          nulls = NullHandling.INTERNAL)
+  public static class GetDrillType implements DrillSimpleFunc {
+
+    @Param
+    FieldReader input;
+    @Output
+    VarCharHolder out;
+    @Inject
+    DrillBuf buf;
+
+    @Override
+    public void setup() {}
+
+    @Override
+    public void eval() {
+
+      String typeName = input.getType().getMinorType().name();
+      byte[] type = typeName.getBytes();
+      buf = buf.reallocIfNeeded(type.length);
+      buf.setBytes(0, type);
+      out.buffer = buf;
+      out.start = 0;
+      out.end = type.length;
+    }
+  }
+
+  @FunctionTemplate(name = "modeOf",
+          scope = FunctionTemplate.FunctionScope.SIMPLE,
+          nulls = NullHandling.INTERNAL)
+  public static class GetMode implements DrillSimpleFunc {
+
+    @Param
+    FieldReader input;
+    @Output
+    VarCharHolder out;
+    @Inject
+    DrillBuf buf;
+
+    @Override
+    public void setup() {}
+
+    @Override
+    public void eval() {
+
+      String typeName = org.apache.drill.common.types.Types.getSqlModeName(
+          input.getType());
+      byte[] type = typeName.getBytes();
       buf = buf.reallocIfNeeded(type.length);
       buf.setBytes(0, type);
       out.buffer = buf;
@@ -173,8 +253,10 @@ public class UnionFunctions {
     @Output
     UnionHolder out;
 
+    @Override
     public void setup() {}
 
+    @Override
     public void eval() {
       out.reader = in;
       out.isSet = in.isSet() ? 1 : 0;
@@ -188,8 +270,10 @@ public class UnionFunctions {
     @Param UnionHolder in;
     @Output UnionHolder out;
 
+    @Override
     public void setup() {}
 
+    @Override
     public void eval() {
       if (in.isSet == 1) {
         if (in.reader.getType().getMinorType() != org.apache.drill.common.types.TypeProtos.MinorType.LIST) {
@@ -209,8 +293,10 @@ public class UnionFunctions {
     @Param UnionHolder in;
     @Output BitHolder out;
 
+    @Override
     public void setup() {}
 
+    @Override
     public void eval() {
       if (in.isSet == 1) {
         out.value = in.getType().getMinorType() == org.apache.drill.common.types.TypeProtos.MinorType.LIST ? 1 : 0;
@@ -227,8 +313,10 @@ public class UnionFunctions {
     @Param UnionHolder in;
     @Output UnionHolder out;
 
+    @Override
     public void setup() {}
 
+    @Override
     public void eval() {
       if (in.isSet == 1) {
         if (in.reader.getType().getMinorType() != org.apache.drill.common.types.TypeProtos.MinorType.MAP) {
@@ -248,8 +336,10 @@ public class UnionFunctions {
     @Param UnionHolder in;
     @Output BitHolder out;
 
+    @Override
     public void setup() {}
 
+    @Override
     public void eval() {
       if (in.isSet == 1) {
         out.value = in.getType().getMinorType() == org.apache.drill.common.types.TypeProtos.MinorType.MAP ? 1 : 0;
@@ -265,8 +355,10 @@ public class UnionFunctions {
     @Param UnionHolder input;
     @Output BitHolder out;
 
+    @Override
     public void setup() { }
 
+    @Override
     public void eval() {
       out.value = input.isSet == 1 ? 1 : 0;
     }
@@ -278,8 +370,10 @@ public class UnionFunctions {
     @Param UnionHolder input;
     @Output BitHolder out;
 
+    @Override
     public void setup() { }
 
+    @Override
     public void eval() {
       out.value = input.isSet == 1 ? 0 : 1;
     }
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestTypeFns.java b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestTypeFns.java
new file mode 100644
index 0000000..02d664f
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestTypeFns.java
@@ -0,0 +1,197 @@
+/*
+ * 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.expr.fn.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.drill.exec.planner.physical.PlannerSettings;
+import org.apache.drill.exec.rpc.RpcException;
+import org.apache.drill.test.ClusterFixture;
+import org.apache.drill.test.ClusterFixtureBuilder;
+import org.apache.drill.test.ClusterTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestTypeFns extends ClusterTest {
+
+  @BeforeClass
+  public static void setup() throws Exception {
+    // Use the following three lines if you add a function
+    // to avoid the need for a full Drill build.
+    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher)
+        .configProperty("drill.classpath.scanning.cache.enabled", false);
+    startCluster(builder);
+
+    // Use the following line if a full Drill build has been
+    // done since adding new functions.
+//    startCluster(ClusterFixture.builder(dirTestWatcher).maxParallelization(1));
+  }
+
+  @Test
+  public void testTypeOf() throws RpcException {
+    // SMALLINT not supported in CAST
+    //doTypeOfTest("SMALLINT");
+    doTypeOfTest("INT");
+    doTypeOfTest("BIGINT");
+    doTypeOfTest("VARCHAR");
+    doTypeOfTest("FLOAT", "FLOAT4");
+    doTypeOfTest("DOUBLE", "FLOAT8");
+    doTypeOfTestSpecial("a", "true", "BIT");
+    doTypeOfTestSpecial("a", "CURRENT_DATE", "DATE");
+    doTypeOfTestSpecial("a", "CURRENT_TIME", "TIME");
+    doTypeOfTestSpecial("a", "CURRENT_TIMESTAMP", "TIMESTAMP");
+    doTypeOfTestSpecial("a", "AGE(CURRENT_TIMESTAMP)", "INTERVAL");
+    doTypeOfTestSpecial("BINARY_STRING(a)", "'\\xde\\xad\\xbe\\xef'", "VARBINARY");
+    try {
+      client.alterSession(PlannerSettings.ENABLE_DECIMAL_DATA_TYPE_KEY, true);
+      doTypeOfTestSpecial("CAST(a AS DECIMAL)", "1", "VARDECIMAL");
+      doTypeOfTestSpecial("CAST(a AS DECIMAL(6, 3))", "1", "VARDECIMAL");
+    } finally {
+      client.resetSession(PlannerSettings.ENABLE_DECIMAL_DATA_TYPE_KEY);
+    }
+  }
+
+  private void doTypeOfTest(String type) throws RpcException {
+    doTypeOfTest(type, type);
+  }
+
+  private void doTypeOfTest(String castType, String resultType) throws RpcException {
+
+    // typeof() returns types using the internal names.
+
+    String sql = "SELECT typeof(CAST(a AS " + castType + ")) FROM (VALUES (1)) AS T(a)";
+    String result = client.queryBuilder().sql(sql).singletonString();
+    assertEquals(resultType, result);
+
+    // For typeof(), null values annoyingly report a type of "NULL"
+
+    sql = "SELECT typeof(CAST(a AS " + castType + ")) FROM cp.`functions/null.json`";
+    result = client.queryBuilder().sql(sql).singletonString();
+    assertEquals("NULL", result);
+  }
+
+  private void doTypeOfTestSpecial(String expr, String value, String resultType) throws RpcException {
+    String sql = "SELECT typeof(" + expr + ") FROM (VALUES (" + value + ")) AS T(a)";
+    String result = client.queryBuilder().sql(sql).singletonString();
+    assertEquals(resultType, result);
+  }
+
+  @Test
+  public void testSqlTypeOf() throws RpcException {
+    // SMALLINT not supported in CAST
+    //doSqlTypeOfTest("SMALLINT");
+    doSqlTypeOfTest("INTEGER");
+    doSqlTypeOfTest("BIGINT");
+    doSqlTypeOfTest("CHARACTER VARYING");
+    doSqlTypeOfTest("FLOAT");
+    doSqlTypeOfTest("DOUBLE");
+    doSqlTypeOfTestSpecial("a", "true", "BOOLEAN");
+    doSqlTypeOfTestSpecial("a", "CURRENT_DATE", "DATE");
+    doSqlTypeOfTestSpecial("a", "CURRENT_TIME", "TIME");
+    doSqlTypeOfTestSpecial("a", "CURRENT_TIMESTAMP", "TIMESTAMP");
+    doSqlTypeOfTestSpecial("a", "AGE(CURRENT_TIMESTAMP)", "INTERVAL");
+    doSqlTypeOfTestSpecial("BINARY_STRING(a)", "'\\xde\\xad\\xbe\\xef'", "BINARY VARYING");
+    try {
+      client.alterSession(PlannerSettings.ENABLE_DECIMAL_DATA_TYPE_KEY, true);
+
+      // These should include precision and scale: DECIMAL(p, s)
+      // But, see DRILL-6378
+
+      doSqlTypeOfTestSpecial("CAST(a AS DECIMAL)", "1", "DECIMAL(38, 0)");
+      doSqlTypeOfTestSpecial("CAST(a AS DECIMAL(6, 3))", "1", "DECIMAL(6, 3)");
+    } finally {
+      client.resetSession(PlannerSettings.ENABLE_DECIMAL_DATA_TYPE_KEY);
+    }
+  }
+
+  private void doSqlTypeOfTest(String type) throws RpcException {
+
+    // sqlTypeOf() returns SQL type names: the names used in CAST.
+
+    String sql = "SELECT sqlTypeOf(CAST(a AS " + type + ")) FROM (VALUES (1)) AS T(a)";
+    String result = client.queryBuilder().sql(sql).singletonString();
+    assertEquals(type, result);
+
+    // Returns same type even value is null.
+
+    sql = "SELECT sqlTypeOf(CAST(a AS " + type + ")) FROM cp.`functions/null.json`";
+    result = client.queryBuilder().sql(sql).singletonString();
+    assertEquals(type, result);
+  }
+
+  private void doSqlTypeOfTestSpecial(String expr, String value, String resultType) throws RpcException {
+    String sql = "SELECT sqlTypeof(" + expr + ") FROM (VALUES (" + value + ")) AS T(a)";
+    String result = client.queryBuilder().sql(sql).singletonString();
+    assertEquals(resultType, result);
+  }
+
+  @Test
+  public void testDrillTypeOf() throws RpcException {
+    // SMALLINT not supported in CAST
+    //doDrillTypeOfTest("SMALLINT");
+    doDrillTypeOfTest("INTEGER", "INT");
+    doDrillTypeOfTest("BIGINT");
+    doDrillTypeOfTest("CHARACTER VARYING", "VARCHAR");
+    doDrillTypeOfTest("FLOAT", "FLOAT4");
+    doDrillTypeOfTest("DOUBLE", "FLOAT8");
+
+    // Omitting the other types. Internal code is identical to
+    // typeof() except for null handling.
+  }
+
+  private void doDrillTypeOfTest(String type) throws RpcException {
+    doDrillTypeOfTest(type, type);
+  }
+
+  private void doDrillTypeOfTest(String castType, String resultType) throws RpcException {
+
+    // drillTypeOf() returns types using the internal names.
+
+    String sql = "SELECT drillTypeOf(CAST(a AS " + castType + ")) FROM (VALUES (1)) AS T(a)";
+    String result = client.queryBuilder().sql(sql).singletonString();
+    assertEquals(resultType, result);
+
+    // Returns same type even value is null.
+
+    sql = "SELECT drillTypeOf(CAST(a AS " + castType + ")) FROM cp.`functions/null.json`";
+    result = client.queryBuilder().sql(sql).singletonString();
+    assertEquals(resultType, result);
+  }
+
+  @Test
+  public void testModeOf() throws RpcException {
+
+    // CSV files with headers use REQUIRED mode
+
+    String sql = "SELECT modeOf(`name`) FROM cp.`store/text/data/cars.csvh`";
+    String result = client.queryBuilder().sql(sql).singletonString();
+    assertEquals("NOT NULL", result);
+
+    // CSV files without headers use REPEATED mode
+
+    sql = "SELECT modeOf(`columns`) FROM cp.`textinput/input2.csv`";
+    result = client.queryBuilder().sql(sql).singletonString();
+    assertEquals("ARRAY", result);
+
+    // JSON files use OPTIONAL mode
+
+    sql = "SELECT modeOf(`name`) FROM cp.`jsoninput/specialchar.json`";
+    result = client.queryBuilder().sql(sql).singletonString();
+    assertEquals("NULLABLE", result);
+  }
+}
diff --git a/exec/java-exec/src/test/resources/functions/null.json b/exec/java-exec/src/test/resources/functions/null.json
new file mode 100644
index 0000000..c601016
--- /dev/null
+++ b/exec/java-exec/src/test/resources/functions/null.json
@@ -0,0 +1 @@
+{a: null}

-- 
To stop receiving notification emails like this one, please contact
volodymyr@apache.org.

[drill] 02/02: DRILL-143: CGroup Support for Drill-on-YARN

Posted by vo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

volodymyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git

commit c6c5d27d91468a29656bee2acba55d3321978aab
Author: Kunal Khatua <ku...@apache.org>
AuthorDate: Mon Apr 23 10:31:21 2018 -0700

    DRILL-143: CGroup Support for Drill-on-YARN
    
    Initial patch
    1. Minor fix up
    2. Updated variable name for pid file
    Revert changes to yarn-drillbit.sh
    Based on discussion for PR #1239 (Ref: https://github.com/apache/drill/pull/1239)
    
    closes #1239
---
 distribution/src/resources/drillbit.sh | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/distribution/src/resources/drillbit.sh b/distribution/src/resources/drillbit.sh
index 7dad34c..88d56c8 100755
--- a/distribution/src/resources/drillbit.sh
+++ b/distribution/src/resources/drillbit.sh
@@ -119,9 +119,9 @@ check_before_start()
 {
   #check that the process is not running
   mkdir -p "$DRILL_PID_DIR"
-  if [ -f $pid ]; then
-    if kill -0 `cat $pid` > /dev/null 2>&1; then
-      echo "$command is already running as process `cat $pid`.  Stop it first."
+  if [ -f $pidFile ]; then
+    if kill -0 `cat $pidFile` > /dev/null 2>&1; then
+      echo "$command is already running as process `cat $pidFile`.  Stop it first."
       exit 1
     fi
   fi
@@ -146,8 +146,8 @@ check_and_enforce_cgroup(){
     if [ -f $SYS_CGROUP_DIR/cpu/$DRILLBIT_CGROUP/cgroup.procs ]; then
       echo $dbitPid > $SYS_CGROUP_DIR/cpu/$DRILLBIT_CGROUP/cgroup.procs
       # Verify Enforcement
-      cgroupStatus=`grep -w $pid $SYS_CGROUP_DIR/cpu/${DRILLBIT_CGROUP}/cgroup.procs`
-      if [ -z "$cgroupStatus" ]; then
+      cgroupStatus=`grep -w $dbitPid $SYS_CGROUP_DIR/cpu/${DRILLBIT_CGROUP}/cgroup.procs`
+      if [ -n "$cgroupStatus" ]; then
         #Ref: https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt
         cpu_quota=`cat ${SYS_CGROUP_DIR}/cpu/${DRILLBIT_CGROUP}/cpu.cfs_quota_us`
         cpu_period=`cat ${SYS_CGROUP_DIR}/cpu/${DRILLBIT_CGROUP}/cpu.cfs_period_us`
@@ -189,8 +189,8 @@ start_bit ( )
   echo "`ulimit -a`" >> "$DRILLBIT_LOG_PATH" 2>&1
   nohup nice -n $DRILL_NICENESS "$DRILL_HOME/bin/runbit" exec ${args[@]} >> "$logout" 2>&1 &
   procId=$!
-  echo $procId > $pid # Yeah, $pid is a file, $procId is the pid...
-  echo $! > $pid
+  echo $procId > $pidFile # Yeah, $pidFile is a file, $procId is the pid...
+  echo $! > $pidFile
   sleep 1
   check_after_start $procId
 }
@@ -198,8 +198,8 @@ start_bit ( )
 stop_bit ( )
 {
   kill_drillbit=$1
-  if [ -f $pid ]; then
-    pidToKill=`cat $pid`
+  if [ -f $pidFile ]; then
+    pidToKill=`cat $pidFile`
     # kill -0 == see if the PID exists
     if kill -0 $pidToKill > /dev/null 2>&1; then
       echo "Stopping $command"
@@ -211,15 +211,15 @@ stop_bit ( )
       retval=$?
       echo "No $command to stop because kill -0 of pid $pidToKill failed with status $retval"
     fi
-    rm $pid > /dev/null 2>&1
+    rm $pidFile > /dev/null 2>&1
   else
-    echo "No $command to stop because no pid file $pid"
+    echo "No $command to stop because no pid file $pidFile"
     retval=1
   fi
   return $retval
 }
 
-pid=$DRILL_PID_DIR/drillbit.pid
+pidFile=$DRILL_PID_DIR/drillbit.pid
 logout="${DRILL_LOG_PREFIX}.out"
 
 thiscmd=$0
@@ -271,12 +271,12 @@ case $startStopStatus in
   ;;
 
 (status)
-  if [ -f $pid ]; then
-    TARGET_PID=`cat $pid`
+  if [ -f $pidFile ]; then
+    TARGET_PID=`cat $pidFile`
     if kill -0 $TARGET_PID > /dev/null 2>&1; then
       echo "$command is running."
     else
-      echo "$pid file is present but $command is not running."
+      echo "$pidFile file is present but $command is not running."
       exit 1
     fi
   else

-- 
To stop receiving notification emails like this one, please contact
volodymyr@apache.org.