use of io.hops.hopsworks.persistence.entity.featurestore.featuregroup.cached.CachedFeature in project hopsworks by logicalclocks.
the class CachedFeaturegroupController method persistCachedFeaturegroupMetadata.
/**
* Persists metadata of a new cached feature group in the cached_feature_group table
*
* @param hiveTable the id of the Hive table in the Hive metastore
* @return Entity of the created cached feature group
*/
private CachedFeaturegroup persistCachedFeaturegroupMetadata(HiveTbls hiveTable, boolean onlineEnabled, TimeTravelFormat timeTravelFormat, List<FeatureGroupFeatureDTO> featureGroupFeatureDTOS) {
CachedFeaturegroup cachedFeaturegroup = new CachedFeaturegroup();
cachedFeaturegroup.setHiveTbls(hiveTable);
cachedFeaturegroup.setOnlineEnabled(onlineEnabled);
cachedFeaturegroup.setTimeTravelFormat(timeTravelFormat);
cachedFeaturegroup.setFeaturesExtraConstraints(buildFeatureExtraConstrains(featureGroupFeatureDTOS, cachedFeaturegroup));
cachedFeaturegroup.setCachedFeatures(featureGroupFeatureDTOS.stream().filter(feature -> feature.getDescription() != null).map(feature -> new CachedFeature(cachedFeaturegroup, feature.getName(), feature.getDescription())).collect(Collectors.toList()));
cachedFeatureGroupFacade.persist(cachedFeaturegroup);
return cachedFeaturegroup;
}
use of io.hops.hopsworks.persistence.entity.featurestore.featuregroup.cached.CachedFeature in project hopsworks by logicalclocks.
the class CachedFeaturegroupController method getFeaturesDTO.
public List<FeatureGroupFeatureDTO> getFeaturesDTO(Featuregroup featureGroup, Project project, Users user) throws FeaturestoreException {
Collection<CachedFeatureExtraConstraints> featureExtraConstraints = featureGroup.getCachedFeaturegroup().getFeaturesExtraConstraints();
HiveTbls hiveTable = featureGroup.getCachedFeaturegroup().getHiveTbls();
List<SQLDefaultConstraint> defaultConstraints = offlineFeatureGroupController.getDefaultConstraints(featureGroup.getFeaturestore(), hiveTable.getTblName(), project, user);
Collection<CachedFeature> cachedFeatures = featureGroup.getCachedFeaturegroup().getCachedFeatures();
List<FeatureGroupFeatureDTO> featureGroupFeatureDTOS = new ArrayList<>();
boolean primary;
boolean hudiPrecombine;
String defaultValue;
String description;
// Add all the columns - if there is a primary key constraint, set the primary key flag
List<HiveColumns> sortedFeatures = hiveTable.getSdId().getCdId().getHiveColumnsCollection().stream().sorted(Comparator.comparing(HiveColumns::getIntegerIdx)).collect(Collectors.toList());
for (HiveColumns hc : sortedFeatures) {
primary = getPrimaryFlag(featureExtraConstraints, hc.getHiveColumnsPK().getColumnName());
hudiPrecombine = getPrecombineFlag(featureGroup, featureExtraConstraints, hc.getHiveColumnsPK().getColumnName());
description = getDescription(cachedFeatures, hc.getHiveColumnsPK().getColumnName());
defaultValue = getDefaultValue(defaultConstraints, hc.getHiveColumnsPK().getColumnName());
featureGroupFeatureDTOS.add(new FeatureGroupFeatureDTO(hc.getHiveColumnsPK().getColumnName(), hc.getTypeName(), description, primary, false, hudiPrecombine, defaultValue, featureGroup.getId()));
}
// Hive stores the partition columns separately
// sort partition columns reversely cause they are then added at the beginning of list and therefore correct
// order again
List<HivePartitionKeys> sortedPartitionKeys = hiveTable.getHivePartitionKeysCollection().stream().sorted(Collections.reverseOrder(Comparator.comparing(HivePartitionKeys::getIntegerIdx))).collect(Collectors.toList());
for (HivePartitionKeys pk : sortedPartitionKeys) {
primary = getPrimaryFlag(featureExtraConstraints, pk.getHivePartitionKeysPK().getPkeyName());
hudiPrecombine = getPrecombineFlag(featureGroup, featureExtraConstraints, pk.getHivePartitionKeysPK().getPkeyName());
defaultValue = getDefaultValue(defaultConstraints, pk.getHivePartitionKeysPK().getPkeyName());
// insert partition keys at beginning
featureGroupFeatureDTOS.add(0, new FeatureGroupFeatureDTO(pk.getHivePartitionKeysPK().getPkeyName(), pk.getPkeyType(), pk.getPkeyComment(), primary, true, hudiPrecombine, defaultValue, featureGroup.getId()));
}
if (featureGroup.getCachedFeaturegroup().getTimeTravelFormat() == TimeTravelFormat.HUDI) {
featureGroupFeatureDTOS = dropHudiSpecFeatureGroupFeature(featureGroupFeatureDTOS);
}
return featureGroupFeatureDTOS;
}
Aggregations