Skip to content

Commit

Permalink
fix string replace function
Browse files Browse the repository at this point in the history
  • Loading branch information
vlowingkloude committed Oct 3, 2024
1 parent 00c0522 commit 224b7f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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

0 comments on commit 224b7f1

Please sign in to comment.