alex-plekhanov commented on code in PR #13068:
URL: https://github.com/apache/ignite/pull/13068#discussion_r3267928323


##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/PlanTemplate.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.planner.tpc;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Scanner;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Contains logic to process plans templates.
+ * Supported templates:
+ * <ul>
+ *     <li>{@code ", id = 123} replaced with the {@code ", id = {id}}</li>
+ *     <li>{@code ", hash=123} replaced with the {@code ", hash={hash}}</li>
+ *     <li>{@code "{INDEX_CASE:IDX1,IDX2}} expands to the plans where 
{INDEX_CASE....} replaced with each of the index from list.</li>
+ *     <li>{@code "{ONEOF}} start and finish with the {@code {ONEOF}} tag. 
Cases separated with the line "=====".
+ *     Creates as many plans as there are cases.
+ *     </li>
+ * </ul>
+ */
+public class PlanTemplate {
+    /** */
+    private static final Pattern ID_PATTERN = Pattern.compile(", id = \\d+");
+
+    /** */
+    private static final Pattern HASH_PATTERN = Pattern.compile(", 
hash=-?\\d+]");
+
+    /** */
+    public final String template;
+
+    /** */
+    public PlanTemplate(String template) {
+        this.template = HASH_PATTERN.matcher(ID_PATTERN.matcher(template)
+            .replaceAll(", id = {id}"))
+            .replaceAll(", hash={hash}");
+    }
+
+    /**
+     * @param actualPlan Plan to match.
+     * @return {@code True} if any expanded plan equals to the parameter.
+     */
+    public boolean match(String actualPlan) {
+        return  expandOneof(template).stream()
+            .flatMap(PlanTemplate::expandIndexCase)
+            .anyMatch(possiblePlan -> possiblePlan.equals(actualPlan));
+    }
+
+    /** Expands plans. Replace {INDEX_CASE} tag with the possible indexes. */
+    private static Stream<String> expandIndexCase(String plan) {

Review Comment:
   All these cases with {INDEX_CASE} are related to proxy indexes. Maybe just 
replace `index=[{index_name}_proxy]` with `index=[{index_name}]` and don't use 
`{INDEX_CASE}` at all?



-- 
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: [email protected]

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

Reply via email to