Skip to content

Commit

Permalink
Implementing util method to compare 2 avro schemas and return list of… (
Browse files Browse the repository at this point in the history
#477)


Co-authored-by: Ajinkya Dande <[email protected]>
  • Loading branch information
ajinkya-dande-git and Ajinkya Dande authored Apr 19, 2023
1 parent ca6496c commit 4fff44b
Show file tree
Hide file tree
Showing 6 changed files with 710 additions and 86 deletions.
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;
}
}
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

}
Loading

0 comments on commit 4fff44b

Please sign in to comment.