private Date getPartDate(Partition part, int timeColIndex) { String partVal = part.getValues().get(timeColIndex); String updatePeriodStr = part.getParameters().get(MetastoreConstants.PARTITION_UPDATE_PERIOD); Date partDate = null; if (updatePeriodStr != null) { UpdatePeriod partInterval = UpdatePeriod.valueOf(updatePeriodStr); try { partDate = partInterval.parse(partVal); } catch (ParseException e) { // ignore } } return partDate; }
private Date getPartDate(Partition part, int timeColIndex) { String partVal = part.getValues().get(timeColIndex); String updatePeriodStr = part.getParameters().get(MetastoreConstants.PARTITION_UPDATE_PERIOD); Date partDate = null; if (updatePeriodStr != null) { UpdatePeriod partInterval = UpdatePeriod.valueOf(updatePeriodStr); try { partDate = partInterval.parse(partVal); } catch (ParseException e) { // ignore } } return partDate; }
public static Date getLatestTimeStampFromPartition(Partition part, String partCol) throws HiveException { if (part != null) { String latestTimeStampStr = part.getParameters().get(MetastoreUtil.getLatestPartTimestampKey(partCol)); String latestPartUpdatePeriod = part.getParameters().get(PARTITION_UPDATE_PERIOD); UpdatePeriod latestUpdatePeriod = UpdatePeriod.valueOf(latestPartUpdatePeriod.toUpperCase()); try { return latestUpdatePeriod.parse(latestTimeStampStr); } catch (ParseException e) { throw new HiveException(e); } } return null; }
public static Date getLatestTimeStampFromPartition(Partition part, String partCol) throws HiveException { if (part != null) { String latestTimeStampStr = part.getParameters().get(MetastoreUtil.getLatestPartTimestampKey(partCol)); String latestPartUpdatePeriod = part.getParameters().get(PARTITION_UPDATE_PERIOD); UpdatePeriod latestUpdatePeriod = UpdatePeriod.valueOf(latestPartUpdatePeriod.toUpperCase()); try { return latestUpdatePeriod.parse(latestTimeStampStr); } catch (ParseException e) { throw new HiveException(e); } } return null; }
private UpdatePeriod populatePartSpec(Partition p, Map<String, Date> timeSpec, Map<String, String> nonTimeSpec) throws HiveException { String timePartColsStr = p.getTable().getTTable().getParameters().get(MetastoreConstants.TIME_PART_COLUMNS); String upParam = p.getParameters().get(MetastoreConstants.PARTITION_UPDATE_PERIOD); UpdatePeriod period = UpdatePeriod.valueOf(upParam); Map<String, String> partSpec = new HashMap<>(); partSpec.putAll(p.getSpec()); if (timePartColsStr != null) { String[] timePartCols = StringUtils.split(timePartColsStr, ','); for (String partCol : timePartCols) { String dateStr = partSpec.get(partCol); Date date; try { date = period.parse(dateStr); } catch (Exception e) { continue; } partSpec.remove(partCol); timeSpec.put(partCol, date); } } if (!partSpec.isEmpty()) { nonTimeSpec.putAll(partSpec); } return period; }
private Set<FactPartition> getFactParts(List<String> partStrings) throws ParseException { Set<FactPartition> factParts = new HashSet<FactPartition>(); for (String partStr : partStrings) { String[] partEls = partStr.split(" "); UpdatePeriod p = null; String partSpec = partEls[1]; switch (partSpec.length()) { case 7: //monthly p = UpdatePeriod.MONTHLY; break; case 10: // daily p = UpdatePeriod.DAILY; break; case 13: // hourly p = UpdatePeriod.HOURLY; break; } FactPartition part = new FactPartition(partEls[0], p.parse(partSpec), p, null, p.format(), Collections.singleton("table1")); factParts.add(part); } return factParts; }
public static TimePartition of(UpdatePeriod updatePeriod, String dateString) throws LensException { if (dateString == null || dateString.isEmpty()) { throw new LensException("time parition date string is null or blank"); } else { if (!updatePeriod.canParseDateString(dateString)) { throw new LensException(getWrongUpdatePeriodMessage(updatePeriod, dateString)); } try { return TimePartition.of(updatePeriod, updatePeriod.parse(dateString)); } catch (ParseException e) { throw new LensException(getWrongUpdatePeriodMessage(updatePeriod, dateString), e); } } }
public static TimePartition of(UpdatePeriod updatePeriod, String dateString) throws LensException { if (dateString == null || dateString.isEmpty()) { throw new LensException("time parition date string is null or blank"); } else { if (!updatePeriod.canParseDateString(dateString)) { throw new LensException(getWrongUpdatePeriodMessage(updatePeriod, dateString)); } try { return TimePartition.of(updatePeriod, updatePeriod.parse(dateString)); } catch (ParseException e) { throw new LensException(getWrongUpdatePeriodMessage(updatePeriod, dateString), e); } } }
@Test(dataProvider = "update-periods") public void testFormat(UpdatePeriod period) throws Exception { RandomDateGenerator randomDateGenerator = new RandomDateGenerator(); for (int i = 0; i < 5000; i++) { Date randomDate = randomDateGenerator.nextDate(); randomDate = period.truncate(randomDate); assertEquals(randomDate, period.parse(period.format(randomDate))); } } }
Date dropTimestamp; try { dropTimestamp = updatePeriod.parse(updatePeriod.format(timePartSpec.get(timeCol))); } catch (ParseException e) { throw new HiveException(e);
Date dropTimestamp; try { dropTimestamp = updatePeriod.parse(updatePeriod.format(timePartSpec.get(timeCol))); } catch (ParseException e) { throw new HiveException(e);
if (!nonTimeParts.containsKey(entry.getKey())) { try { updatePeriod.parse(entry.getValue()); } catch (java.text.ParseException e) { ignore = true;
timePartSpecElement.setKey(entry.getKey()); timePartSpecElement .setValue(getXMLGregorianCalendar(UpdatePeriod.valueOf(xp.getUpdatePeriod().name()).parse( entry.getValue()))); xp.getTimePartitionSpec().getPartSpecElement().add(timePartSpecElement);
timePartSpecElement.setKey(entry.getKey()); timePartSpecElement .setValue(getXMLGregorianCalendar(UpdatePeriod.valueOf(xp.getUpdatePeriod().name()).parse( entry.getValue()))); xp.getTimePartitionSpec().getPartSpecElement().add(timePartSpecElement);