diff --git a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java index ea40b7fd4dd..fd937a89cd6 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java @@ -127,10 +127,10 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio if (request.fieldDataCache()) { clearedAtLeastOne = true; if (request.fields() == null || request.fields().length == 0) { - service.cache().fieldData().clear("api"); + service.fieldData().clear(); } else { for (String field : request.fields()) { - service.cache().fieldData().clear("api", field); + service.fieldData().clearField(field); } } } @@ -142,7 +142,7 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio if (request.fields() != null && request.fields().length > 0) { // only clear caches relating to the specified fields for (String field : request.fields()) { - service.cache().fieldData().clear("api", field); + service.fieldData().clearField(field); } } else { service.cache().clear("api"); diff --git a/src/main/java/org/elasticsearch/common/lucene/HashedBytesRef.java b/src/main/java/org/elasticsearch/common/lucene/HashedBytesRef.java new file mode 100644 index 00000000000..44873602d2f --- /dev/null +++ b/src/main/java/org/elasticsearch/common/lucene/HashedBytesRef.java @@ -0,0 +1,86 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.common.lucene; + +import org.apache.lucene.util.BytesRef; + +/** + * A wrapped to {@link BytesRef} that also caches the hashCode for it. + */ +public class HashedBytesRef { + + public BytesRef bytes; + public int hash; + + public HashedBytesRef() { + } + + public HashedBytesRef(String bytes) { + this(new BytesRef(bytes)); + } + + public HashedBytesRef(BytesRef bytes) { + this(bytes, bytes.hashCode()); + } + + public HashedBytesRef(BytesRef bytes, int hash) { + this.bytes = bytes; + this.hash = hash; + } + + public HashedBytesRef resetHashCode() { + this.hash = bytes.hashCode(); + return this; + } + + public HashedBytesRef reset(BytesRef bytes, int hash) { + this.bytes = bytes; + this.hash = hash; + return this; + } + + @Override + public int hashCode() { + return hash; + } + + @Override + public boolean equals(Object other) { + if (other instanceof HashedBytesRef) { + return bytes.equals(((HashedBytesRef) other).bytes); + } + return false; + } + + @Override + public String toString() { + return bytes.toString(); + } + + public HashedBytesRef deepCopy() { + return deepCopyOf(this); + } + + public static HashedBytesRef deepCopyOf(HashedBytesRef other) { + BytesRef copy = new BytesRef(); + copy.copyBytes(other.bytes); + return new HashedBytesRef(copy, other.hash); + } +} diff --git a/src/main/java/org/elasticsearch/common/lucene/Lucene.java b/src/main/java/org/elasticsearch/common/lucene/Lucene.java index 5fabf1c00b9..b0bd62b6c8d 100644 --- a/src/main/java/org/elasticsearch/common/lucene/Lucene.java +++ b/src/main/java/org/elasticsearch/common/lucene/Lucene.java @@ -32,7 +32,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.index.analysis.AnalyzerScope; import org.elasticsearch.index.analysis.NamedAnalyzer; -import org.elasticsearch.index.field.data.FieldDataType; +import org.elasticsearch.index.fielddata.IndexFieldData; import java.io.IOException; import java.lang.reflect.Field; @@ -215,7 +215,7 @@ public class Lucene { out.writeString(sortField.getField()); } if (sortField.getComparatorSource() != null) { - writeSortType(out, ((FieldDataType.ExtendedFieldComparatorSource) sortField.getComparatorSource()).reducedType()); + writeSortType(out, ((IndexFieldData.XFieldComparatorSource) sortField.getComparatorSource()).reducedType()); } else { writeSortType(out, sortField.getType()); } diff --git a/src/main/java/org/elasticsearch/index/cache/CacheStats.java b/src/main/java/org/elasticsearch/index/cache/CacheStats.java index eb1c420ae4b..d8ce6149da1 100644 --- a/src/main/java/org/elasticsearch/index/cache/CacheStats.java +++ b/src/main/java/org/elasticsearch/index/cache/CacheStats.java @@ -34,42 +34,28 @@ import java.io.IOException; */ public class CacheStats implements Streamable, ToXContent { - long fieldEvictions; long filterEvictions; long filterCount; - long fieldSize; long filterSize; long idCacheSize; public CacheStats() { } - public CacheStats(long fieldEvictions, long filterEvictions, long fieldSize, long filterSize, long filterCount, long idCacheSize) { - this.fieldEvictions = fieldEvictions; + public CacheStats(long filterEvictions, long filterSize, long filterCount, long idCacheSize) { this.filterEvictions = filterEvictions; - this.fieldSize = fieldSize; this.filterSize = filterSize; this.filterCount = filterCount; this.idCacheSize = idCacheSize; } public void add(CacheStats stats) { - this.fieldEvictions += stats.fieldEvictions; this.filterEvictions += stats.filterEvictions; - this.fieldSize += stats.fieldSize; this.filterSize += stats.filterSize; this.filterCount += stats.filterCount; this.idCacheSize += stats.idCacheSize; } - public long fieldEvictions() { - return this.fieldEvictions; - } - - public long getFieldEvictions() { - return this.fieldEvictions(); - } - public long filterEvictions() { return this.filterEvictions; } @@ -94,22 +80,6 @@ public class CacheStats implements Streamable, ToXContent { return filterCount; } - public long fieldSizeInBytes() { - return this.fieldSize; - } - - public long getFieldSizeInBytes() { - return fieldSizeInBytes(); - } - - public ByteSizeValue fieldSize() { - return new ByteSizeValue(fieldSize); - } - - public ByteSizeValue getFieldSize() { - return this.fieldSize(); - } - public long filterSizeInBytes() { return this.filterSize; } @@ -145,9 +115,6 @@ public class CacheStats implements Streamable, ToXContent { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Fields.CACHE); - builder.field(Fields.FIELD_EVICTIONS, fieldEvictions); - builder.field(Fields.FIELD_SIZE, fieldSize().toString()); - builder.field(Fields.FIELD_SIZE_IN_BYTES, fieldSize); builder.field(Fields.FILTER_COUNT, filterCount); builder.field(Fields.FILTER_EVICTIONS, filterEvictions); builder.field(Fields.FILTER_SIZE, filterSize().toString()); @@ -160,9 +127,6 @@ public class CacheStats implements Streamable, ToXContent { static final class Fields { static final XContentBuilderString CACHE = new XContentBuilderString("cache"); - static final XContentBuilderString FIELD_SIZE = new XContentBuilderString("field_size"); - static final XContentBuilderString FIELD_SIZE_IN_BYTES = new XContentBuilderString("field_size_in_bytes"); - static final XContentBuilderString FIELD_EVICTIONS = new XContentBuilderString("field_evictions"); static final XContentBuilderString FILTER_EVICTIONS = new XContentBuilderString("filter_evictions"); static final XContentBuilderString FILTER_COUNT = new XContentBuilderString("filter_count"); static final XContentBuilderString FILTER_SIZE = new XContentBuilderString("filter_size"); @@ -179,9 +143,7 @@ public class CacheStats implements Streamable, ToXContent { @Override public void readFrom(StreamInput in) throws IOException { - fieldEvictions = in.readVLong(); filterEvictions = in.readVLong(); - fieldSize = in.readVLong(); filterSize = in.readVLong(); filterCount = in.readVLong(); idCacheSize = in.readVLong(); @@ -189,9 +151,7 @@ public class CacheStats implements Streamable, ToXContent { @Override public void writeTo(StreamOutput out) throws IOException { - out.writeVLong(fieldEvictions); out.writeVLong(filterEvictions); - out.writeVLong(fieldSize); out.writeVLong(filterSize); out.writeVLong(filterCount); out.writeVLong(idCacheSize); diff --git a/src/main/java/org/elasticsearch/index/cache/IndexCache.java b/src/main/java/org/elasticsearch/index/cache/IndexCache.java index 0e2957bdded..7b184c321eb 100644 --- a/src/main/java/org/elasticsearch/index/cache/IndexCache.java +++ b/src/main/java/org/elasticsearch/index/cache/IndexCache.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; -import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.cache.filter.FilterCache; import org.elasticsearch.index.cache.id.IdCache; import org.elasticsearch.index.cache.query.parser.QueryParserCache; @@ -44,8 +43,6 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo private final FilterCache filterCache; - private final FieldDataCache fieldDataCache; - private final QueryParserCache queryParserCache; private final IdCache idCache; @@ -58,11 +55,9 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo private CacheStats latestCacheStats; @Inject - public IndexCache(Index index, @IndexSettings Settings indexSettings, FilterCache filterCache, FieldDataCache fieldDataCache, - QueryParserCache queryParserCache, IdCache idCache) { + public IndexCache(Index index, @IndexSettings Settings indexSettings, FilterCache filterCache, QueryParserCache queryParserCache, IdCache idCache) { super(index, indexSettings); this.filterCache = filterCache; - this.fieldDataCache = fieldDataCache; this.queryParserCache = queryParserCache; this.idCache = idCache; @@ -81,7 +76,7 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo public synchronized void invalidateCache() { FilterCache.EntriesStats filterEntriesStats = filterCache.entriesStats(); - latestCacheStats = new CacheStats(fieldDataCache.evictions(), filterCache.evictions(), fieldDataCache.sizeInBytes(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, idCache.sizeInBytes()); + latestCacheStats = new CacheStats(filterCache.evictions(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, idCache.sizeInBytes()); latestCacheStatsTimestamp = System.currentTimeMillis(); } @@ -89,7 +84,7 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo long timestamp = System.currentTimeMillis(); if ((timestamp - latestCacheStatsTimestamp) > refreshInterval.millis()) { FilterCache.EntriesStats filterEntriesStats = filterCache.entriesStats(); - latestCacheStats = new CacheStats(fieldDataCache.evictions(), filterCache.evictions(), fieldDataCache.sizeInBytes(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, idCache.sizeInBytes()); + latestCacheStats = new CacheStats(filterCache.evictions(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, idCache.sizeInBytes()); latestCacheStatsTimestamp = timestamp; } return latestCacheStats; @@ -99,10 +94,6 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo return filterCache; } - public FieldDataCache fieldData() { - return fieldDataCache; - } - public IdCache idCache() { return this.idCache; } @@ -114,7 +105,6 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo @Override public void close() throws ElasticSearchException { filterCache.close(); - fieldDataCache.close(); idCache.close(); queryParserCache.close(); if (clusterService != null) { @@ -124,13 +114,11 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo public void clear(IndexReader reader) { filterCache.clear(reader); - fieldDataCache.clear(reader); idCache.clear(reader); } public void clear(String reason) { filterCache.clear(reason); - fieldDataCache.clear(reason); idCache.clear(); queryParserCache.clear(); } diff --git a/src/main/java/org/elasticsearch/index/cache/IndexCacheModule.java b/src/main/java/org/elasticsearch/index/cache/IndexCacheModule.java index c95535c2b70..4b090477069 100644 --- a/src/main/java/org/elasticsearch/index/cache/IndexCacheModule.java +++ b/src/main/java/org/elasticsearch/index/cache/IndexCacheModule.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.cache; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.cache.field.data.FieldDataCacheModule; import org.elasticsearch.index.cache.filter.FilterCacheModule; import org.elasticsearch.index.cache.id.IdCacheModule; import org.elasticsearch.index.cache.query.parser.QueryParserCacheModule; @@ -40,7 +39,6 @@ public class IndexCacheModule extends AbstractModule { @Override protected void configure() { new FilterCacheModule(settings).configure(binder()); - new FieldDataCacheModule(settings).configure(binder()); new IdCacheModule(settings).configure(binder()); new QueryParserCacheModule(settings).configure(binder()); diff --git a/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java b/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java deleted file mode 100644 index a1ba5b4cc41..00000000000 --- a/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.cache.field.data; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.index.IndexReader; -import org.elasticsearch.common.component.CloseableComponent; -import org.elasticsearch.index.IndexComponent; -import org.elasticsearch.index.field.data.FieldData; -import org.elasticsearch.index.field.data.FieldDataType; - -import java.io.IOException; - -/** - * - */ -public interface FieldDataCache extends IndexComponent, CloseableComponent { - - FieldData cache(FieldDataType type, AtomicReader reader, String fieldName) throws IOException; - - String type(); - - void clear(String reason, String fieldName); - - void clear(String reason); - - void clear(IndexReader reader); - - long evictions(); - - long sizeInBytes(); - - long sizeInBytes(String fieldName); -} diff --git a/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCacheModule.java b/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCacheModule.java deleted file mode 100644 index 6abca05d508..00000000000 --- a/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCacheModule.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.cache.field.data; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Scopes; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.cache.field.data.resident.ResidentFieldDataCache; - -/** - * - */ -public class FieldDataCacheModule extends AbstractModule { - - public static final class FieldDataCacheSettings { - public static final String FIELD_DATA_CACHE_TYPE = "index.cache.field.type"; - } - - private final Settings settings; - - public FieldDataCacheModule(Settings settings) { - this.settings = settings; - } - - @Override - protected void configure() { - bind(FieldDataCache.class) - .to(settings.getAsClass(FieldDataCacheSettings.FIELD_DATA_CACHE_TYPE, ResidentFieldDataCache.class, "org.elasticsearch.index.cache.field.data.", "FieldDataCache")) - .in(Scopes.SINGLETON); - } -} diff --git a/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java b/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java deleted file mode 100644 index 04c404f0343..00000000000 --- a/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.cache.field.data.none; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.index.IndexReader; -import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldData; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.settings.IndexSettings; - -import java.io.IOException; - -/** - * - */ -public class NoneFieldDataCache extends AbstractIndexComponent implements FieldDataCache { - - @Inject - public NoneFieldDataCache(Index index, @IndexSettings Settings indexSettings) { - super(index, indexSettings); - logger.debug("Using no field cache"); - } - - @Override - public FieldData cache(FieldDataType type, AtomicReader reader, String fieldName) throws IOException { - return FieldData.load(type, reader, fieldName); - } - - @Override - public String type() { - return "none"; - } - - @Override - public void clear(String reason, String fieldName) { - - } - - @Override - public void clear(String reason) { - } - - @Override - public void clear(IndexReader reader) { - } - - @Override - public void close() throws ElasticSearchException { - } - - @Override - public long sizeInBytes() { - return 0; - } - - @Override - public long sizeInBytes(String fieldName) { - return 0; - } - - @Override - public long evictions() { - return 0; - } -} diff --git a/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java b/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java deleted file mode 100644 index 6bd2effb578..00000000000 --- a/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.cache.field.data.resident; - -import com.google.common.base.Objects; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.RemovalListener; -import com.google.common.cache.RemovalNotification; -import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.metrics.CounterMetric; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.cache.field.data.support.AbstractConcurrentMapFieldDataCache; -import org.elasticsearch.index.field.data.FieldData; -import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.index.settings.IndexSettingsService; - -import java.util.concurrent.TimeUnit; - -/** - * - */ -public class ResidentFieldDataCache extends AbstractConcurrentMapFieldDataCache implements RemovalListener { - - private final IndexSettingsService indexSettingsService; - - private volatile int maxSize; - private volatile TimeValue expire; - - private final CounterMetric evictions = new CounterMetric(); - - private final ApplySettings applySettings = new ApplySettings(); - - @Inject - public ResidentFieldDataCache(Index index, @IndexSettings Settings indexSettings, IndexSettingsService indexSettingsService) { - super(index, indexSettings); - this.indexSettingsService = indexSettingsService; - - this.maxSize = indexSettings.getAsInt("index.cache.field.max_size", componentSettings.getAsInt("max_size", -1)); - this.expire = indexSettings.getAsTime("index.cache.field.expire", componentSettings.getAsTime("expire", null)); - logger.debug("using [resident] field cache with max_size [{}], expire [{}]", maxSize, expire); - - indexSettingsService.addListener(applySettings); - } - - @Override - public void close() throws ElasticSearchException { - indexSettingsService.removeListener(applySettings); - super.close(); - } - - @Override - protected Cache buildFieldDataMap() { - CacheBuilder cacheBuilder = CacheBuilder.newBuilder().removalListener(this); - if (maxSize != -1) { - cacheBuilder.maximumSize(maxSize); - } - if (expire != null) { - cacheBuilder.expireAfterAccess(expire.nanos(), TimeUnit.NANOSECONDS); - } - return cacheBuilder.build(); - } - - @Override - public String type() { - return "resident"; - } - - @Override - public long evictions() { - return evictions.count(); - } - - @Override - public void onRemoval(RemovalNotification removalNotification) { - if (removalNotification.wasEvicted()) { - evictions.inc(); - } - } - - static { - IndexMetaData.addDynamicSettings( - "index.cache.field.max_size", - "index.cache.field.expire" - ); - } - - class ApplySettings implements IndexSettingsService.Listener { - @Override - public void onRefreshSettings(Settings settings) { - int maxSize = settings.getAsInt("index.cache.field.max_size", ResidentFieldDataCache.this.maxSize); - TimeValue expire = settings.getAsTime("index.cache.field.expire", ResidentFieldDataCache.this.expire); - boolean changed = false; - if (maxSize != ResidentFieldDataCache.this.maxSize) { - logger.info("updating index.cache.field.max_size from [{}] to [{}]", ResidentFieldDataCache.this.maxSize, maxSize); - changed = true; - ResidentFieldDataCache.this.maxSize = maxSize; - } - if (!Objects.equal(expire, ResidentFieldDataCache.this.expire)) { - logger.info("updating index.cache.field.expire from [{}] to [{}]", ResidentFieldDataCache.this.expire, expire); - changed = true; - ResidentFieldDataCache.this.expire = expire; - } - if (changed) { - clear("update_settings"); - } - } - } -} diff --git a/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java b/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java deleted file mode 100644 index 38f83fd6105..00000000000 --- a/src/main/java/org/elasticsearch/index/cache/field/data/soft/SoftFieldDataCache.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.cache.field.data.soft; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.RemovalListener; -import com.google.common.cache.RemovalNotification; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.metrics.CounterMetric; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.cache.field.data.support.AbstractConcurrentMapFieldDataCache; -import org.elasticsearch.index.field.data.FieldData; -import org.elasticsearch.index.settings.IndexSettings; - -/** - * - */ -public class SoftFieldDataCache extends AbstractConcurrentMapFieldDataCache implements RemovalListener { - - private final CounterMetric evictions = new CounterMetric(); - - @Inject - public SoftFieldDataCache(Index index, @IndexSettings Settings indexSettings) { - super(index, indexSettings); - } - - @Override - protected Cache buildFieldDataMap() { - CacheBuilder cacheBuilder = CacheBuilder.newBuilder().softValues().removalListener(this); - return cacheBuilder.build(); - } - - @Override - public long evictions() { - return evictions.count(); - } - - @Override - public String type() { - return "soft"; - } - - @Override - public void onRemoval(RemovalNotification removalNotification) { - if (removalNotification.wasEvicted()) { - evictions.inc(); - } - } -} diff --git a/src/main/java/org/elasticsearch/index/cache/field/data/support/AbstractConcurrentMapFieldDataCache.java b/src/main/java/org/elasticsearch/index/cache/field/data/support/AbstractConcurrentMapFieldDataCache.java deleted file mode 100644 index 7edb9f90ac6..00000000000 --- a/src/main/java/org/elasticsearch/index/cache/field/data/support/AbstractConcurrentMapFieldDataCache.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.cache.field.data.support; - -import com.google.common.cache.Cache; -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.SegmentReader; -import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldData; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.settings.IndexSettings; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.TimeUnit; - -/** - * - */ -public abstract class AbstractConcurrentMapFieldDataCache extends AbstractIndexComponent implements FieldDataCache, SegmentReader.CoreClosedListener { - - private final ConcurrentMap> cache; - - private final Object creationMutex = new Object(); - - protected AbstractConcurrentMapFieldDataCache(Index index, @IndexSettings Settings indexSettings) { - super(index, indexSettings); - this.cache = ConcurrentCollections.newConcurrentMap(); - } - - @Override - public void close() throws ElasticSearchException { - clear("close"); - } - - @Override - public void clear(String reason, String fieldName) { - logger.debug("clearing field [{}] cache, reason [{}]", fieldName, reason); - for (Map.Entry> entry : cache.entrySet()) { - entry.getValue().invalidate(fieldName); - } - } - - @Override - public void clear(String reason) { - logger.debug("full cache clear, reason [{}]", reason); - cache.clear(); - } - - @Override - public void onClose(SegmentReader owner) { - clear(owner); - } - - @Override - public void clear(IndexReader reader) { - cache.remove(reader.getCoreCacheKey()); - } - - @Override - public long sizeInBytes() { - // the overhead of the map is not really relevant... - long sizeInBytes = 0; - for (Cache map : cache.values()) { - for (FieldData fieldData : map.asMap().values()) { - sizeInBytes += fieldData.sizeInBytes(); - } - } - return sizeInBytes; - } - - @Override - public long sizeInBytes(String fieldName) { - long sizeInBytes = 0; - for (Cache map : cache.values()) { - FieldData fieldData = map.getIfPresent(fieldName); - if (fieldData != null) { - sizeInBytes += fieldData.sizeInBytes(); - } - } - return sizeInBytes; - } - - @Override - public FieldData cache(FieldDataType type, AtomicReader reader, String fieldName) throws IOException { - Cache fieldDataCache = cache.get(reader.getCoreCacheKey()); - if (fieldDataCache == null) { - synchronized (creationMutex) { - fieldDataCache = cache.get(reader.getCoreCacheKey()); - if (fieldDataCache == null) { - fieldDataCache = buildFieldDataMap(); - if (reader instanceof SegmentReader) { - ((SegmentReader) reader).addCoreClosedListener(this); - } - cache.put(reader.getCoreCacheKey(), fieldDataCache); - } - } - } - FieldData fieldData = fieldDataCache.getIfPresent(fieldName); - if (fieldData == null) { - synchronized (fieldDataCache) { - fieldData = fieldDataCache.getIfPresent(fieldName); - if (fieldData == null) { - try { - long time = System.nanoTime(); - fieldData = FieldData.load(type, reader, fieldName); - fieldDataCache.put(fieldName, fieldData); - long took = System.nanoTime() - time; - if (logger.isTraceEnabled()) { - logger.trace("loaded field [{}] for reader [{}], took [{}], took_millis [{}]", fieldName, reader, TimeValue.timeValueNanos(took), TimeUnit.NANOSECONDS.toMillis(took)); - } - } catch (OutOfMemoryError e) { - logger.warn("loading field [" + fieldName + "] caused out of memory failure", e); - final OutOfMemoryError outOfMemoryError = new OutOfMemoryError("loading field [" + fieldName + "] caused out of memory failure"); - outOfMemoryError.initCause(e); - throw outOfMemoryError; - } - } - } - } - return fieldData; - } - - protected abstract Cache buildFieldDataMap(); -} diff --git a/src/main/java/org/elasticsearch/index/field/data/FieldData.java b/src/main/java/org/elasticsearch/index/field/data/FieldData.java deleted file mode 100644 index acb7b96e9da..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/FieldData.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.util.concurrent.ThreadLocals; - -import java.io.IOException; - -/** - * - */ -// General TODOs on FieldData -// TODO Optimize the order (both int[] and int[][] when they are sparse, create an Order abstraction) -public abstract class FieldData { - - private final ThreadLocal> cachedDocFieldData = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(createFieldData()); - } - }; - - private final String fieldName; - - private long sizeInBytes = -1; - - protected FieldData(String fieldName) { - this.fieldName = fieldName; - } - - /** - * The field name of this field data. - */ - public final String fieldName() { - return fieldName; - } - - public Doc docFieldData(int docId) { - Doc docFieldData = cachedDocFieldData.get().get(); - docFieldData.setDocId(docId); - return docFieldData; - } - - public long sizeInBytes() { - if (sizeInBytes == -1) { - sizeInBytes = computeSizeInBytes(); - } - return sizeInBytes; - } - - protected abstract long computeSizeInBytes(); - - protected abstract Doc createFieldData(); - - /** - * Is the field data a multi valued one (has multiple values / terms per document id) or not. - */ - public abstract boolean multiValued(); - - /** - * Is there a value associated with this document id. - */ - public abstract boolean hasValue(int docId); - - public abstract BytesRef stringValue(int docId); - - public abstract void forEachValue(StringValueProc proc); - - public static interface StringValueProc { - void onValue(BytesRef value); - } - - public abstract void forEachValueInDoc(int docId, StringValueInDocProc proc); - - public static interface StringValueInDocProc { - void onValue(int docId, BytesRef value); - - void onMissing(int docId); - } - - public abstract void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc); - - public static interface OrdinalInDocProc { - void onOrdinal(int docId, int ordinal); - } - - /** - * The type of this field data. - */ - public abstract FieldDataType type(); - - public static FieldData load(FieldDataType type, AtomicReader reader, String fieldName) throws IOException { - return type.load(reader, fieldName); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/FieldDataType.java b/src/main/java/org/elasticsearch/index/field/data/FieldDataType.java deleted file mode 100644 index d2d724f2a4b..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/FieldDataType.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.search.FieldComparatorSource; -import org.apache.lucene.search.SortField; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.bytes.ByteFieldDataType; -import org.elasticsearch.index.field.data.doubles.DoubleFieldDataType; -import org.elasticsearch.index.field.data.floats.FloatFieldDataType; -import org.elasticsearch.index.field.data.ints.IntFieldDataType; -import org.elasticsearch.index.field.data.longs.LongFieldDataType; -import org.elasticsearch.index.field.data.shorts.ShortFieldDataType; -import org.elasticsearch.index.field.data.strings.StringFieldDataType; - -import java.io.IOException; - -/** - * - */ -public interface FieldDataType { - - public static final class DefaultTypes { - public static final StringFieldDataType STRING = new StringFieldDataType(); - public static final ByteFieldDataType BYTE = new ByteFieldDataType(); - public static final ShortFieldDataType SHORT = new ShortFieldDataType(); - public static final IntFieldDataType INT = new IntFieldDataType(); - public static final LongFieldDataType LONG = new LongFieldDataType(); - public static final FloatFieldDataType FLOAT = new FloatFieldDataType(); - public static final DoubleFieldDataType DOUBLE = new DoubleFieldDataType(); - } - - ExtendedFieldComparatorSource newFieldComparatorSource(FieldDataCache cache, @Nullable String missing); - - T load(AtomicReader reader, String fieldName) throws IOException; - - // we need this extended source we we have custom comparators to reuse our field data - // in this case, we need to reduce type that will be used when search results are reduced - // on another node (we don't have the custom source them...) - public abstract class ExtendedFieldComparatorSource extends FieldComparatorSource { - - public abstract SortField.Type reducedType(); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/NumericDocFieldData.java b/src/main/java/org/elasticsearch/index/field/data/NumericDocFieldData.java deleted file mode 100644 index c1783c01e61..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/NumericDocFieldData.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data; - -/** - * - */ -public class NumericDocFieldData extends DocFieldData { - - public NumericDocFieldData(T fieldData) { - super(fieldData); - } - - public int getIntValue() { - return fieldData.intValue(docId); - } - - public long getLongValue() { - return fieldData.longValue(docId); - } - - public float getFloatValue() { - return fieldData.floatValue(docId); - } - - public double getDoubleValue() { - return fieldData.doubleValue(docId); - } - - public short getShortValue() { - return fieldData.shortValue(docId); - } - - public byte getByteValue() { - return fieldData.byteValue(docId); - } - - public double[] getDoubleValues() { - return fieldData.doubleValues(docId); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/NumericFieldData.java b/src/main/java/org/elasticsearch/index/field/data/NumericFieldData.java deleted file mode 100644 index 42acb4f82d5..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/NumericFieldData.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data; - -/** - * - */ -public abstract class NumericFieldData extends FieldData { - - protected NumericFieldData(String fieldName) { - super(fieldName); - } - - /** - * Returns the value of the specified number as an int. - * This may involve rounding or truncation. - * - * @return the numeric value represented by this object after conversion - * to type int. - */ - public abstract int intValue(int docId); - - /** - * Returns the value of the specified number as a long. - * This may involve rounding or truncation. - * - * @return the numeric value represented by this object after conversion - * to type long. - */ - public abstract long longValue(int docId); - - /** - * Returns the value of the specified number as a float. - * This may involve rounding. - * - * @return the numeric value represented by this object after conversion - * to type float. - */ - public abstract float floatValue(int docId); - - /** - * Returns the value of the specified number as a double. - * This may involve rounding. - * - * @return the numeric value represented by this object after conversion - * to type double. - */ - public abstract double doubleValue(int docId); - - /** - * Returns the value of the specified number as a byte. - * This may involve rounding or truncation. - * - * @return the numeric value represented by this object after conversion - * to type byte. - */ - public byte byteValue(int docId) { - return (byte) intValue(docId); - } - - /** - * Returns the value of the specified number as a short. - * This may involve rounding or truncation. - * - * @return the numeric value represented by this object after conversion - * to type short. - */ - public short shortValue(int docId) { - return (short) intValue(docId); - } - - @Override - public Doc docFieldData(int docId) { - return super.docFieldData(docId); - } - - public abstract double[] doubleValues(int docId); - - public abstract void forEachValueInDoc(int docId, DoubleValueInDocProc proc); - - public abstract void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc); - - public abstract void forEachValueInDoc(int docId, LongValueInDocProc proc); - - public abstract void forEachValueInDoc(int docId, MissingLongValueInDocProc proc); - - public static interface DoubleValueInDocProc { - void onValue(int docId, double value); - } - - public static interface LongValueInDocProc { - void onValue(int docId, long value); - } - - public static interface MissingLongValueInDocProc { - void onValue(int docId, long value); - - void onMissing(int docId); - } - - public static interface MissingDoubleValueInDocProc { - void onValue(int docId, double value); - - void onMissing(int docId); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldData.java b/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldData.java deleted file mode 100644 index a3e602e719a..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldData.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.bytes; - -import gnu.trove.list.array.TByteArrayList; -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.FieldCache; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.NumericFieldData; -import org.elasticsearch.index.field.data.support.FieldDataLoader; - -import java.io.IOException; - -/** - * - */ -public abstract class ByteFieldData extends NumericFieldData { - - static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; - - protected final byte[] values; - - protected ByteFieldData(String fieldName, byte[] values) { - super(fieldName); - this.values = values; - } - - @Override - protected long computeSizeInBytes() { - return 1 * values.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - public final byte[] values() { - return this.values; - } - - abstract public byte value(int docId); - - abstract public byte[] values(int docId); - - @Override - public ByteDocFieldData docFieldData(int docId) { - return super.docFieldData(docId); - } - - @Override - protected ByteDocFieldData createFieldData() { - return new ByteDocFieldData(this); - } - - @Override - public void forEachValue(StringValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(new BytesRef(Byte.toString(values[i]))); - } - } - - @Override - public BytesRef stringValue(int docId) { - return new BytesRef(Byte.toString(value(docId))); - } - - @Override - public byte byteValue(int docId) { - return value(docId); - } - - @Override - public short shortValue(int docId) { - return value(docId); - } - - @Override - public int intValue(int docId) { - return (int) value(docId); - } - - @Override - public long longValue(int docId) { - return (long) value(docId); - } - - @Override - public float floatValue(int docId) { - return (float) value(docId); - } - - @Override - public double doubleValue(int docId) { - return (double) value(docId); - } - - @Override - public FieldDataType type() { - return FieldDataType.DefaultTypes.BYTE; - } - - public void forEachValue(ValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(values[i]); - } - } - - public static interface ValueProc { - void onValue(byte value); - } - - public abstract void forEachValueInDoc(int docId, ValueInDocProc proc); - - public static interface ValueInDocProc { - void onValue(int docId, byte value); - - void onMissing(int docID); - } - - public static ByteFieldData load(AtomicReader reader, String field) throws IOException { - return FieldDataLoader.load(reader, field, new ByteTypeLoader()); - } - - static class ByteTypeLoader extends FieldDataLoader.FreqsTypeLoader { - - private final TByteArrayList terms = new TByteArrayList(); - - ByteTypeLoader() { - super(); - // the first one indicates null value - terms.add((byte) 0); - } - - @Override - public void collectTerm(BytesRef term) { - terms.add((byte) FieldCache.NUMERIC_UTILS_INT_PARSER.parseInt(term)); - } - - @Override - public ByteFieldData buildSingleValue(String field, int[] ordinals) { - return new SingleValueByteFieldData(field, ordinals, terms.toArray()); - } - - @Override - public ByteFieldData buildMultiValue(String field, int[][] ordinals) { - return new MultiValueByteFieldData(field, ordinals, terms.toArray()); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldDataComparator.java b/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldDataComparator.java deleted file mode 100644 index c7abe4b95f3..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldDataComparator.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.bytes; - -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR: Monitor against FieldComparator.Short -public class ByteFieldDataComparator extends NumericFieldDataComparator { - - private final byte[] values; - private short bottom; - - public ByteFieldDataComparator(int numHits, String fieldName, FieldDataCache fieldDataCache) { - super(fieldName, fieldDataCache); - values = new byte[numHits]; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.BYTE; - } - - @Override - public int compare(int slot1, int slot2) { - return values[slot1] - values[slot2]; - } - - @Override - public int compareBottom(int doc) { - return bottom - currentFieldData.byteValue(doc); - } - - @Override - public int compareDocToValue(int doc, Byte val2) throws IOException { - byte val1 = currentFieldData.byteValue(doc); - return val1 - val2; - } - - @Override - public void copy(int slot, int doc) { - values[slot] = currentFieldData.byteValue(doc); - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public Byte value(int slot) { - return values[slot]; - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldDataMissingComparator.java b/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldDataMissingComparator.java deleted file mode 100644 index fe699897f8f..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldDataMissingComparator.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.bytes; - -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR: Monitor against FieldComparator.Short -public class ByteFieldDataMissingComparator extends NumericFieldDataComparator { - - private final byte[] values; - private short bottom; - private final byte missingValue; - - public ByteFieldDataMissingComparator(int numHits, String fieldName, FieldDataCache fieldDataCache, byte missingValue) { - super(fieldName, fieldDataCache); - values = new byte[numHits]; - this.missingValue = missingValue; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.BYTE; - } - - @Override - public int compare(int slot1, int slot2) { - return values[slot1] - values[slot2]; - } - - @Override - public int compareBottom(int doc) { - byte value = missingValue; - if (currentFieldData.hasValue(doc)) { - value = currentFieldData.byteValue(doc); - } - return bottom - value; - } - - @Override - public int compareDocToValue(int doc, Byte val2) throws IOException { - byte val1 = missingValue; - if (currentFieldData.hasValue(doc)) { - val1 = currentFieldData.byteValue(doc); - } - return val1 - val2; - } - - @Override - public void copy(int slot, int doc) { - byte value = missingValue; - if (currentFieldData.hasValue(doc)) { - value = currentFieldData.byteValue(doc); - } - values[slot] = value; - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public Byte value(int slot) { - return values[slot]; - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldDataType.java b/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldDataType.java deleted file mode 100644 index 40201d1116e..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/bytes/ByteFieldDataType.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.bytes; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.search.FieldComparator; -import org.apache.lucene.search.SortField; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; - -import java.io.IOException; - -/** - * - */ -public class ByteFieldDataType implements FieldDataType { - - @Override - public ExtendedFieldComparatorSource newFieldComparatorSource(final FieldDataCache cache, final String missing) { - if (missing == null) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new ByteFieldDataComparator(numHits, fieldname, cache); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.BYTE; - } - }; - } - if (missing.equals("_last")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new ByteFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Byte.MIN_VALUE : Byte.MAX_VALUE); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.BYTE; - } - }; - } - if (missing.equals("_first")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new ByteFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Byte.MAX_VALUE : Byte.MIN_VALUE); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.BYTE; - } - }; - } - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new ByteFieldDataMissingComparator(numHits, fieldname, cache, Byte.parseByte(missing)); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.BYTE; - } - }; - } - - @Override - public ByteFieldData load(AtomicReader reader, String fieldName) throws IOException { - return ByteFieldData.load(reader, fieldName); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/bytes/MultiValueByteFieldData.java b/src/main/java/org/elasticsearch/index/field/data/bytes/MultiValueByteFieldData.java deleted file mode 100644 index e699fd0bb5f..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/bytes/MultiValueByteFieldData.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.bytes; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; -import org.elasticsearch.index.field.data.doubles.DoubleFieldData; - -/** - * - */ -public class MultiValueByteFieldData extends ByteFieldData { - - private static final int VALUE_CACHE_SIZE = 10; - - private ThreadLocal> doublesValuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - double[][] value = new double[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new double[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - private ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - byte[][] value = new byte[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new byte[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - // order with value 0 indicates no value - private final int[][] ordinals; - - public MultiValueByteFieldData(String fieldName, int[][] ordinals, byte[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - long size = super.computeSizeInBytes(); - size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array - for (int[] ordinal : ordinals) { - size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - return size; - } - - @Override - public boolean multiValued() { - return true; - } - - @Override - public boolean hasValue(int docId) { - for (int[] ordinal : ordinals) { - if (ordinal[docId] != 0) { - return true; - } - } - return false; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, new BytesRef(Byte.toString(values[loc]))); - } - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onOrdinal(docId, 0); - } - break; - } - proc.onOrdinal(docId, loc); - } - } - - @Override - public double[] doubleValues(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] == 0) { - break; - } - length++; - } - if (length == 0) { - return DoubleFieldData.EMPTY_DOUBLE_ARRAY; - } - double[] doubles; - if (length < VALUE_CACHE_SIZE) { - doubles = doublesValuesCache.get().get()[length]; - } else { - doubles = new double[length]; - } - for (int i = 0; i < length; i++) { - doubles[i] = values[ordinals[i][docId]]; - } - return doubles; - } - - @Override - public byte value(int docId) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - return values[loc]; - } - } - return 0; - } - - @Override - public byte[] values(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] == 0) { - break; - } - length++; - } - if (length == 0) { - return EMPTY_BYTE_ARRAY; - } - byte[] bytes; - if (length < VALUE_CACHE_SIZE) { - bytes = valuesCache.get().get()[length]; - } else { - bytes = new byte[length]; - } - for (int i = 0; i < length; i++) { - bytes[i] = values[ordinals[i][docId]]; - } - return bytes; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/bytes/SingleValueByteFieldData.java b/src/main/java/org/elasticsearch/index/field/data/bytes/SingleValueByteFieldData.java deleted file mode 100644 index e258b0b419f..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/bytes/SingleValueByteFieldData.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.bytes; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; -import org.elasticsearch.index.field.data.doubles.DoubleFieldData; - -/** - * - */ -public class SingleValueByteFieldData extends ByteFieldData { - - private ThreadLocal> doublesValuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new double[1]); - } - }; - - private ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new byte[1]); - } - }; - - // order with value 0 indicates no value - private final int[] ordinals; - - public SingleValueByteFieldData(String fieldName, int[] ordinals, byte[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - return super.computeSizeInBytes() + - RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - @Override - public boolean multiValued() { - return false; - } - - @Override - public boolean hasValue(int docId) { - return ordinals[docId] != 0; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, new BytesRef(Byte.toString(values[loc]))); - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - proc.onOrdinal(docId, ordinals[docId]); - } - - @Override - public byte value(int docId) { - return values[ordinals[docId]]; - } - - @Override - public double[] doubleValues(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return DoubleFieldData.EMPTY_DOUBLE_ARRAY; - } - double[] ret = doublesValuesCache.get().get(); - ret[0] = values[loc]; - return ret; - } - - @Override - public byte[] values(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return EMPTY_BYTE_ARRAY; - } - byte[] ret = valuesCache.get().get(); - ret[0] = values[loc]; - return ret; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldData.java b/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldData.java deleted file mode 100644 index 26747293d72..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldData.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.doubles; - -import gnu.trove.list.array.TDoubleArrayList; -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.FieldCache; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.NumericFieldData; -import org.elasticsearch.index.field.data.support.FieldDataLoader; - -import java.io.IOException; - -/** - * - */ -public abstract class DoubleFieldData extends NumericFieldData { - - public static final double[] EMPTY_DOUBLE_ARRAY = new double[0]; - - protected final double[] values; - - protected DoubleFieldData(String fieldName, double[] values) { - super(fieldName); - this.values = values; - } - - @Override - protected long computeSizeInBytes() { - return RamUsage.NUM_BYTES_DOUBLE * values.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - public final double[] values() { - return this.values; - } - - abstract public double value(int docId); - - abstract public double[] values(int docId); - - @Override - public DoubleDocFieldData docFieldData(int docId) { - return super.docFieldData(docId); - } - - @Override - protected DoubleDocFieldData createFieldData() { - return new DoubleDocFieldData(this); - } - - @Override - public BytesRef stringValue(int docId) { - return new BytesRef(Double.toString(value(docId))); - } - - @Override - public void forEachValue(StringValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(new BytesRef(Double.toString(values[i]))); - } - } - - @Override - public byte byteValue(int docId) { - return (byte) value(docId); - } - - @Override - public short shortValue(int docId) { - return (short) value(docId); - } - - @Override - public int intValue(int docId) { - return (int) value(docId); - } - - @Override - public long longValue(int docId) { - return (long) value(docId); - } - - @Override - public float floatValue(int docId) { - return (float) value(docId); - } - - @Override - public double doubleValue(int docId) { - return value(docId); - } - - @Override - public FieldDataType type() { - return FieldDataType.DefaultTypes.DOUBLE; - } - - public void forEachValue(ValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(values[i]); - } - } - - public static interface ValueProc { - void onValue(double value); - } - - public abstract void forEachValueInDoc(int docId, ValueInDocProc proc); - - public static interface ValueInDocProc { - void onValue(int docId, double value); - - void onMissing(int docId); - } - - public static DoubleFieldData load(AtomicReader reader, String field) throws IOException { - return FieldDataLoader.load(reader, field, new DoubleTypeLoader()); - } - - static class DoubleTypeLoader extends FieldDataLoader.FreqsTypeLoader { - - private final TDoubleArrayList terms = new TDoubleArrayList(); - - DoubleTypeLoader() { - super(); - // the first one indicates null value - terms.add(0); - } - - @Override - public void collectTerm(BytesRef term) { - terms.add(FieldCache.NUMERIC_UTILS_DOUBLE_PARSER.parseDouble(term)); - } - - @Override - public DoubleFieldData buildSingleValue(String field, int[] ordinals) { - return new SingleValueDoubleFieldData(field, ordinals, terms.toArray()); - } - - @Override - public DoubleFieldData buildMultiValue(String field, int[][] ordinals) { - return new MultiValueDoubleFieldData(field, ordinals, terms.toArray()); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataComparator.java b/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataComparator.java deleted file mode 100644 index ea6407da50d..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataComparator.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.doubles; - -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR: Monitor against FieldComparator.Double -public class DoubleFieldDataComparator extends NumericFieldDataComparator { - - private final double[] values; - private double bottom; - - public DoubleFieldDataComparator(int numHits, String fieldName, FieldDataCache fieldDataCache) { - super(fieldName, fieldDataCache); - values = new double[numHits]; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.DOUBLE; - } - - @Override - public int compare(int slot1, int slot2) { - final double v1 = values[slot1]; - final double v2 = values[slot2]; - if (v1 > v2) { - return 1; - } else if (v1 < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareBottom(int doc) { - final double v2 = currentFieldData.doubleValue(doc); - if (bottom > v2) { - return 1; - } else if (bottom < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareDocToValue(int doc, Double val2) throws IOException { - double val1 = currentFieldData.doubleValue(doc); - return Double.compare(val1, val2); - } - - @Override - public void copy(int slot, int doc) { - values[slot] = currentFieldData.doubleValue(doc); - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public Double value(int slot) { - return values[slot]; - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataMissingComparator.java b/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataMissingComparator.java deleted file mode 100644 index 425b37bef45..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataMissingComparator.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.doubles; - -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR: Monitor against FieldComparator.Double -public class DoubleFieldDataMissingComparator extends NumericFieldDataComparator { - - private final double[] values; - private double bottom; - private final double missingValue; - - public DoubleFieldDataMissingComparator(int numHits, String fieldName, FieldDataCache fieldDataCache, double missingValue) { - super(fieldName, fieldDataCache); - values = new double[numHits]; - this.missingValue = missingValue; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.DOUBLE; - } - - @Override - public int compare(int slot1, int slot2) { - final double v1 = values[slot1]; - final double v2 = values[slot2]; - if (v1 > v2) { - return 1; - } else if (v1 < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareBottom(int doc) { - double v2 = missingValue; - if (currentFieldData.hasValue(doc)) { - v2 = currentFieldData.doubleValue(doc); - } - if (bottom > v2) { - return 1; - } else if (bottom < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareDocToValue(int doc, Double val2) throws IOException { - double val1 = missingValue; - if (currentFieldData.hasValue(doc)) { - val1 = currentFieldData.doubleValue(doc); - } - return Double.compare(val1, val2); - } - - @Override - public void copy(int slot, int doc) { - double value = missingValue; - if (currentFieldData.hasValue(doc)) { - value = currentFieldData.doubleValue(doc); - } - values[slot] = value; - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public Double value(int slot) { - return values[slot]; - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataType.java b/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataType.java deleted file mode 100644 index d7bd9370937..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataType.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.doubles; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.search.FieldComparator; -import org.apache.lucene.search.SortField; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; - -import java.io.IOException; - -/** - * - */ -public class DoubleFieldDataType implements FieldDataType { - - @Override - public ExtendedFieldComparatorSource newFieldComparatorSource(final FieldDataCache cache, final String missing) { - if (missing == null) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new DoubleFieldDataComparator(numHits, fieldname, cache); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.DOUBLE; - } - }; - } - if (missing.equals("_last")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new DoubleFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.DOUBLE; - } - }; - } - if (missing.equals("_first")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new DoubleFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.DOUBLE; - } - }; - } - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new DoubleFieldDataMissingComparator(numHits, fieldname, cache, Double.parseDouble(missing)); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.DOUBLE; - } - }; - } - - @Override - public DoubleFieldData load(AtomicReader reader, String fieldName) throws IOException { - return DoubleFieldData.load(reader, fieldName); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/doubles/MultiValueDoubleFieldData.java b/src/main/java/org/elasticsearch/index/field/data/doubles/MultiValueDoubleFieldData.java deleted file mode 100644 index 1b3bcfd2739..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/doubles/MultiValueDoubleFieldData.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.doubles; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; - -/** - * - */ -public class MultiValueDoubleFieldData extends DoubleFieldData { - - private static final int VALUE_CACHE_SIZE = 10; - - private ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - double[][] value = new double[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new double[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - // order with value 0 indicates no value - private final int[][] ordinals; - - public MultiValueDoubleFieldData(String fieldName, int[][] ordinals, double[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - long size = super.computeSizeInBytes(); - size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array - for (int[] ordinal : ordinals) { - size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - return size; - } - - @Override - public boolean multiValued() { - return true; - } - - @Override - public boolean hasValue(int docId) { - for (int[] ordinal : ordinals) { - if (ordinal[docId] != 0) { - return true; - } - } - return false; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, new BytesRef(Double.toString(values[loc]))); - } - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - proc.onValue(docId, (long) values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, (long) values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onOrdinal(docId, 0); - } - break; - } - proc.onOrdinal(docId, loc); - } - } - - @Override - public double[] doubleValues(int docId) { - return values(docId); - } - - @Override - public double value(int docId) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - return values[loc]; - } - } - return 0; - } - - @Override - public double[] values(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] == 0) { - break; - } - length++; - } - if (length == 0) { - return EMPTY_DOUBLE_ARRAY; - } - double[] doubles; - if (length < VALUE_CACHE_SIZE) { - doubles = valuesCache.get().get()[length]; - } else { - doubles = new double[length]; - } - for (int i = 0; i < length; i++) { - doubles[i] = values[ordinals[i][docId]]; - } - return doubles; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/doubles/SingleValueDoubleFieldData.java b/src/main/java/org/elasticsearch/index/field/data/doubles/SingleValueDoubleFieldData.java deleted file mode 100644 index 829a352a641..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/doubles/SingleValueDoubleFieldData.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.doubles; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; - -/** - * - */ -public class SingleValueDoubleFieldData extends DoubleFieldData { - - private ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new double[1]); - } - }; - - // order with value 0 indicates no value - private final int[] ordinals; - - public SingleValueDoubleFieldData(String fieldName, int[] ordinals, double[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - return super.computeSizeInBytes() + - RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - @Override - public boolean multiValued() { - return false; - } - - @Override - public boolean hasValue(int docId) { - return ordinals[docId] != 0; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, new BytesRef(Double.toString(values[loc]))); - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, (long) values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, (long) values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - proc.onOrdinal(docId, ordinals[docId]); - } - - @Override - public double[] doubleValues(int docId) { - return values(docId); - } - - @Override - public double value(int docId) { - return values[ordinals[docId]]; - } - - @Override - public double[] values(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return EMPTY_DOUBLE_ARRAY; - } - double[] ret = valuesCache.get().get(); - ret[0] = values[loc]; - return ret; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldData.java b/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldData.java deleted file mode 100644 index fe4c555ab12..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldData.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.floats; - -import gnu.trove.list.array.TFloatArrayList; -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.FieldCache; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.NumericFieldData; -import org.elasticsearch.index.field.data.support.FieldDataLoader; - -import java.io.IOException; - -/** - * - */ -public abstract class FloatFieldData extends NumericFieldData { - - static final float[] EMPTY_FLOAT_ARRAY = new float[0]; - - protected final float[] values; - - protected FloatFieldData(String fieldName, float[] values) { - super(fieldName); - this.values = values; - } - - @Override - protected long computeSizeInBytes() { - return RamUsage.NUM_BYTES_FLOAT * values.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - public final float[] values() { - return this.values; - } - - abstract public float value(int docId); - - abstract public float[] values(int docId); - - @Override - public FloatDocFieldData docFieldData(int docId) { - return super.docFieldData(docId); - } - - @Override - protected FloatDocFieldData createFieldData() { - return new FloatDocFieldData(this); - } - - @Override - public BytesRef stringValue(int docId) { - return new BytesRef(Float.toString(value(docId))); - } - - @Override - public void forEachValue(StringValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(new BytesRef(Float.toString(values[i]))); - } - } - - @Override - public byte byteValue(int docId) { - return (byte) value(docId); - } - - @Override - public short shortValue(int docId) { - return (short) value(docId); - } - - @Override - public int intValue(int docId) { - return (int) value(docId); - } - - @Override - public long longValue(int docId) { - return (long) value(docId); - } - - @Override - public float floatValue(int docId) { - return value(docId); - } - - @Override - public double doubleValue(int docId) { - return (double) value(docId); - } - - @Override - public FieldDataType type() { - return FieldDataType.DefaultTypes.FLOAT; - } - - public void forEachValue(ValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(values[i]); - } - } - - public static interface ValueProc { - void onValue(float value); - } - - public abstract void forEachValueInDoc(int docId, ValueInDocProc proc); - - public static interface ValueInDocProc { - void onValue(int docId, float value); - - void onMissing(int docId); - } - - public static FloatFieldData load(AtomicReader reader, String field) throws IOException { - return FieldDataLoader.load(reader, field, new FloatTypeLoader()); - } - - static class FloatTypeLoader extends FieldDataLoader.FreqsTypeLoader { - - private final TFloatArrayList terms = new TFloatArrayList(); - - FloatTypeLoader() { - super(); - // the first one indicates null value - terms.add(0); - } - - @Override - public void collectTerm(BytesRef term) { - terms.add(FieldCache.NUMERIC_UTILS_FLOAT_PARSER.parseFloat(term)); - } - - @Override - public FloatFieldData buildSingleValue(String field, int[] ordinals) { - return new SingleValueFloatFieldData(field, ordinals, terms.toArray()); - } - - @Override - public FloatFieldData buildMultiValue(String field, int[][] ordinals) { - return new MultiValueFloatFieldData(field, ordinals, terms.toArray()); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldDataComparator.java b/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldDataComparator.java deleted file mode 100644 index 8341043fbdb..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldDataComparator.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.floats; - -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR - Monitor against FieldComparator.Float -public class FloatFieldDataComparator extends NumericFieldDataComparator { - - private final float[] values; - private float bottom; - - public FloatFieldDataComparator(int numHits, String fieldName, FieldDataCache fieldDataCache) { - super(fieldName, fieldDataCache); - values = new float[numHits]; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.FLOAT; - } - - @Override - public int compare(int slot1, int slot2) { - // TODO: are there sneaky non-branch ways to compute - // sign of float? - final float v1 = values[slot1]; - final float v2 = values[slot2]; - if (v1 > v2) { - return 1; - } else if (v1 < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareBottom(int doc) { - // TODO: are there sneaky non-branch ways to compute - // sign of float? - final float v2 = currentFieldData.floatValue(doc); - if (bottom > v2) { - return 1; - } else if (bottom < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareDocToValue(int doc, Float val2) throws IOException { - float val1 = currentFieldData.floatValue(doc); - return Float.compare(val1, val2); - } - - @Override - public void copy(int slot, int doc) { - values[slot] = currentFieldData.floatValue(doc); - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public Float value(int slot) { - return values[slot]; - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldDataMissingComparator.java b/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldDataMissingComparator.java deleted file mode 100644 index 540a7fbbf00..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldDataMissingComparator.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.floats; - -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR - Monitor against FieldComparator.Float -public class FloatFieldDataMissingComparator extends NumericFieldDataComparator { - - private final float[] values; - private float bottom; - private final float missingValue; - - public FloatFieldDataMissingComparator(int numHits, String fieldName, FieldDataCache fieldDataCache, float missingValue) { - super(fieldName, fieldDataCache); - values = new float[numHits]; - this.missingValue = missingValue; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.FLOAT; - } - - @Override - public int compare(int slot1, int slot2) { - // TODO: are there sneaky non-branch ways to compute - // sign of float? - final float v1 = values[slot1]; - final float v2 = values[slot2]; - if (v1 > v2) { - return 1; - } else if (v1 < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareBottom(int doc) { - // TODO: are there sneaky non-branch ways to compute - // sign of float? - float v2 = missingValue; - if (currentFieldData.hasValue(doc)) { - v2 = currentFieldData.floatValue(doc); - } - if (bottom > v2) { - return 1; - } else if (bottom < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareDocToValue(int doc, Float val2) throws IOException { - float val1 = missingValue; - if (currentFieldData.hasValue(doc)) { - val1 = currentFieldData.floatValue(doc); - } - return Float.compare(val1, val2); - } - - @Override - public void copy(int slot, int doc) { - float value = missingValue; - if (currentFieldData.hasValue(doc)) { - value = currentFieldData.floatValue(doc); - } - values[slot] = value; - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public Float value(int slot) { - return values[slot]; - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldDataType.java b/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldDataType.java deleted file mode 100644 index 037ee25f8f5..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/floats/FloatFieldDataType.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.floats; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.search.FieldComparator; -import org.apache.lucene.search.SortField; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; - -import java.io.IOException; - -/** - * - */ -public class FloatFieldDataType implements FieldDataType { - - @Override - public ExtendedFieldComparatorSource newFieldComparatorSource(final FieldDataCache cache, final String missing) { - if (missing == null) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new FloatFieldDataComparator(numHits, fieldname, cache); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.FLOAT; - } - }; - } - if (missing.equals("_last")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new FloatFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.FLOAT; - } - }; - } - if (missing.equals("_first")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new FloatFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.FLOAT; - } - }; - } - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new FloatFieldDataMissingComparator(numHits, fieldname, cache, Float.parseFloat(missing)); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.FLOAT; - } - }; - } - - @Override - public FloatFieldData load(AtomicReader reader, String fieldName) throws IOException { - return FloatFieldData.load(reader, fieldName); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/floats/MultiValueFloatFieldData.java b/src/main/java/org/elasticsearch/index/field/data/floats/MultiValueFloatFieldData.java deleted file mode 100644 index 0b7ce83d0a4..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/floats/MultiValueFloatFieldData.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.floats; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; -import org.elasticsearch.index.field.data.doubles.DoubleFieldData; - -/** - * - */ -public class MultiValueFloatFieldData extends FloatFieldData { - - private static final int VALUE_CACHE_SIZE = 10; - - private ThreadLocal> doublesValuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - double[][] value = new double[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new double[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - private ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - float[][] value = new float[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new float[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - // order with value 0 indicates no value - private final int[][] ordinals; - - public MultiValueFloatFieldData(String fieldName, int[][] ordinals, float[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - long size = super.computeSizeInBytes(); - size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array - for (int[] ordinal : ordinals) { - size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - return size; - } - - @Override - public boolean multiValued() { - return true; - } - - @Override - public boolean hasValue(int docId) { - for (int[] ordinal : ordinals) { - if (ordinal[docId] != 0) { - return true; - } - } - return false; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, new BytesRef(Double.toString(values[loc]))); - } - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - proc.onValue(docId, (long) values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, (long) values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onOrdinal(docId, 0); - } - break; - } - proc.onOrdinal(docId, loc); - } - } - - @Override - public double[] doubleValues(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] == 0) { - break; - } - length++; - } - if (length == 0) { - return DoubleFieldData.EMPTY_DOUBLE_ARRAY; - } - double[] doubles; - if (length < VALUE_CACHE_SIZE) { - doubles = doublesValuesCache.get().get()[length]; - } else { - doubles = new double[length]; - } - for (int i = 0; i < length; i++) { - doubles[i] = values[ordinals[i][docId]]; - } - return doubles; - } - - @Override - public float value(int docId) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - return values[loc]; - } - } - return 0; - } - - @Override - public float[] values(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] == 0) { - break; - } - length++; - } - if (length == 0) { - return EMPTY_FLOAT_ARRAY; - } - float[] floats; - if (length < VALUE_CACHE_SIZE) { - floats = valuesCache.get().get()[length]; - } else { - floats = new float[length]; - } - for (int i = 0; i < length; i++) { - floats[i] = values[ordinals[i][docId]]; - } - return floats; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/floats/SingleValueFloatFieldData.java b/src/main/java/org/elasticsearch/index/field/data/floats/SingleValueFloatFieldData.java deleted file mode 100644 index 8814ba50303..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/floats/SingleValueFloatFieldData.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.floats; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; -import org.elasticsearch.index.field.data.doubles.DoubleFieldData; - -/** - * - */ -public class SingleValueFloatFieldData extends FloatFieldData { - - private ThreadLocal> doublesValuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new double[1]); - } - }; - - private ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new float[1]); - } - }; - - // order with value 0 indicates no value - private final int[] ordinals; - - public SingleValueFloatFieldData(String fieldName, int[] ordinals, float[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - return super.computeSizeInBytes() + - RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - @Override - public boolean multiValued() { - return false; - } - - @Override - public boolean hasValue(int docId) { - return ordinals[docId] != 0; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, new BytesRef(Float.toString(values[loc]))); - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, (long) values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, (long) values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - proc.onOrdinal(docId, ordinals[docId]); - } - - @Override - public double[] doubleValues(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return DoubleFieldData.EMPTY_DOUBLE_ARRAY; - } - double[] ret = doublesValuesCache.get().get(); - ret[0] = values[loc]; - return ret; - } - - @Override - public float value(int docId) { - return values[ordinals[docId]]; - } - - @Override - public float[] values(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return EMPTY_FLOAT_ARRAY; - } - float[] ret = valuesCache.get().get(); - ret[0] = values[loc]; - return ret; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldData.java b/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldData.java deleted file mode 100644 index 05a77687d75..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldData.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.ints; - -import gnu.trove.list.array.TIntArrayList; -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.FieldCache; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.NumericFieldData; -import org.elasticsearch.index.field.data.support.FieldDataLoader; - -import java.io.IOException; - -/** - * - */ -public abstract class IntFieldData extends NumericFieldData { - - static final int[] EMPTY_INT_ARRAY = new int[0]; - - protected final int[] values; - - protected IntFieldData(String fieldName, int[] values) { - super(fieldName); - this.values = values; - } - - @Override - protected long computeSizeInBytes() { - return RamUsage.NUM_BYTES_INT * values.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - public final int[] values() { - return this.values; - } - - abstract public int value(int docId); - - abstract public int[] values(int docId); - - @Override - public IntDocFieldData docFieldData(int docId) { - return super.docFieldData(docId); - } - - @Override - protected IntDocFieldData createFieldData() { - return new IntDocFieldData(this); - } - - @Override - public BytesRef stringValue(int docId) { - return new BytesRef(Integer.toString(value(docId))); - } - - @Override - public void forEachValue(StringValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(new BytesRef(Integer.toString(values[i]))); - } - } - - @Override - public byte byteValue(int docId) { - return (byte) value(docId); - } - - @Override - public short shortValue(int docId) { - return (short) value(docId); - } - - @Override - public int intValue(int docId) { - return value(docId); - } - - @Override - public long longValue(int docId) { - return (long) value(docId); - } - - @Override - public float floatValue(int docId) { - return (float) value(docId); - } - - @Override - public double doubleValue(int docId) { - return (double) value(docId); - } - - @Override - public FieldDataType type() { - return FieldDataType.DefaultTypes.INT; - } - - public void forEachValue(ValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(values[i]); - } - } - - public static interface ValueProc { - void onValue(int value); - } - - public abstract void forEachValueInDoc(int docId, ValueInDocProc proc); - - public static interface ValueInDocProc { - void onValue(int docId, int value); - - void onMissing(int docId); - } - - public static IntFieldData load(AtomicReader reader, String field) throws IOException { - return FieldDataLoader.load(reader, field, new IntTypeLoader()); - } - - static class IntTypeLoader extends FieldDataLoader.FreqsTypeLoader { - - private final TIntArrayList terms = new TIntArrayList(); - - IntTypeLoader() { - super(); - // the first one indicates null value - terms.add(0); - } - - @Override - public void collectTerm(BytesRef term) { - terms.add(FieldCache.NUMERIC_UTILS_INT_PARSER.parseInt(term)); - } - - @Override - public IntFieldData buildSingleValue(String field, int[] ordinals) { - return new SingleValueIntFieldData(field, ordinals, terms.toArray()); - } - - @Override - public IntFieldData buildMultiValue(String field, int[][] ordinals) { - return new MultiValueIntFieldData(field, ordinals, terms.toArray()); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldDataComparator.java b/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldDataComparator.java deleted file mode 100644 index 963f116ae11..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldDataComparator.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.ints; - -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR - Monitor against FieldComparator.Int -public class IntFieldDataComparator extends NumericFieldDataComparator { - - private final int[] values; - - private int bottom; // Value of bottom of queue - - public IntFieldDataComparator(int numHits, String fieldName, FieldDataCache fieldDataCache) { - super(fieldName, fieldDataCache); - values = new int[numHits]; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.INT; - } - - @Override - public int compare(int slot1, int slot2) { - // TODO: there are sneaky non-branch ways to compute - // -1/+1/0 sign - // Cannot return values[slot1] - values[slot2] because that - // may overflow - final int v1 = values[slot1]; - final int v2 = values[slot2]; - if (v1 > v2) { - return 1; - } else if (v1 < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareBottom(int doc) { - // TODO: there are sneaky non-branch ways to compute - // -1/+1/0 sign - // Cannot return bottom - values[slot2] because that - // may overflow -// final int v2 = currentReaderValues[doc]; - final int v2 = currentFieldData.intValue(doc); - if (bottom > v2) { - return 1; - } else if (bottom < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareDocToValue(int doc, Integer val2) throws IOException { - int val1 = currentFieldData.intValue(doc); - return val1 - val2; - } - - @Override - public void copy(int slot, int doc) { - values[slot] = currentFieldData.intValue(doc); - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public Integer value(int slot) { - return values[slot]; - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldDataMissingComparator.java b/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldDataMissingComparator.java deleted file mode 100644 index a96cdac5aa1..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldDataMissingComparator.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.ints; - -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR - Monitor against FieldComparator.Int -public class IntFieldDataMissingComparator extends NumericFieldDataComparator { - - private final int[] values; - - private int bottom; // Value of bottom of queue - private final int missingValue; - - public IntFieldDataMissingComparator(int numHits, String fieldName, FieldDataCache fieldDataCache, int missingValue) { - super(fieldName, fieldDataCache); - values = new int[numHits]; - this.missingValue = missingValue; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.INT; - } - - @Override - public int compare(int slot1, int slot2) { - // TODO: there are sneaky non-branch ways to compute - // -1/+1/0 sign - // Cannot return values[slot1] - values[slot2] because that - // may overflow - final int v1 = values[slot1]; - final int v2 = values[slot2]; - if (v1 > v2) { - return 1; - } else if (v1 < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareBottom(int doc) { - // TODO: there are sneaky non-branch ways to compute - // -1/+1/0 sign - // Cannot return bottom - values[slot2] because that - // may overflow -// final int v2 = currentReaderValues[doc]; - int v2 = missingValue; - if (currentFieldData.hasValue(doc)) { - v2 = currentFieldData.intValue(doc); - } - if (bottom > v2) { - return 1; - } else if (bottom < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareDocToValue(int doc, Integer val2) throws IOException { - int val1 = missingValue; - if (currentFieldData.hasValue(doc)) { - val1 = currentFieldData.intValue(doc); - } - return val1 - val2; - } - - @Override - public void copy(int slot, int doc) { - int value = missingValue; - if (currentFieldData.hasValue(doc)) { - value = currentFieldData.intValue(doc); - } - values[slot] = value; - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public Integer value(int slot) { - return values[slot]; - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldDataType.java b/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldDataType.java deleted file mode 100644 index 4b8adc65b99..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/ints/IntFieldDataType.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.ints; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.search.FieldComparator; -import org.apache.lucene.search.SortField; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; - -import java.io.IOException; - -/** - * - */ -public class IntFieldDataType implements FieldDataType { - - @Override - public ExtendedFieldComparatorSource newFieldComparatorSource(final FieldDataCache cache, final String missing) { - if (missing == null) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new IntFieldDataComparator(numHits, fieldname, cache); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.INT; - } - }; - } - if (missing.equals("_last")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new IntFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Integer.MIN_VALUE : Integer.MAX_VALUE); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.INT; - } - }; - } - if (missing.equals("_first")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new IntFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Integer.MAX_VALUE : Integer.MIN_VALUE); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.INT; - } - }; - } - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new IntFieldDataMissingComparator(numHits, fieldname, cache, Integer.parseInt(missing)); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.INT; - } - }; - } - - @Override - public IntFieldData load(AtomicReader reader, String fieldName) throws IOException { - return IntFieldData.load(reader, fieldName); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/ints/MultiValueIntFieldData.java b/src/main/java/org/elasticsearch/index/field/data/ints/MultiValueIntFieldData.java deleted file mode 100644 index 26f825b12cf..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/ints/MultiValueIntFieldData.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.ints; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; -import org.elasticsearch.index.field.data.doubles.DoubleFieldData; - -/** - * - */ -public class MultiValueIntFieldData extends IntFieldData { - - private static final int VALUE_CACHE_SIZE = 10; - - private ThreadLocal> doublesValuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - double[][] value = new double[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new double[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - private ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - int[][] value = new int[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new int[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - // order with value 0 indicates no value - private final int[][] ordinals; - - public MultiValueIntFieldData(String fieldName, int[][] ordinals, int[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - long size = super.computeSizeInBytes(); - size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array - for (int[] ordinal : ordinals) { - size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - return size; - } - - @Override - public boolean multiValued() { - return true; - } - - @Override - public boolean hasValue(int docId) { - for (int[] ordinal : ordinals) { - if (ordinal[docId] != 0) { - return true; - } - } - return false; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, new BytesRef(Integer.toString(values[loc]))); - } - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onOrdinal(docId, 0); - } - break; - } - proc.onOrdinal(docId, loc); - } - } - - @Override - public double[] doubleValues(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] == 0) { - break; - } - length++; - } - if (length == 0) { - return DoubleFieldData.EMPTY_DOUBLE_ARRAY; - } - double[] doubles; - if (length < VALUE_CACHE_SIZE) { - doubles = doublesValuesCache.get().get()[length]; - } else { - doubles = new double[length]; - } - for (int i = 0; i < length; i++) { - doubles[i] = values[ordinals[i][docId]]; - } - return doubles; - } - - @Override - public int value(int docId) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - return values[loc]; - } - } - return 0; - } - - @Override - public int[] values(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] == 0) { - break; - } - length++; - } - if (length == 0) { - return EMPTY_INT_ARRAY; - } - int[] ints; - if (length < VALUE_CACHE_SIZE) { - ints = valuesCache.get().get()[length]; - } else { - ints = new int[length]; - } - for (int i = 0; i < length; i++) { - ints[i] = values[ordinals[i][docId]]; - } - return ints; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/ints/SingleValueIntFieldData.java b/src/main/java/org/elasticsearch/index/field/data/ints/SingleValueIntFieldData.java deleted file mode 100644 index 499066b6935..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/ints/SingleValueIntFieldData.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.ints; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; -import org.elasticsearch.index.field.data.doubles.DoubleFieldData; - -/** - * - */ -public class SingleValueIntFieldData extends IntFieldData { - - private ThreadLocal> doublesValuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new double[1]); - } - }; - - private ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new int[1]); - } - }; - - // order with value 0 indicates no value - private final int[] ordinals; - - public SingleValueIntFieldData(String fieldName, int[] ordinals, int[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - return super.computeSizeInBytes() + - RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - @Override - public boolean multiValued() { - return false; - } - - @Override - public boolean hasValue(int docId) { - return ordinals[docId] != 0; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, new BytesRef(Integer.toString(values[loc]))); - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - proc.onOrdinal(docId, ordinals[docId]); - } - - @Override - public double[] doubleValues(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return DoubleFieldData.EMPTY_DOUBLE_ARRAY; - } - double[] ret = doublesValuesCache.get().get(); - ret[0] = values[loc]; - return ret; - } - - @Override - public int value(int docId) { - return values[ordinals[docId]]; - } - - @Override - public int[] values(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return EMPTY_INT_ARRAY; - } - int[] ret = valuesCache.get().get(); - ret[0] = values[loc]; - return ret; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldData.java b/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldData.java deleted file mode 100644 index 736d90c6448..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldData.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.longs; - -import gnu.trove.list.array.TLongArrayList; -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.search.FieldCache; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.NumericFieldData; -import org.elasticsearch.index.field.data.support.FieldDataLoader; -import org.joda.time.DateTimeZone; -import org.joda.time.MutableDateTime; - -import java.io.IOException; - -/** - * - */ -public abstract class LongFieldData extends NumericFieldData { - - static final long[] EMPTY_LONG_ARRAY = new long[0]; - static final MutableDateTime[] EMPTY_DATETIME_ARRAY = new MutableDateTime[0]; - - ThreadLocal> dateTimeCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new MutableDateTime(DateTimeZone.UTC)); - } - }; - - protected final long[] values; - - protected LongFieldData(String fieldName, long[] values) { - super(fieldName); - this.values = values; - } - - @Override - protected long computeSizeInBytes() { - return RamUsage.NUM_BYTES_LONG * values.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - public final long[] values() { - return this.values; - } - - abstract public long value(int docId); - - abstract public long[] values(int docId); - - public MutableDateTime date(int docId) { - MutableDateTime dateTime = dateTimeCache.get().get(); - dateTime.setMillis(value(docId)); - return dateTime; - } - - public void date(int docId, MutableDateTime dateTime) { - dateTime.setMillis(value(docId)); - } - - public abstract MutableDateTime[] dates(int docId); - - @Override - public LongDocFieldData docFieldData(int docId) { - return super.docFieldData(docId); - } - - @Override - protected LongDocFieldData createFieldData() { - return new LongDocFieldData(this); - } - - @Override - public void forEachValue(StringValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(new BytesRef(Long.toString(values[i]))); - } - } - - @Override - public BytesRef stringValue(int docId) { - return new BytesRef(Long.toString(value(docId))); - } - - @Override - public byte byteValue(int docId) { - return (byte) value(docId); - } - - @Override - public short shortValue(int docId) { - return (short) value(docId); - } - - @Override - public int intValue(int docId) { - return (int) value(docId); - } - - @Override - public long longValue(int docId) { - return value(docId); - } - - @Override - public float floatValue(int docId) { - return (float) value(docId); - } - - @Override - public double doubleValue(int docId) { - return (double) value(docId); - } - - @Override - public FieldDataType type() { - return FieldDataType.DefaultTypes.LONG; - } - - public void forEachValue(ValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(values[i]); - } - } - - public static interface ValueProc { - void onValue(long value); - } - - public abstract void forEachValueInDoc(int docId, ValueInDocProc proc); - - public static interface ValueInDocProc { - void onValue(int docId, long value); - - void onMissing(int docId); - } - - public abstract void forEachValueInDoc(int docId, DateValueInDocProc proc); - - public abstract void forEachValueInDoc(int docId, MutableDateTime dateTime, DateValueInDocProc proc); - - public static interface DateValueInDocProc { - void onValue(int docId, MutableDateTime dateTime); - } - - public static LongFieldData load(AtomicReader reader, String field) throws IOException { - return FieldDataLoader.load(reader, field, new LongTypeLoader()); - } - - static class LongTypeLoader extends FieldDataLoader.FreqsTypeLoader { - - private final TLongArrayList terms = new TLongArrayList(); - - LongTypeLoader() { - super(); - // the first one indicates null value - terms.add(0); - } - - @Override - public void collectTerm(BytesRef term) { - terms.add(FieldCache.NUMERIC_UTILS_LONG_PARSER.parseLong(term)); - } - - @Override - public LongFieldData buildSingleValue(String field, int[] ordinals) { - return new SingleValueLongFieldData(field, ordinals, terms.toArray()); - } - - @Override - public LongFieldData buildMultiValue(String field, int[][] ordinals) { - return new MultiValueLongFieldData(field, ordinals, terms.toArray()); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldDataComparator.java b/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldDataComparator.java deleted file mode 100644 index 6de15ea4033..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldDataComparator.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.longs; - -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR - Monitor against FieldComparator.Long -public class LongFieldDataComparator extends NumericFieldDataComparator { - - private final long[] values; - private long bottom; - - public LongFieldDataComparator(int numHits, String fieldName, FieldDataCache fieldDataCache) { - super(fieldName, fieldDataCache); - values = new long[numHits]; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.LONG; - } - - @Override - public int compare(int slot1, int slot2) { - // TODO: there are sneaky non-branch ways to compute - // -1/+1/0 sign - final long v1 = values[slot1]; - final long v2 = values[slot2]; - if (v1 > v2) { - return 1; - } else if (v1 < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareBottom(int doc) { - // TODO: there are sneaky non-branch ways to compute - // -1/+1/0 sign -// final long v2 = currentReaderValues[doc]; - final long v2 = currentFieldData.longValue(doc); - if (bottom > v2) { - return 1; - } else if (bottom < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareDocToValue(int doc, Long val2) throws IOException { - long val1 = currentFieldData.longValue(doc); - return (int) (val1 - val2); - } - - @Override - public void copy(int slot, int doc) { - values[slot] = currentFieldData.longValue(doc); - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public Long value(int slot) { - return values[slot]; - } - -} diff --git a/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldDataMissingComparator.java b/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldDataMissingComparator.java deleted file mode 100644 index fb2617d48f2..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldDataMissingComparator.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.longs; - -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR - Monitor against FieldComparator.Long -public class LongFieldDataMissingComparator extends NumericFieldDataComparator { - - private final long[] values; - private long bottom; - private final long missingValue; - - public LongFieldDataMissingComparator(int numHits, String fieldName, FieldDataCache fieldDataCache, long missingValue) { - super(fieldName, fieldDataCache); - values = new long[numHits]; - this.missingValue = missingValue; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.LONG; - } - - @Override - public int compare(int slot1, int slot2) { - // TODO: there are sneaky non-branch ways to compute - // -1/+1/0 sign - final long v1 = values[slot1]; - final long v2 = values[slot2]; - if (v1 > v2) { - return 1; - } else if (v1 < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareBottom(int doc) { - // TODO: there are sneaky non-branch ways to compute - // -1/+1/0 sign -// final long v2 = currentReaderValues[doc]; - long v2 = missingValue; - if (currentFieldData.hasValue(doc)) { - v2 = currentFieldData.longValue(doc); - } - if (bottom > v2) { - return 1; - } else if (bottom < v2) { - return -1; - } else { - return 0; - } - } - - @Override - public int compareDocToValue(int doc, Long val2) throws IOException { - long val1 = missingValue; - if (currentFieldData.hasValue(doc)) { - val1 = currentFieldData.longValue(doc); - } - return (int) (val1 - val2); - } - - @Override - public void copy(int slot, int doc) { - long value = missingValue; - if (currentFieldData.hasValue(doc)) { - value = currentFieldData.longValue(doc); - } - values[slot] = value; - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public Long value(int slot) { - return Long.valueOf(values[slot]); - } - -} diff --git a/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldDataType.java b/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldDataType.java deleted file mode 100644 index 545ad883fba..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/longs/LongFieldDataType.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.longs; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.search.FieldComparator; -import org.apache.lucene.search.SortField; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; - -import java.io.IOException; - -/** - * - */ -public class LongFieldDataType implements FieldDataType { - - @Override - public ExtendedFieldComparatorSource newFieldComparatorSource(final FieldDataCache cache, final String missing) { - if (missing == null) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new LongFieldDataComparator(numHits, fieldname, cache); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.LONG; - } - }; - } - if (missing.equals("_last")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new LongFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Long.MIN_VALUE : Long.MAX_VALUE); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.LONG; - } - }; - } - if (missing.equals("_first")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new LongFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Long.MAX_VALUE : Long.MIN_VALUE); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.LONG; - } - }; - } - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new LongFieldDataMissingComparator(numHits, fieldname, cache, Long.parseLong(missing)); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.LONG; - } - }; - } - - @Override - public LongFieldData load(AtomicReader reader, String fieldName) throws IOException { - return LongFieldData.load(reader, fieldName); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/longs/MultiValueLongFieldData.java b/src/main/java/org/elasticsearch/index/field/data/longs/MultiValueLongFieldData.java deleted file mode 100644 index edaabc8f1e3..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/longs/MultiValueLongFieldData.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.longs; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; -import org.elasticsearch.index.field.data.doubles.DoubleFieldData; -import org.joda.time.DateTimeZone; -import org.joda.time.MutableDateTime; - -/** - * - */ -public class MultiValueLongFieldData extends LongFieldData { - - private static final int VALUE_CACHE_SIZE = 10; - - private ThreadLocal> doublesValuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - double[][] value = new double[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new double[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - private ThreadLocal> dateTimesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - MutableDateTime[][] value = new MutableDateTime[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new MutableDateTime[i]; - for (int j = 0; j < i; j++) { - value[i][j] = new MutableDateTime(DateTimeZone.UTC); - } - } - return new ThreadLocals.CleanableValue(value); - } - }; - - - private ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - long[][] value = new long[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new long[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - // order with value 0 indicates no value - private final int[][] ordinals; - - public MultiValueLongFieldData(String fieldName, int[][] ordinals, long[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - long size = super.computeSizeInBytes(); - size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array - for (int[] ordinal : ordinals) { - size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - return size; - } - - @Override - public boolean multiValued() { - return true; - } - - @Override - public boolean hasValue(int docId) { - for (int[] ordinal : ordinals) { - if (ordinal[docId] != 0) { - return true; - } - } - return false; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, new BytesRef(Long.toString(values[loc]))); - } - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onOrdinal(docId, 0); - } - break; - } - proc.onOrdinal(docId, loc); - } - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachValueInDoc(int docId, DateValueInDocProc proc) { - MutableDateTime dateTime = dateTimeCache.get().get(); - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - dateTime.setMillis(values[loc]); - proc.onValue(docId, dateTime); - } - } - - @Override - public void forEachValueInDoc(int docId, MutableDateTime dateTime, DateValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc == 0) { - break; - } - dateTime.setMillis(values[loc]); - proc.onValue(docId, dateTime); - } - } - - @Override - public MutableDateTime[] dates(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] != 0) { - length++; - } - } - if (length == 0) { - return EMPTY_DATETIME_ARRAY; - } - MutableDateTime[] dates; - if (length < VALUE_CACHE_SIZE) { - dates = dateTimesCache.get().get()[length]; - } else { - dates = new MutableDateTime[length]; - for (int i = 0; i < dates.length; i++) { - dates[i] = new MutableDateTime(); - } - } - int i = 0; - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - dates[i++].setMillis(values[loc]); - } - } - return dates; - } - - @Override - public double[] doubleValues(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] == 0) { - break; - } - length++; - } - if (length == 0) { - return DoubleFieldData.EMPTY_DOUBLE_ARRAY; - } - double[] doubles; - if (length < VALUE_CACHE_SIZE) { - doubles = doublesValuesCache.get().get()[length]; - } else { - doubles = new double[length]; - } - for (int i = 0; i < length; i++) { - doubles[i] = values[ordinals[i][docId]]; - } - return doubles; - } - - @Override - public long value(int docId) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - return values[loc]; - } - } - return 0; - } - - @Override - public long[] values(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] == 0) { - break; - } - length++; - } - if (length == 0) { - return EMPTY_LONG_ARRAY; - } - long[] longs; - if (length < VALUE_CACHE_SIZE) { - longs = valuesCache.get().get()[length]; - } else { - longs = new long[length]; - } - for (int i = 0; i < length; i++) { - longs[i] = values[ordinals[i][docId]]; - } - return longs; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/longs/SingleValueLongFieldData.java b/src/main/java/org/elasticsearch/index/field/data/longs/SingleValueLongFieldData.java deleted file mode 100644 index 29561e9ed20..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/longs/SingleValueLongFieldData.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.longs; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; -import org.elasticsearch.index.field.data.doubles.DoubleFieldData; -import org.joda.time.DateTimeZone; -import org.joda.time.MutableDateTime; - -/** - * - */ -public class SingleValueLongFieldData extends LongFieldData { - - private ThreadLocal> doublesValuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new double[1]); - } - }; - - private ThreadLocal> datesValuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - MutableDateTime[] date = new MutableDateTime[1]; - date[0] = new MutableDateTime(DateTimeZone.UTC); - return new ThreadLocals.CleanableValue(date); - } - }; - - private ThreadLocal valuesCache = new ThreadLocal() { - @Override - protected long[] initialValue() { - return new long[1]; - } - }; - - // order with value 0 indicates no value - private final int[] ordinals; - - public SingleValueLongFieldData(String fieldName, int[] ordinals, long[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - return super.computeSizeInBytes() + - RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - @Override - public boolean multiValued() { - return false; - } - - @Override - public boolean hasValue(int docId) { - return ordinals[docId] != 0; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, new BytesRef(Long.toString(values[loc]))); - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - proc.onOrdinal(docId, ordinals[docId]); - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, DateValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - MutableDateTime dateTime = dateTimeCache.get().get(); - dateTime.setMillis(values[loc]); - proc.onValue(docId, dateTime); - } - - @Override - public void forEachValueInDoc(int docId, MutableDateTime dateTime, DateValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - dateTime.setMillis(values[loc]); - proc.onValue(docId, dateTime); - } - - @Override - public MutableDateTime[] dates(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return EMPTY_DATETIME_ARRAY; - } - MutableDateTime[] ret = datesValuesCache.get().get(); - ret[0].setMillis(values[loc]); - return ret; - } - - @Override - public double[] doubleValues(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return DoubleFieldData.EMPTY_DOUBLE_ARRAY; - } - double[] ret = doublesValuesCache.get().get(); - ret[0] = values[loc]; - return ret; - } - - @Override - public long value(int docId) { - return values[ordinals[docId]]; - } - - @Override - public long[] values(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return EMPTY_LONG_ARRAY; - } - long[] ret = valuesCache.get(); - ret[0] = values[loc]; - return ret; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/shorts/MultiValueShortFieldData.java b/src/main/java/org/elasticsearch/index/field/data/shorts/MultiValueShortFieldData.java deleted file mode 100644 index 12ee6191614..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/shorts/MultiValueShortFieldData.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.shorts; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; -import org.elasticsearch.index.field.data.doubles.DoubleFieldData; - -/** - * - */ -public class MultiValueShortFieldData extends ShortFieldData { - - private static final int VALUE_CACHE_SIZE = 10; - - private ThreadLocal> doublesValuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - double[][] value = new double[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new double[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - private ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - short[][] value = new short[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new short[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - // order with value 0 indicates no value - private final int[][] ordinals; - - public MultiValueShortFieldData(String fieldName, int[][] ordinals, short[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - long size = super.computeSizeInBytes(); - size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array - for (int[] ordinal : ordinals) { - size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - return size; - } - - @Override - public boolean multiValued() { - return true; - } - - @Override - public boolean hasValue(int docId) { - for (int[] ordinal : ordinals) { - if (ordinal[docId] != 0) { - return true; - } - } - return false; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - boolean found = false; - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - found = true; - proc.onValue(docId, new BytesRef(Short.toString(values[loc]))); - } - } - if (!found) { - proc.onMissing(docId); - } - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - proc.onValue(docId, values[loc]); - } - } - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - proc.onValue(docId, values[loc]); - } - } - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - boolean found = false; - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - found = true; - proc.onValue(docId, values[loc]); - } - } - if (!found) { - proc.onMissing(docId); - } - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - boolean found = false; - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - found = true; - proc.onValue(docId, values[loc]); - } - } - if (!found) { - proc.onMissing(docId); - } - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - boolean found = false; - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - found = true; - proc.onValue(docId, values[loc]); - } - } - if (!found) { - proc.onMissing(docId); - } - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - boolean found = false; - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - found = true; - proc.onOrdinal(docId, loc); - } - } - if (!found) { - proc.onOrdinal(docId, 0); - } - } - - @Override - public double[] doubleValues(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] != 0) { - length++; - } - } - if (length == 0) { - return DoubleFieldData.EMPTY_DOUBLE_ARRAY; - } - double[] doubles; - if (length < VALUE_CACHE_SIZE) { - doubles = doublesValuesCache.get().get()[length]; - } else { - doubles = new double[length]; - } - int i = 0; - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - doubles[i++] = values[loc]; - } - } - return doubles; - } - - @Override - public short value(int docId) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - return values[loc]; - } - } - return 0; - } - - @Override - public short[] values(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] != 0) { - length++; - } - } - if (length == 0) { - return EMPTY_SHORT_ARRAY; - } - short[] shorts; - if (length < VALUE_CACHE_SIZE) { - shorts = valuesCache.get().get()[length]; - } else { - shorts = new short[length]; - } - int i = 0; - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - shorts[i++] = values[loc]; - } - } - return shorts; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldData.java b/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldData.java deleted file mode 100644 index 3c02442255a..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldData.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.shorts; - -import gnu.trove.list.array.TShortArrayList; -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.search.FieldCache; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.NumericFieldData; -import org.elasticsearch.index.field.data.support.FieldDataLoader; - -import java.io.IOException; - -/** - * - */ -public abstract class ShortFieldData extends NumericFieldData { - - static final short[] EMPTY_SHORT_ARRAY = new short[0]; - - protected final short[] values; - - protected ShortFieldData(String fieldName, short[] values) { - super(fieldName); - this.values = values; - } - - @Override - protected long computeSizeInBytes() { - return RamUsage.NUM_BYTES_SHORT * values.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - public final short[] values() { - return this.values; - } - - abstract public short value(int docId); - - abstract public short[] values(int docId); - - @Override - public ShortDocFieldData docFieldData(int docId) { - return super.docFieldData(docId); - } - - @Override - protected ShortDocFieldData createFieldData() { - return new ShortDocFieldData(this); - } - - @Override - public void forEachValue(StringValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(new BytesRef(Short.toString(values[i]))); - } - } - - @Override - public BytesRef stringValue(int docId) { - return new BytesRef(Short.toString(value(docId))); - } - - @Override - public byte byteValue(int docId) { - return (byte) value(docId); - } - - @Override - public short shortValue(int docId) { - return value(docId); - } - - @Override - public int intValue(int docId) { - return (int) value(docId); - } - - @Override - public long longValue(int docId) { - return (long) value(docId); - } - - @Override - public float floatValue(int docId) { - return (float) value(docId); - } - - @Override - public double doubleValue(int docId) { - return (double) value(docId); - } - - @Override - public FieldDataType type() { - return FieldDataType.DefaultTypes.SHORT; - } - - public void forEachValue(ValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(values[i]); - } - } - - public static interface ValueProc { - void onValue(short value); - } - - public abstract void forEachValueInDoc(int docId, ValueInDocProc proc); - - public static interface ValueInDocProc { - void onValue(int docId, short value); - - void onMissing(int docId); - } - - public static ShortFieldData load(AtomicReader reader, String field) throws IOException { - return FieldDataLoader.load(reader, field, new ShortTypeLoader()); - } - - static class ShortTypeLoader extends FieldDataLoader.FreqsTypeLoader { - - private final TShortArrayList terms = new TShortArrayList(); - - ShortTypeLoader() { - super(); - // the first one indicates null value - terms.add((short) 0); - } - - @Override - public void collectTerm(BytesRef term) { - terms.add((short) FieldCache.NUMERIC_UTILS_INT_PARSER.parseInt(term)); - } - - @Override - public ShortFieldData buildSingleValue(String field, int[] ordinals) { - return new SingleValueShortFieldData(field, ordinals, terms.toArray()); - } - - @Override - public ShortFieldData buildMultiValue(String field, int[][] ordinals) { - return new MultiValueShortFieldData(field, ordinals, terms.toArray()); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataComparator.java b/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataComparator.java deleted file mode 100644 index 0d437899625..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataComparator.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.shorts; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR: Monitor against FieldComparator.Short -public class ShortFieldDataComparator extends NumericFieldDataComparator { - - private final short[] values; - private short bottom; - - public ShortFieldDataComparator(int numHits, String fieldName, FieldDataCache fieldDataCache) { - super(fieldName, fieldDataCache); - values = new short[numHits]; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.SHORT; - } - - @Override - public int compare(int slot1, int slot2) { - return values[slot1] - values[slot2]; - } - - @Override - public int compareBottom(int doc) { - return bottom - currentFieldData.shortValue(doc); - } - - @Override - public void copy(int slot, int doc) { - values[slot] = currentFieldData.shortValue(doc); - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public int compareDocToValue(int doc, Short val2) throws IOException { - short val1 = currentFieldData.shortValue(doc); - return val1 - val2; - } - - @Override - public Short value(int slot) { - return values[slot]; - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataMissingComparator.java b/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataMissingComparator.java deleted file mode 100644 index a85e3510217..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataMissingComparator.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.shorts; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.NumericFieldDataComparator; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR: Monitor against FieldComparator.Short -public class ShortFieldDataMissingComparator extends NumericFieldDataComparator { - - private final short[] values; - private short bottom; - private final short missingValue; - - public ShortFieldDataMissingComparator(int numHits, String fieldName, FieldDataCache fieldDataCache, short missingValue) { - super(fieldName, fieldDataCache); - values = new short[numHits]; - this.missingValue = missingValue; - } - - @Override - public FieldDataType fieldDataType() { - return FieldDataType.DefaultTypes.SHORT; - } - - @Override - public int compare(int slot1, int slot2) { - return values[slot1] - values[slot2]; - } - - @Override - public int compareBottom(int doc) { - short value = missingValue; - if (currentFieldData.hasValue(doc)) { - value = currentFieldData.shortValue(doc); - } - return bottom - value; - } - - @Override - public void copy(int slot, int doc) { - short value = missingValue; - if (currentFieldData.hasValue(doc)) { - value = currentFieldData.shortValue(doc); - } - values[slot] = value; - } - - @Override - public void setBottom(final int bottom) { - this.bottom = values[bottom]; - } - - @Override - public int compareDocToValue(int doc, Short val2) throws IOException { - short val1 = missingValue; - if (currentFieldData.hasValue(doc)) { - val1 = currentFieldData.shortValue(doc); - } - return val1 - val2; - } - - @Override - public Short value(int slot) { - return values[slot]; - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataType.java b/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataType.java deleted file mode 100644 index b69d47ef031..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataType.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.shorts; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.search.FieldComparator; -import org.apache.lucene.search.SortField; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; - -import java.io.IOException; - -/** - * - */ -public class ShortFieldDataType implements FieldDataType { - - @Override - public ExtendedFieldComparatorSource newFieldComparatorSource(final FieldDataCache cache, final String missing) { - if (missing == null) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new ShortFieldDataComparator(numHits, fieldname, cache); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.SHORT; - } - }; - } - if (missing.equals("_last")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new ShortFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Short.MIN_VALUE : Short.MAX_VALUE); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.SHORT; - } - }; - } - if (missing.equals("_first")) { - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new ShortFieldDataMissingComparator(numHits, fieldname, cache, reversed ? Short.MAX_VALUE : Short.MIN_VALUE); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.SHORT; - } - }; - } - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new ShortFieldDataMissingComparator(numHits, fieldname, cache, Short.parseShort(missing)); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.SHORT; - } - }; - } - - @Override - public ShortFieldData load(AtomicReader reader, String fieldName) throws IOException { - return ShortFieldData.load(reader, fieldName); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/shorts/SingleValueShortFieldData.java b/src/main/java/org/elasticsearch/index/field/data/shorts/SingleValueShortFieldData.java deleted file mode 100644 index 732a0cd81ec..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/shorts/SingleValueShortFieldData.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.shorts; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; -import org.elasticsearch.index.field.data.doubles.DoubleFieldData; - -/** - * - */ -public class SingleValueShortFieldData extends ShortFieldData { - - private ThreadLocal> doublesValuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new double[1]); - } - }; - - private ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new short[1]); - } - }; - - // order with value 0 indicates no value - private final int[] ordinals; - - public SingleValueShortFieldData(String fieldName, int[] ordinals, short[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - return super.computeSizeInBytes() + - RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - @Override - public boolean multiValued() { - return false; - } - - @Override - public boolean hasValue(int docId) { - return ordinals[docId] != 0; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, new BytesRef(Short.toString(values[loc]))); - } - - @Override - public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, LongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, MissingLongValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachValueInDoc(int docId, ValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - proc.onOrdinal(docId, ordinals[docId]); - } - - @Override - public short value(int docId) { - return values[ordinals[docId]]; - } - - @Override - public double[] doubleValues(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return DoubleFieldData.EMPTY_DOUBLE_ARRAY; - } - double[] ret = doublesValuesCache.get().get(); - ret[0] = values[loc]; - return ret; - } - - @Override - public short[] values(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return EMPTY_SHORT_ARRAY; - } - short[] ret = valuesCache.get().get(); - ret[0] = values[loc]; - return ret; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/strings/MultiValueStringFieldData.java b/src/main/java/org/elasticsearch/index/field/data/strings/MultiValueStringFieldData.java deleted file mode 100644 index 1cbf77876ea..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/strings/MultiValueStringFieldData.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.strings; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; - -/** - * - */ -public class MultiValueStringFieldData extends StringFieldData { - - private static final BytesRef[] EMPTY_ARRAY = new BytesRef[0]; - - private static final int VALUE_CACHE_SIZE = 100; - - private static ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - BytesRef[][] value = new BytesRef[VALUE_CACHE_SIZE][]; - for (int i = 0; i < value.length; i++) { - value[i] = new BytesRef[i]; - } - return new ThreadLocals.CleanableValue(value); - } - }; - - // order with value 0 indicates no value - private final int[][] ordinals; - - public MultiValueStringFieldData(String fieldName, int[][] ordinals, BytesRef[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - long size = super.computeSizeInBytes(); - size += RamUsage.NUM_BYTES_ARRAY_HEADER; // for the top level array - for (int[] ordinal : ordinals) { - size += RamUsage.NUM_BYTES_INT * ordinal.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - return size; - } - - @Override - public boolean multiValued() { - return true; - } - - @Override - public boolean hasValue(int docId) { - for (int[] ordinal : ordinals) { - if (ordinal[docId] != 0) { - return true; - } - } - return false; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onMissing(docId); - } - break; - } - proc.onValue(docId, values[loc]); - } - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - for (int i = 0; i < ordinals.length; i++) { - int loc = ordinals[i][docId]; - if (loc == 0) { - if (i == 0) { - proc.onOrdinal(docId, 0); - } - break; - } - proc.onOrdinal(docId, loc); - } - } - - @Override - public BytesRef value(int docId) { - for (int[] ordinal : ordinals) { - int loc = ordinal[docId]; - if (loc != 0) { - return values[loc]; - } - } - return null; - } - - @Override - public BytesRef[] values(int docId) { - int length = 0; - for (int[] ordinal : ordinals) { - if (ordinal[docId] == 0) { - break; - } - length++; - } - if (length == 0) { - return EMPTY_ARRAY; - } - BytesRef[] refs; - if (length < VALUE_CACHE_SIZE) { - refs = valuesCache.get().get()[length]; - } else { - refs = new BytesRef[length]; - } - for (int i = 0; i < length; i++) { - refs[i] = values[ordinals[i][docId]]; - } - return refs; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/field/data/strings/SingleValueStringFieldData.java b/src/main/java/org/elasticsearch/index/field/data/strings/SingleValueStringFieldData.java deleted file mode 100644 index b13c6cf4dfd..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/strings/SingleValueStringFieldData.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.strings; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.common.util.concurrent.ThreadLocals; - -/** - * - */ -public class SingleValueStringFieldData extends StringFieldData { - - private static final BytesRef[] EMPTY_ARRAY = new BytesRef[0]; - - private static ThreadLocal> valuesCache = new ThreadLocal>() { - @Override - protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new BytesRef[1]); - } - }; - - // order with value 0 indicates no value - private final int[] ordinals; - - public SingleValueStringFieldData(String fieldName, int[] ordinals, BytesRef[] values) { - super(fieldName, values); - this.ordinals = ordinals; - } - - @Override - protected long computeSizeInBytes() { - return super.computeSizeInBytes() + - RamUsage.NUM_BYTES_INT * ordinals.length + RamUsage.NUM_BYTES_ARRAY_HEADER; - } - - int[] ordinals() { - return ordinals; - } - - @Override - public void forEachOrdinalInDoc(int docId, OrdinalInDocProc proc) { - proc.onOrdinal(docId, ordinals[docId]); - } - - @Override - public boolean multiValued() { - return false; - } - - @Override - public boolean hasValue(int docId) { - return ordinals[docId] != 0; - } - - @Override - public void forEachValueInDoc(int docId, StringValueInDocProc proc) { - int loc = ordinals[docId]; - if (loc == 0) { - proc.onMissing(docId); - return; - } - proc.onValue(docId, values[loc]); - } - - @Override - public BytesRef value(int docId) { - return values[ordinals[docId]]; - } - - @Override - public BytesRef[] values(int docId) { - int loc = ordinals[docId]; - if (loc == 0) { - return EMPTY_ARRAY; - } - BytesRef[] ret = valuesCache.get().get(); - ret[0] = values[loc]; - return ret; - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/strings/StringDocFieldData.java b/src/main/java/org/elasticsearch/index/field/data/strings/StringDocFieldData.java deleted file mode 100644 index 2c75ed6d63e..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/strings/StringDocFieldData.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.strings; - -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.index.field.data.DocFieldData; - -/** - * - */ -public class StringDocFieldData extends DocFieldData { - - public StringDocFieldData(StringFieldData fieldData) { - super(fieldData); - } - - public String getValue() { - BytesRef value = fieldData.value(docId); - if (value == null) { - return null; - } - return value.utf8ToString(); - } - - public String[] getValues() { - BytesRef[] values = fieldData.values(docId); - if (values == null) { - return null; - } - String[] stringValues = new String[values.length]; - for (int i = 0; i < values.length; i++) { - stringValues[i] = values[i].utf8ToString(); - } - return stringValues; - } - - public BytesRef getBytesValue() { - return fieldData.value(docId); - } - - public BytesRef[] getBytesValues() { - return fieldData.values(docId); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/strings/StringFieldData.java b/src/main/java/org/elasticsearch/index/field/data/strings/StringFieldData.java deleted file mode 100644 index 1f45f5d1fa4..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/strings/StringFieldData.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.strings; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.RamUsage; -import org.elasticsearch.index.field.data.FieldData; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.support.FieldDataLoader; - -import java.io.IOException; -import java.util.ArrayList; - -/** - * - */ -public abstract class StringFieldData extends FieldData { - - protected final BytesRef[] values; - - protected StringFieldData(String fieldName, BytesRef[] values) { - super(fieldName); - this.values = values; - } - - @Override - protected long computeSizeInBytes() { - long size = RamUsage.NUM_BYTES_ARRAY_HEADER; - for (BytesRef value : values) { - if (value != null) { - size += RamUsage.NUM_BYTES_OBJECT_REF + RamUsage.NUM_BYTES_OBJECT_HEADER + - RamUsage.NUM_BYTES_ARRAY_HEADER + (value.length + (2 * RamUsage.NUM_BYTES_INT)); - } - } - return size; - } - - public BytesRef[] values() { - return this.values; - } - - abstract public BytesRef value(int docId); - - abstract public BytesRef[] values(int docId); - - @Override - public StringDocFieldData docFieldData(int docId) { - return super.docFieldData(docId); - } - - @Override - public BytesRef stringValue(int docId) { - return value(docId); - } - - @Override - protected StringDocFieldData createFieldData() { - return new StringDocFieldData(this); - } - - @Override - public FieldDataType type() { - return FieldDataType.DefaultTypes.STRING; - } - - @Override - public void forEachValue(StringValueProc proc) { - for (int i = 1; i < values.length; i++) { - proc.onValue(values[i]); - } - } - - public static StringFieldData load(AtomicReader reader, String field) throws IOException { - return FieldDataLoader.load(reader, field, new StringTypeLoader()); - } - - static class StringTypeLoader extends FieldDataLoader.FreqsTypeLoader { - - private final ArrayList terms = new ArrayList(); - - StringTypeLoader() { - super(); - // the first one indicates null value - terms.add(null); - } - - @Override - public void collectTerm(BytesRef term) { - terms.add(term); - } - - @Override - public StringFieldData buildSingleValue(String field, int[] ordinals) { - return new SingleValueStringFieldData(field, ordinals, terms.toArray(new BytesRef[terms.size()])); - } - - @Override - public StringFieldData buildMultiValue(String field, int[][] ordinals) { - return new MultiValueStringFieldData(field, ordinals, terms.toArray(new BytesRef[terms.size()])); - } - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/strings/StringFieldDataType.java b/src/main/java/org/elasticsearch/index/field/data/strings/StringFieldDataType.java deleted file mode 100644 index c5e9f797850..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/strings/StringFieldDataType.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.strings; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.search.FieldComparator; -import org.apache.lucene.search.SortField; -import org.elasticsearch.ElasticSearchIllegalArgumentException; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; - -import java.io.IOException; - -/** - * - */ -public class StringFieldDataType implements FieldDataType { - - @Override - public ExtendedFieldComparatorSource newFieldComparatorSource(final FieldDataCache cache, final String missing) { - if (missing != null) { - throw new ElasticSearchIllegalArgumentException("Sorting on string type field does not support missing parameter"); - } - return new ExtendedFieldComparatorSource() { - @Override - public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { - return new StringOrdValFieldDataComparator(numHits, fieldname, sortPos, reversed, cache); - } - - @Override - public SortField.Type reducedType() { - return SortField.Type.STRING; - } - }; - } - - @Override - public StringFieldData load(AtomicReader reader, String fieldName) throws IOException { - return StringFieldData.load(reader, fieldName); - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/strings/StringOrdValFieldDataComparator.java b/src/main/java/org/elasticsearch/index/field/data/strings/StringOrdValFieldDataComparator.java deleted file mode 100644 index 0c9d6dd6d6a..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/strings/StringOrdValFieldDataComparator.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.strings; - -import org.apache.lucene.index.AtomicReaderContext; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.FieldComparator; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldData; -import org.elasticsearch.index.field.data.FieldDataType; - -import java.io.IOException; - -/** - * - */ -// LUCENE MONITOR: Monitor against FieldComparator#String -public class StringOrdValFieldDataComparator extends FieldComparator { - - private final FieldDataCache fieldDataCache; - - private final int[] ords; - private final BytesRef[] values; - private final int[] readerGen; - - private int currentReaderGen = -1; - private BytesRef[] lookup; - private int[] order; - private final String field; - - private int bottomSlot = -1; - private int bottomOrd; - private boolean bottomSameReader; - private BytesRef bottomValue; - - public StringOrdValFieldDataComparator(int numHits, String field, int sortPos, boolean reversed, FieldDataCache fieldDataCache) { - this.fieldDataCache = fieldDataCache; - ords = new int[numHits]; - values = new BytesRef[numHits]; - readerGen = new int[numHits]; - this.field = field; - } - - @Override - public int compare(int slot1, int slot2) { - if (readerGen[slot1] == readerGen[slot2]) { - return ords[slot1] - ords[slot2]; - } - - final BytesRef val1 = values[slot1]; - final BytesRef val2 = values[slot2]; - if (val1 == null) { - if (val2 == null) { - return 0; - } - return -1; - } else if (val2 == null) { - return 1; - } - return val1.compareTo(val2); - } - - @Override - public int compareBottom(int doc) { - assert bottomSlot != -1; - if (bottomSameReader) { - // ord is precisely comparable, even in the equal case - return bottomOrd - this.order[doc]; - } else { - // ord is only approx comparable: if they are not - // equal, we can use that; if they are equal, we - // must fallback to compare by value - final int order = this.order[doc]; - final int cmp = bottomOrd - order; - if (cmp != 0) { - return cmp; - } - - final BytesRef val2 = lookup[order]; - if (bottomValue == null) { - if (val2 == null) { - return 0; - } - // bottom wins - return -1; - } else if (val2 == null) { - // doc wins - return 1; - } - return bottomValue.compareTo(val2); - } - } - - @Override - public void copy(int slot, int doc) { - final int ord = order[doc]; - ords[slot] = ord; - assert ord >= 0; - values[slot] = lookup[ord]; - readerGen[slot] = currentReaderGen; - } - - @Override - public FieldComparator setNextReader(AtomicReaderContext context) throws IOException { - FieldData cleanFieldData = fieldDataCache.cache(FieldDataType.DefaultTypes.STRING, context.reader(), field); - if (cleanFieldData instanceof MultiValueStringFieldData) { - throw new IOException("Can't sort on string types with more than one value per doc, or more than one token per field"); - } - SingleValueStringFieldData fieldData = (SingleValueStringFieldData) cleanFieldData; - currentReaderGen++; - order = fieldData.ordinals(); - lookup = fieldData.values(); - assert lookup.length > 0; - if (bottomSlot != -1) { - setBottom(bottomSlot); - } - return this; - } - - @Override - public int compareDocToValue(int doc, BytesRef otherVal) throws IOException { - BytesRef val = values[ords[doc]]; - if (otherVal == null) { - if (val == null) { - return 0; - } - return -1; - } else if (val == null) { - return 1; - } - return val.compareTo(otherVal); - } - - @Override - public void setBottom(final int bottom) { - bottomSlot = bottom; - - bottomValue = values[bottomSlot]; - if (currentReaderGen == readerGen[bottomSlot]) { - bottomOrd = ords[bottomSlot]; - bottomSameReader = true; - } else { - if (bottomValue == null) { - ords[bottomSlot] = 0; - bottomOrd = 0; - bottomSameReader = true; - readerGen[bottomSlot] = currentReaderGen; - } else { - final int index = binarySearch(bottomValue, lookup); - if (index < 0) { - bottomOrd = -index - 2; - bottomSameReader = false; - } else { - bottomOrd = index; - // exact value match - bottomSameReader = true; - readerGen[bottomSlot] = currentReaderGen; - ords[bottomSlot] = bottomOrd; - } - } - } - } - - private static int binarySearch(BytesRef value, BytesRef[] values) { - return binarySearch(value, values, 1, values.length-1); - } - - private static int binarySearch(BytesRef value, BytesRef[] values, int low, int high) { - while (low <= high) { - int mid = (low + high) >>> 1; - BytesRef midVal = values[mid]; - int cmp; - if (midVal != null) { - cmp = midVal.compareTo(value); - } else { - cmp = -1; - } - - if (cmp < 0) - low = mid + 1; - else if (cmp > 0) - high = mid - 1; - else - return mid; - } - return -(low + 1); - } - - @Override - public BytesRef value(int slot) { - return values[slot]; - } - - public BytesRef[] getValues() { - return values; - } - - public int getBottomSlot() { - return bottomSlot; - } - - public String getField() { - return field; - } - -} diff --git a/src/main/java/org/elasticsearch/index/field/data/support/FieldDataLoader.java b/src/main/java/org/elasticsearch/index/field/data/support/FieldDataLoader.java deleted file mode 100644 index a52525f5438..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/support/FieldDataLoader.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.support; - -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.index.DocsEnum; -import org.apache.lucene.index.Terms; -import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.index.field.data.FieldData; - -import java.io.IOException; -import java.util.ArrayList; - -/** - * - */ -public class FieldDataLoader { - - @SuppressWarnings({"StringEquality"}) - public static T load(AtomicReader reader, String field, TypeLoader loader) throws IOException { - - loader.init(); - ArrayList ordinals = new ArrayList(); - int[] idx = new int[reader.maxDoc()]; - ordinals.add(new int[reader.maxDoc()]); - - int t = 1; // current term number - - Terms terms = reader.terms(field); - if (terms == null) { - return loader.buildSingleValue(field, ordinals.get(0)); // Return empty field data if field doesn't exists. - } - - TermsEnum termsEnum = terms.iterator(null); - try { - DocsEnum docsEnum = null; - for (BytesRef term = termsEnum.next(); term != null; term = termsEnum.next()) { - loader.collectTerm(BytesRef.deepCopyOf(term)); - docsEnum = termsEnum.docs(reader.getLiveDocs(), docsEnum, 0); - for (int docId = docsEnum.nextDoc(); docId != DocsEnum.NO_MORE_DOCS; docId = docsEnum.nextDoc()) { - int[] ordinal; - if (idx[docId] >= ordinals.size()) { - ordinal = new int[reader.maxDoc()]; - ordinals.add(ordinal); - } else { - ordinal = ordinals.get(idx[docId]); - } - ordinal[docId] = t; - idx[docId]++; - } - t++; - } - } catch (RuntimeException e) { - if (e.getClass().getName().endsWith("StopFillCacheException")) { - // all is well, in case numeric parsers are used. - } else { - throw e; - } - } - - if (ordinals.size() == 1) { - return loader.buildSingleValue(field, ordinals.get(0)); - } else { - int[][] nativeOrdinals = new int[ordinals.size()][]; - for (int i = 0; i < nativeOrdinals.length; i++) { - nativeOrdinals[i] = ordinals.get(i); - } - return loader.buildMultiValue(field, nativeOrdinals); - } - } - - public static interface TypeLoader { - - void init(); - - void collectTerm(BytesRef term); - - T buildSingleValue(String fieldName, int[] ordinals); - - T buildMultiValue(String fieldName, int[][] ordinals); - } - - public static abstract class FreqsTypeLoader implements TypeLoader { - - protected FreqsTypeLoader() { - } - - @Override - public void init() { - } - } -} diff --git a/src/main/java/org/elasticsearch/index/field/data/support/NumericFieldDataComparator.java b/src/main/java/org/elasticsearch/index/field/data/support/NumericFieldDataComparator.java deleted file mode 100644 index f56a3bb10d2..00000000000 --- a/src/main/java/org/elasticsearch/index/field/data/support/NumericFieldDataComparator.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.field.data.support; - -import org.apache.lucene.index.AtomicReaderContext; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.FieldComparator; -import org.elasticsearch.index.cache.field.data.FieldDataCache; -import org.elasticsearch.index.field.data.FieldDataType; -import org.elasticsearch.index.field.data.NumericFieldData; - -import java.io.IOException; - -/** - * - */ -public abstract class NumericFieldDataComparator extends FieldComparator { - - private final String fieldName; - - protected final FieldDataCache fieldDataCache; - - protected NumericFieldData currentFieldData; - - public NumericFieldDataComparator(String fieldName, FieldDataCache fieldDataCache) { - this.fieldName = fieldName; - this.fieldDataCache = fieldDataCache; - } - - public abstract FieldDataType fieldDataType(); - - @Override - public NumericFieldDataComparator setNextReader(AtomicReaderContext context) throws IOException { - currentFieldData = (NumericFieldData) fieldDataCache.cache(fieldDataType(), context.reader(), fieldName); - return this; - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/fielddata/AbstractIndexFieldData.java b/src/main/java/org/elasticsearch/index/fielddata/AbstractIndexFieldData.java new file mode 100644 index 00000000000..54751f306be --- /dev/null +++ b/src/main/java/org/elasticsearch/index/fielddata/AbstractIndexFieldData.java @@ -0,0 +1,39 @@ +package org.elasticsearch.index.fielddata; + +import org.apache.lucene.index.IndexReader; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.AbstractIndexComponent; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.mapper.FieldMapper; +import org.elasticsearch.index.settings.IndexSettings; + +/** + */ +public abstract class AbstractIndexFieldData extends AbstractIndexComponent implements IndexFieldData { + + private final FieldMapper.Names fieldNames; + protected final FieldDataType fieldDataType; + protected final IndexFieldDataCache cache; + + public AbstractIndexFieldData(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) { + super(index, indexSettings); + this.fieldNames = fieldNames; + this.fieldDataType = fieldDataType; + this.cache = cache; + } + + @Override + public FieldMapper.Names getFieldNames() { + return this.fieldNames; + } + + @Override + public void clear() { + cache.clear(index, fieldNames.indexName()); + } + + @Override + public void clear(IndexReader reader) { + cache.clear(index, reader); + } +} diff --git a/src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java b/src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java new file mode 100644 index 00000000000..c2681fab839 --- /dev/null +++ b/src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java @@ -0,0 +1,67 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.fielddata; + +/** + * The thread safe {@link org.apache.lucene.index.AtomicReader} level cache of the data. + */ +public interface AtomicFieldData