public static Map<String, Map<UpdatePeriod, String>> storageTablePrefixMapOfStorage(XStorageTables storageTables) { Map<String, Map<UpdatePeriod, String>> storageTableMap = new HashMap<>(); if (storageTables != null && !storageTables.getStorageTable().isEmpty()) { for (XStorageTableElement sTbl : storageTables.getStorageTable()) { Map<UpdatePeriod, String> storageNameMap = new HashMap<>(); if (sTbl.getUpdatePeriods() != null && sTbl.getUpdatePeriods().getUpdatePeriodTableDescriptor() != null && !sTbl .getUpdatePeriods().getUpdatePeriodTableDescriptor().isEmpty()) { for (XUpdatePeriodTableDescriptor updatePeriodTable : sTbl.getUpdatePeriods() .getUpdatePeriodTableDescriptor()) { // Get table name with update period as the prefix. storageNameMap.put(UpdatePeriod.valueOf(updatePeriodTable.getUpdatePeriod().value()), updatePeriodTable.getUpdatePeriod() + "_" + sTbl.getStorageName()); } } else { for (XUpdatePeriod updatePeriod : sTbl.getUpdatePeriods().getUpdatePeriod()) { storageNameMap.put(UpdatePeriod.valueOf(updatePeriod.value()), sTbl.getStorageName()); } } storageTableMap.put(sTbl.getStorageName(), storageNameMap); } } return storageTableMap; }
public static Map<String, Map<UpdatePeriod, String>> storageTablePrefixMapOfStorage(XStorageTables storageTables) { Map<String, Map<UpdatePeriod, String>> storageTableMap = new HashMap<>(); if (storageTables != null && !storageTables.getStorageTable().isEmpty()) { for (XStorageTableElement sTbl : storageTables.getStorageTable()) { Map<UpdatePeriod, String> storageNameMap = new HashMap<>(); if (sTbl.getUpdatePeriods() != null && sTbl.getUpdatePeriods().getUpdatePeriodTableDescriptor() != null && !sTbl .getUpdatePeriods().getUpdatePeriodTableDescriptor().isEmpty()) { for (XUpdatePeriodTableDescriptor updatePeriodTable : sTbl.getUpdatePeriods() .getUpdatePeriodTableDescriptor()) { // Get table name with update period as the prefix. storageNameMap.put(UpdatePeriod.valueOf(updatePeriodTable.getUpdatePeriod().value()), updatePeriodTable.getUpdatePeriod() + "_" + sTbl.getStorageName()); } } else { for (XUpdatePeriod updatePeriod : sTbl.getUpdatePeriods().getUpdatePeriod()) { storageNameMap.put(UpdatePeriod.valueOf(updatePeriod.value()), sTbl.getStorageName()); } } storageTableMap.put(sTbl.getStorageName(), storageNameMap); } } return storageTableMap; }
@Override public void updatePartitions(LensSessionHandle sessionid, String tblName, String storageName, XPartitionList xPartitions) throws LensException { try (SessionContext ignored = new SessionContext(sessionid)) { CubeMetastoreClient client = getClient(sessionid); Set<String> storageTableNames = getAllTablesForStorage(sessionid, tblName, storageName); Map<UpdatePeriod, List<Partition>> partitionsToUpdate = new HashMap<>(); for (String storageTableName : storageTableNames) { for (XPartition xPartition : xPartitions.getPartition()) { Partition existingPartition = client.getPartitionByFilter(storageTableName, StorageConstants.getPartFilter(JAXBUtils.getFullPartSpecAsMap(xPartition))); JAXBUtils.updatePartitionFromXPartition(existingPartition, xPartition); UpdatePeriod updatePeriod = UpdatePeriod.valueOf(xPartition.getUpdatePeriod().value()); List<Partition> partitionList = partitionsToUpdate.get(updatePeriod); if (partitionList == null) { partitionList = new ArrayList<>(); partitionsToUpdate.put(updatePeriod, partitionList); } partitionList.add(existingPartition); } } client.updatePartitions(tblName, storageName, partitionsToUpdate); } catch (HiveException | ClassNotFoundException | InvalidOperationException exc) { throw new LensException(exc); } }
@Override public void updatePartition(LensSessionHandle sessionid, String tblName, String storageName, XPartition xPartition) throws LensException { try (SessionContext ignored = new SessionContext(sessionid)) { CubeMetastoreClient client = getClient(sessionid); String storageTableName = client .getStorageTableName(tblName, storageName, UpdatePeriod.valueOf(xPartition.getUpdatePeriod().name())); Partition existingPartition = client.getPartitionByFilter(storageTableName, StorageConstants.getPartFilter(JAXBUtils.getFullPartSpecAsMap(xPartition))); JAXBUtils.updatePartitionFromXPartition(existingPartition, xPartition); client.updatePartition(tblName, storageName, existingPartition, UpdatePeriod.valueOf(xPartition.getUpdatePeriod().value())); } catch (HiveException | ClassNotFoundException | InvalidOperationException | UnsupportedOperationException exc) { throw new LensException(exc); } }