Skip to content

Commit 4433970

Browse files
authored
fix: return null in getNString if the value is null (#3604)
1 parent f3c9661 commit 4433970

File tree

3 files changed

+83
-3
lines changed

3 files changed

+83
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## [0.8.4] - 2023-11-16
3+
## [0.8.4] - 2023-11-17
44

55
### Features
66
- Support new SQL statements `SHOW CREATE TABLE`, `TRUNCATE` and [Alpha] `LEFT JOIN` (#3500 #3542 @dl239, #3576 @aceforeverd)
@@ -22,7 +22,7 @@
2222
- Tablet may crash after deleting an index in certain cases (#3561 @dl239)
2323
- There are some syntax errors in maintenance tools (#3545 @vagetablechicken)
2424
- Updating TTL fails if the deployment SQL contains multpile databases (#3503 @dl239)
25-
- Other minor bug fixes (#3518 #3567 @dl239, #3543 @aceforeverd, #3521 #3580 @vagetablechicken, #3594 #3597 @tobegit3hub)
25+
- Other minor bug fixes (#3518 #3567 #3604 @dl239, #3543 @aceforeverd, #3521 #3580 @vagetablechicken, #3594 #3597 @tobegit3hub)
2626

2727
### Code Refactoring
2828
#3547 @aceforeverd

java/openmldb-jdbc/src/main/java/com/_4paradigm/openmldb/jdbc/DirectResultSet.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com._4paradigm.openmldb.common.codec.RowView;
2020
import com._4paradigm.openmldb.sdk.Schema;
21+
import com._4paradigm.openmldb.sdk.Common;
2122

2223
import java.nio.ByteBuffer;
2324
import java.sql.*;
@@ -151,7 +152,10 @@ public Timestamp getTimestamp(int i) throws SQLException {
151152
public String getNString(int i) throws SQLException {
152153
int realIdx = i - 1;
153154
try {
154-
return rowView.getString(realIdx);
155+
if (rowView.isNull(realIdx)) {
156+
return null;
157+
}
158+
return rowView.getValue(realIdx, Common.sqlType2ProtoType(schema.getColumnType(realIdx))).toString();
155159
} catch (Exception e) {
156160
throw new SQLException(e.getMessage());
157161
}

java/openmldb-jdbc/src/test/java/com/_4paradigm/openmldb/jdbc/RequestPreparedStatementTest.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,80 @@ public void testDeploymentBatchRequest(String compressType, String storageMode)
415415
}
416416
}
417417
}
418+
419+
@Test
420+
public void testResultSetNull() {
421+
java.sql.Statement state = executor.getStatement();
422+
String dbname = "db" + random.nextInt(100000);
423+
String deploymentName = "dp_test1";
424+
try {
425+
state.execute("drop database if exists " + dbname + ";");
426+
state.execute("create database " + dbname + ";");
427+
state.execute("use " + dbname + ";");
428+
String baseSql = "create table trans(c1 string,\n" +
429+
" c3 int,\n" +
430+
" c4 bigint,\n" +
431+
" c5 float,\n" +
432+
" c6 double,\n" +
433+
" c7 timestamp,\n" +
434+
" c8 date,\n" +
435+
" index(key=c1, ts=c7));";
436+
state.execute(baseSql);
437+
String selectSql = "SELECT c1, c3, sum(c4) OVER w1 as w1_c4_sum FROM trans WINDOW w1 AS " +
438+
"(PARTITION BY trans.c1 ORDER BY trans.c7 ROWS_RANGE BETWEEN 2s PRECEDING AND 0s OPEN PRECEDING EXCLUDE CURRENT_TIME);";
439+
String deploySql = "DEPLOY " + deploymentName + " " + selectSql;
440+
state.execute(deploySql);
441+
} catch (SQLException e) {
442+
e.printStackTrace();
443+
Assert.fail();
444+
}
445+
PreparedStatement pstmt = null;
446+
ResultSet resultSet = null;
447+
try {
448+
Thread.sleep(100);
449+
pstmt = executor.getCallablePreparedStmt(dbname, deploymentName);
450+
451+
pstmt.setString(1, "aa");
452+
pstmt.setInt(2, 20);
453+
pstmt.setNull(3, Types.BIGINT);
454+
pstmt.setFloat(4, 1.1f);
455+
pstmt.setDouble(5, 2.1);
456+
pstmt.setTimestamp(6, new Timestamp(0));
457+
pstmt.setDate(7, Date.valueOf("2020-05-01"));
458+
459+
resultSet = pstmt.executeQuery();
460+
461+
Assert.assertEquals(resultSet.getMetaData().getColumnCount(), 3);
462+
while (resultSet.next()) {
463+
Assert.assertEquals(resultSet.getString(1), "aa");
464+
Assert.assertEquals(resultSet.getNString(1), "aa");
465+
Assert.assertEquals(resultSet.getInt(2), 20);
466+
Assert.assertEquals(resultSet.getNString(2), "20");
467+
Assert.assertTrue(resultSet.getNString(3) == null);
468+
}
469+
470+
state.execute("drop deployment " + deploymentName + ";");
471+
String drop = "drop table trans;";
472+
boolean ok = executor.executeDDL(dbname, drop);
473+
Assert.assertTrue(ok);
474+
ok = executor.dropDB(dbname);
475+
Assert.assertTrue(ok);
476+
} catch (Exception e) {
477+
e.printStackTrace();
478+
Assert.fail();
479+
} finally {
480+
try {
481+
state.close();
482+
if (resultSet != null) {
483+
resultSet.close();
484+
}
485+
if (pstmt != null) {
486+
pstmt.close();
487+
}
488+
} catch (Exception throwables) {
489+
throwables.printStackTrace();
490+
}
491+
}
492+
}
493+
418494
}

0 commit comments

Comments
 (0)