tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject git commit: TAJO-532: Fix warnings in tajo-common. (jinho)
Date Tue, 04 Feb 2014 08:33:29 GMT
Updated Branches:
  refs/heads/master 0c0111cdf -> 51919cf9e


TAJO-532: Fix warnings in tajo-common. (jinho)


Project: http://git-wip-us.apache.org/repos/asf/incubator-tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tajo/commit/51919cf9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/51919cf9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/51919cf9

Branch: refs/heads/master
Commit: 51919cf9eb7c2b96d9f20126c780c3c26a4e8a05
Parents: 0c0111c
Author: jinossy <jinossy@gmail.com>
Authored: Tue Feb 4 17:32:26 2014 +0900
Committer: jinossy <jinossy@gmail.com>
Committed: Tue Feb 4 17:32:26 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |   2 +
 dev-support/findbugs-exclude.xml                |   5 +
 .../src/main/java/org/apache/tajo/QueryId.java  |   2 +-
 .../java/org/apache/tajo/QueryIdFactory.java    |   8 +-
 .../java/org/apache/tajo/TajoConstants.java     |  12 +--
 .../java/org/apache/tajo/common/type/IPv4.java  |   8 +-
 .../org/apache/tajo/common/type/TimeRange.java  |  10 +-
 .../java/org/apache/tajo/conf/TajoConf.java     |  10 +-
 .../org/apache/tajo/datum/TimestampDatum.java   |   7 ++
 .../java/org/apache/tajo/util/FileUtil.java     | 105 +++++++++++--------
 .../java/org/apache/tajo/util/NumberUtil.java   |  16 ++-
 .../main/java/org/apache/tajo/util/TUtil.java   |  14 +--
 .../java/org/apache/tajo/util/TajoIdUtils.java  |   2 +-
 .../apache/tajo/datum/TestTimestampDatum.java   |   2 +-
 14 files changed, 119 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index e3c433f..f95b852 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -414,6 +414,8 @@ Release 0.8.0 - unreleased
 
   TASKS
 
+    TAJO-532: Fix warnings in tajo-common. (jinho)
+
     TAJO-520: Move tajo-core-storage to tajo-storage. (jinho)
 
     TAJO-536: Fix warnings in tajo-core-storage. (jinho)

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/dev-support/findbugs-exclude.xml
----------------------------------------------------------------------
diff --git a/dev-support/findbugs-exclude.xml b/dev-support/findbugs-exclude.xml
index e30545a..0f967de 100644
--- a/dev-support/findbugs-exclude.xml
+++ b/dev-support/findbugs-exclude.xml
@@ -19,9 +19,14 @@
     <Class name="~org.apache.tajo.engine.parser.*"/>
   </Match>
 
+  <!-- Generated code -->
   <Match>
     <Class name="~org\.apache\.tajo\..*Proto.*"/>
   </Match>
