@Override public List<String> listRoleNames() { boolean success = false; Query query = null; try { openTransaction(); LOG.debug("Executing listAllRoleNames"); query = pm.newQuery("select roleName from org.apache.hadoop.hive.metastore.model.MRole"); query.setResult("roleName"); Collection names = (Collection) query.execute(); List<String> roleNames = new ArrayList<>(); for (Iterator i = names.iterator(); i.hasNext();) { roleNames.add((String) i.next()); } success = commitTransaction(); return roleNames; } finally { rollbackAndCleanup(success, query); } }
query = pm.newQuery(MTable.class); query.declareImports("import java.lang.String"); query.setResult("tableName"); query.setResultClass(java.lang.String.class); if (maxTables >= 0) {
@Override public List<String> getCatalogs() throws MetaException { LOG.debug("Fetching all catalog names"); boolean commited = false; List<String> catalogs = null; String queryStr = "select name from org.apache.hadoop.hive.metastore.model.MCatalog"; Query query = null; openTransaction(); try { query = pm.newQuery(queryStr); query.setResult("name"); catalogs = new ArrayList<>((Collection<String>) query.execute()); commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } Collections.sort(catalogs); return catalogs; }
query.setResult("functionName"); query.setOrdering("functionName ascending"); Collection names = (Collection) query.executeWithArray(parameterVals.toArray(new String[parameterVals.size()]));
@Override public List<String> getDatabases(String catName, String pattern) throws MetaException { if (pattern == null || pattern.equals("*")) { return getAllDatabases(catName); } boolean commited = false; List<String> databases = null; Query query = null; try { openTransaction(); // Take the pattern and split it on the | to get all the composing // patterns String[] subpatterns = pattern.trim().split("\\|"); StringBuilder filterBuilder = new StringBuilder(); List<String> parameterVals = new ArrayList<>(subpatterns.length); appendSimpleCondition(filterBuilder, "catalogName", new String[] {catName}, parameterVals); appendPatternCondition(filterBuilder, "name", subpatterns, parameterVals); query = pm.newQuery(MDatabase.class, filterBuilder.toString()); query.setResult("name"); query.setOrdering("name ascending"); Collection<String> names = (Collection<String>) query.executeWithArray(parameterVals.toArray(new String[0])); databases = new ArrayList<>(names); commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } return databases; }
} else { query.setResult(Joiner.on(',').join(fieldNames));
@Override public List<String> getAllDatabases(String catName) throws MetaException { boolean commited = false; List<String> databases = null; Query query = null; catName = normalizeIdentifier(catName); openTransaction(); try { query = pm.newQuery("select name from org.apache.hadoop.hive.metastore.model.MDatabase " + "where catalogName == catname"); query.declareParameters("java.lang.String catname"); query.setResult("name"); databases = new ArrayList<>((Collection<String>) query.execute(catName)); commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } Collections.sort(databases); return databases; }
query.setOrdering("partitionName descending"); query.setResult("partitionName");
private List<String> getPartitionNamesNoTxn(String catName, String dbName, String tableName, short max) { List<String> pns = new ArrayList<>(); if (max == 0) { return pns; } catName = normalizeIdentifier(catName); dbName = normalizeIdentifier(dbName); tableName = normalizeIdentifier(tableName); Query query = pm.newQuery("select partitionName from org.apache.hadoop.hive.metastore.model.MPartition " + "where table.database.name == t1 && table.tableName == t2 && table.database.catalogName == t3 " + "order by partitionName asc"); query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3"); query.setResult("partitionName"); if (max > 0) { query.setRange(0, max); } Collection<String> names = (Collection<String>) query.execute(dbName, tableName, catName); pns.addAll(names); if (query != null) { query.closeAll(); } return pns; }
query.setResult("tableName"); query.setOrdering("tableName ascending"); Collection<String> names = (Collection<String>) query.executeWithArray(parameterVals.toArray(new String[0]));
private boolean constraintNameAlreadyExists(String name) { boolean commited = false; Query constraintExistsQuery = null; String constraintNameIfExists = null; try { openTransaction(); name = normalizeIdentifier(name); constraintExistsQuery = pm.newQuery(MConstraint.class, "constraintName == name"); constraintExistsQuery.declareParameters("java.lang.String name"); constraintExistsQuery.setUnique(true); constraintExistsQuery.setResult("name"); constraintNameIfExists = (String) constraintExistsQuery.execute(name); commited = commitTransaction(); } finally { rollbackAndCleanup(commited, constraintExistsQuery); } return constraintNameIfExists != null && !constraintNameIfExists.isEmpty(); }
/** * Detaches column descriptors from storage descriptors; returns the set of unique CDs * thus detached. This is done before dropping partitions because CDs are reused between * SDs; so, we remove the links to delete SDs and then check the returned CDs to see if * they are referenced by other SDs. */ private HashSet<MColumnDescriptor> detachCdsFromSdsNoTxn( String catName, String dbName, String tblName, List<String> partNames) { ObjectPair<Query, Map<String, String>> queryWithParams = getPartQueryWithParams(catName, dbName, tblName, partNames); Query query = queryWithParams.getFirst(); query.setClass(MPartition.class); query.setResult("sd"); @SuppressWarnings("unchecked") List<MStorageDescriptor> sds = (List<MStorageDescriptor>)query.executeWithMap( queryWithParams.getSecond()); HashSet<MColumnDescriptor> candidateCds = new HashSet<>(); for (MStorageDescriptor sd : sds) { if (sd != null && sd.getCD() != null) { candidateCds.add(sd.getCD()); sd.setCD(null); } } if (query != null) { query.closeAll(); } return candidateCds; }
q.setResult(partValuesSelect.toString());
private boolean poolHasChildren(MWMResourcePlan resourcePlan, String poolPath) { boolean commited = false; Query query = null; try { openTransaction(); query = pm.newQuery(MWMPool.class, "resourcePlan == rp && path.startsWith(poolPath)"); query.declareParameters("MWMResourcePlan rp, java.lang.String poolPath"); query.setResult("count(this)"); query.setUnique(true); Long count = (Long) query.execute(resourcePlan, poolPath + "."); commited = commitTransaction(); return count != null && count > 0; } finally { rollbackAndCleanup(commited, query); } }
+ "&& this.table.tableName == t3"); query.declareParameters("String t1, String t2, String t3"); query.setResult("this.partitionName, this.sd.location"); if (max >= 0) {
dbExistsQuery.declareParameters("java.lang.String db, java.lang.String cat"); dbExistsQuery.setUnique(true); dbExistsQuery.setResult("name"); String dbNameIfExists = (String) dbExistsQuery.execute(db, catName); if (org.apache.commons.lang.StringUtils.isEmpty(dbNameIfExists)) {
@Override public List<String> getMaterializedViewsForRewriting(String catName, String dbName) throws MetaException, NoSuchObjectException { final String db_name = normalizeIdentifier(dbName); catName = normalizeIdentifier(catName); boolean commited = false; Query<?> query = null; List<String> tbls = null; try { openTransaction(); dbName = normalizeIdentifier(dbName); query = pm.newQuery(MTable.class, "database.name == db && database.catalogName == cat && tableType == tt && rewriteEnabled == re"); query.declareParameters( "java.lang.String db, java.lang.String cat, java.lang.String tt, boolean re"); query.setResult("tableName"); Collection<String> names = (Collection<String>) query.executeWithArray( db_name, catName, TableType.MATERIALIZED_VIEW.toString(), true); tbls = new ArrayList<>(names); commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } return tbls; }
query.setResult(resultsCol);
public Long getTotal() { if (total == null) { Query newQuery = query.getPersistenceManager().newQuery(query); newQuery.setOrdering(null); newQuery.setResult("COUNT(id)"); total = (Long) newQuery.executeWithMap(map); } return total; }
private void checkSetResultFails(PersistenceManager pm, String s) { Query q = pm.newQuery(TestClass.class); q.setResult(s); try { q.execute(); fail(); } catch (JDOUserException e) { //good, we got an JDOUSerException() } }