richardstartin commented on a change in pull request #7990:
URL: https://github.com/apache/pinot/pull/7990#discussion_r782960420



##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/geospatial/transform/function/StWithinFunction.java
##########
@@ -0,0 +1,92 @@
+/**
+ * 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.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.operator.transform.function.BaseTransformFunction;
+import 
org.apache.pinot.core.operator.transform.function.LiteralTransformFunction;
+import org.apache.pinot.core.operator.transform.function.TransformFunction;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.segment.local.utils.GeometrySerializer;
+import org.apache.pinot.segment.local.utils.GeometryUtils;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.locationtech.jts.geom.Geometry;
+
+
+/**
+ * Function that checks the containment of the two geo-spatial objects. It 
returns true if and only if
+ * first geometry is completely inside second geometry.
+ */
+public class StWithinFunction extends BaseTransformFunction {
+  public static final String FUNCTION_NAME = "ST_Within";
+  private TransformFunction _firstArgument;
+  private TransformFunction _secondArgument;
+  private int[] _results;
+
+  @Override
+  public String getName() {
+    return FUNCTION_NAME;
+  }
+
+  @Override
+  public void init(List<TransformFunction> arguments, Map<String, DataSource> 
dataSourceMap) {
+    Preconditions
+        .checkArgument(arguments.size() == 2, "2 arguments are required for 
transform function: %s", getName());
+    TransformFunction transformFunction = arguments.get(0);
+    
Preconditions.checkArgument(transformFunction.getResultMetadata().isSingleValue(),
+        "First argument must be single-valued for transform function: %s", 
getName());
+    
Preconditions.checkArgument(transformFunction.getResultMetadata().getDataType() 
== FieldSpec.DataType.BYTES
+        || transformFunction instanceof LiteralTransformFunction, "The first 
argument must be of bytes type");
+    _firstArgument = transformFunction;
+    transformFunction = arguments.get(1);
+    
Preconditions.checkArgument(transformFunction.getResultMetadata().isSingleValue(),
+        "Second argument must be single-valued for transform function: %s", 
getName());
+    
Preconditions.checkArgument(transformFunction.getResultMetadata().getDataType() 
== FieldSpec.DataType.BYTES
+        || transformFunction instanceof LiteralTransformFunction, "The second 
argument must be of bytes type");
+    _secondArgument = transformFunction;
+  }
+
+  @Override
+  public TransformResultMetadata getResultMetadata() {
+    return INT_SV_NO_DICTIONARY_METADATA;
+  }
+
+  @Override
+  public int[] transformToIntValuesSV(ProjectionBlock projectionBlock) {
+    if (_results == null) {
+      _results = new int[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+    }

Review comment:
       This is a common pattern but one I am trying to move transform functions 
away from - use `projectionBlock.getNumDocs()` in preference to 
`DocIdSetPlanNode.MAX_DOC_PER_CALL` because it might be much smaller than 10k 
if there is any filtering.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to