Login  Register

[GitHub] [carbondata] VenuReddy2103 commented on a change in pull request #4012: [CARBONDATA-4051] Geo spatial index algorithm improvement and UDFs enhancement

Posted by GitBox on Nov 30, 2020; 4:16pm
URL: http://apache-carbondata-dev-mailing-list-archive.168.s1.nabble.com/GitHub-carbondata-shenjiayu17-opened-a-new-pull-request-4012-CARBONDATA-4051-Geo-spatial-index-algort-tp103286p103888.html


VenuReddy2103 commented on a change in pull request #4012:
URL: https://github.com/apache/carbondata/pull/4012#discussion_r532569787



##########
File path: geo/src/main/java/org/apache/carbondata/geo/scan/expression/PolygonListExpression.java
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.carbondata.geo.scan.expression;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.carbondata.common.annotations.InterfaceAudience;
+import org.apache.carbondata.core.datastore.block.SegmentProperties;
+import org.apache.carbondata.core.metadata.datatype.DataTypes;
+import org.apache.carbondata.core.scan.expression.ColumnExpression;
+import org.apache.carbondata.core.scan.expression.Expression;
+import org.apache.carbondata.core.scan.expression.ExpressionResult;
+import org.apache.carbondata.core.scan.expression.UnknownExpression;
+import org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression;
+import org.apache.carbondata.core.scan.filter.executer.FilterExecutor;
+import org.apache.carbondata.core.scan.filter.intf.ExpressionType;
+import org.apache.carbondata.core.scan.filter.intf.RowIntf;
+import org.apache.carbondata.core.scan.filter.resolver.FilterResolverIntf;
+import org.apache.carbondata.core.scan.filter.resolver.RowLevelFilterResolverImpl;
+import org.apache.carbondata.core.util.CustomIndex;
+import org.apache.carbondata.geo.GeoConstants;
+import org.apache.carbondata.geo.GeoHashIndex;
+import org.apache.carbondata.geo.GeoHashUtils;
+import org.apache.carbondata.geo.scan.filter.executor.PolygonFilterExecutorImpl;
+
+/**
+ * InPolygonList expression processor. It inputs the InPolygonList string to the Geo
+ * implementation's query method, gets a list of range of IDs from each polygon and
+ * calculates the and/or/diff range list to filter as an output. And then, build
+ * InExpression with list of all the IDs present in those list of ranges.
+ */
+@InterfaceAudience.Internal
+public class PolygonListExpression extends UnknownExpression implements ConditionalExpression {
+
+  private String polygonListString;
+
+  private String opType;
+
+  private GeoHashIndex instance;
+
+  private List<Long[]> ranges = new ArrayList<Long[]>();
+
+  private ColumnExpression column;
+
+  private static final ExpressionResult trueExpRes =
+      new ExpressionResult(DataTypes.BOOLEAN, true);
+
+  private static final ExpressionResult falseExpRes =
+      new ExpressionResult(DataTypes.BOOLEAN, false);
+
+  public PolygonListExpression(String polygonListString, String opType, String columnName,
+      CustomIndex indexInstance) {
+    this.polygonListString = polygonListString;
+    this.opType = opType;
+    this.instance = (GeoHashIndex)indexInstance;
+    this.column = new ColumnExpression(columnName, DataTypes.LONG);
+  }
+
+  private void processExpression() {
+    try {
+      // 1. parse the polygon list string
+      List<String> polygons = new ArrayList<>();
+      Pattern pattern = Pattern.compile(GeoConstants.POLYGON_REG_EXPRESSION);
+      Matcher matcher = pattern.matcher(polygonListString);
+      while (matcher.find()) {
+        String matchedStr = matcher.group();
+        polygons.add(matchedStr);
+      }
+      if (polygons.size() < 2) {
+        throw new RuntimeException("polygon list need at least 2 polygons, really has " +
+            polygons.size());
+      }
+      // 2. get the range list of each polygon
+      List<Long[]> processedRangeList = instance.query(polygons.get(0));
+      for (int i = 1; i < polygons.size(); i++) {
+        List<Long[]> tempRangeList = instance.query(polygons.get(i));
+        processedRangeList = GeoHashUtils.processRangeList(
+            processedRangeList, tempRangeList, opType);
+      }
+      ranges = processedRangeList;
+      GeoHashUtils.validateRangeList(ranges);

Review comment:
       Intention of validateRangeList() to check if each element of List<Long[]> is only array of 2 elements(i.e., has only min and max value of range) was because `instance` class can be implemented by any user class adhering to `CustomIndex` interface. To make sure, `query()` returns list of array of only 2 elements, have this validation.
   I think, we need to call `validateRangeList()` right after each call to `instance.query()`. Not required at the end after merge.
   check for other places too in this PR.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[hidden email]