You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2020/07/19 22:10:48 UTC

[asterixdb] 05/07: [ASTERIXDB-2758][TEST] Test for ensuring translation from wildcard pattern to REGEX is done properly

This is an automated email from the ASF dual-hosted git repository.

mblow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git

commit ad3ee2eb480306d859add1f20a0adb5904c589a3
Author: Hussain Towaileb <Hu...@Gmail.com>
AuthorDate: Thu Jul 9 22:02:06 2020 +0300

    [ASTERIXDB-2758][TEST] Test for ensuring translation from wildcard pattern to REGEX is done properly
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    - Added a unit test to ensure the translation from wildcard
      patterns to regex pattern is done properly.
    
    Change-Id: Ieb7fb8d86e1b33ac351c3a6f9f14c3b77eac2988
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/7164
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Hussain Towaileb <hu...@gmail.com>
    Reviewed-by: Ali Alsuliman <al...@gmail.com>
---
 .../external_dataset/aws/WildCardToRegexTest.java  | 97 ++++++++++++++++++++++
 1 file changed, 97 insertions(+)

diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/external_dataset/aws/WildCardToRegexTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/external_dataset/aws/WildCardToRegexTest.java
new file mode 100644
index 0000000..f15b657
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/external_dataset/aws/WildCardToRegexTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.asterix.test.external_dataset.aws;
+
+import static org.apache.asterix.external.util.ExternalDataUtils.patternToRegex;
+
+import java.util.regex.Pattern;
+
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class WildCardToRegexTest extends TestCase {
+
+    @Test
+    public void test() throws HyracksDataException {
+        String result = patternToRegex("*?[abc]");
+        assertEquals(".*.[abc]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("*?[!@#$%^&*()+<>|=!{}.]");
+        assertEquals(".*.[^@#\\$%\\^&\\*\\(\\)\\+\\<\\>\\|\\=\\!\\{\\}\\.]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("**??[[a-z*0-9]]");
+        assertEquals(".*.*..[\\[a-z\\*0-9]\\]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("**??[[a-z*0-9]]");
+        assertEquals(".*.*..[\\[a-z\\*0-9]\\]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("*?[!abc]");
+        assertEquals(".*.[^abc]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("[!]abc");
+        assertEquals("\\[\\!\\]abc", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("[!]abc]");
+        assertEquals("[^\\]abc]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("[]]");
+        assertEquals("[\\]]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("[]abcd");
+        assertEquals("\\[\\]abcd", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("[]abcd]");
+        assertEquals("[\\]abcd]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("[^]");
+        assertEquals("[\\^]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("[^]]");
+        assertEquals("[\\^]\\]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("[!]");
+        assertEquals("\\[\\!\\]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("[!]]");
+        assertEquals("[^\\]]", result);
+        Pattern.compile(result);
+
+        result = patternToRegex("[][!][^]]]]*[![*a-zA--&&^$||0-9B$\\\\*&&]*&&[^a-b||0--9][[[");
+        assertEquals(
+                "[\\]\\[\\!][\\^]\\]\\]\\].*[^\\[\\*a-zA\\-\\-\\&\\&\\^\\$\\|\\|0-9B\\$\\\\\\\\\\*\\&\\&].*&&[\\^a-b\\|\\|0\\-\\-9]\\[\\[\\[",
+                result);
+        Pattern.compile(result);
+    }
+}