Skip to content

Commit

Permalink
Give a descriptive error message when the 'field' type is invalid.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtibshirani committed Oct 29, 2019
1 parent ed95d9f commit c6f3f6d
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ public DenseVectorFunction(ScoreScript scoreScript,
}
}

if (field instanceof DenseVectorScriptDocValues) {
if (field instanceof String) {
String fieldName = (String) field;
docValues = (DenseVectorScriptDocValues) scoreScript.getDoc().get(fieldName);
} else if (field instanceof DenseVectorScriptDocValues) {
docValues = (DenseVectorScriptDocValues) field;
deprecationLogger.deprecatedAndMaybeLog("vector_function_signature", DEPRECATION_MESSAGE);
} else {
String fieldName = (String) field;
docValues = (DenseVectorScriptDocValues) scoreScript.getDoc().get(fieldName);
throw new IllegalArgumentException("For vector functions, the 'field' argument must be of type String or " +
"VectorScriptDocValues");
}
}

Expand Down Expand Up @@ -230,12 +233,15 @@ public SparseVectorFunction(ScoreScript scoreScript,
// Sort dimensions in the ascending order and sort values in the same order as their corresponding dimensions
sortSparseDimsFloatValues(queryDims, queryValues, n);

if (field instanceof SparseVectorScriptDocValues) {
if (field instanceof String) {
String fieldName = (String) field;
docValues = (SparseVectorScriptDocValues) scoreScript.getDoc().get(fieldName);
} else if (field instanceof SparseVectorScriptDocValues) {
docValues = (SparseVectorScriptDocValues) field;
deprecationLogger.deprecatedAndMaybeLog("vector_function_signature", DEPRECATION_MESSAGE);
} else {
String fieldName = (String) field;
docValues = (SparseVectorScriptDocValues) scoreScript.getDoc().get(fieldName);
throw new IllegalArgumentException("For vector functions, the 'field' argument must be of type String or " +
"VectorScriptDocValues");
}

deprecationLogger.deprecatedAndMaybeLog("sparse_vector_function", SparseVectorFieldMapper.DEPRECATION_MESSAGE);
Expand Down

0 comments on commit c6f3f6d

Please sign in to comment.