Skip to content

Commit

Permalink
fix: return null in getNString if the value is null (#3604)
Browse files Browse the repository at this point in the history
  • Loading branch information
dl239 authored Nov 17, 2023
1 parent f3c9661 commit 4433970
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## [0.8.4] - 2023-11-16
## [0.8.4] - 2023-11-17

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

### Code Refactoring
#3547 @aceforeverd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com._4paradigm.openmldb.common.codec.RowView;
import com._4paradigm.openmldb.sdk.Schema;
import com._4paradigm.openmldb.sdk.Common;

import java.nio.ByteBuffer;
import java.sql.*;
Expand Down Expand Up @@ -151,7 +152,10 @@ public Timestamp getTimestamp(int i) throws SQLException {
public String getNString(int i) throws SQLException {
int realIdx = i - 1;
try {
return rowView.getString(realIdx);
if (rowView.isNull(realIdx)) {
return null;
}
return rowView.getValue(realIdx, Common.sqlType2ProtoType(schema.getColumnType(realIdx))).toString();
} catch (Exception e) {
throw new SQLException(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,80 @@ public void testDeploymentBatchRequest(String compressType, String storageMode)
}
}
}

@Test
public void testResultSetNull() {
java.sql.Statement state = executor.getStatement();
String dbname = "db" + random.nextInt(100000);
String deploymentName = "dp_test1";
try {
state.execute("drop database if exists " + dbname + ";");
state.execute("create database " + dbname + ";");
state.execute("use " + dbname + ";");
String baseSql = "create table trans(c1 string,\n" +
" c3 int,\n" +
" c4 bigint,\n" +
" c5 float,\n" +
" c6 double,\n" +
" c7 timestamp,\n" +
" c8 date,\n" +
" index(key=c1, ts=c7));";
state.execute(baseSql);
String selectSql = "SELECT c1, c3, sum(c4) OVER w1 as w1_c4_sum FROM trans WINDOW w1 AS " +
"(PARTITION BY trans.c1 ORDER BY trans.c7 ROWS_RANGE BETWEEN 2s PRECEDING AND 0s OPEN PRECEDING EXCLUDE CURRENT_TIME);";
String deploySql = "DEPLOY " + deploymentName + " " + selectSql;
state.execute(deploySql);
} catch (SQLException e) {
e.printStackTrace();
Assert.fail();
}
PreparedStatement pstmt = null;
ResultSet resultSet = null;
try {
Thread.sleep(100);
pstmt = executor.getCallablePreparedStmt(dbname, deploymentName);

pstmt.setString(1, "aa");
pstmt.setInt(2, 20);
pstmt.setNull(3, Types.BIGINT);
pstmt.setFloat(4, 1.1f);
pstmt.setDouble(5, 2.1);
pstmt.setTimestamp(6, new Timestamp(0));
pstmt.setDate(7, Date.valueOf("2020-05-01"));

resultSet = pstmt.executeQuery();

Assert.assertEquals(resultSet.getMetaData().getColumnCount(), 3);
while (resultSet.next()) {
Assert.assertEquals(resultSet.getString(1), "aa");
Assert.assertEquals(resultSet.getNString(1), "aa");
Assert.assertEquals(resultSet.getInt(2), 20);
Assert.assertEquals(resultSet.getNString(2), "20");
Assert.assertTrue(resultSet.getNString(3) == null);
}

state.execute("drop deployment " + deploymentName + ";");
String drop = "drop table trans;";
boolean ok = executor.executeDDL(dbname, drop);
Assert.assertTrue(ok);
ok = executor.dropDB(dbname);
Assert.assertTrue(ok);
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
} finally {
try {
state.close();
if (resultSet != null) {
resultSet.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (Exception throwables) {
throwables.printStackTrace();
}
}
}

}

0 comments on commit 4433970

Please sign in to comment.