tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject git commit: TAJO-586: containFunction shouldn't throw NoSuchFunctionException. (jinho)
Date Thu, 06 Feb 2014 09:03:24 GMT
Updated Branches:
  refs/heads/master 2761436b2 -> d0206493b


TAJO-586: containFunction shouldn't throw NoSuchFunctionException. (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/d0206493
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/d0206493
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/d0206493

Branch: refs/heads/master
Commit: d0206493bfb2a60b647ad2d1dd555d3da50892b7
Parents: 2761436
Author: jinossy <jinossy@gmail.com>
Authored: Thu Feb 6 18:02:32 2014 +0900
Committer: jinossy <jinossy@gmail.com>
Committed: Thu Feb 6 18:02:32 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../tajo/catalog/AbstractCatalogClient.java     |  9 +++-
 .../org/apache/tajo/catalog/CatalogServer.java  | 30 ++++++------
 .../tajo/catalog/store/AbstractDBStore.java     |  2 +-
 .../org/apache/tajo/catalog/TestCatalog.java    | 51 ++++++++++++--------
 .../tajo/engine/planner/ExprAnnotator.java      |  4 +-
 6 files changed, 57 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/d0206493/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9cffeee..7f58b4a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -246,6 +246,8 @@ Release 0.8.0 - unreleased
 
   BUG FIXES
 
+    TAJO-586: containFunction shouldn't throw NoSuchFunctionException. (jinho)
+
     TAJO-582: Invalid split calculation. (jinho)
 
     TAJO-581: Inline view on column partitioned table causes NPE. (hyunsik)

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/d0206493/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
index c711deb..1a7e54c 100644
--- a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
+++ b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
@@ -363,8 +363,13 @@ public abstract class AbstractCatalogClient implements CatalogService
{
           }
         }
       }.withRetries();
-    } catch (ServiceException e) {
-      LOG.error(e.getMessage(), e);
+    } catch(ServiceException e) {
+      // this is not good. we need to define user massage exception
+      if(e.getCause() instanceof NoSuchFunctionException){
+        LOG.debug(e.getMessage());
+      } else {
+        LOG.error(e.getMessage(), e);
+      }
     }
 
     if (descProto == null) {

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/d0206493/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
index 69e0248..62d6e27 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
@@ -99,11 +99,11 @@ public class CatalogServer extends AbstractService {
   }
 
   @Override
-  public void init(Configuration _conf) {
-    this.conf = (TajoConf)_conf;
+  public void init(Configuration conf) {
 
     Constructor<?> cons;
     try {
+      this.conf = (TajoConf) conf;
       Class<?> storeClass = this.conf.getClass(CatalogConstants.STORE_CLASS, DerbyStore.class);
 
       LOG.info("Catalog Store Class: " + storeClass.getCanonicalName());
@@ -509,7 +509,7 @@ public class CatalogServer extends AbstractService {
           }
         }
       }
-      throw new NoSuchFunctionException(signature, params);
+      return null;
     }
 
     private FunctionDescProto findFunction(String signature, FunctionType type, List<DataType>
params) {
@@ -520,7 +520,7 @@ public class CatalogServer extends AbstractService {
           }
         }
       }
