-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing util method to compare 2 avro schemas and return list of… (
#477) Co-authored-by: Ajinkya Dande <[email protected]>
- Loading branch information
1 parent
ca6496c
commit 4fff44b
Showing
6 changed files
with
710 additions
and
86 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
parser/src/main/java/com/linkedin/avroutil1/model/AvroSchemaDifference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2022 LinkedIn Corp. | ||
* Licensed under the BSD 2-Clause License (the "License"). | ||
* See License in the project root for license information. | ||
*/ | ||
|
||
package com.linkedin.avroutil1.model; | ||
|
||
/** | ||
* The AvroSchemaDifference class is used to record the differences identified while comparing two Avro schemas. This class | ||
* records the code location of the difference identified in schemaA and the corrosponding location in schemaB and records the | ||
* summary of difference | ||
* * It supports comparing schemas defined in Avro IDL (.avdl) or Avro schema (.avsc) formats. | ||
*/ | ||
public class AvroSchemaDifference { | ||
|
||
/** | ||
* {@link CodeLocation} of the difference in schemaA | ||
*/ | ||
private final CodeLocation schemaALocation; | ||
|
||
/** | ||
* {@link CodeLocation} of the difference in schemaB | ||
*/ | ||
private final CodeLocation schemaBLocation; | ||
|
||
/** | ||
* Enum representing Avro schema difference types. | ||
*/ | ||
AvroSchemaDifferenceType avroSchemaDifferenceType; | ||
|
||
/** | ||
* Summary of the difference between the schemas | ||
*/ | ||
private final String differenceSummary; | ||
|
||
/** | ||
* Constructor for creating an AvroSchemaDifference object. | ||
* | ||
* @param schemaALocation The {@link CodeLocation} of the difference in schemaA | ||
* @param schemaBLocation The {@link CodeLocation} of the difference in schemaB | ||
* @param avroSchemaDifferenceType The AvroSchemaDifferenceType representing the type of difference | ||
* @param differenceSummary The summary of the difference between the schemas | ||
*/ | ||
public AvroSchemaDifference(CodeLocation schemaALocation, | ||
CodeLocation schemaBLocation, | ||
AvroSchemaDifferenceType avroSchemaDifferenceType, | ||
String differenceSummary) { | ||
this.schemaALocation = schemaALocation; | ||
this.schemaBLocation = schemaBLocation; | ||
this.avroSchemaDifferenceType = avroSchemaDifferenceType; | ||
this.differenceSummary = differenceSummary; | ||
} | ||
|
||
public CodeLocation getSchemaALocation() { | ||
return schemaALocation; | ||
} | ||
|
||
public CodeLocation getSchemaBLocation() { | ||
return schemaBLocation; | ||
} | ||
|
||
public AvroSchemaDifferenceType getAvroSchemaDifferenceType() { | ||
return avroSchemaDifferenceType; | ||
} | ||
|
||
public String getDifferenceSummary() { | ||
return differenceSummary; | ||
} | ||
|
||
/** | ||
* Overrides the default toString() method to return a custom string representation | ||
* of the AvroSchemaDifference object. | ||
* | ||
* @return A string representation of the AvroSchemaDifference object | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "[" + avroSchemaDifferenceType.toString() + "] " + | ||
", SchemaALocation: " + ((schemaALocation != null) ? schemaALocation.toString() : "null") + | ||
", SchemaBLocation: " + ((schemaBLocation != null) ? schemaBLocation.toString() : "null") + | ||
", DifferenceSummary: " + differenceSummary; | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
parser/src/main/java/com/linkedin/avroutil1/model/AvroSchemaDifferenceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2022 LinkedIn Corp. | ||
* Licensed under the BSD 2-Clause License (the "License"). | ||
* See License in the project root for license information. | ||
*/ | ||
|
||
package com.linkedin.avroutil1.model; | ||
|
||
/** | ||
* Enum representing Avro schema difference types. | ||
*/ | ||
public enum AvroSchemaDifferenceType { | ||
|
||
/** | ||
* Null schema provided. | ||
*/ | ||
NULL_SCHEMA, | ||
|
||
/** | ||
* Schema reference mismatch between schema A and schema B. | ||
*/ | ||
SCHEMA_REFERENCE_MISMATCH, | ||
|
||
/** | ||
* Type mismatch between schema A and schema B. | ||
*/ | ||
TYPE_MISMATCH, | ||
|
||
/** | ||
* Aliases mismatch between schema A and schema B. | ||
*/ | ||
ALIASES_MISMATCH, | ||
|
||
/** | ||
* JSON property count mismatch between schema A and schema B. | ||
*/ | ||
JSON_PROPERTY_COUNT_MISMATCH, | ||
|
||
/** | ||
* JSON property mismatch between schema A and schema B. | ||
*/ | ||
JSON_PROPERTY_MISMATCH, | ||
|
||
/** | ||
* Enum name mismatch between schema A and schema B. | ||
*/ | ||
ENUM_NAME_MISMATCH, | ||
|
||
/** | ||
* Enum symbol mismatch between schema A and schema B. | ||
*/ | ||
ENUM_SYMBOL_MISMATCH, | ||
|
||
/** | ||
* Fixed name mismatch between schema A and schema B. | ||
*/ | ||
FIXED_NAME_MISMATCH, | ||
|
||
/** | ||
* Fixed size mismatch between schema A and schema B. | ||
*/ | ||
FIXED_SIZE_MISMATCH, | ||
|
||
/** | ||
* Union size mismatch between schema A and schema B. | ||
*/ | ||
UNION_SIZE_MISMATCH, | ||
|
||
/** | ||
* Record name mismatch between schema A and schema B. | ||
*/ | ||
RECORD_NAME_MISMATCH, | ||
|
||
/** | ||
* Record field name mismatch between schema A and schema B. | ||
*/ | ||
RECORD_FIELD_NAME_MISMATCH, | ||
|
||
/** | ||
* Record default value mismatch between schema A and schema B. | ||
*/ | ||
RECORD_DEFAULT_VALUE_MISMATCH, | ||
|
||
/** | ||
* Default value mismatch in schema A or schema B. | ||
*/ | ||
DEFAULT_VALUE_MISMATCH, | ||
|
||
/** | ||
* Record field position mismatch between schema A and schema B. | ||
*/ | ||
RECORD_FIELD_POSITION_MISMATCH, | ||
|
||
/** | ||
* Additional field found in schema A or schema B. | ||
*/ | ||
ADDITIONAL_FIELD | ||
|
||
} |
Oops, something went wrong.