forked from crate/crate
-
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.
- Loading branch information
1 parent
044245d
commit f200b5b
Showing
3 changed files
with
96 additions
and
7 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
sql/src/main/java/io/crate/operation/reference/doc/lucene/GeoPointColumnReference.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,75 @@ | ||
/* | ||
* Licensed to CRATE Technology GmbH ("Crate") under one or more contributor | ||
* license agreements. See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. Crate 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. | ||
* | ||
* However, if you have executed another commercial license agreement | ||
* with Crate these terms will supersede the license and you may use the | ||
* software solely pursuant to the terms of the relevant commercial agreement. | ||
*/ | ||
|
||
package io.crate.operation.reference.doc.lucene; | ||
|
||
import io.crate.exceptions.GroupByOnArrayUnsupportedException; | ||
import io.crate.types.DataType; | ||
import io.crate.types.DataTypes; | ||
import org.apache.lucene.index.AtomicReaderContext; | ||
import org.elasticsearch.common.geo.GeoPoint; | ||
import org.elasticsearch.index.fielddata.GeoPointValues; | ||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData; | ||
|
||
public class GeoPointColumnReference extends FieldCacheExpression<IndexGeoPointFieldData, Double[]> { | ||
|
||
private GeoPointValues values; | ||
|
||
public GeoPointColumnReference(String columnName) { | ||
super(columnName); | ||
} | ||
|
||
@Override | ||
public Double[] value() { | ||
switch (values.setDocument(docId)) { | ||
case 0: | ||
return null; | ||
case 1: | ||
GeoPoint gp = values.nextValue(); | ||
return new Double[] { gp.lon(), gp.lat() }; | ||
default: | ||
throw new GroupByOnArrayUnsupportedException(columnName()); | ||
} | ||
} | ||
|
||
@Override | ||
public void setNextReader(AtomicReaderContext context) { | ||
super.setNextReader(context); | ||
values = indexFieldData.load(context).getGeoPointValues(); | ||
} | ||
|
||
@Override | ||
public DataType returnType() { | ||
return DataTypes.GEO_POINT; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) | ||
return false; | ||
if (obj == this) | ||
return true; | ||
if (!(obj instanceof GeoPointColumnReference)) | ||
return false; | ||
return columnName.equals(((GeoPointColumnReference) obj).columnName); | ||
} | ||
|
||
} |
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