Package com.esri.hadoop.hive

Source Code of com.esri.hadoop.hive.ST_Y

package com.esri.hadoop.hive;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.io.BytesWritable;
// DoubleWritable - must use hive-serde2; the other one produces struct {value:d.d}
import org.apache.hadoop.hive.serde2.io.DoubleWritable;
import org.apache.hive.pdk.HivePdkUnitTest;
import org.apache.hive.pdk.HivePdkUnitTests;

import com.esri.core.geometry.ogc.OGCGeometry;
import com.esri.core.geometry.ogc.OGCPoint;

@Description(name = "ST_Y",
   value = "_FUNC_(point) - returns the Y coordinate of point",
   extended = "Example:\n"
   + "  SELECT _FUNC_(ST_Point(1.5, 2.5)) FROM src LIMIT 1;  --  2.5"
)
@HivePdkUnitTests(
  cases = {
    @HivePdkUnitTest(
      query = "select ST_Y(ST_Point(1,2)) from onerow",
      result = "2"
      ),
    @HivePdkUnitTest(
      query = "select ST_Y(ST_LineString(1.5,2.5, 3.0,2.2)) from onerow",
      result = "null"
      ),
    @HivePdkUnitTest(
      query = "select ST_Y(null) from onerow",
      result = "null"
      )
  }
)

public class ST_Y extends ST_GeometryAccessor {
  public static final DoubleWritable resultDouble = new DoubleWritable();
  static final Log LOG = LogFactory.getLog(ST_Y.class.getName());

  public DoubleWritable evaluate(BytesWritable geomref) {
    if (geomref == null || geomref.getLength() == 0) {
      LogUtils.Log_ArgumentsNull(LOG);
      return null;
    }

    OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref);
    if (ogcGeometry == null){
      return null;
    }

    switch(GeometryUtils.getType(geomref)) {
    case ST_POINT:
      OGCPoint pt = (OGCPoint)ogcGeometry;
      resultDouble.set(pt.Y());
      return resultDouble;
    default:
      LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_POINT, GeometryUtils.getType(geomref));
      return null;
    }
  }

}
TOP

Related Classes of com.esri.hadoop.hive.ST_Y

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.