LUCENE-10082: add detail to schema inconsistency error messages

This commit is contained in:
Michael Sokolov 2021-09-01 14:23:17 +00:00
parent e3e54c95c9
commit ee7a719dd8
6 changed files with 81 additions and 33 deletions

View File

@ -1336,12 +1336,40 @@ final class IndexingChain implements Accountable {
this.name = name;
}
private void assertSame(boolean same) {
if (same == false) {
throw new IllegalArgumentException(errMsg + "[" + name + "] of doc [" + docID + "].");
private void assertSame(String label, boolean expected, boolean given) {
if (expected != given) {
raiseNotSame(label, expected, given);
}
}
private void assertSame(String label, int expected, int given) {
if (expected != given) {
raiseNotSame(label, expected, given);
}
}
private void assertSame(String label, Object expected, Object given) {
if (expected != given) {
raiseNotSame(label, expected, given);
}
}
private void raiseNotSame(String label, Object expected, Object given) {
throw new IllegalArgumentException(
errMsg
+ "["
+ name
+ "] of doc ["
+ docID
+ "]. "
+ label
+ ": expected '"
+ expected
+ "', but it has '"
+ given
+ "'.");
}
void updateAttributes(Map<String, String> attrs) {
attrs.forEach((k, v) -> this.attributes.put(k, v));
}
@ -1353,10 +1381,9 @@ final class IndexingChain implements Accountable {
omitNorms = newOmitNorms;
storeTermVector = newStoreTermVector;
} else {
assertSame(
indexOptions == newIndexOptions
&& omitNorms == newOmitNorms
&& storeTermVector == newStoreTermVector);
assertSame("index options", indexOptions, newIndexOptions);
assertSame("omit norms", omitNorms, newOmitNorms);
assertSame("store term vector", storeTermVector, newStoreTermVector);
}
}
@ -1365,7 +1392,8 @@ final class IndexingChain implements Accountable {
this.docValuesType = newDocValuesType;
this.dvGen = newDvGen;
} else {
assertSame(docValuesType == newDocValuesType && dvGen == newDvGen);
assertSame("doc values type", docValuesType, newDocValuesType);
assertSame("doc values generation", dvGen, newDvGen);
}
}
@ -1375,10 +1403,9 @@ final class IndexingChain implements Accountable {
pointIndexDimensionCount = indexDimensionCount;
pointNumBytes = numBytes;
} else {
assertSame(
pointDimensionCount == dimensionCount
&& pointIndexDimensionCount == indexDimensionCount
&& pointNumBytes == numBytes);
assertSame("point dimension", pointDimensionCount, dimensionCount);
assertSame("point index dimension", pointIndexDimensionCount, indexDimensionCount);
assertSame("point num bytes", pointNumBytes, numBytes);
}
}
@ -1387,7 +1414,8 @@ final class IndexingChain implements Accountable {
this.vectorDimension = dimension;
this.vectorSimilarityFunction = similarityFunction;
} else {
assertSame(vectorSimilarityFunction == similarityFunction && vectorDimension == dimension);
assertSame("vector similarity function", vectorSimilarityFunction, similarityFunction);
assertSame("vector dimension", vectorDimension, dimension);
}
}
@ -1406,17 +1434,18 @@ final class IndexingChain implements Accountable {
}
void assertSameSchema(FieldInfo fi) {
assertSame("index options", fi.getIndexOptions(), indexOptions);
assertSame("omit norms", fi.omitsNorms(), omitNorms);
assertSame("store term vector", fi.hasVectors(), storeTermVector);
assertSame("doc values type", fi.getDocValuesType(), docValuesType);
assertSame("doc values generation", fi.getDocValuesGen(), dvGen);
assertSame(
indexOptions == fi.getIndexOptions()
&& omitNorms == fi.omitsNorms()
&& storeTermVector == fi.hasVectors()
&& docValuesType == fi.getDocValuesType()
&& dvGen == fi.getDocValuesGen()
&& pointDimensionCount == fi.getPointDimensionCount()
&& pointIndexDimensionCount == fi.getPointIndexDimensionCount()
&& pointNumBytes == fi.getPointNumBytes()
&& vectorDimension == fi.getVectorDimension()
&& vectorSimilarityFunction == fi.getVectorSimilarityFunction());
"vector similarity function", fi.getVectorSimilarityFunction(), vectorSimilarityFunction);
assertSame("vector dimension", fi.getVectorDimension(), vectorDimension);
assertSame("point dimension", fi.getPointDimensionCount(), pointDimensionCount);
assertSame(
"point index dimension", fi.getPointIndexDimensionCount(), pointIndexDimensionCount);
assertSame("point num bytes", fi.getPointNumBytes(), pointNumBytes);
}
}
}

View File

