Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.mapper;
import org.apache.lucene.search.Query;
import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.common.xcontent.support.XContentMapValues;
import org.opensearch.index.compositeindex.datacube.Dimension;
import org.opensearch.index.compositeindex.datacube.DimensionFactory;
import org.opensearch.index.compositeindex.datacube.Metric;
import org.opensearch.index.compositeindex.datacube.MetricStat;
import org.opensearch.index.compositeindex.datacube.startree.StarTreeField;
import org.opensearch.index.compositeindex.datacube.startree.StarTreeFieldConfiguration;
import org.opensearch.index.compositeindex.datacube.startree.StarTreeIndexSettings;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.search.lookup.SearchLookup;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
import java.util.stream.Collectors;
/**
* A field mapper for star tree fields
*
* @opensearch.experimental
*/
@ExperimentalApi
public class StarTreeMapper extends ParametrizedFieldMapper {
public static final String CONTENT_TYPE = "star_tree";
public static final String CONFIG = "config";
public static final String MAX_LEAF_DOCS = "max_leaf_docs";
public static final String SKIP_STAR_NODE_IN_DIMS = "skip_star_node_creation_for_dimensions";
public static final String BUILD_MODE = "build_mode";
public static final String ORDERED_DIMENSIONS = "ordered_dimensions";
public static final String METRICS = "metrics";
public static final String STATS = "stats";
@Override
public ParametrizedFieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName(), objBuilder).init(this);
}
/**
* Builder for the star tree field mapper
*
* @opensearch.internal
*/
public static class Builder extends ParametrizedFieldMapper.Builder {
private ObjectMapper.Builder objbuilder;
@SuppressWarnings("unchecked")
private final Parameter config = new Parameter<>(CONFIG, false, () -> null, (name, context, nodeObj) -> {
if (nodeObj instanceof Map, ?>) {
Map paramMap = (Map) nodeObj;
int maxLeafDocs = XContentMapValues.nodeIntegerValue(
paramMap.get(MAX_LEAF_DOCS),
StarTreeIndexSettings.STAR_TREE_DEFAULT_MAX_LEAF_DOCS.get(context.getSettings())
);
if (maxLeafDocs < 1) {
throw new IllegalArgumentException(
String.format(Locale.ROOT, "%s [%s] must be greater than 0", MAX_LEAF_DOCS, maxLeafDocs)
);
}
paramMap.remove(MAX_LEAF_DOCS);
Set skipStarInDims = new LinkedHashSet<>(
List.of(XContentMapValues.nodeStringArrayValue(paramMap.getOrDefault(SKIP_STAR_NODE_IN_DIMS, new ArrayList())))
);
paramMap.remove(SKIP_STAR_NODE_IN_DIMS);
StarTreeFieldConfiguration.StarTreeBuildMode buildMode = StarTreeFieldConfiguration.StarTreeBuildMode.OFF_HEAP;
List dimensions = buildDimensions(name, paramMap, context);
paramMap.remove(ORDERED_DIMENSIONS);
List metrics = buildMetrics(name, paramMap, context);
paramMap.remove(METRICS);
paramMap.remove(CompositeDataCubeFieldType.NAME);
for (String dim : skipStarInDims) {
if (dimensions.stream().filter(d -> d.getField().equals(dim)).findAny().isEmpty()) {
throw new IllegalArgumentException(
String.format(
Locale.ROOT,
"[%s] in skip_star_node_creation_for_dimensions should be part of ordered_dimensions",
dim
)
);
}
}
StarTreeFieldConfiguration spec = new StarTreeFieldConfiguration(maxLeafDocs, skipStarInDims, buildMode);
DocumentMapperParser.checkNoRemainingFields(
paramMap,
context.indexVersionCreated(),
"Star tree mapping definition has unsupported parameters: "
);
return new StarTreeField(this.name, dimensions, metrics, spec);
} else {
throw new IllegalArgumentException(
String.format(Locale.ROOT, "unable to parse config for star tree field [%s]", this.name)
);
}
}, m -> toType(m).starTreeField);
/**
* Build dimensions from mapping
*/
@SuppressWarnings("unchecked")
private List buildDimensions(String fieldName, Map map, Mapper.TypeParser.ParserContext context) {
Object dims = XContentMapValues.extractValue("ordered_dimensions", map);
if (dims == null) {
throw new IllegalArgumentException(
String.format(Locale.ROOT, "ordered_dimensions is required for star tree field [%s]", fieldName)
);
}
List dimensions = new LinkedList<>();
if (dims instanceof List>) {
List