From 7397007e05ed361805ecc3c2752e1472062c918f Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Fri, 18 Jan 2013 12:00:49 +0100 Subject: [PATCH] initial commit --- .../common/lucene/HashedBytesRef.java | 76 + .../fielddata/AbstractIndexFieldData.java | 32 + .../index/fielddata/AtomicFieldData.java | 66 + .../fielddata/AtomicNumericFieldData.java | 37 + .../fielddata/AtomicOrdinalFieldData.java | 40 + .../index/fielddata/ByteValues.java | 198 +++ .../index/fielddata/BytesValues.java | 305 ++++ .../index/fielddata/DoubleValues.java | 100 ++ .../index/fielddata/FieldDataType.java | 56 + .../index/fielddata/FloatValues.java | 198 +++ .../index/fielddata/HashedBytesValues.java | 411 +++++ .../index/fielddata/IndexFieldData.java | 77 + .../index/fielddata/IndexFieldDataCache.java | 91 ++ .../fielddata/IndexFieldDataService.java | 124 ++ .../fielddata/IndexNumericFieldData.java | 48 + .../fielddata/IndexOrdinalFieldData.java | 37 + .../index/fielddata/IntValues.java | 198 +++ .../index/fielddata/LongValues.java | 100 ++ .../index/fielddata/OrdinalsBytesValues.java | 73 + .../fielddata/OrdinalsHashedBytesValues.java | 87 ++ .../index/fielddata/OrdinalsStringValues.java | 31 + .../index/fielddata/ScriptDocValues.java | 258 ++++ .../index/fielddata/ShortValues.java | 198 +++ .../index/fielddata/StringValues.java | 102 ++ .../BytesRefFieldComparatorSource.java | 52 + .../BytesRefOrdValComparator.java | 475 ++++++ .../BytesRefValComparator.java | 119 ++ .../DoubleValuesComparator.java | 105 ++ .../DoubleValuesComparatorSource.java | 62 + .../fielddata/ordinals/DocIdOrdinals.java | 122 ++ .../fielddata/ordinals/EmptyOrdinals.java | 112 ++ .../ordinals/MultiFlatArrayOrdinals.java | 187 +++ .../index/fielddata/ordinals/Ordinals.java | 153 ++ .../ordinals/SingleArrayOrdinals.java | 129 ++ .../ordinals/SinglePackedOrdinals.java | 133 ++ .../ConcreteBytesRefAtomicFieldData.java | 673 +++++++++ .../plain/ConcreteBytesRefIndexFieldData.java | 155 ++ .../plain/DoubleArrayAtomicFieldData.java | 913 +++++++++++ .../plain/DoubleArrayIndexFieldData.java | 156 ++ .../index/fielddata/util/ByteArrayRef.java | 172 +++ .../fielddata/util/BytesRefArrayRef.java | 59 + .../index/fielddata/util/DoubleArrayRef.java | 172 +++ .../index/fielddata/util/FloatArrayRef.java | 172 +++ .../index/fielddata/util/IntArrayRef.java | 172 +++ .../index/fielddata/util/LongArrayRef.java | 172 +++ .../index/fielddata/util/ShortArrayRef.java | 172 +++ .../index/fielddata/util/StringArrayRef.java | 149 ++ .../fielddata/AbstractFieldDataTests.java | 413 +++++ .../ConcreteBytesStringFieldDataTests.java | 35 + .../index/fielddata/DoubleFieldDataTests.java | 32 + .../fielddata/NumericFieldDataTests.java | 1344 +++++++++++++++++ .../index/fielddata/StringFieldDataTests.java | 741 +++++++++ 52 files changed, 10294 insertions(+) create mode 100644 src/main/java/org/elasticsearch/common/lucene/HashedBytesRef.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/AbstractIndexFieldData.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/AtomicNumericFieldData.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/AtomicOrdinalFieldData.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/ByteValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/BytesValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/DoubleValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/FieldDataType.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/FloatValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/HashedBytesValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/IndexFieldData.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataCache.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/IndexFieldDataService.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/IndexNumericFieldData.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/IndexOrdinalFieldData.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/IntValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/LongValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/OrdinalsBytesValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/OrdinalsHashedBytesValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/OrdinalsStringValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/ShortValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/StringValues.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/BytesRefFieldComparatorSource.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/BytesRefOrdValComparator.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/BytesRefValComparator.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/DoubleValuesComparator.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/DoubleValuesComparatorSource.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/ordinals/DocIdOrdinals.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/ordinals/EmptyOrdinals.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/ordinals/MultiFlatArrayOrdinals.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/ordinals/Ordinals.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/ordinals/SingleArrayOrdinals.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/ordinals/SinglePackedOrdinals.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/plain/ConcreteBytesRefAtomicFieldData.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/plain/ConcreteBytesRefIndexFieldData.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/plain/DoubleArrayAtomicFieldData.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/plain/DoubleArrayIndexFieldData.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/util/ByteArrayRef.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/util/BytesRefArrayRef.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/util/DoubleArrayRef.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/util/FloatArrayRef.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/util/IntArrayRef.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/util/LongArrayRef.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/util/ShortArrayRef.java create mode 100644 src/main/java/org/elasticsearch/index/fielddata/util/StringArrayRef.java create mode 100644 src/test/java/org/elasticsearch/test/unit/index/fielddata/AbstractFieldDataTests.java create mode 100644 src/test/java/org/elasticsearch/test/unit/index/fielddata/ConcreteBytesStringFieldDataTests.java create mode 100644 src/test/java/org/elasticsearch/test/unit/index/fielddata/DoubleFieldDataTests.java create mode 100644 src/test/java/org/elasticsearch/test/unit/index/fielddata/NumericFieldDataTests.java create mode 100644 src/test/java/org/elasticsearch/test/unit/index/fielddata/StringFieldDataTests.java 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..299de543e9a --- /dev/null +++ b/src/main/java/org/elasticsearch/common/lucene/HashedBytesRef.java @@ -0,0 +1,76 @@ +/* + * 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(); + } +} 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..894d98f50fa --- /dev/null +++ b/src/main/java/org/elasticsearch/index/fielddata/AbstractIndexFieldData.java @@ -0,0 +1,32 @@ +package org.elasticsearch.index.fielddata; + +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.AbstractIndexComponent; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.settings.IndexSettings; + +/** + */ +public abstract class AbstractIndexFieldData extends AbstractIndexComponent implements IndexFieldData { + + private final String fieldName; + protected final FieldDataType fieldDataType; + protected final IndexFieldDataCache cache; + + public AbstractIndexFieldData(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType fieldDataType, IndexFieldDataCache cache) { + super(index, indexSettings); + this.fieldName = fieldName; + this.fieldDataType = fieldDataType; + this.cache = cache; + } + + @Override + public String getFieldName() { + return this.fieldName; + } + + @Override + public void clear() { + cache.clear(index, fieldName); + } +} 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..1648a320397 --- /dev/null +++ b/src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java @@ -0,0 +1,66 @@ +/* + * 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