Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHOENIX-1287 Use the joni byte[] regex engine in place of j.u.regex (…
…Shuxiong Ye)
- Loading branch information
1 parent
7ef1718
commit 3f6b259
Showing
43 changed files
with
1,952 additions
and
161 deletions.
There are no files selected for viewing
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
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
88 changes: 88 additions & 0 deletions
88
phoenix-core/src/it/java/org/apache/phoenix/end2end/LikeExpressionIT.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,88 @@ | |||
/* | |||
* 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.phoenix.end2end; | |||
|
|||
import static org.apache.phoenix.util.TestUtil.closeStmtAndConn; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
|
|||
import java.sql.Connection; | |||
import java.sql.DriverManager; | |||
import java.sql.PreparedStatement; | |||
import java.sql.ResultSet; | |||
import java.sql.SQLException; | |||
import java.sql.Statement; | |||
|
|||
import org.junit.Before; | |||
import org.junit.Test; | |||
|
|||
public class LikeExpressionIT extends BaseHBaseManagedTimeIT { | |||
@Before | |||
public void doBeforeTestSetup() throws Exception { | |||
Connection conn = null; | |||
PreparedStatement stmt = null; | |||
try { | |||
conn = DriverManager.getConnection(getUrl()); | |||
String ddl; | |||
ddl = "CREATE TABLE testTable (k VARCHAR NOT NULL PRIMARY KEY, i INTEGER)"; | |||
conn.createStatement().execute(ddl); | |||
conn.commit(); | |||
} finally { | |||
closeStmtAndConn(stmt, conn); | |||
} | |||
insertRow(conn, "123n7-app-2-", 1); | |||
insertRow(conn, "132n7-App-2-", 2); | |||
insertRow(conn, "213n7-app-2-", 4); | |||
insertRow(conn, "231n7-App-2-", 8); | |||
insertRow(conn, "312n7-app-2-", 16); | |||
insertRow(conn, "321n7-App-2-", 32); | |||
} | |||
|
|||
private void insertRow(Connection conn, String k, int i) throws SQLException { | |||
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO testTable VALUES (?, ?)"); | |||
stmt.setString(1, k); | |||
stmt.setInt(2, i); | |||
stmt.executeUpdate(); | |||
conn.commit(); | |||
} | |||
|
|||
private void testLikeExpression(Connection conn, String likeStr, int numResult, int expectedSum) | |||
throws Exception { | |||
String cmd = "select k, i from testTable where k like '" + likeStr + "'"; | |||
Statement stmt = conn.createStatement(); | |||
ResultSet rs = stmt.executeQuery(cmd); | |||
int sum = 0; | |||
for (int i = 0; i < numResult; ++i) { | |||
assertTrue(rs.next()); | |||
sum += rs.getInt("i"); | |||
} | |||
assertFalse(rs.next()); | |||
assertEquals(sum, expectedSum); | |||
} | |||
|
|||
@Test | |||
public void testLikeExpression() throws Exception { | |||
Connection conn = DriverManager.getConnection(getUrl()); | |||
// wildcard | |||
testLikeExpression(conn, "%1%3%7%2%", 3, 7); | |||
// CaseSensitive | |||
testLikeExpression(conn, "%A%", 3, 42); | |||
conn.close(); | |||
} | |||
} |
100 changes: 100 additions & 0 deletions
100
phoenix-core/src/it/java/org/apache/phoenix/end2end/RegexpReplaceFunctionIT.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,100 @@ | |||
/* | |||
* 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.phoenix.end2end; | |||
|
|||
import static org.apache.phoenix.util.TestUtil.GROUPBYTEST_NAME; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
|
|||
import java.sql.Connection; | |||
import java.sql.DriverManager; | |||
import java.sql.PreparedStatement; | |||
import java.sql.ResultSet; | |||
import java.sql.SQLException; | |||
import java.sql.Statement; | |||
|
|||
import org.junit.Before; | |||
import org.junit.Test; | |||
|
|||
|
|||
public class RegexpReplaceFunctionIT extends BaseHBaseManagedTimeIT { | |||
|
|||
private int id; | |||
|
|||
@Before | |||
public void doBeforeTestSetup() throws Exception { | |||
ensureTableCreated(getUrl(), GROUPBYTEST_NAME); | |||
Connection conn = DriverManager.getConnection(getUrl()); | |||
insertRow(conn, "Report11", 10); | |||
insertRow(conn, "Report11", 10); | |||
insertRow(conn, "Report22", 30); | |||
insertRow(conn, "Report33", 30); | |||
conn.commit(); | |||
conn.close(); | |||
} | |||
|
|||
private void insertRow(Connection conn, String uri, int appcpu) throws SQLException { | |||
PreparedStatement statement = conn.prepareStatement("UPSERT INTO " + GROUPBYTEST_NAME + "(id, uri, appcpu) values (?,?,?)"); | |||
statement.setString(1, "id" + id); | |||
statement.setString(2, uri); | |||
statement.setInt(3, appcpu); | |||
statement.executeUpdate(); | |||
id++; | |||
} | |||
|
|||
@Test | |||
public void testGroupByScanWithRegexpReplace() throws Exception { | |||
Connection conn = DriverManager.getConnection(getUrl()); | |||
Statement stmt = conn.createStatement(); | |||
ResultSet rs = stmt.executeQuery("select REGEXP_REPLACE(uri, '[1-3]+', '*') suburi, sum(appcpu) sumcpu from " + GROUPBYTEST_NAME + " group by suburi"); | |||
assertTrue(rs.next()); | |||
assertEquals(rs.getString("suburi"), "Report*"); | |||
assertEquals(rs.getInt("sumcpu"), 80); | |||
assertFalse(rs.next()); | |||
|
|||
stmt = conn.createStatement(); | |||
rs = stmt.executeQuery("select REGEXP_REPLACE(uri, '[1-3]+') suburi, sum(appcpu) sumcpu from " + GROUPBYTEST_NAME + " group by suburi"); | |||
assertTrue(rs.next()); | |||
assertEquals(rs.getString("suburi"), "Report"); | |||
assertEquals(rs.getInt("sumcpu"), 80); | |||
assertFalse(rs.next()); | |||
|
|||
conn.close(); | |||
} | |||
|
|||
@Test | |||
public void testFilterWithRegexReplace() throws Exception { | |||
Connection conn = DriverManager.getConnection(getUrl()); | |||
ResultSet rs = conn.createStatement().executeQuery("select id from " + GROUPBYTEST_NAME + " where REGEXP_REPLACE(uri, '[2-3]+', '*') = 'Report*'"); | |||
assertTrue(rs.next()); | |||
assertEquals("id2", rs.getString(1)); | |||
assertTrue(rs.next()); | |||
assertEquals("id3", rs.getString(1)); | |||
assertFalse(rs.next()); | |||
|
|||
rs = conn.createStatement().executeQuery("select id from " + GROUPBYTEST_NAME + " where REGEXP_REPLACE(uri, '[2-3]+') = 'Report'"); | |||
assertTrue(rs.next()); | |||
assertEquals("id2", rs.getString(1)); | |||
assertTrue(rs.next()); | |||
assertEquals("id3", rs.getString(1)); | |||
assertFalse(rs.next()); | |||
conn.close(); | |||
} | |||
|
|||
} |
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
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
48 changes: 48 additions & 0 deletions
48
phoenix-core/src/main/java/org/apache/phoenix/expression/ByteBasedLikeExpression.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 | Original file line | 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.phoenix.expression; | |||
|
|||
import java.util.List; | |||
|
|||
import org.apache.phoenix.expression.util.regex.AbstractBasePattern; | |||
import org.apache.phoenix.expression.util.regex.JONIPattern; | |||
import org.apache.phoenix.parse.LikeParseNode.LikeType; | |||
|
|||
public class ByteBasedLikeExpression extends LikeExpression { | |||
|
|||
public ByteBasedLikeExpression() { | |||
} | |||
|
|||
public ByteBasedLikeExpression(List<Expression> children) { | |||
super(children); | |||
} | |||
|
|||
@Override | |||
protected AbstractBasePattern compilePatternSpec(String value) { | |||
return new JONIPattern(value); | |||
} | |||
|
|||
public static LikeExpression create(List<Expression> children, LikeType likeType) { | |||
return new ByteBasedLikeExpression(addLikeTypeChild(children, likeType)); | |||
} | |||
|
|||
@Override | |||
public LikeExpression clone(List<Expression> children) { | |||
return new ByteBasedLikeExpression(children); | |||
} | |||
} |
Oops, something went wrong.