forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commits add doc values support to geo point using the exact same approach as for numeric data: geo points for a given document are stored uncompressed and sequentially in a single binary doc values field. Close elastic#4207
- Loading branch information
Showing
7 changed files
with
273 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointBinaryDVAtomicFieldData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* 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.plain; | ||
|
||
import org.apache.lucene.index.AtomicReader; | ||
import org.apache.lucene.index.BinaryDocValues; | ||
import org.apache.lucene.util.BytesRef; | ||
import org.elasticsearch.common.geo.GeoPoint; | ||
import org.elasticsearch.common.util.ByteUtils; | ||
import org.elasticsearch.index.fielddata.AtomicGeoPointFieldData; | ||
import org.elasticsearch.index.fielddata.GeoPointValues; | ||
import org.elasticsearch.index.fielddata.ScriptDocValues; | ||
|
||
final class GeoPointBinaryDVAtomicFieldData extends AtomicGeoPointFieldData<ScriptDocValues> { | ||
|
||
private final AtomicReader reader; | ||
private final BinaryDocValues values; | ||
|
||
GeoPointBinaryDVAtomicFieldData(AtomicReader reader, BinaryDocValues values) { | ||
super(); | ||
this.reader = reader; | ||
this.values = values == null ? BinaryDocValues.EMPTY : values; | ||
} | ||
|
||
@Override | ||
public boolean isMultiValued() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isValuesOrdered() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getNumDocs() { | ||
return reader.maxDoc(); | ||
} | ||
|
||
@Override | ||
public long getNumberUniqueValues() { | ||
return Long.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public long getMemorySizeInBytes() { | ||
return -1; // not exposed by Lucene | ||
} | ||
|
||
@Override | ||
public ScriptDocValues getScriptValues() { | ||
return new ScriptDocValues.GeoPoints(getGeoPointValues()); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public GeoPointValues getGeoPointValues() { | ||
return new GeoPointValues(true) { | ||
|
||
final BytesRef bytes = new BytesRef(); | ||
int i = Integer.MAX_VALUE; | ||
int valueCount = 0; | ||
final GeoPoint point = new GeoPoint(); | ||
|
||
@Override | ||
public int setDocument(int docId) { | ||
values.get(docId, bytes); | ||
assert bytes.length % 16 == 0; | ||
i = 0; | ||
return valueCount = (bytes.length >>> 4); | ||
} | ||
|
||
@Override | ||
public GeoPoint nextValue() { | ||
assert i < 2 * valueCount; | ||
final double lat = ByteUtils.readDoubleLE(bytes.bytes, bytes.offset + i++ * 8); | ||
final double lon = ByteUtils.readDoubleLE(bytes.bytes, bytes.offset + i++ * 8); | ||
return point.reset(lat, lon); | ||
} | ||
|
||
}; | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointBinaryDVIndexFieldData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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.plain; | ||
|
||
import org.apache.lucene.index.AtomicReaderContext; | ||
import org.elasticsearch.ElasticSearchIllegalArgumentException; | ||
import org.elasticsearch.ElasticSearchIllegalStateException; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.fielddata.*; | ||
import org.elasticsearch.index.fielddata.fieldcomparator.SortMode; | ||
import org.elasticsearch.index.mapper.FieldMapper; | ||
import org.elasticsearch.index.mapper.FieldMapper.Names; | ||
|
||
import java.io.IOException; | ||
|
||
public class GeoPointBinaryDVIndexFieldData extends DocValuesIndexFieldData implements IndexGeoPointFieldData<AtomicGeoPointFieldData<ScriptDocValues>> { | ||
|
||
public GeoPointBinaryDVIndexFieldData(Index index, Names fieldNames) { | ||
super(index, fieldNames); | ||
} | ||
|
||
@Override | ||
public boolean valuesOrdered() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public final XFieldComparatorSource comparatorSource(@Nullable Object missingValue, SortMode sortMode) { | ||
throw new ElasticSearchIllegalArgumentException("can't sort on geo_point field without using specific sorting feature, like geo_distance"); | ||
} | ||
|
||
@Override | ||
public AtomicGeoPointFieldData<ScriptDocValues> load(AtomicReaderContext context) { | ||
try { | ||
return new GeoPointBinaryDVAtomicFieldData(context.reader(), context.reader().getBinaryDocValues(fieldNames.indexName())); | ||
} catch (IOException e) { | ||
throw new ElasticSearchIllegalStateException("Cannot load doc values", e); | ||
} | ||
} | ||
|
||
@Override | ||
public AtomicGeoPointFieldData<ScriptDocValues> loadDirect(AtomicReaderContext context) throws Exception { | ||
return load(context); | ||
} | ||
|
||
public static class Builder implements IndexFieldData.Builder { | ||
|
||
@Override | ||
public IndexFieldData<?> build(Index index, Settings indexSettings, FieldMapper<?> mapper, IndexFieldDataCache cache) { | ||
final FieldMapper.Names fieldNames = mapper.names(); | ||
return new GeoPointBinaryDVIndexFieldData(index, fieldNames); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.