MarcosZyk commented on code in PR #8607:
URL: https://github.com/apache/iotdb/pull/8607#discussion_r1057517724


##########
node-commons/src/test/java/org/apache/iotdb/commons/path/PatternDFATest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.iotdb.commons.path;
+
+import org.apache.iotdb.commons.exception.IllegalPathException;
+import org.apache.iotdb.commons.path.fa.IFAState;
+import org.apache.iotdb.commons.path.fa.IFATransition;
+import org.apache.iotdb.commons.path.fa.IPatternFA;
+import org.apache.iotdb.commons.path.fa.dfa.PatternDFA;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.Iterator;
+import java.util.List;
+
+public class PatternDFATest {
+  @Test
+  public void testMatchFullPath() throws IllegalPathException {
+    PartialPath p1 = new PartialPath("root.sg1.d1.*");
+
+    Assert.assertTrue(p1.matchFullPath(new PartialPath("root.sg1.d1.s2")));
+    Assert.assertTrue(checkMatchUsingDFA(p1, new 
PartialPath("root.sg1.d1.s2")));
+    Assert.assertFalse(p1.matchFullPath(new PartialPath("root.sg1.d1")));
+    Assert.assertFalse(checkMatchUsingDFA(p1, new PartialPath("root.sg1.d1")));
+    Assert.assertFalse(p1.matchFullPath(new PartialPath("root.sg2.d1.*")));
+    Assert.assertFalse(checkMatchUsingDFA(p1, new 
PartialPath("root.sg2.d1.*")));
+    Assert.assertFalse(p1.matchFullPath(new PartialPath("", false)));
+    Assert.assertFalse(checkMatchUsingDFA(p1, new PartialPath("", false)));
+
+    PartialPath path = new PartialPath("root.sg1.d1.s1");
+    String[] patterns1 = {
+      "root.sg1.d1.s1",
+      "root.sg1.*.s1",
+      "root.*.d1.*",
+      "root.*.*.*",
+      "root.s*.d1.s1",
+      "root.*g1.d1.s1",
+      "root.s*.d1.*",
+      "root.s*.d*.s*",
+      "root.**",
+      "root.**.s1",
+      "root.sg1.**",
+    };
+    for (String pattern : patterns1) {
+      Assert.assertTrue(new PartialPath(pattern).matchFullPath(path));
+      Assert.assertTrue(checkMatchUsingDFA(new PartialPath(pattern), path));
+    }
+
+    String[] patterns2 = {
+      "root2.sg1.d1.s1",
+      "root.sg1.*.s2",
+      "root.*.d2.s1",
+      "root.*.d*.s2",
+      "root.*.a*.s1",
+      "root.*",
+      "root.*.*",
+      "root.s*.d*.a*",
+      "root2.**",
+      "root.**.s2",
+      "root.**.d1",
+      "root.sg2.**",
+    };
+    for (String pattern : patterns2) {
+      Assert.assertFalse(new PartialPath(pattern).matchFullPath(path));
+      Assert.assertFalse(checkMatchUsingDFA(new PartialPath(pattern), path));
+    }
+  }
+
+  // TODO: remove this
+  @Test
+  @Ignore
+  public void test() throws IllegalPathException {
+
+    Assert.assertFalse(

Review Comment:
   Remove this.



##########
node-commons/src/main/java/org/apache/iotdb/commons/path/fa/dfa/graph/DFAGraph.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.iotdb.commons.path.fa.dfa.graph;
+
+import org.apache.iotdb.commons.path.fa.IFAState;
+import org.apache.iotdb.commons.path.fa.IFATransition;
+import org.apache.iotdb.commons.path.fa.dfa.DFAState;
+import org.apache.iotdb.commons.utils.TestOnly;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+public class DFAGraph {
+  private final List<IFAState> dfaStateList = new ArrayList<>();
+  private final List<IFAState>[] dfaTransitionTable;
+
+  public DFAGraph(NFAGraph nfaGraph, Collection<IFATransition> transitions) {
+    dfaTransitionTable = new List[transitions.size()];
+    int closureSize = nfaGraph.getStateSize();
+    // init start state
+    int index = 0;
+    // Map NFAStateClosure to DFASate
+    Map<Closure, DFAState> closureStateMap = new HashMap<>();
+    for (IFATransition transition : transitions) {
+      dfaTransitionTable[transition.getIndex()] = new ArrayList<>();
+      dfaTransitionTable[transition.getIndex()].add(null);
+    }
+    DFAState curState = new DFAState(index);
+    dfaStateList.add(curState);
+    Closure curClosure = new Closure(closureSize);
+    curClosure.addState(curState);
+    closureStateMap.put(curClosure, curState);
+    Stack<Closure> closureStack = new Stack<>();
+    closureStack.push(curClosure);
+
+    // construct DFA
+    while (!closureStack.isEmpty()) {
+      curClosure = closureStack.pop();
+      for (IFATransition transition : transitions) {

Review Comment:
   Add annotation ```subset construction``` referred to fundamentals of 
compiling.



-- 
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: reviews-unsubscr...@iotdb.apache.org

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

Reply via email to