madrob commented on a change in pull request #2121:
URL: https://github.com/apache/lucene-solr/pull/2121#discussion_r538804398
##########
File path:
solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
##########
@@ -143,6 +147,15 @@ public SolrInputDocument merge(final SolrInputDocument
fromDoc, SolrInputDocumen
return toDoc;
}
+ private static String getID(SolrInputDocument doc, IndexSchema schema) {
+ String id = "";
Review comment:
can we default to `(unknown id)` otherwise the error message will look
weird I think.
##########
File path:
solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
##########
@@ -553,7 +574,15 @@ private Object getNativeFieldValue(String fieldName,
Object val) {
return val;
}
SchemaField sf = schema.getField(fieldName);
- return sf.getType().toNativeType(val);
+ try {
+ return sf.getType().toNativeType(val);
+ } catch (SolrException ex) {
+ throw new SolrException(SolrException.ErrorCode.getErrorCode(ex.code()),
+ "Error converting field '" + sf.getName() + "'='" +val+"' to native
type, msg=" + ex.getMessage(), ex);
Review comment:
I don't think we want `msg` copied since it will be in the cause anyway.
##########
File path:
solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesStandalone.java
##########
@@ -121,6 +123,36 @@ public void deleteAllAndCommit() throws Exception {
assertU(commit("softCommit", "false"));
}
+ @Test
+ public void testUpdateBadRequest() throws Exception {
+ final long version1 = addAndGetVersion(sdoc("id", "1", "title_s", "first",
"inplace_updatable_float", 41), null);
+ assertU(commit());
+
+ // invalid value with set operation
+ SolrException e = expectThrows(SolrException.class,
+ () -> addAndAssertVersion(version1, "id", "1",
"inplace_updatable_float", map("set", "NOT_NUMBER")));
+ assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, e.code());
+ MatcherAssert.assertThat(e.getMessage(), containsString("For input string:
\"NOT_NUMBER\""));
+
+ // invalid value with inc operation
+ e = expectThrows(SolrException.class,
+ () -> addAndAssertVersion(version1, "id", "1",
"inplace_updatable_float", map("inc", "NOT_NUMBER")));
+ assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, e.code());
+ MatcherAssert.assertThat(e.getMessage(), containsString("For input string:
\"NOT_NUMBER\""));
+
+ // inc op with null value
+ e = expectThrows(SolrException.class,
+ () -> addAndAssertVersion(version1, "id", "1",
"inplace_updatable_float", map("inc", null)));
+ assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, e.code());
+ MatcherAssert.assertThat(e.getMessage(), containsString("Invalid input
'null' for field inplace_updatable_float"));
+
+ e = expectThrows(SolrException.class,
+ () -> addAndAssertVersion(version1, "id", "1",
"inplace_updatable_float",
Review comment:
This surprises me a little bit that we can't increment a float by an
integer amount?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]