Skip to content

Commit 610e83a

Browse files
mgodwanAditya Khera
authored andcommitted
Fix access specifier for FieldMapper method to allow usage by plugins (opensearch-project#19113)
* Fix access specifier for FieldMapper method to allow usage by plugins Signed-off-by: Mohit Godwani <[email protected]> * Apply spotless Signed-off-by: Mohit Godwani <[email protected]> --------- Signed-off-by: Mohit Godwani <[email protected]>
1 parent b98c172 commit 610e83a

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.index.mapper;
10+
11+
import org.opensearch.action.DocWriteResponse;
12+
import org.opensearch.action.admin.indices.refresh.RefreshResponse;
13+
import org.opensearch.action.get.GetResponse;
14+
import org.opensearch.action.index.IndexRequestBuilder;
15+
import org.opensearch.common.settings.Settings;
16+
import org.opensearch.common.unit.TimeValue;
17+
import org.opensearch.common.xcontent.XContentType;
18+
import org.opensearch.core.rest.RestStatus;
19+
import org.opensearch.test.OpenSearchIntegTestCase;
20+
21+
import java.io.IOException;
22+
23+
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING;
24+
import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
25+
26+
public class ScaledFloatDerivedSourceIT extends OpenSearchIntegTestCase {
27+
28+
private static final String INDEX_NAME = "test";
29+
30+
public void testScaledFloatDerivedSource() throws Exception {
31+
Settings.Builder settings = Settings.builder();
32+
settings.put(indexSettings());
33+
settings.put("index.derived_source.enabled", "true");
34+
35+
prepareCreate(INDEX_NAME).setSettings(settings)
36+
.setMapping(
37+
jsonBuilder().startObject()
38+
.startObject("properties")
39+
.startObject("foo")
40+
.field("type", "scaled_float")
41+
.field("scaling_factor", "100")
42+
.endObject()
43+
.endObject()
44+
.endObject()
45+
)
46+
.get();
47+
48+
ensureGreen(INDEX_NAME);
49+
50+
String docId = "one_doc";
51+
assertEquals(DocWriteResponse.Result.CREATED, prepareIndex(docId, 1.2123422f).get().getResult());
52+
53+
RefreshResponse refreshResponse = refresh(INDEX_NAME);
54+
assertEquals(RestStatus.OK, refreshResponse.getStatus());
55+
assertEquals(0, refreshResponse.getFailedShards());
56+
assertEquals(INDEX_NUMBER_OF_SHARDS_SETTING.get(settings.build()).intValue(), refreshResponse.getSuccessfulShards());
57+
58+
GetResponse getResponse = client().prepareGet()
59+
.setFetchSource(true)
60+
.setId(docId)
61+
.setIndex(INDEX_NAME)
62+
.get(TimeValue.timeValueMinutes(1));
63+
assertTrue(getResponse.isExists());
64+
assertEquals(1.21d, getResponse.getSourceAsMap().get("foo"));
65+
}
66+
67+
private IndexRequestBuilder prepareIndex(String id, float number) throws IOException {
68+
return client().prepareIndex(INDEX_NAME)
69+
.setId(id)
70+
.setSource(jsonBuilder().startObject().field("foo", number).endObject().toString(), XContentType.JSON);
71+
}
72+
}

server/src/main/java/org/opensearch/index/mapper/FieldMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ protected void canDeriveSourceInternal() {
642642
/**
643643
* Validates if doc values is enabled for a field or not
644644
*/
645-
void checkDocValuesForDerivedSource() {
645+
protected void checkDocValuesForDerivedSource() {
646646
if (!mappedFieldType.hasDocValues()) {
647647
throw new UnsupportedOperationException("Unable to derive source for [" + name() + "] with doc values disabled");
648648
}
@@ -651,7 +651,7 @@ void checkDocValuesForDerivedSource() {
651651
/**
652652
* Validates if stored field is enabled for a field or not
653653
*/
654-
void checkStoredForDerivedSource() {
654+
protected void checkStoredForDerivedSource() {
655655
if (!mappedFieldType.isStored()) {
656656
throw new UnsupportedOperationException("Unable to derive source for [" + name() + "] with store disabled");
657657
}
@@ -660,7 +660,7 @@ void checkStoredForDerivedSource() {
660660
/**
661661
* Validates if doc_values or stored field is enabled for a field or not
662662
*/
663-
void checkStoredAndDocValuesForDerivedSource() {
663+
protected void checkStoredAndDocValuesForDerivedSource() {
664664
if (!mappedFieldType.isStored() && !mappedFieldType.hasDocValues()) {
665665
throw new UnsupportedOperationException("Unable to derive source for [" + name() + "] with stored and " + "docValues disabled");
666666
}

0 commit comments

Comments
 (0)