+  <Match>
+    <Class name="~org.apache.tajo.common.TajoDataTypes.*"/>
+  </Match>
+  <!---->
 
   <Match>
     <!--

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/main/java/org/apache/tajo/QueryId.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/QueryId.java b/tajo-common/src/main/java/org/apache/tajo/QueryId.java
index af1ae56..d9d5f73 100644
--- a/tajo-common/src/main/java/org/apache/tajo/QueryId.java
+++ b/tajo-common/src/main/java/org/apache/tajo/QueryId.java
@@ -19,7 +19,7 @@
 package org.apache.tajo;
 
 public class QueryId implements Comparable<QueryId> {
-  public static String SEPARATOR = "_";
+  public static final String SEPARATOR = "_";
   public static final String QUERY_ID_PREFIX = "q";
 
   private String id;

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/main/java/org/apache/tajo/QueryIdFactory.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/QueryIdFactory.java b/tajo-common/src/main/java/org/apache/tajo/QueryIdFactory.java
index b0affe9..8ac0d54 100644
--- a/tajo-common/src/main/java/org/apache/tajo/QueryIdFactory.java
+++ b/tajo-common/src/main/java/org/apache/tajo/QueryIdFactory.java
@@ -28,13 +28,13 @@ import java.util.concurrent.atomic.AtomicInteger;
 public class QueryIdFactory {
   public static final QueryId NULL_QUERY_ID = newQueryId(TajoIdUtils.MASTER_ID_FORMAT.format(0),
0);
 
-  public static DecimalFormat ID_FORMAT = new DecimalFormat("0000");
+  public static final DecimalFormat ID_FORMAT = new DecimalFormat("0000");
 
-  public static DecimalFormat EB_ID_FORMAT = new DecimalFormat("000000");
+  public static final  DecimalFormat EB_ID_FORMAT = new DecimalFormat("000000");
 
-  public static DecimalFormat QU_ID_FORMAT = new DecimalFormat("000000");
+  public static final  DecimalFormat QU_ID_FORMAT = new DecimalFormat("000000");
 
-  public static DecimalFormat ATTEMPT_ID_FORMAT = new DecimalFormat("00");
+  public static final  DecimalFormat ATTEMPT_ID_FORMAT = new DecimalFormat("00");
 
   private static Map<String, AtomicInteger> queryNexIdMap = new HashMap<String,
AtomicInteger>();
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/main/java/org/apache/tajo/TajoConstants.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/TajoConstants.java b/tajo-common/src/main/java/org/apache/tajo/TajoConstants.java
index dc3b1f2..8cdc7bb 100644
--- a/tajo-common/src/main/java/org/apache/tajo/TajoConstants.java
+++ b/tajo-common/src/main/java/org/apache/tajo/TajoConstants.java
@@ -19,13 +19,13 @@
 package org.apache.tajo;
 
 public class TajoConstants {
-  public static String TAJO_VERSION = "0.8.0-SNAPSHOT";
-  public static String SYSTEM_CONF_FILENAME = "system_conf.xml";
+  public static final String TAJO_VERSION = "0.8.0-SNAPSHOT";
+  public static final String SYSTEM_CONF_FILENAME = "system_conf.xml";
 
-  public static String SYSTEM_DIR_NAME = "system";
-  public static String WAREHOUSE_DIR_NAME = "warehouse";
-  public static String SYSTEM_RESOURCE_DIR_NAME = "resource";
-  public static String RESULT_DIR_NAME="RESULT";
+  public static final String SYSTEM_DIR_NAME = "system";
+  public static final String WAREHOUSE_DIR_NAME = "warehouse";
+  public static final String SYSTEM_RESOURCE_DIR_NAME = "resource";
+  public static final String RESULT_DIR_NAME="RESULT";
 
   private TajoConstants() {}
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/main/java/org/apache/tajo/common/type/IPv4.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/common/type/IPv4.java b/tajo-common/src/main/java/org/apache/tajo/common/type/IPv4.java
index 1643674..957cd89 100644
--- a/tajo-common/src/main/java/org/apache/tajo/common/type/IPv4.java
+++ b/tajo-common/src/main/java/org/apache/tajo/common/type/IPv4.java
@@ -155,13 +155,13 @@ public class IPv4 implements Writable, Comparable<IPv4> {
 	
 	@Override
 	public String toString() {
-		String str = "";
+		StringBuilder sb = new StringBuilder();
 		int i;
 		for (i = 0; i < 3; i++) {
-			str += (((int)ipBytes[i] << 24) >> 24 & 0xFF) + ".";
+			sb.append(((int)ipBytes[i] << 24) >> 24 & 0xFF).append(".");
 		}
-		str += (((int)ipBytes[i] << 24) >> 24 & 0xFF);
-		return str;
+		sb.append(((int)ipBytes[i] << 24) >> 24 & 0xFF);
+		return sb.toString();
 	}
 	
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/main/java/org/apache/tajo/common/type/TimeRange.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/common/type/TimeRange.java b/tajo-common/src/main/java/org/apache/tajo/common/type/TimeRange.java
index 4cd122c..aace401 100644
--- a/tajo-common/src/main/java/org/apache/tajo/common/type/TimeRange.java
+++ b/tajo-common/src/main/java/org/apache/tajo/common/type/TimeRange.java
@@ -72,9 +72,9 @@ public class TimeRange implements Comparable<TimeRange>{
 		bb.putLong(this.begin);
 		return bb.hashCode();
 	}
-	
-	@Override
-	public String toString() {
-		return new String("(" + begin + ", " + end + ")");
-	}
+
+  @Override
+  public String toString() {
+    return "(" + begin + ", " + end + ")";
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
index 38aa191..de1b3c9 100644
--- a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
+++ b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
@@ -26,6 +26,7 @@ import org.apache.tajo.TajoConstants;
 import org.apache.tajo.util.NetUtils;
 import org.apache.tajo.util.TUtil;
 
+import java.io.IOException;
 import java.io.PrintStream;
 import java.net.InetSocketAddress;
 import java.util.Map;
@@ -447,16 +448,11 @@ public class TajoConf extends Configuration {
     return path.indexOf("file:/") == 0 || path.indexOf("hdfs:/") == 0;
   }
 
-  public static Path getStagingDir(TajoConf conf) {
+  public static Path getStagingDir(TajoConf conf) throws IOException {
     String stagingDirString = conf.getVar(ConfVars.STAGING_ROOT_DIR);
     if (!hasScheme(stagingDirString)) {
       Path warehousePath = getWarehouseDir(conf);
-      FileSystem fs;
-      try {
-        fs = warehousePath.getFileSystem(conf);
-      } catch (Throwable e) {
-        throw null;
-      }
+      FileSystem fs = warehousePath.getFileSystem(conf);
       Path path = new Path(fs.getUri().toString(), stagingDirString);
       conf.setVar(ConfVars.STAGING_ROOT_DIR, path.toString());
       return path;

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/main/java/org/apache/tajo/datum/TimestampDatum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/TimestampDatum.java b/tajo-common/src/main/java/org/apache/tajo/datum/TimestampDatum.java
index c1fad56..8dfa318 100644
--- a/tajo-common/src/main/java/org/apache/tajo/datum/TimestampDatum.java
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/TimestampDatum.java
@@ -18,6 +18,7 @@
 
 package org.apache.tajo.datum;
 
+import com.google.common.base.Objects;
 import org.apache.commons.lang.StringUtils;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.datum.exception.InvalidOperationException;
@@ -177,6 +178,7 @@ public class TimestampDatum extends Datum {
     }
   }
 
+  @Override
   public boolean equals(Object obj) {
     if (obj instanceof TimestampDatum) {
       TimestampDatum another = (TimestampDatum) obj;
@@ -185,4 +187,9 @@ public class TimestampDatum extends Datum {
       throw new InvalidOperationException();
     }
   }
+
+  @Override
+  public int hashCode(){
+     return Objects.hashCode(dateTime);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/main/java/org/apache/tajo/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/FileUtil.java b/tajo-common/src/main/java/org/apache/tajo/util/FileUtil.java
index 194be55..778bcbb 100644
--- a/tajo-common/src/main/java/org/apache/tajo/util/FileUtil.java
+++ b/tajo-common/src/main/java/org/apache/tajo/util/FileUtil.java
@@ -23,59 +23,80 @@ import org.apache.hadoop.fs.FSDataInputStream;
 import org.apache.hadoop.fs.FSDataOutputStream;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.IOUtils;
 
 import java.io.*;
 
 public class FileUtil {
-	public static void writeProto(File file, Message proto) throws IOException {
-		FileOutputStream stream = new FileOutputStream(file);
-		stream.write(proto.toByteArray());
-		stream.close();		
-	}
-	public static void writeProto(OutputStream out, Message proto) throws IOException {
-		out.write(proto.toByteArray());
-	}
-	
-	public static void writeProto(FileSystem fs, Path path, Message proto) throws IOException
{
-		FSDataOutputStream stream = fs.create(path);
-		stream.write(proto.toByteArray());
-		stream.close();
-	}
-	
-	public static Message loadProto(File file, Message proto) throws IOException {
-		FileInputStream in = new FileInputStream(file);
-		Message.Builder builder = proto.newBuilderForType().mergeFrom(in);		
-		return builder.build();
-	}
-	
-	public static Message loadProto(InputStream in, Message proto) throws IOException {
-		Message.Builder builder = proto.newBuilderForType().mergeFrom(in);
-		return builder.build();
-	}
-	
-	public static Message loadProto(FileSystem fs,
+  public static void writeProto(File file, Message proto) throws IOException {
+    FileOutputStream stream = null;
+    try {
+      stream = new FileOutputStream(file);
+      stream.write(proto.toByteArray());
+    } finally {
+      IOUtils.closeStream(stream);
+    }
+  }
+
+  public static void writeProto(OutputStream out, Message proto) throws IOException {
+    out.write(proto.toByteArray());
+  }
+
+  public static void writeProto(FileSystem fs, Path path, Message proto) throws IOException
{
+    FSDataOutputStream stream = fs.create(path);
+    try {
+      stream.write(proto.toByteArray());
+    } finally {
+      IOUtils.closeStream(stream);
+    }
+  }
+
+  public static Message loadProto(File file, Message proto) throws IOException {
+    FileInputStream in = null;
+    try {
+      in = new FileInputStream(file);
+      Message.Builder builder = proto.newBuilderForType().mergeFrom(in);
+      return builder.build();
+    } finally {
+      IOUtils.closeStream(in);
+    }
+  }
+
+  public static Message loadProto(InputStream in, Message proto) throws IOException {
+    Message.Builder builder = proto.newBuilderForType().mergeFrom(in);
+    return builder.build();
+  }
+
+  public static Message loadProto(FileSystem fs,
                                   Path path, Message proto) throws IOException {
-		FSDataInputStream in = new FSDataInputStream(fs.open(path));
-		Message.Builder builder = proto.newBuilderForType().mergeFrom(in);
-		return builder.build();
-	}
-	
-	public static File getFile(String path) {
-		return new File(path);
-	}
-	
-	public static String readTextFile(File file) throws IOException {
+    FSDataInputStream in = null;
+    try {
+      in = new FSDataInputStream(fs.open(path));
+      Message.Builder builder = proto.newBuilderForType().mergeFrom(in);
+      return builder.build();
+    } finally {
+      IOUtils.closeStream(in);
+    }
+  }
+
+  public static File getFile(String path) {
+    return new File(path);
+  }
+
+  public static String readTextFile(File file) throws IOException {
     StringBuilder fileData = new StringBuilder(1000);
-    BufferedReader reader = new BufferedReader(
-            new FileReader(file));
+    BufferedReader reader = new BufferedReader(new FileReader(file));
     char[] buf = new char[1024];
     int numRead;
-    while((numRead=reader.read(buf)) != -1){
+    try {
+      while ((numRead = reader.read(buf)) != -1) {
         String readData = String.valueOf(buf, 0, numRead);
         fileData.append(readData);
         buf = new char[1024];
+      }
+    } finally {
+      IOUtils.cleanup(null, reader);
     }
-    reader.close();
     return fileData.toString();
   }
 
@@ -83,7 +104,7 @@ public class FileUtil {
     int unit = si ? 1000 : 1024;
     if (bytes < unit) return bytes + " B";
     int exp = (int) (Math.log(bytes) / Math.log(unit));
-    String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
+    String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
     return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/main/java/org/apache/tajo/util/NumberUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/NumberUtil.java b/tajo-common/src/main/java/org/apache/tajo/util/NumberUtil.java
index 1846d78..c8205eb 100644
--- a/tajo-common/src/main/java/org/apache/tajo/util/NumberUtil.java
+++ b/tajo-common/src/main/java/org/apache/tajo/util/NumberUtil.java
@@ -55,16 +55,24 @@ public class NumberUtil {
   private static void benchmark(int num){
     System.out.println("Start benchmark. # of :" + num);
     long start =  System.currentTimeMillis();
+
+    byte[] bytes;
+    long size = 0;
     for (int i = 0; i < num; i ++){
-      String.valueOf(i).getBytes();
+      bytes = String.valueOf(i).getBytes();
+      size += bytes.length;
     }
 
     long end =  System.currentTimeMillis();
-    System.out.println("JDK getBytes() \t\t\t\t" + (end - start) + " ms");
+    System.out.println("JDK getBytes() \t\t\t\t" + (end - start) + " ms, " + "Total: " +
size / (1024 * 1024) + "MB");
+    size = 0;
+
     for (int i = 0; i < num; i ++){
-      toAsciiBytes(i);
+      bytes = toAsciiBytes(i);
+      size += bytes.length;
     }
-    System.out.println( "NumberUtil toByte() \t" + (System.currentTimeMillis() - end) + "
ms");
+    System.out.println( "NumberUtil toByte() \t" + (System.currentTimeMillis() - end)
+        + " ms, " + "Total: " + size / (1024 * 1024) + "MB");
   }
 
   public static void main(String[] args) throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/main/java/org/apache/tajo/util/TUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/TUtil.java b/tajo-common/src/main/java/org/apache/tajo/util/TUtil.java
index df7c79f..e9d8219 100644
--- a/tajo-common/src/main/java/org/apache/tajo/util/TUtil.java
+++ b/tajo-common/src/main/java/org/apache/tajo/util/TUtil.java
@@ -18,6 +18,8 @@
 
 package org.apache.tajo.util;
 
+import com.google.common.base.Objects;
+
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -26,7 +28,7 @@ import java.util.concurrent.ConcurrentHashMap;
  */
 public class TUtil {
   /**
-   * check two objects as equals. 
+   * check two objects as equals.
    * It will return true even if they are all null.
    *
    * @param s1 the first object to be compared.
@@ -35,13 +37,7 @@ public class TUtil {
    * @return true if they are equal or all null
    */
   public static boolean checkEquals(Object s1, Object s2) {
-    if (s1 == null ^ s2 == null) {
-      return false;
-    } else if (s1 == null && s2 == null) {
-      return true;
-    } else {
-      return s1.equals(s2);
-    }
+    return Objects.equal(s1, s2);
   }
 
   /**
@@ -61,7 +57,7 @@ public class TUtil {
       return Arrays.equals(s1, s2);
     }
   }
-  
+
   public static <T> T[] concat(T[] first, T[] second) {
     T[] result = Arrays.copyOf(first, first.length + second.length);
     System.arraycopy(second, 0, result, first.length, second.length);

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/main/java/org/apache/tajo/util/TajoIdUtils.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/TajoIdUtils.java b/tajo-common/src/main/java/org/apache/tajo/util/TajoIdUtils.java
index 521befc..978af6f 100644
--- a/tajo-common/src/main/java/org/apache/tajo/util/TajoIdUtils.java
+++ b/tajo-common/src/main/java/org/apache/tajo/util/TajoIdUtils.java
@@ -26,7 +26,7 @@ import org.apache.tajo.QueryUnitId;
 import java.text.DecimalFormat;
 
 public class TajoIdUtils {
-  public static DecimalFormat MASTER_ID_FORMAT = new DecimalFormat("0000000000000");
+  public static final DecimalFormat MASTER_ID_FORMAT = new DecimalFormat("0000000000000");
 
   public static ExecutionBlockId createExecutionBlockId(String idStr) {
     String[] tokens = idStr.split("_");

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/51919cf9/tajo-common/src/test/java/org/apache/tajo/datum/TestTimestampDatum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/test/java/org/apache/tajo/datum/TestTimestampDatum.java b/tajo-common/src/test/java/org/apache/tajo/datum/TestTimestampDatum.java
index 4a6b181..bb06946 100644
--- a/tajo-common/src/test/java/org/apache/tajo/datum/TestTimestampDatum.java
+++ b/tajo-common/src/test/java/org/apache/tajo/datum/TestTimestampDatum.java
@@ -41,7 +41,7 @@ public class TestTimestampDatum {
 		Datum d = DatumFactory.createTimeStamp(timestamp);
     assertEquals(Type.TIMESTAMP, d.type());
 	}
-	
+
 	@Test(expected = InvalidCastException.class)
 	public final void testAsInt4() {
     Datum d = DatumFactory.createTimeStamp(timestamp);


Mime
View raw message