mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-31 04:25:29 +00:00
fix(metadata-io): remove assert in favor of exceptions (#8035)
This commit is contained in:
parent
dc4a20301f
commit
820981072f
@ -55,7 +55,10 @@ public class Features {
|
||||
|
||||
@Nonnull
|
||||
public static List<Features> merge(@Nonnull List<Features> featureList1, @Nonnull List<Features> featureList2) {
|
||||
assert (featureList1.size() == featureList2.size());
|
||||
if (featureList1.size() != featureList2.size()) {
|
||||
throw new IllegalArgumentException(String.format("Expected both lists to have the same number of elements. %s != %s",
|
||||
featureList1.size(), featureList2.size()));
|
||||
}
|
||||
return Streams.zip(featureList1.stream(), featureList2.stream(), Features::merge).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -413,7 +413,10 @@ public class TimelineServiceImpl implements TimelineService {
|
||||
SemanticVersion curGroupVersion = null;
|
||||
long transactionId = FIRST_TRANSACTION_ID - 1;
|
||||
for (Map.Entry<Long, List<ChangeTransaction>> entry : changeTransactionsMap.entrySet()) {
|
||||
assert (transactionId < entry.getKey());
|
||||
if (transactionId >= entry.getKey()) {
|
||||
throw new IllegalArgumentException(String.format("transactionId should be < previous. %s >= %s",
|
||||
transactionId, entry.getKey()));
|
||||
}
|
||||
transactionId = entry.getKey();
|
||||
SemanticChangeType highestChangeInGroup = SemanticChangeType.NONE;
|
||||
ChangeTransaction highestChangeTransaction = entry.getValue().stream()
|
||||
|
@ -84,11 +84,16 @@ public class EditableDatasetPropertiesChangeEventGenerator
|
||||
@Override
|
||||
public ChangeTransaction getSemanticDiff(EntityAspect previousValue, EntityAspect currentValue,
|
||||
ChangeCategory element, JsonPatch rawDiff, boolean rawDiffsRequested) {
|
||||
|
||||
if (currentValue == null) {
|
||||
throw new IllegalArgumentException("EntityAspect currentValue should not be null");
|
||||
}
|
||||
|
||||
if (!previousValue.getAspect().equals(EDITABLE_DATASET_PROPERTIES_ASPECT_NAME) || !currentValue.getAspect()
|
||||
.equals(EDITABLE_DATASET_PROPERTIES_ASPECT_NAME)) {
|
||||
throw new IllegalArgumentException("Aspect is not " + EDITABLE_DATASET_PROPERTIES_ASPECT_NAME);
|
||||
}
|
||||
assert (currentValue != null);
|
||||
|
||||
List<ChangeEvent> changeEvents = new ArrayList<>();
|
||||
if (element == ChangeCategory.DOCUMENTATION) {
|
||||
EditableDatasetProperties baseDatasetProperties = getEditableDatasetPropertiesFromAspect(previousValue);
|
||||
|
@ -221,11 +221,15 @@ public class EditableSchemaMetadataChangeEventGenerator extends EntityChangeEven
|
||||
public ChangeTransaction getSemanticDiff(EntityAspect previousValue, EntityAspect currentValue,
|
||||
ChangeCategory element, JsonPatch rawDiff, boolean rawDiffsRequested) {
|
||||
|
||||
if (currentValue == null) {
|
||||
throw new IllegalArgumentException("EntityAspect currentValue should not be null");
|
||||
}
|
||||
|
||||
if (!previousValue.getAspect().equals(EDITABLE_SCHEMA_METADATA_ASPECT_NAME) || !currentValue.getAspect()
|
||||
.equals(EDITABLE_SCHEMA_METADATA_ASPECT_NAME)) {
|
||||
throw new IllegalArgumentException("Aspect is not " + EDITABLE_SCHEMA_METADATA_ASPECT_NAME);
|
||||
}
|
||||
assert (currentValue != null);
|
||||
|
||||
EditableSchemaMetadata baseEditableSchemaMetadata = getEditableSchemaMetadataFromAspect(previousValue);
|
||||
EditableSchemaMetadata targetEditableSchemaMetadata = getEditableSchemaMetadataFromAspect(currentValue);
|
||||
List<ChangeEvent> changeEvents = new ArrayList<>();
|
||||
|
@ -133,11 +133,16 @@ public class GlossaryTermsChangeEventGenerator extends EntityChangeEventGenerato
|
||||
@Override
|
||||
public ChangeTransaction getSemanticDiff(EntityAspect previousValue, EntityAspect currentValue,
|
||||
ChangeCategory element, JsonPatch rawDiff, boolean rawDiffsRequested) {
|
||||
|
||||
if (currentValue == null) {
|
||||
throw new IllegalArgumentException("EntityAspect currentValue should not be null");
|
||||
}
|
||||
|
||||
if (!previousValue.getAspect().equals(GLOSSARY_TERMS_ASPECT_NAME) || !currentValue.getAspect()
|
||||
.equals(GLOSSARY_TERMS_ASPECT_NAME)) {
|
||||
throw new IllegalArgumentException("Aspect is not " + GLOSSARY_TERMS_ASPECT_NAME);
|
||||
}
|
||||
assert (currentValue != null);
|
||||
|
||||
GlossaryTerms baseGlossaryTerms = getGlossaryTermsFromAspect(previousValue);
|
||||
GlossaryTerms targetGlossaryTerms = getGlossaryTermsFromAspect(currentValue);
|
||||
List<ChangeEvent> changeEvents = new ArrayList<>();
|
||||
|
@ -152,11 +152,16 @@ public class InstitutionalMemoryChangeEventGenerator extends EntityChangeEventGe
|
||||
@Override
|
||||
public ChangeTransaction getSemanticDiff(EntityAspect previousValue, EntityAspect currentValue,
|
||||
ChangeCategory element, JsonPatch rawDiff, boolean rawDiffsRequested) {
|
||||
|
||||
if (currentValue == null) {
|
||||
throw new IllegalArgumentException("EntityAspect currentValue should not be null");
|
||||
}
|
||||
|
||||
if (!previousValue.getAspect().equals(INSTITUTIONAL_MEMORY_ASPECT_NAME) || !currentValue.getAspect()
|
||||
.equals(INSTITUTIONAL_MEMORY_ASPECT_NAME)) {
|
||||
throw new IllegalArgumentException("Aspect is not " + INSTITUTIONAL_MEMORY_ASPECT_NAME);
|
||||
}
|
||||
assert (currentValue != null);
|
||||
|
||||
InstitutionalMemory baseInstitutionalMemory = getInstitutionalMemoryFromAspect(previousValue);
|
||||
InstitutionalMemory targetInstitutionalMemory = getInstitutionalMemoryFromAspect(currentValue);
|
||||
List<ChangeEvent> changeEvents = new ArrayList<>();
|
||||
|
@ -147,11 +147,15 @@ public class OwnershipChangeEventGenerator extends EntityChangeEventGenerator<Ow
|
||||
@Override
|
||||
public ChangeTransaction getSemanticDiff(EntityAspect previousValue, EntityAspect currentValue,
|
||||
ChangeCategory element, JsonPatch rawDiff, boolean rawDiffsRequested) {
|
||||
|
||||
if (currentValue == null) {
|
||||
throw new IllegalArgumentException("EntityAspect currentValue should not be null");
|
||||
}
|
||||
|
||||
if (!previousValue.getAspect().equals(OWNERSHIP_ASPECT_NAME) || !currentValue.getAspect()
|
||||
.equals(OWNERSHIP_ASPECT_NAME)) {
|
||||
throw new IllegalArgumentException("Aspect is not " + OWNERSHIP_ASPECT_NAME);
|
||||
}
|
||||
assert (currentValue != null);
|
||||
|
||||
Ownership baseOwnership = getOwnershipFromAspect(previousValue);
|
||||
Ownership targetOwnership = getOwnershipFromAspect(currentValue);
|
||||
|
@ -298,7 +298,9 @@ public class SchemaMetadataChangeEventGenerator extends EntityChangeEventGenerat
|
||||
}
|
||||
|
||||
private static void sortFieldsByPath(SchemaMetadata schemaMetadata) {
|
||||
assert (schemaMetadata != null);
|
||||
if (schemaMetadata == null) {
|
||||
throw new IllegalArgumentException("SchemaMetadata should not be null");
|
||||
}
|
||||
List<SchemaField> schemaFields = new ArrayList<>(schemaMetadata.getFields());
|
||||
schemaFields.sort(Comparator.comparing(SchemaField::getFieldPath));
|
||||
schemaMetadata.setFields(new SchemaFieldArray(schemaFields));
|
||||
@ -453,7 +455,11 @@ public class SchemaMetadataChangeEventGenerator extends EntityChangeEventGenerat
|
||||
|
||||
SchemaMetadata baseSchema = getSchemaMetadataFromAspect(previousValue);
|
||||
SchemaMetadata targetSchema = getSchemaMetadataFromAspect(currentValue);
|
||||
assert (targetSchema != null);
|
||||
|
||||
if (targetSchema == null) {
|
||||
throw new IllegalStateException("SchemaMetadata targetSchema should not be null");
|
||||
}
|
||||
|
||||
List<ChangeEvent> changeEvents;
|
||||
try {
|
||||
changeEvents = new ArrayList<>(
|
||||
|
@ -464,7 +464,10 @@ public class ESAggregatedStatsDAO {
|
||||
// 3.1 Do a DFS of the aggregation tree and generate the rows.
|
||||
rowGenHelper(filterAgg.getAggregations(), 0, groupingBuckets.length, rows, rowAcc,
|
||||
ImmutableList.copyOf(groupingBuckets), ImmutableList.copyOf(aggregationSpecs), aspectSpec);
|
||||
assert (rowAcc.isEmpty());
|
||||
|
||||
if (!rowAcc.isEmpty()) {
|
||||
throw new IllegalStateException("Expected stack to be empty.");
|
||||
}
|
||||
|
||||
resultTable.setRows(new StringArrayArray(rows));
|
||||
return resultTable;
|
||||
|
Loading…
x
Reference in New Issue
Block a user