/** * Add a new partition for a storage of dimension * * @param sessionid The sessionid in which user is working * @param dimTableName dimension table name * @param storage storage name * @param partition {@link XPartition} representation of partition * @return {@link APIResult} with state {@link Status#SUCCEEDED}, if add was successful. {@link APIResult} with state * {@link Status#FAILED}, if add has failed */ @POST @Path("/dimtables/{dimTableName}/storages/{storage}/partition") public APIResult addPartitionToDimStorage(@QueryParam("sessionid") LensSessionHandle sessionid, @PathParam("dimTableName") String dimTableName, @PathParam("storage") String storage, XPartition partition) throws LensException { checkSessionId(sessionid); checkNonNullArgs("Partition is null", partition); checkNonNullArgs("Partition elements are null", partition.getFactOrDimensionTableName(), partition.getUpdatePeriod()); return successOrPartialOrFailure(getSvc().addPartitionToDimStorage(sessionid, dimTableName, storage, partition), 1); }
/** * Add a new partition for a storage of fact * * @param sessionid The sessionid in which user is working * @param factName fact table name * @param storage storage name * @param partition {@link XPartition} representation of partition * @return {@link APIResult} with state {@link Status#SUCCEEDED}, if add was successful. {@link APIResult} with state * {@link Status#FAILED}, if add has failed */ @POST @Path("/facts/{factName}/storages/{storage}/partition") public APIResult addPartitionToFactStorage(@QueryParam("sessionid") LensSessionHandle sessionid, @PathParam("factName") String factName, @PathParam("storage") String storage, XPartition partition) throws LensException { checkSessionId(sessionid); checkNonNullArgs("Partition is null", partition); checkNonNullArgs("Partition elements are null", partition.getFactOrDimensionTableName(), partition.getUpdatePeriod()); return successOrPartialOrFailure(getSvc().addPartitionToFactStorage(sessionid, factName, storage, partition), 1); }
@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); } }
public static Map<String, String> getFullPartSpecAsMap(XPartition partition) { Map<String, String> spec = Maps.newHashMap(); if (partition.getTimePartitionSpec() != null) { for (XTimePartSpecElement timePartSpecElement : partition.getTimePartitionSpec().getPartSpecElement()) { spec.put(timePartSpecElement.getKey(), UpdatePeriod.valueOf(partition.getUpdatePeriod().name()).format() .format(getDateFromXML(timePartSpecElement.getValue()))); } } if (partition.getNonTimePartitionSpec() != null) { for (XPartSpecElement partSpecElement : partition.getNonTimePartitionSpec().getPartSpecElement()) { spec.put(partSpecElement.getKey(), partSpecElement.getValue()); } } return spec; } }
public static Map<String, String> getFullPartSpecAsMap(XPartition partition) { Map<String, String> spec = Maps.newHashMap(); if (partition.getTimePartitionSpec() != null) { for (XTimePartSpecElement timePartSpecElement : partition.getTimePartitionSpec().getPartSpecElement()) { spec.put(timePartSpecElement.getKey(), UpdatePeriod.valueOf(partition.getUpdatePeriod().name()).format() .format(getDateFromXML(timePartSpecElement.getValue()))); } } if (partition.getNonTimePartitionSpec() != null) { for (XPartSpecElement partSpecElement : partition.getNonTimePartitionSpec().getPartSpecElement()) { spec.put(partSpecElement.getKey(), partSpecElement.getValue()); } } return spec; } }
private APIResult checkAndUpdatePartitions(LensSessionHandle sessionid, String table, String storage, XPartition partition) throws LensException { checkSessionId(sessionid); checkNonNullArgs("Partition is null", partition); checkNonNullArgs("Partition elements are null", partition.getFactOrDimensionTableName(), partition.getUpdatePeriod()); getSvc().updatePartition(sessionid, table, storage, partition); return success(); } }
public static void updatePartitionFromXPartition(Partition partition, XPartition xp) throws ClassNotFoundException { partition.getParameters().putAll(mapFromXProperties(xp.getPartitionParameters())); partition.getTPartition().getSd().getSerdeInfo().setParameters(mapFromXProperties(xp.getSerdeParameters())); partition.setLocation(xp.getLocation()); if (xp.getInputFormat() != null) { partition.setInputFormatClass(Class.forName(xp.getInputFormat()).asSubclass(InputFormat.class)); } if (xp.getOutputFormat() != null) { Class<? extends HiveOutputFormat> outputFormatClass = Class.forName(xp.getOutputFormat()).asSubclass(HiveOutputFormat.class); partition.setOutputFormatClass(outputFormatClass); } partition.getParameters().put(MetastoreConstants.PARTITION_UPDATE_PERIOD, xp.getUpdatePeriod().name()); partition.getTPartition().getSd().getSerdeInfo().setSerializationLib(xp.getSerdeClassname()); }
public static void updatePartitionFromXPartition(Partition partition, XPartition xp) throws ClassNotFoundException { partition.getParameters().putAll(mapFromXProperties(xp.getPartitionParameters())); partition.getTPartition().getSd().getSerdeInfo().setParameters(mapFromXProperties(xp.getSerdeParameters())); partition.setLocation(xp.getLocation()); if (xp.getInputFormat() != null) { partition.setInputFormatClass(Class.forName(xp.getInputFormat()).asSubclass(InputFormat.class)); } if (xp.getOutputFormat() != null) { Class<? extends HiveOutputFormat> outputFormatClass = Class.forName(xp.getOutputFormat()).asSubclass(HiveOutputFormat.class); partition.setOutputFormatClass(outputFormatClass); } partition.getParameters().put(MetastoreConstants.PARTITION_UPDATE_PERIOD, xp.getUpdatePeriod().name()); partition.getTPartition().getSd().getSerdeInfo().setSerializationLib(xp.getSerdeClassname()); }
@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); } }
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);
assertEquals(timePartSpec.getKey(), fullPartSpec.getKey()); assertEquals( UpdatePeriod.valueOf(xp.getUpdatePeriod().name()).format(JAXBUtils.getDateFromXML(timePartSpec.getValue())), fullPartSpec.getValue()); DateTime date = target().path("metastore/cubes").path("testCube").path("latestdate")
public static StoragePartitionDesc storagePartSpecFromXPartition( XPartition xpart) { StoragePartitionDesc partDesc = new StoragePartitionDesc( xpart.getFactOrDimensionTableName(), timePartSpecfromXTimePartSpec(xpart.getTimePartitionSpec()), nonTimePartSpecfromXNonTimePartSpec(xpart.getNonTimePartitionSpec()), UpdatePeriod.valueOf(xpart.getUpdatePeriod().name())); partDesc.setPartParams(mapFromXProperties(xpart.getPartitionParameters())); partDesc.setSerdeParams(mapFromXProperties(xpart.getSerdeParameters())); partDesc.setLocation(xpart.getLocation()); partDesc.setInputFormat(xpart.getInputFormat()); partDesc.setOutputFormat(xpart.getOutputFormat()); partDesc.setSerializationLib(xpart.getSerdeClassname()); return partDesc; }
public static StoragePartitionDesc storagePartSpecFromXPartition( XPartition xpart) { StoragePartitionDesc partDesc = new StoragePartitionDesc( xpart.getFactOrDimensionTableName(), timePartSpecfromXTimePartSpec(xpart.getTimePartitionSpec()), nonTimePartSpecfromXNonTimePartSpec(xpart.getNonTimePartitionSpec()), UpdatePeriod.valueOf(xpart.getUpdatePeriod().name())); partDesc.setPartParams(mapFromXProperties(xpart.getPartitionParameters())); partDesc.setSerdeParams(mapFromXProperties(xpart.getSerdeParameters())); partDesc.setLocation(xpart.getLocation()); partDesc.setInputFormat(xpart.getInputFormat()); partDesc.setOutputFormat(xpart.getOutputFormat()); partDesc.setSerializationLib(xpart.getSerdeClassname()); return partDesc; }
theUpdatePeriod = this.getUpdatePeriod(); strategy.appendField(locator, this, "updatePeriod", buffer, theUpdatePeriod);
theUpdatePeriod = this.getUpdatePeriod(); strategy.appendField(locator, this, "updatePeriod", buffer, theUpdatePeriod);
lhsUpdatePeriod = this.getUpdatePeriod(); XUpdatePeriod rhsUpdatePeriod; rhsUpdatePeriod = that.getUpdatePeriod(); if (!strategy.equals(LocatorUtils.property(thisLocator, "updatePeriod", lhsUpdatePeriod), LocatorUtils.property(thatLocator, "updatePeriod", rhsUpdatePeriod), lhsUpdatePeriod, rhsUpdatePeriod)) { return false;
lhsUpdatePeriod = this.getUpdatePeriod(); XUpdatePeriod rhsUpdatePeriod; rhsUpdatePeriod = that.getUpdatePeriod(); if (!strategy.equals(LocatorUtils.property(thisLocator, "updatePeriod", lhsUpdatePeriod), LocatorUtils.property(thatLocator, "updatePeriod", rhsUpdatePeriod), lhsUpdatePeriod, rhsUpdatePeriod)) { return false;
theUpdatePeriod = this.getUpdatePeriod(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "updatePeriod", theUpdatePeriod), currentHashCode, theUpdatePeriod);
theUpdatePeriod = this.getUpdatePeriod(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "updatePeriod", theUpdatePeriod), currentHashCode, theUpdatePeriod);