Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,28 @@ public enum TransformFunctionType {
MAPVALUE("mapValue"),

// Special type for annotation based scalar functions
SCALAR("scalar");
SCALAR("scalar"),

// Geo constructors
ST_GEOG_FROM_TEXT("ST_GeogFromText"),
ST_GEOM_FROM_TEXT("ST_GeomFromText"),
ST_GEOG_FROM_WKB("ST_GeogFromWKB"),
ST_GEOM_FROM_WKB("ST_GeomFromWKB"),
ST_POINT("ST_Point"),
ST_POLYGON("ST_Polygon"),

// Geo measurements
ST_AREA("ST_Area"),
ST_DISTANCE("ST_Distance"),
ST_GEOMETRY_TYPE("ST_GeometryType"),

// Geo outputs
ST_AS_BINARY("ST_AsBinary"),
ST_AS_TEXT("ST_AsText"),

// Geo relationship
ST_CONTAINS("ST_Contains"),
ST_EQUALS("ST_Equals");

private final String _name;

Expand Down
5 changes: 4 additions & 1 deletion pinot-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>

<dependency>
<groupId>org.locationtech.jts</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Eclipse license ok to add? So far we have taken Apache/MIT/Gnu.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is okay to include.
Per https://www.apache.org/legal/resolved.html#category-a, Eclipse Distribution License 1.0 can be included. And JTS is dual-licensed under Eclipse Public License 2.0 and Eclipse Distribution License 1.0 (https://github.com/locationtech/jts#license)

<artifactId>jts-core</artifactId>
</dependency>
<!-- test -->
<dependency>
<groupId>org.apache.pinot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.apache.pinot.core.geospatial;

/**
* The geometry type.
*/
public enum GeometryType {
POINT(false, 0, "ST_Point"),
MULTI_POINT(true, 1, "ST_MultiPoint"),
LINE_STRING(false, 2, "ST_LineString"),
MULTI_LINE_STRING(true, 3, "ST_MultiLineString"),
POLYGON(false, 4, "ST_Polygon"),
MULTI_POLYGON(true, 5, "ST_MultiPolygon"),
GEOMETRY_COLLECTION(true, 6, "ST_GeomCollection");

private static final GeometryType[] ID_TO_TYPE_MAP =
new GeometryType[]{POINT, MULTI_POINT, LINE_STRING, MULTI_LINE_STRING, POLYGON, MULTI_POLYGON, GEOMETRY_COLLECTION};
private final boolean _multiType;
private final int _id;
private final String _name;

GeometryType(boolean multiType, int id, String name) {
_multiType = multiType;
_id = id;
_name = name;
}

public boolean isMultiType() {
return _multiType;
}

public String getName() {
return _name;
}

/**
* @return the id of the serialization type
*/
public int id() {
return _id;
}

/**
* Constructs the serialization type from the id
* @param id id of the serialization type
* @return the serialization type
*/
public static GeometryType fromID(int id) {
if (id > ID_TO_TYPE_MAP.length) {
throw new IllegalArgumentException("Invalid type id: " + id);
}
return ID_TO_TYPE_MAP[id];
}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.apache.pinot.core.geospatial;

import com.google.common.base.Joiner;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.PrecisionModel;


/**
* Utility methods for the geometry.
*/
public class GeometryUtils {
/**
* Coordinate system of lat/lng per https://epsg.io/4326
*/
public static int GEOGRAPHY_SRID = 4326;
public static byte GEOGRAPHY_SET_MASK = (byte) 0x80;
public static byte GEOGRAPHY_GET_MASK = (byte) 0x7f;
public static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory();
public static final GeometryFactory GEOGRAPHY_FACTORY = new GeometryFactory(new PrecisionModel(), GEOGRAPHY_SRID);
public static final double EARTH_RADIUS_KM = 6371.01;
public static final double EARTH_RADIUS_M = EARTH_RADIUS_KM * 1000.0;
public static final Joiner OR_JOINER = Joiner.on(" or ");

private GeometryUtils() {
}

/**
* Checks if the given geo-spatial object is a geography object.
* @param geometry the given object to check
* @return <code>true</code> if the given geo-spatial object is a geography object, <code>false</code> otherwise
*/
public static boolean isGeography(Geometry geometry) {
return geometry.getSRID() == GEOGRAPHY_SRID;
}
}
Loading