Package io.crate.operation.reference.doc.lucene

Source Code of io.crate.operation.reference.doc.lucene.GeoPointColumnReference

/*
* 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);
    }

}
TOP

Related Classes of io.crate.operation.reference.doc.lucene.GeoPointColumnReference

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.