@Override public ReturnState createTable(RpcController controller, TableDescProto request) { String[] splitted = CatalogUtil.splitFQTableName(request.getTableName()); String dbName = splitted[0]; String tbName = splitted[1]; if (linkedMetadataManager.existsDatabase(dbName)) { return errInsufficientPrivilege("drop a table in database '" + dbName + "'"); } if (metaDictionary.isSystemDatabase(dbName)) { return errInsufficientPrivilege("create a table in database '" + dbName + "'"); } wlock.lock(); try { store.createTable(request); LOG.info( String.format( "relation \"%s\" is added to the catalog (%s)", CatalogUtil.getCanonicalTableName(dbName, tbName), bindAddressStr)); return OK; } catch (Throwable t) { printStackTraceIfError(LOG, t); return returnError(t); } finally { wlock.unlock(); } }
@Override public ReturnState dropTable(RpcController controller, TableIdentifierProto request) throws ServiceException { String dbName = request.getDatabaseName(); String tbName = request.getTableName(); if (linkedMetadataManager.existsDatabase(dbName)) { return errInsufficientPrivilege("drop a table in database '" + dbName + "'"); } if (metaDictionary.isSystemDatabase(dbName)) { return errInsufficientPrivilege("drop a table in database '" + dbName + "'"); } wlock.lock(); try { store.dropTable(dbName, tbName); LOG.info( String.format( "relation \"%s\" is deleted from the catalog (%s)", CatalogUtil.getCanonicalTableName(dbName, tbName), bindAddressStr)); return OK; } catch (Throwable t) { printStackTraceIfError(LOG, t); return returnError(t); } finally { wlock.unlock(); } }
private FunctionDescProto findFunction( String signature, FunctionType type, List<TajoDataTypes.DataType> params, boolean strictTypeCheck) { List<FunctionDescProto> candidates = Lists.newArrayList(); if (functions.containsKey(signature)) { if (strictTypeCheck) { for (FunctionDescProto func : functions.get(signature)) { if (func.getSignature().getType() == type && func.getSignature().getParameterTypesList().equals(params)) { candidates.add(func); } } } else { for (FunctionDescProto func : functions.get(signature)) { if (func.getSignature().getParameterTypesList() != null && CatalogUtil.isMatchedFunction( func.getSignature().getParameterTypesList(), params)) { candidates.add(func); } } } } // if there are more than one function candidates, we choose the nearest matched function. if (candidates.size() > 0) { return findNearestMatchedFunction(candidates); } else { return null; } }
@Override public ReturnState alterTable(RpcController controller, AlterTableDescProto proto) { String[] split = CatalogUtil.splitTableName(proto.getTableName()); if (linkedMetadataManager.existsDatabase(split[0])) { return errInsufficientPrivilege("alter a table in database '" + split[0] + "'"); } if (metaDictionary.isSystemDatabase(split[0])) { return errInsufficientPrivilege("alter a table in database '" + split[0] + "'"); } wlock.lock(); try { store.alterTable(proto); return OK; } catch (Throwable t) { printStackTraceIfError(LOG, t); return returnError(t); } finally { wlock.unlock(); } }
private FunctionDescProto findFunction(String signature, List<TajoDataTypes.DataType> params) { List<FunctionDescProto> candidates = Lists.newArrayList(); if (functions.containsKey(signature)) { for (FunctionDescProto func : functions.get(signature)) { if (func.getSignature().getParameterTypesList() != null && func.getSignature().getParameterTypesList().equals(params)) { candidates.add(func); } } } /* * * FALL BACK to look for nearest match * WORKING BUT BAD WAY TO IMPLEMENT.I WOULD RATHER implement compareTo in FunctionDesc to keep them * in sorted order of param types LIKE INT1 SHOULD BE BEFORE INT2 should be before INT3 so on. * Due to possibility of multiple parameters and types the permutation and combinations are endless * to implement compareTo so decided to take the shortcut. * * */ if (functions.containsKey(signature)) { for (FunctionDescProto func : functions.get(signature)) { if (func.getSignature().getParameterTypesList() != null && CatalogUtil.isMatchedFunction( func.getSignature().getParameterTypesList(), params)) { candidates.add(func); } } // if there are more than one function candidates, we choose the nearest matched function. if (candidates.size() > 0) { return findNearestMatchedFunction(candidates); } else { return null; } } return null; }