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

fix(schema-blame): check if list of ChangeTransactions is empty before processing #7263

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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
Expand All @@ -21,6 +21,7 @@

/*
Returns the most recent changes made to each column in a dataset at each dataset version.
TODO: Add tests for this resolver.
*/
@Slf4j
public class GetSchemaBlameResolver implements DataFetcher<CompletableFuture<GetSchemaBlameResult>> {
Expand All @@ -41,11 +42,17 @@ public CompletableFuture<GetSchemaBlameResult> get(final DataFetchingEnvironment

return CompletableFuture.supplyAsync(() -> {
try {
final Set<ChangeCategory> changeCategorySet = new HashSet<>();
changeCategorySet.add(ChangeCategory.TECHNICAL_SCHEMA);
Urn datasetUrn = Urn.createFromString(datasetUrnString);
List<ChangeTransaction> changeTransactionList =
_timelineService.getTimeline(datasetUrn, changeCategorySet, startTime, endTime, null, null, false);
final Set<ChangeCategory> changeCategorySet = Collections.singleton(ChangeCategory.TECHNICAL_SCHEMA);
final Urn datasetUrn = Urn.createFromString(datasetUrnString);
final List<ChangeTransaction> changeTransactionList =
_timelineService.getTimeline(
datasetUrn,
changeCategorySet,
startTime,
endTime,
null,
null,
false);
return SchemaBlameMapper.map(changeTransactionList, version);
} catch (URISyntaxException u) {
log.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.extern.slf4j.Slf4j;
import org.apache.maven.artifact.versioning.ComparableVersion;
Expand All @@ -32,27 +33,29 @@
@Slf4j
public class SchemaBlameMapper {

public static GetSchemaBlameResult map(List<ChangeTransaction> changeTransactions, @Nullable String versionCutoff) {
GetSchemaBlameResult result = new GetSchemaBlameResult();
public static GetSchemaBlameResult map(@Nonnull final List<ChangeTransaction> changeTransactions,
@Nullable final String versionCutoff) {
final GetSchemaBlameResult result = new GetSchemaBlameResult();
if (changeTransactions.isEmpty()) {
log.debug("Change transactions are empty");
return result;
}

Map<String, SchemaFieldBlame> schemaBlameMap = new HashMap<>();
final Map<String, SchemaFieldBlame> schemaBlameMap = new HashMap<>();

String latestSemanticVersionString =
final String latestSemanticVersionString =
truncateSemanticVersion(changeTransactions.get(changeTransactions.size() - 1).getSemVer());

String semanticVersionFilterString = versionCutoff == null ? latestSemanticVersionString : versionCutoff;
Optional<ComparableVersion> semanticVersionFilterOptional = createSemanticVersion(semanticVersionFilterString);
if (!semanticVersionFilterOptional.isPresent()) {
final String semanticVersionFilterString = versionCutoff == null ? latestSemanticVersionString : versionCutoff;
final Optional<ComparableVersion> semanticVersionFilterOptional =
createSemanticVersion(semanticVersionFilterString);
if (semanticVersionFilterOptional.isEmpty()) {
return result;
}

ComparableVersion semanticVersionFilter = semanticVersionFilterOptional.get();
final ComparableVersion semanticVersionFilter = semanticVersionFilterOptional.get();

List<ChangeTransaction> reversedChangeTransactions = changeTransactions.stream()
final List<ChangeTransaction> reversedChangeTransactions = changeTransactions.stream()
.map(TimelineUtils::semanticVersionChangeTransactionPair)
.filter(Optional::isPresent)
.map(Optional::get)
Expand All @@ -62,9 +65,13 @@ public static GetSchemaBlameResult map(List<ChangeTransaction> changeTransaction
.map(Pair::getSecond)
.collect(Collectors.toList());

String selectedSemanticVersion = truncateSemanticVersion(reversedChangeTransactions.get(0).getSemVer());
long selectedSemanticVersionTimestamp = reversedChangeTransactions.get(0).getTimestamp();
String selectedVersionStamp = reversedChangeTransactions.get(0).getVersionStamp();
if (reversedChangeTransactions.isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here is the change- ok nice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup this is the important part. Made a bunch of things final just to improve readability

return result;
}

final String selectedSemanticVersion = truncateSemanticVersion(reversedChangeTransactions.get(0).getSemVer());
final long selectedSemanticVersionTimestamp = reversedChangeTransactions.get(0).getTimestamp();
final String selectedVersionStamp = reversedChangeTransactions.get(0).getVersionStamp();
result.setVersion(
new SemanticVersionStruct(selectedSemanticVersion, selectedSemanticVersionTimestamp, selectedVersionStamp));

Expand All @@ -74,12 +81,12 @@ public static GetSchemaBlameResult map(List<ChangeTransaction> changeTransaction
continue;
}

String schemaUrn = changeEvent.getModifier();
final String schemaUrn = changeEvent.getModifier();
if (schemaUrn == null || schemaBlameMap.containsKey(schemaUrn)) {
continue;
}

SchemaFieldBlame schemaFieldBlame = new SchemaFieldBlame();
final SchemaFieldBlame schemaFieldBlame = new SchemaFieldBlame();

SchemaFieldKey schemaFieldKey;
try {
Expand All @@ -90,10 +97,10 @@ public static GetSchemaBlameResult map(List<ChangeTransaction> changeTransaction
continue;
}

String fieldPath = schemaFieldKey.getFieldPath();
final String fieldPath = schemaFieldKey.getFieldPath();
schemaFieldBlame.setFieldPath(fieldPath);

SchemaFieldChange schemaFieldChange =
final SchemaFieldChange schemaFieldChange =
getLastSchemaFieldChange(changeEvent, changeTransaction.getTimestamp(), changeTransaction.getSemVer(),
changeTransaction.getVersionStamp());
schemaFieldBlame.setSchemaFieldChange(schemaFieldChange);
Expand Down