-      throw new NoSuchFunctionException(signature, params);
+      return null;
     }
 
     private FunctionDescProto findFunction(FunctionDescProto target) {
@@ -533,13 +533,9 @@ public class CatalogServer extends AbstractService {
       FunctionSignature signature = FunctionSignature.create(funcDesc);
 
       if (functions.containsKey(funcDesc.getSignature())) {
-        try {
-          FunctionDescProto found = findFunction(funcDesc);
-          if (found != null) {
-            throw new AlreadyExistsFunctionException(signature.toString());
-          }
-        } catch (NoSuchFunctionException e) {
-          //create function
+        FunctionDescProto found = findFunction(funcDesc);
+        if (found != null) {
+          throw new AlreadyExistsFunctionException(signature.toString());
         }
       }
 
@@ -568,15 +564,18 @@ public class CatalogServer extends AbstractService {
     @Override
     public FunctionDescProto getFunctionMeta(RpcController controller, GetFunctionMetaRequest
request)
         throws ServiceException {
+      FunctionDescProto function = null;
       if (request.hasFunctionType()) {
         if (containFunction(request.getSignature(), request.getFunctionType(), request.getParameterTypesList()))
{
-          FunctionDescProto desc = findFunction(request.getSignature(), request.getFunctionType(),
-              request.getParameterTypesList());
-          return desc;
+          function = findFunction(request.getSignature(), request.getFunctionType(), request.getParameterTypesList());
         }
+      } else {
+        function = findFunction(request.getSignature(), request.getParameterTypesList());
+      }
+
+      if (function == null) {
         throw new NoSuchFunctionException(request.getSignature(), request.getParameterTypesList());
       } else {
-        FunctionDescProto function = findFunction(request.getSignature(), request.getParameterTypesList());
         return function;
       }
     }
@@ -591,7 +590,6 @@ public class CatalogServer extends AbstractService {
       } else {
         returnValue = containFunction(request.getSignature(), request.getParameterTypesList());
       }
-
       return BoolProto.newBuilder().setValue(returnValue).build();
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/d0206493/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
index 5d6f747..1ac9d80 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
@@ -974,7 +974,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements
Catalo
       }
       proto = resultToIndexDescProto(res);
     } catch (SQLException se) {
-      new IOException(se);
+      throw new IOException(se);
     } finally {
       CatalogUtil.closeSQLWrapper(res, stmt);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/d0206493/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
b/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
index 4dfc97a..441ffe5 100644
--- a/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
+++ b/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
@@ -59,6 +59,10 @@ public class TestCatalog {
     server.init(conf);
     server.start();
     catalog = new LocalCatalogWrapper(server);
+
+    for(String table : catalog.getAllTableNames()){
+      catalog.deleteTable(table);
+    }
 	}
 	
 	@AfterClass
@@ -87,7 +91,7 @@ public class TestCatalog {
     catalog.deleteTable("getTable");
     assertFalse(catalog.existsTable("getTable"));
 	}
-	
+
 	@Test
 	public void testAddTableNoName() throws Exception {
 	  schema1 = new Schema();
@@ -98,9 +102,9 @@ public class TestCatalog {
 	  TableMeta info = CatalogUtil.newTableMeta(StoreType.CSV);
 	  TableDesc desc = new TableDesc();
 	  desc.setMeta(info);
-	  
-	  assertFalse(catalog.addTable(desc));
-	}
+
+    assertFalse(catalog.addTable(desc));
+  }
 
   static IndexDesc desc1;
   static IndexDesc desc2;
@@ -123,7 +127,7 @@ public class TestCatalog {
 	@Test
 	public void testAddAndDelIndex() throws Exception {
 	  TableDesc desc = TestDBStore.prepareTable();
-	  catalog.addTable(desc);
+	  assertTrue(catalog.addTable(desc));
 	  
 	  assertFalse(catalog.existIndex(desc1.getName()));
 	  assertFalse(catalog.existIndex("indexed", "id"));
@@ -143,7 +147,8 @@ public class TestCatalog {
 	  assertFalse(catalog.existIndex(desc2.getName()));
 	  
 	  catalog.deleteTable(desc.getName());
-	}
+    assertFalse(catalog.existsTable(desc.getName()));
+  }
 	
 	public static class TestFunc1 extends Function {
 		public TestFunc1() {
@@ -173,23 +178,23 @@ public class TestCatalog {
     }
   }
 
-  @Test(expected = NoSuchFunctionException.class)
-	public final void testRegisterAndFindFunc() throws Exception { 
-		assertFalse(catalog.containFunction("test10", FunctionType.GENERAL));
-		FunctionDesc meta = new FunctionDesc("test10", TestFunc2.class, FunctionType.GENERAL,
+  @Test
+  public final void testRegisterAndFindFunc() throws Exception {
+    assertFalse(catalog.containFunction("test10", FunctionType.GENERAL));
+    FunctionDesc meta = new FunctionDesc("test10", TestFunc2.class, FunctionType.GENERAL,
         CatalogUtil.newSimpleDataType(Type.INT4),
         CatalogUtil.newSimpleDataTypeArray(Type.INT4, Type.BLOB));
 
     catalog.createFunction(meta);
-		assertTrue(catalog.containFunction("test10", CatalogUtil.newSimpleDataTypeArray(Type.INT4,
Type.BLOB)));
-		FunctionDesc retrived = catalog.getFunction("test10", CatalogUtil.newSimpleDataTypeArray(Type.INT4,
Type.BLOB));
+    assertTrue(catalog.containFunction("test10", CatalogUtil.newSimpleDataTypeArray(Type.INT4,
Type.BLOB)));
+    FunctionDesc retrived = catalog.getFunction("test10", CatalogUtil.newSimpleDataTypeArray(Type.INT4,
Type.BLOB));
 
-		assertEquals(retrived.getSignature(),"test10");
-		assertEquals(retrived.getFuncClass(),TestFunc2.class);
-		assertEquals(retrived.getFuncType(),FunctionType.GENERAL);
+    assertEquals(retrived.getSignature(), "test10");
+    assertEquals(retrived.getFuncClass(), TestFunc2.class);
+    assertEquals(retrived.getFuncType(), FunctionType.GENERAL);
 
-		catalog.getFunction("test10", CatalogUtil.newSimpleDataTypeArray(Type.BLOB, Type.INT4));
-	}
+    assertFalse(catalog.containFunction("test10", CatalogUtil.newSimpleDataTypeArray(Type.BLOB,
Type.INT4)));
+  }
   
 
 	@Test
@@ -208,9 +213,17 @@ public class TestCatalog {
 		assertEquals(retrived.getFuncType(),FunctionType.UDF);
 	}
 
-  @Test(expected = NoSuchFunctionException.class)
+  @Test
   public final void testSuchFunctionException() throws Exception {
-    catalog.getFunction("test123", CatalogUtil.newSimpleDataTypeArray(Type.INT4));
+    try {
+      assertFalse(catalog.containFunction("test123", CatalogUtil.newSimpleDataTypeArray(Type.INT4)));
+      catalog.getFunction("test123", CatalogUtil.newSimpleDataTypeArray(Type.INT4));
+      fail();
+    } catch (NoSuchFunctionException nsfe) {
+      // succeed test
+    } catch (Throwable e) {
+      fail(e.getMessage());
+    }
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/d0206493/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprAnnotator.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprAnnotator.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprAnnotator.java
index f25064f..4c2118e 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprAnnotator.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprAnnotator.java
@@ -394,9 +394,7 @@ public class ExprAnnotator extends BaseAlgebraVisitor<ExprAnnotator.Context,
Eva
     }
 
     FunctionDesc funcDesc = catalog.getFunction(expr.getSignature(), paramTypes);
-    if (funcDesc == null) {
-      throw new NoSuchFunctionException(expr.getSignature(), paramTypes);
-    }
+
     try {
     CatalogProtos.FunctionType functionType = funcDesc.getFuncType();
     if (functionType == CatalogProtos.FunctionType.GENERAL


Mime
View raw message