Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to support IP field in star tree indexing #16641

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class StarTreeMapperIT extends OpenSearchIntegTestCase {
.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), new ByteSizeValue(512, ByteSizeUnit.MB))
.build();

private static XContentBuilder createMinimalTestMapping(boolean invalidDim, boolean invalidMetric, boolean ipdim) {
private static XContentBuilder createMinimalTestMapping(boolean invalidDim, boolean invalidMetric, boolean wildcard) {
try {
return jsonBuilder().startObject()
.startObject("composite")
Expand All @@ -68,7 +68,7 @@ private static XContentBuilder createMinimalTestMapping(boolean invalidDim, bool
.endObject()
.startArray("ordered_dimensions")
.startObject()
.field("name", getDim(invalidDim, ipdim))
.field("name", getDim(invalidDim, wildcard))
.endObject()
.startObject()
.field("name", "keyword_dv")
Expand Down Expand Up @@ -102,8 +102,16 @@ private static XContentBuilder createMinimalTestMapping(boolean invalidDim, bool
.field("type", "keyword")
.field("doc_values", false)
.endObject()
.startObject("ip_no_dv")
.field("type", "ip")
.field("doc_values", false)
.endObject()
.startObject("ip")
.field("type", "ip")
.field("doc_values", true)
.endObject()
.startObject("wildcard")
.field("type", "wildcard")
.field("doc_values", false)
.endObject()
.endObject()
Expand Down Expand Up @@ -362,11 +370,11 @@ private XContentBuilder getMappingWithDuplicateFields(boolean isDuplicateDim, bo
return mapping;
}

private static String getDim(boolean hasDocValues, boolean isKeyword) {
private static String getDim(boolean hasDocValues, boolean isWildCard) {
if (hasDocValues) {
return random().nextBoolean() ? "numeric" : "keyword";
} else if (isKeyword) {
return "ip";
return random().nextBoolean() ? "numeric" : random().nextBoolean() ? "keyword" : "ip_no_dv";
} else if (isWildCard) {
return "wildcard";
}
return "numeric_dv";
}
Expand Down Expand Up @@ -748,7 +756,7 @@ public void testUnsupportedDim() {
() -> prepareCreate(TEST_INDEX).setSettings(settings).setMapping(createMinimalTestMapping(false, false, true)).get()
);
assertEquals(
"Failed to parse mapping [_doc]: unsupported field type associated with dimension [ip] as part of star tree field [startree-1]",
"Failed to parse mapping [_doc]: unsupported field type associated with dimension [wildcard] as part of star tree field [startree-1]",
ex.getMessage()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
import org.opensearch.index.compositeindex.datacube.startree.builder.StarTreesBuilder;
import org.opensearch.index.compositeindex.datacube.startree.index.CompositeIndexValues;
import org.opensearch.index.compositeindex.datacube.startree.index.StarTreeValues;
import org.opensearch.index.fielddata.IndexNumericFieldData;
import org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.opensearch.index.mapper.CompositeMappedFieldType;
import org.opensearch.index.mapper.DocCountFieldMapper;
import org.opensearch.index.mapper.KeywordFieldMapper;
import org.opensearch.index.mapper.MappedFieldType;
import org.opensearch.index.mapper.MapperService;

import java.io.IOException;
Expand All @@ -44,6 +46,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -262,22 +265,38 @@
return DocValues.emptySortedSet();
}
});
}
// TODO : change this logic to evaluate for sortedNumericField specifically
else {
} else if (isSortedNumericField(compositeField)) {
fieldProducerMap.put(compositeField, new EmptyDocValuesProducer() {
@Override
public SortedNumericDocValues getSortedNumeric(FieldInfo field) {
return DocValues.emptySortedNumeric();
}
});
} else {
throw new IllegalStateException(
String.format(Locale.ROOT, "Unsupported DocValues field associated with the composite field : %s", compositeField)

Check warning on line 277 in server/src/main/java/org/opensearch/index/codec/composite/composite912/Composite912DocValuesWriter.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/codec/composite/composite912/Composite912DocValuesWriter.java#L276-L277

Added lines #L276 - L277 were not covered by tests
);
}
}
compositeFieldSet.remove(compositeField);
}

private boolean isSortedSetField(String field) {
return mapperService.fieldType(field) instanceof KeywordFieldMapper.KeywordFieldType;
MappedFieldType ft = mapperService.fieldType(field);
assert ft.isAggregatable();
return ft.fielddataBuilder(
"",
() -> { throw new UnsupportedOperationException("SearchLookup not available"); }

Check warning on line 289 in server/src/main/java/org/opensearch/index/codec/composite/composite912/Composite912DocValuesWriter.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/codec/composite/composite912/Composite912DocValuesWriter.java#L289

Added line #L289 was not covered by tests
) instanceof SortedSetOrdinalsIndexFieldData.Builder;
}

private boolean isSortedNumericField(String field) {
MappedFieldType ft = mapperService.fieldType(field);
assert ft.isAggregatable();
return ft.fielddataBuilder(
"",
() -> { throw new UnsupportedOperationException("SearchLookup not available"); }

Check warning on line 298 in server/src/main/java/org/opensearch/index/codec/composite/composite912/Composite912DocValuesWriter.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/codec/composite/composite912/Composite912DocValuesWriter.java#L298

Added line #L298 was not covered by tests
) instanceof IndexNumericFieldData.Builder;
}

@Override
Expand Down Expand Up @@ -370,5 +389,4 @@
segmentWriteState.segmentSuffix
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import java.util.stream.Collectors;

import static org.opensearch.index.compositeindex.datacube.DateDimension.CALENDAR_INTERVALS;
import static org.opensearch.index.compositeindex.datacube.KeywordDimension.KEYWORD;
import static org.opensearch.index.compositeindex.datacube.IpDimension.IP;
import static org.opensearch.index.compositeindex.datacube.OrdinalDimension.ORDINAL;

/**
* Dimension factory class mainly used to parse and create dimension from the mappings
Expand All @@ -44,8 +45,10 @@ public static Dimension parseAndCreateDimension(
return parseAndCreateDateDimension(name, dimensionMap, c);
case NumericDimension.NUMERIC:
return new NumericDimension(name);
case KEYWORD:
return new KeywordDimension(name);
case ORDINAL:
return new OrdinalDimension(name);
case IP:
bharath-techie marked this conversation as resolved.
Show resolved Hide resolved
return new IpDimension(name);
default:
throw new IllegalArgumentException(
String.format(Locale.ROOT, "unsupported field type associated with dimension [%s] as part of star tree field", name)
Expand All @@ -69,8 +72,10 @@ public static Dimension parseAndCreateDimension(
return parseAndCreateDateDimension(name, dimensionMap, c);
case NUMERIC:
return new NumericDimension(name);
case KEYWORD:
return new KeywordDimension(name);
case ORDINAL:
return new OrdinalDimension(name);
case IP:
return new IpDimension(name);
default:
throw new IllegalArgumentException(
String.format(Locale.ROOT, "unsupported field type associated with star tree dimension [%s]", name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ public enum DimensionType {
DATE,

/**
* Represents a keyword dimension type.
* This is used for dimensions that contain keyword ordinals.
* Represents dimension types which uses ordinals.
* This is used for dimensions that contain sortedSet ordinals.
*/
KEYWORD
ORDINAL,

/**
* Represents an IP dimension type.
* This is used for dimensions that contain IP ordinals.
*/
IP
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.index.compositeindex.datacube;

import org.apache.lucene.index.DocValuesType;
import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.mapper.CompositeDataCubeFieldType;

import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

/**
* Composite index keyword dimension class
*
* @opensearch.experimental
*/
@ExperimentalApi
public class IpDimension implements Dimension {
public static final String IP = "ip";
private final String field;

public IpDimension(String field) {
this.field = field;
}

@Override
public String getField() {
return field;
}

@Override
public int getNumSubDimensions() {
return 1;
}

@Override
public void setDimensionValues(Long value, Consumer<Long> dimSetter) {
// This will set the keyword dimension value's ordinal
dimSetter.accept(value);
}

@Override
public List<String> getSubDimensionNames() {
return List.of(field);
}

@Override
public DocValuesType getDocValuesType() {
return DocValuesType.SORTED_SET;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(CompositeDataCubeFieldType.NAME, field);
builder.field(CompositeDataCubeFieldType.TYPE, IP);
builder.endObject();
return builder;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IpDimension dimension = (IpDimension) o;
return Objects.equals(field, dimension.getField());

Check warning on line 75 in server/src/main/java/org/opensearch/index/compositeindex/datacube/IpDimension.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/datacube/IpDimension.java#L74-L75

Added lines #L74 - L75 were not covered by tests
}

@Override
public int hashCode() {
return Objects.hash(field);

Check warning on line 80 in server/src/main/java/org/opensearch/index/compositeindex/datacube/IpDimension.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/datacube/IpDimension.java#L80

Added line #L80 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
* @opensearch.experimental
*/
@ExperimentalApi
public class KeywordDimension implements Dimension {
public static final String KEYWORD = "keyword";
public class OrdinalDimension implements Dimension {
public static final String ORDINAL = "ordinal";
private final String field;

public KeywordDimension(String field) {
public OrdinalDimension(String field) {
this.field = field;
}

Expand Down Expand Up @@ -62,7 +62,7 @@
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(CompositeDataCubeFieldType.NAME, field);
builder.field(CompositeDataCubeFieldType.TYPE, KEYWORD);
builder.field(CompositeDataCubeFieldType.TYPE, ORDINAL);
builder.endObject();
return builder;
}
Expand All @@ -71,7 +71,7 @@
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
KeywordDimension dimension = (KeywordDimension) o;
OrdinalDimension dimension = (OrdinalDimension) o;

Check warning on line 74 in server/src/main/java/org/opensearch/index/compositeindex/datacube/OrdinalDimension.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/compositeindex/datacube/OrdinalDimension.java#L74

Added line #L74 was not covered by tests
return Objects.equals(field, dimension.getField());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.network.InetAddresses;
import org.opensearch.index.compositeindex.datacube.DimensionType;
import org.opensearch.index.fielddata.IndexFieldData;
import org.opensearch.index.fielddata.ScriptDocValues;
import org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
Expand All @@ -62,6 +63,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -156,6 +158,11 @@ public IpFieldMapper build(BuilderContext context) {
);
}

@Override
public Optional<DimensionType> getSupportedDataCubeDimensionType() {
return Optional.of(DimensionType.IP);
}

}

public static final TypeParser PARSER = new TypeParser((n, c) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public KeywordFieldMapper build(BuilderContext context) {

@Override
public Optional<DimensionType> getSupportedDataCubeDimensionType() {
return Optional.of(DimensionType.KEYWORD);
return Optional.of(DimensionType.ORDINAL);
}
}

Expand Down
Loading
Loading