|
7 | 7 | package com.linkedin.avroutil1.builder.operations.codegen.own; |
8 | 8 |
|
9 | 9 | import com.linkedin.avroutil1.builder.operations.OperationContext; |
| 10 | +import com.linkedin.avroutil1.builder.operations.SchemaSet; |
10 | 11 | import com.linkedin.avroutil1.builder.operations.codegen.CodeGenOpConfig; |
11 | 12 | import com.linkedin.avroutil1.builder.operations.codegen.OperationContextBuilder; |
12 | 13 | import com.linkedin.avroutil1.builder.operations.codegen.util.AvscFileFinderUtil; |
13 | 14 | import com.linkedin.avroutil1.builder.operations.codegen.vanilla.ClasspathSchemaSet; |
14 | 15 | import com.linkedin.avroutil1.builder.operations.codegen.vanilla.ResolverPathSchemaSet; |
15 | | -import com.linkedin.avroutil1.builder.operations.SchemaSet; |
| 16 | +import com.linkedin.avroutil1.builder.operations.codegen.util.SchemaComparisonUtil; |
16 | 17 | import com.linkedin.avroutil1.compatibility.AvroCompatibilityHelper; |
17 | 18 | import com.linkedin.avroutil1.compatibility.AvscGenerationConfig; |
18 | | -import com.linkedin.avroutil1.compatibility.SchemaComparisonConfiguration; |
19 | 19 | import com.linkedin.avroutil1.model.AvroNamedSchema; |
20 | 20 | import com.linkedin.avroutil1.model.AvroSchema; |
21 | 21 | import com.linkedin.avroutil1.model.SchemaOrRef; |
22 | 22 | import com.linkedin.avroutil1.parser.avsc.AvroParseContext; |
23 | 23 | import com.linkedin.avroutil1.parser.avsc.AvscParseResult; |
24 | 24 | import com.linkedin.avroutil1.parser.avsc.AvscParser; |
25 | | -import com.linkedin.avroutil1.util.ConfigurableAvroSchemaComparator; |
26 | | -import com.linkedin.avroutil1.writer.avsc.AvscSchemaWriter; |
27 | | -import com.linkedin.avroutil1.writer.avsc.AvscWriterConfig; |
| 25 | +import org.apache.avro.Schema; |
| 26 | +import org.slf4j.Logger; |
| 27 | +import org.slf4j.LoggerFactory; |
| 28 | + |
| 29 | + |
28 | 30 | import java.io.File; |
29 | 31 | import java.util.Collections; |
30 | 32 | import java.util.HashSet; |
|
34 | 36 | import java.util.StringJoiner; |
35 | 37 | import java.util.stream.Collectors; |
36 | 38 | import java.util.stream.Stream; |
37 | | -import org.apache.avro.Schema; |
38 | | -import org.slf4j.Logger; |
39 | | -import org.slf4j.LoggerFactory; |
40 | 39 |
|
41 | 40 |
|
42 | 41 | public class AvroUtilOperationContextBuilder implements OperationContextBuilder { |
@@ -122,8 +121,7 @@ public OperationContext buildOperationContext(CodeGenOpConfig config) throws Exc |
122 | 121 | if (cpSchema != null) { |
123 | 122 | // check if the schema on classpath is the same as the one we are trying to generate |
124 | 123 | AvroSchema avroSchemaFromClasspath = (new AvscParser()).parse(cpSchema.toString()).getTopLevelSchema(); |
125 | | - boolean areEqual = ConfigurableAvroSchemaComparator.equals(avroSchemaFromClasspath, schema, |
126 | | - SchemaComparisonConfiguration.STRICT); |
| 124 | + boolean areEqual = SchemaComparisonUtil.equalsAvroSchema(avroSchemaFromClasspath, schema, config.getJsonPropsToIgnore()); |
127 | 125 | if (!areEqual) { |
128 | 126 | throw new IllegalStateException("Schema with name " + fullName |
129 | 127 | + " is defined in the filesystem and on the classpath, but the two schemas are not equal."); |
@@ -155,28 +153,26 @@ public OperationContext buildOperationContext(CodeGenOpConfig config) throws Exc |
155 | 153 | System.err.println("WARNING: schema " + fqcn + " found in 2+ places: " + allFilesString); |
156 | 154 | break; |
157 | 155 | case FAIL_IF_DIFFERENT: |
158 | | - String baseSchema = null; |
| 156 | + AvroNamedSchema baseNamed = null; |
159 | 157 | AvscParseResult baseSchemaResult = null; |
| 158 | + // Use SchemaComparisonUtil to build the comparison configuration |
160 | 159 | for (AvscParseResult duplicateParseResult : duplicateEntry.getValue()) { |
161 | | - if (baseSchema == null) { |
162 | | - baseSchema = new AvscSchemaWriter().generateAvsc(duplicateParseResult.getDefinedSchema(fqcn), |
163 | | - AvscWriterConfig.CORRECT_MITIGATED); |
| 160 | + AvroNamedSchema currentNamed = duplicateParseResult.getDefinedSchema(fqcn); |
| 161 | + if (baseNamed == null) { |
| 162 | + baseNamed = currentNamed; |
164 | 163 | baseSchemaResult = duplicateParseResult; |
165 | 164 | continue; |
166 | 165 | } |
167 | | - String currSchema = new AvscSchemaWriter().generateAvsc(duplicateParseResult.getDefinedSchema(fqcn), |
168 | | - AvscWriterConfig.CORRECT_MITIGATED); |
169 | | - |
170 | | - // TODO: compare canonical forms when canonicalization work is complete |
| 166 | + // Compare using SchemaComparisonUtil for consistent schema comparison |
| 167 | + boolean equal = SchemaComparisonUtil.equalsAvroSchema(baseNamed, currentNamed, config.getJsonPropsToIgnore()); |
171 | 168 | long baseLineNumber = baseSchemaResult.getDefinedSchema(fqcn).getCodeLocation().getEnd().getLineNumber(); |
172 | | - long duplicateLineNumber = |
173 | | - duplicateParseResult.getDefinedSchema(fqcn).getCodeLocation().getEnd().getLineNumber(); |
174 | | - String errorMsg = "schema " + fqcn + " found DIFFERENT in 2+ places: " + baseSchemaResult.getURI() + "#L" |
| 169 | + long duplicateLineNumber = currentNamed.getCodeLocation().getEnd().getLineNumber(); |
| 170 | + String msg = "schema " + fqcn + " found DIFFERENT in 2+ places: " + baseSchemaResult.getURI() + "#L" |
175 | 171 | + baseLineNumber + " and " + duplicateParseResult.getURI() + "#L" + duplicateLineNumber; |
176 | | - if (!baseSchema.equals(currSchema)) { |
177 | | - throw new RuntimeException("ERROR: " + errorMsg); |
| 172 | + if (!equal) { |
| 173 | + throw new RuntimeException("ERROR: " + msg); |
178 | 174 | } else { |
179 | | - System.err.println("WARNING: " + errorMsg); |
| 175 | + System.err.println("WARNING: " + msg); |
180 | 176 | } |
181 | 177 | } |
182 | 178 | break; |
|
0 commit comments