Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SQL string replace function #518

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/src/main/java/org/polypheny/db/functions/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,13 @@ public static String replace( String s, String search, String replacement ) {
return s.replace( search, replacement );
}

/**
* SQL {@code REPLACE(string, search, replacement)} function.
*/
public static PolyString replace( PolyString s, PolyString search, PolyString replacement ) {
return PolyString.of( s.value.replace( search.value, replacement.value ) );
}


/**
* Helper for "array element reference". Caller has already ensured that array and index are not null. Index is 1-based, per SQL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ public static void stop() throws SQLException {

// --------------- Tests ---------------

@Test
public void stringReplaceTest() throws SQLException {
try ( TestHelper.JdbcConnection polyphenyDbConnection = new TestHelper.JdbcConnection( true ) ) {
Connection connection = polyphenyDbConnection.getConnection();
try ( Statement statement = connection.createStatement() ) {
List<Object[]> expectedResult = ImmutableList.of(
new Object[]{"Hello"}
);
TestHelper.checkResultSet(
statement.executeQuery( "SELECT replace('Hi', 'i', 'ello')" ),
expectedResult,
true );
}
}
}


@Test
public void concatenatesTwoString() throws SQLException {
Expand Down