@ -115,7 +115,9 @@ public class TestPerFieldConsistency extends LuceneTestCase {
}
IllegalArgumentException exception =
expectThrows(IllegalArgumentException.class, () -> writer.addDocument(doc));
assertTrue(exception.getMessage().contains(errorMsg));
assertTrue(
"'" + errorMsg + "' not found in '" + exception.getMessage() + "'",
exception.getMessage().contains(errorMsg));
}
private static void doTestDocWithExtraSchemaOptionsThrowsError(
@ -125,7 +127,9 @@ public class TestPerFieldConsistency extends LuceneTestCase {
doc.add(extra);
IllegalArgumentException exception =
expectThrows(IllegalArgumentException.class, () -> writer.addDocument(doc));
assertTrue(exception.getMessage().contains(errorMsg));
assertTrue(
"'" + errorMsg + "' not found in '" + exception.getMessage() + "'",
exception.getMessage().contains(errorMsg));
}
public void testDocWithMissingSchemaOptionsThrowsError() throws IOException {

View File

@ -52,7 +52,12 @@ public class TestIndexOptions extends LuceneTestCase {
IllegalArgumentException.class,
() -> w.addDocument(Collections.singleton(new Field("foo", "bar", ft2))));
assertEquals(
"Inconsistency of field data structures across documents for field [foo] of doc [1].",
"Inconsistency of field data structures across documents for field [foo] of doc [1]."
+ " index options: expected '"
+ from
+ "', but it has '"
+ to
+ "'.",
e.getMessage());
}
w.close();

View File

@ -2824,7 +2824,11 @@ public class TestIndexSorting extends LuceneTestCase {
doc.add(dvs.get(j));
exc = expectThrows(IllegalArgumentException.class, () -> w.addDocument(doc));
assertEquals(
"Inconsistency of field data structures across documents for field [field] of doc [2].",
"Inconsistency of field data structures across documents for field [field] of doc [2]. doc values type: expected '"
+ dvs.get(i).fieldType().docValuesType()
+ "', but it has '"
+ dvs.get(j).fieldType().docValuesType()
+ "'.",
exc.getMessage());
w.rollback();
IOUtils.close(w);

View File

@ -74,7 +74,8 @@ public class TestPointValues extends LuceneTestCase {
w.addDocument(doc);
});
assertEquals(
"Inconsistency of field data structures across documents for field [dim] of doc [0].",
"Inconsistency of field data structures across documents for field [dim] of doc [0]."
+ " point dimension: expected '1', but it has '2'.",
expected.getMessage());
w.close();
dir.close();
@ -97,7 +98,8 @@ public class TestPointValues extends LuceneTestCase {
w.addDocument(doc2);
});
assertEquals(
"Inconsistency of field data structures across documents for field [dim] of doc [1].",
"Inconsistency of field data structures across documents for field [dim] of doc [1]."
+ " point dimension: expected '1', but it has '2'.",
expected.getMessage());
w.close();
dir.close();
@ -254,7 +256,8 @@ public class TestPointValues extends LuceneTestCase {
w.addDocument(doc);
});
assertEquals(
"Inconsistency of field data structures across documents for field [dim] of doc [0].",
"Inconsistency of field data structures across documents for field [dim] of doc [0]."
+ " point num bytes: expected '4', but it has '6'.",
expected.getMessage());
w.close();
dir.close();
@ -277,7 +280,8 @@ public class TestPointValues extends LuceneTestCase {
w.addDocument(doc2);
});
assertEquals(
"Inconsistency of field data structures across documents for field [dim] of doc [1].",
"Inconsistency of field data structures across documents for field [dim] of doc [1]."
+ " point num bytes: expected '4', but it has '6'.",
expected.getMessage());
w.close();
dir.close();

View File

@ -100,7 +100,8 @@ public abstract class BaseKnnVectorsFormatTestCase extends BaseIndexFileFormatTe
IllegalArgumentException expected =
expectThrows(IllegalArgumentException.class, () -> w.addDocument(doc2));
String errMsg =
"Inconsistency of field data structures across documents for field [f] of doc [1].";
"Inconsistency of field data structures across documents for field [f] of doc [1]."
+ " vector dimension: expected '4', but it has '3'.";
assertEquals(errMsg, expected.getMessage());
}
@ -136,7 +137,8 @@ public abstract class BaseKnnVectorsFormatTestCase extends BaseIndexFileFormatTe
IllegalArgumentException expected =
expectThrows(IllegalArgumentException.class, () -> w.addDocument(doc2));
String errMsg =
"Inconsistency of field data structures across documents for field [f] of doc [1].";
"Inconsistency of field data structures across documents for field [f] of doc [1]."
+ " vector similarity function: expected 'DOT_PRODUCT', but it has 'EUCLIDEAN'.";
assertEquals(errMsg, expected.getMessage());
}