-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for var and const functions.
- Loading branch information
1 parent
3342760
commit 577c36b
Showing
6 changed files
with
445 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
.../java/org/apache/pinot/common/function/scalar/regexp/RegexpExtractConstFunctionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* 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.common.function.scalar.regexp; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
|
||
public class RegexpExtractConstFunctionsTest { | ||
|
||
@Test | ||
public void test() { | ||
RegexpExtractConstFunctions f = new RegexpExtractConstFunctions(); | ||
|
||
assertEquals(f.regexpExtractConst("val abe eee", "(a[bcd]e)"), "abe"); | ||
assertEquals(f.regexpExtractConst("val ade eee", "(a[bcd]e)"), "ade"); | ||
assertEquals(f.regexpExtractConst("val age eee", "(a[bcd]e)"), ""); | ||
// f caches first pattern and ignores second argument | ||
assertEquals(f.regexpExtractConst("val abe ace", "(a[bcd]e) (a[bcd]e)", 2), ""); | ||
|
||
f = new RegexpExtractConstFunctions(); | ||
assertEquals(f.regexpExtractConst("val abe ace", "(a[bcd]e) (a[bcd]e)", 2), "ace"); | ||
|
||
f = new RegexpExtractConstFunctions(); | ||
assertEquals(f.regexpExtractConst("abe ace ade", "(a[bcd]e) (a[bcd]e) (a[bcd]e)", 3), "ade"); | ||
|
||
f = new RegexpExtractConstFunctions(); | ||
assertEquals(f.regexpExtractConst("abe ace ade", "(a[bcd]e)", 5, "wrong"), "wrong"); | ||
assertEquals(f.regexpExtractConst("aa bb cc", "(a[bcd]e)", 1, "wrong"), "wrong"); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...st/java/org/apache/pinot/common/function/scalar/regexp/RegexpExtractVarFunctionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* 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.common.function.scalar.regexp; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static org.apache.pinot.common.function.scalar.regexp.RegexpExtractVarFunctions.regexpExtract; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
|
||
public class RegexpExtractVarFunctionsTest { | ||
|
||
@Test | ||
public void test() { | ||
assertEquals(regexpExtract("val abe eee", "(a[bcd]e)"), "abe"); | ||
assertEquals(regexpExtract("val ade eee", "(a[bcd]e)"), "ade"); | ||
assertEquals(regexpExtract("val age eee", "(a[bcd]e)"), ""); | ||
|
||
assertEquals(regexpExtract("val abe ace", "(a[bcd]e) (a[bcd]e)", 2), "ace"); | ||
assertEquals(regexpExtract("abe ace ade", "(a[bcd]e) (a[bcd]e) (a[bcd]e)", 3), "ade"); | ||
|
||
assertEquals(regexpExtract("abe ace ade", "(a[bcd]e)", 5, "wrong"), "wrong"); | ||
assertEquals(regexpExtract("aa bb cc", "(a[bcd]e)", 1, "wrong"), "wrong"); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...est/java/org/apache/pinot/common/function/scalar/regexp/RegexpLikeConstFunctionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* 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.common.function.scalar.regexp; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
|
||
public class RegexpLikeConstFunctionsTest { | ||
|
||
@Test | ||
public void testLike() { | ||
RegexpLikeConstFunctions f = new RegexpLikeConstFunctions(); | ||
|
||
assertTrue(f.likeConst("ab", "%ab%")); | ||
assertTrue(f.likeConst("aaba", "%ab%")); | ||
assertTrue(f.likeConst("$ab$", "%ab%")); | ||
|
||
assertFalse(f.likeConst("", "%ab%")); | ||
assertFalse(f.likeConst("_", "%ab%")); | ||
assertFalse(f.likeConst("a", "%ab%")); | ||
assertFalse(f.likeConst("b", "%ab%")); | ||
|
||
//returns true because function matches against first pattern | ||
assertTrue(f.likeConst("aab", "abb")); | ||
} | ||
|
||
@Test | ||
public void testRegexpLike() { | ||
RegexpLikeConstFunctions f = new RegexpLikeConstFunctions(); | ||
|
||
assertTrue(f.regexpLikeConst("ab", ".*ab.*")); | ||
assertTrue(f.regexpLikeConst("aaba", ".*ab.*")); | ||
assertTrue(f.regexpLikeConst("$ab$", ".*ab.*")); | ||
|
||
assertFalse(f.regexpLikeConst("", ".*ab.*")); | ||
assertFalse(f.regexpLikeConst("_", ".*ab.*")); | ||
assertFalse(f.regexpLikeConst("a", ".*ab.*")); | ||
assertFalse(f.regexpLikeConst("b", ".*ab.*")); | ||
|
||
//returns true because function matches against first pattern | ||
assertTrue(f.regexpLikeConst("aab", "ab")); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
.../test/java/org/apache/pinot/common/function/scalar/regexp/RegexpLikeVarFunctionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* 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.common.function.scalar.regexp; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static org.apache.pinot.common.function.scalar.regexp.RegexpLikeVarFunctions.like; | ||
import static org.apache.pinot.common.function.scalar.regexp.RegexpLikeVarFunctions.regexpLike; | ||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
|
||
public class RegexpLikeVarFunctionsTest { | ||
|
||
@Test | ||
public void testLike() { | ||
assertTrue(like("ab", "%ab%")); | ||
assertTrue(like("aaba", "%ab%")); | ||
assertTrue(like("$ab$", "%ab%")); | ||
|
||
assertFalse(like("", "%ab%")); | ||
assertFalse(like("_", "%ab%")); | ||
assertFalse(like("a", "%ab%")); | ||
assertFalse(like("b", "%ab%")); | ||
|
||
assertFalse(like("aab", "ab")); | ||
} | ||
|
||
@Test | ||
public void testRegexpLike() { | ||
assertTrue(regexpLike("ab", ".*ab.*")); | ||
assertTrue(regexpLike("aaba", ".*ab.*")); | ||
assertTrue(regexpLike("$ab$", ".*ab.*")); | ||
|
||
assertFalse(regexpLike("", ".*ab.*")); | ||
assertFalse(regexpLike("_", ".*ab.*")); | ||
assertFalse(regexpLike("a", ".*ab.*")); | ||
assertFalse(regexpLike("b", ".*ab.*")); | ||
|
||
//returns true because function matches against first pattern | ||
assertFalse(regexpLike("aab", "abb")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.