Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOPSWORKS-2238] Feature Group schema primary key info not set for partition keys #792

Merged
merged 1 commit into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hopsworks-IT/src/test/ruby/spec/featuregroup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1075,8 +1075,8 @@
parsed_json = JSON.parse(json_result)
expect_status(200)

expect(parsed_json.first["features"].select{ |f| f["name"] == "testfeature"}.first["primary"] == true)
expect(parsed_json.first["features"].select{ |f| f["name"] == "testfeature"}.first["partition"] == true)
expect(parsed_json.first["features"].select{ |f| f["name"] == "testfeature"}.first["primary"]).to be true
expect(parsed_json.first["features"].select{ |f| f["name"] == "testfeature"}.first["partition"]).to be true
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,21 @@ public List<FeatureGroupFeatureDTO> getFeaturesDTO(CachedFeaturegroup cachedFeat
offlineFeatureGroupController.getDefaultConstraints(featurestore, hiveTable.getTblName(), project, user);

List<FeatureGroupFeatureDTO> featureGroupFeatureDTOS = new ArrayList<>();
boolean primary;
String defaultValue;
// Add all the columns - if there is a primary key constraint, set the primary key flag
for (HiveColumns hc : hiveTable.getSdId().getCdId().getHiveColumnsCollection()) {
boolean primary = featureExtraConstraints.stream().anyMatch(pk ->
pk.getName().equals(hc.getHiveColumnsPK().getColumnName()));
String defaultValue = getDefaultValue(defaultConstraints, hc.getHiveColumnsPK().getColumnName());
primary = getPrimaryFlag(featureExtraConstraints, hc.getHiveColumnsPK().getColumnName());
defaultValue = getDefaultValue(defaultConstraints, hc.getHiveColumnsPK().getColumnName());
featureGroupFeatureDTOS.add(new FeatureGroupFeatureDTO(hc.getHiveColumnsPK().getColumnName(), hc.getTypeName(),
hc.getComment(), primary, defaultValue));
}
// Hive stores the partition columns separately. Add them
for (HivePartitionKeys pk : hiveTable.getHivePartitionKeysCollection()) {
String defaultValue = getDefaultValue(defaultConstraints, pk.getHivePartitionKeysPK().getPkeyName());
primary = getPrimaryFlag(featureExtraConstraints, pk.getHivePartitionKeysPK().getPkeyName());
defaultValue = getDefaultValue(defaultConstraints, pk.getHivePartitionKeysPK().getPkeyName());
featureGroupFeatureDTOS.add(new FeatureGroupFeatureDTO(pk.getHivePartitionKeysPK().getPkeyName(),
pk.getPkeyType(), pk.getPkeyComment(), false, true, defaultValue));
pk.getPkeyType(), pk.getPkeyComment(), primary, true, defaultValue));
}
if (cachedFeaturegroup.getTimeTravelFormat() == TimeTravelFormat.HUDI){
featureGroupFeatureDTOS = dropHudiSpecFeatureGroupFeature(featureGroupFeatureDTOS);
Expand All @@ -430,6 +432,10 @@ private String getDefaultValue(List<SQLDefaultConstraint> defaultConstraints, St
.map(SQLDefaultConstraint::getDefault_value).findAny().orElse(null);
}

private boolean getPrimaryFlag(Collection<CachedFeatureExtraConstraints> featureExtraConstraints, String columnName) {
return featureExtraConstraints.stream().anyMatch(pk -> pk.getName().equals(columnName));
}

/**
* Gets the SQL schema that was used to create the Hive table for a featuregroup
*
Expand Down