Skip to content

Commit

Permalink
updates from review
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrik-es committed Nov 11, 2024
1 parent 556c260 commit 1850b85
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.index.mapper;

import org.apache.lucene.util.BytesRef;
import org.elasticsearch.index.IndexSettings;

import java.net.InetAddress;

/**
* Collects dimensions from documents.
*/
public interface DocumentDimensions {

/**
* Build an index's DocumentDimensions using its settings
*/
static DocumentDimensions fromIndexSettings(IndexSettings indexSettings) {
return indexSettings.getMode().buildDocumentDimensions(indexSettings);
}

/**
* This overloaded method tries to take advantage of the fact that the UTF-8
* value is already computed in some cases when we want to collect
* dimensions, so we can save re-computing the UTF-8 encoding.
*/
DocumentDimensions addString(String fieldName, BytesRef utf8Value);

default DocumentDimensions addString(String fieldName, String value) {
return addString(fieldName, new BytesRef(value));
}

DocumentDimensions addIp(String fieldName, InetAddress value);

DocumentDimensions addLong(String fieldName, long value);

DocumentDimensions addUnsignedLong(String fieldName, long value);

DocumentDimensions addBoolean(String fieldName, boolean value);

DocumentDimensions validate(IndexSettings settings);

/**
* Noop implementation that doesn't perform validations on dimension fields
*/
enum Noop implements DocumentDimensions {

INSTANCE;

@Override
public DocumentDimensions addString(String fieldName, BytesRef utf8Value) {
return this;
}

@Override
public DocumentDimensions addString(String fieldName, String value) {
return this;
}

@Override
public DocumentDimensions addIp(String fieldName, InetAddress value) {
return this;
}

@Override
public DocumentDimensions addLong(String fieldName, long value) {
return this;
}

@Override
public DocumentDimensions addUnsignedLong(String fieldName, long value) {
return this;
}

@Override
public DocumentDimensions addBoolean(String fieldName, boolean value) {
return this;
}

@Override
public DocumentDimensions validate(IndexSettings settings) {
return this;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/**
* Implementation of routing fields, using field matching based on the routing path content.
*/
public class RoutingPathFields implements RoutingFields {
public final class RoutingPathFields implements RoutingFields {

private static final int SEED = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void testWithBuilder() throws Exception {
routingPathFields.addUnsignedLong("path.unsigned_long_name", randomLongBetween(0, Long.MAX_VALUE));
current = routingPathFields.buildHash();
assertTrue(current.length() > previous.length());
assertArrayEquals(current.array(), routingPathFields.buildHash().array());
}

public void testWithoutBuilder() throws Exception {
Expand Down Expand Up @@ -85,5 +86,7 @@ public void testWithoutBuilder() throws Exception {
routingPathFields.addUnsignedLong("path.unsigned_long_name", randomLongBetween(0, Long.MAX_VALUE));
current = routingPathFields.buildHash();
assertTrue(current.length() > previous.length());
assertArrayEquals(current.array(), routingPathFields.buildHash().array()
);
}
}

0 comments on commit 1850b85

Please sign in to comment.