fix(dameng): preserve numeric bit result values

Closes #6674
This commit is contained in:
t8y2 committed 2026-08-19 08:31:40 +00:00
1 parent dee9d52761
commit 1315b25c3e
2 files changed
+72 -2

No files matched your search

@@ -1851,7 +1851,8 @@ public final class DamengAgent extends AbstractJdbcAgent {
case Types.FLOAT, Types.REAL -> rs.getFloat(index); case Types.FLOAT, Types.REAL -> rs.getFloat(index);
case Types.DOUBLE -> rs.getDouble(index); case Types.DOUBLE -> rs.getDouble(index);
case Types.DECIMAL, Types.NUMERIC -> rs.getBigDecimal(index); case Types.DECIMAL, Types.NUMERIC -> rs.getBigDecimal(index);
case Types.BOOLEAN, Types.BIT -> rs.getBoolean(index); case Types.BOOLEAN -> rs.getBoolean(index);
case Types.BIT -> rs.getByte(index);
case Types.CHAR, Types.VARCHAR, Types.LONGVARCHAR, case Types.CHAR, Types.VARCHAR, Types.LONGVARCHAR,
Types.NCHAR, Types.NVARCHAR, Types.LONGNVARCHAR, Types.NCHAR, Types.NVARCHAR, Types.LONGNVARCHAR,
Types.CLOB, Types.NCLOB -> rs.getString(index); Types.CLOB, Types.NCLOB -> rs.getString(index);
@@ -20,6 +20,23 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
class DamengAgentPagingTest { class DamengAgentPagingTest {
@Test
void executeQueryPageSerializesBitValuesAsNumericBytes() {
assertBitResponse(Boolean.FALSE, "0");
assertBitResponse(Boolean.TRUE, "1");
}
@Test
void executeQueryPagePreservesNullBitAndBooleanValues() {
String nullBitResponse = executeSingleValueQuery("FLAG", Types.BIT, null, null, null);
String booleanResponse = executeSingleValueQuery("FLAG", Types.BOOLEAN, Boolean.TRUE, null, null);
assertFalse(nullBitResponse.contains("\"error\""), nullBitResponse);
assertTrue(nullBitResponse.contains("\"rows\":[[null]]"), nullBitResponse);
assertFalse(booleanResponse.contains("\"error\""), booleanResponse);
assertTrue(booleanResponse.contains("\"rows\":[[true]]"), booleanResponse);
}
@Test @Test
void executeQueryPageStringifiesTimestampValuesBeforeJsonRpcSerialization() { void executeQueryPageStringifiesTimestampValuesBeforeJsonRpcSerialization() {
DamengAgent agent = new DamengAgent(); DamengAgent agent = new DamengAgent();
@@ -118,6 +135,40 @@ class DamengAgentPagingTest {
assertFalse(response.contains("SerialBlob"), response); assertFalse(response.contains("SerialBlob"), response);
} }
private static void assertBitResponse(Boolean value, String expected) {
String response = executeSingleValueQuery("FLAG", Types.BIT, value, null, null);
assertFalse(response.contains("\"error\""), response);
assertTrue(response.contains("\"rows\":[[" + expected + "]]"), response);
assertFalse(response.contains("\"rows\":[[" + value + "]]"), response);
}
private static String executeSingleValueQuery(
String columnLabel,
int sqlType,
Object objectValue,
String stringValue,
byte[] bytesValue
) {
DamengAgent agent = new DamengAgent();
TestSupport.setPrivateConnection(
agent,
singleValueConnection(columnLabel, sqlType, objectValue, stringValue, bytesValue)
);
return handleRequest(new JsonRpcServer(agent), """
{
"jsonrpc": "2.0",
"id": 1,
"method": "execute_query_page",
"params": {
"sql": "SELECT FLAG FROM sample",
"schema": "SYS",
"pageSize": 100
}
}
""");
}
private static Connection singleValueConnection( private static Connection singleValueConnection(
String columnLabel, String columnLabel,
int sqlType, int sqlType,
@@ -191,6 +242,24 @@ class DamengAgentPagingTest {
if ("getObject".equals(name)) { if ("getObject".equals(name)) {
return objectValue; return objectValue;
} }
if ("getBoolean".equals(name)) {
if (objectValue instanceof Boolean value) {
return value;
}
if (objectValue instanceof Number value) {
return value.intValue() != 0;
}
return false;
}
if ("getByte".equals(name)) {
if (objectValue instanceof Boolean value) {
return value ? (byte) 1 : (byte) 0;
}
if (objectValue instanceof Number value) {
return value.byteValue();
}
return (byte) 0;
}
if ("getString".equals(name)) { if ("getString".equals(name)) {
return stringValue; return stringValue;
} }
@@ -198,7 +267,7 @@ class DamengAgentPagingTest {
return bytesValue; return bytesValue;
} }
if ("wasNull".equals(name)) { if ("wasNull".equals(name)) {
return false; return objectValue == null && stringValue == null && bytesValue == null;
} }
if ("close".equals(name)) { if ("close".equals(name)) {
return null; return null;