JackieTien97 commented on code in PR #18962:
URL: https://github.com/apache/iotdb/pull/18962#discussion_r4336375584
##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java:
##########
@@ -741,12 +796,20 @@ public Time getTime(String arg0, Calendar arg1) throws
SQLException {
@Override
public Timestamp getTimestamp(int columnIndex) throws SQLException {
- return convertToTimestamp(getLong(columnIndex), statement.getTimeFactor());
+ try {
+ return ioTDBRpcDataSet.getTimestamp(columnIndex);
+ } catch (StatementExecutionException e) {
+ throw new SQLException(e.getMessage());
+ }
}
@Override
public Timestamp getTimestamp(String columnName) throws SQLException {
- return new Timestamp(getLong(columnName));
+ try {
+ return ioTDBRpcDataSet.getTimestamp(columnName);
Review Comment:
[P2] Preserve pre-epoch timestamps when reading by label
With millisecond precision and a timestamp column containing `-1500`,
`getTimestamp("ts")` now throws `SQLException: nanos > 999999999 or < 0`; the
same test passes on the PR base and returns `new Timestamp(-1500L)`. This new
path delegates to `RpcUtils.convertToTimestamp()`, whose ordinary
division/remainder produces a negative nanos component for negative values that
are not whole seconds. Please fix the shared conversion to use floor-based
seconds and a nonnegative fractional component, and cover negative timestamps,
before routing this getter through it.
##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBTablePreparedStatement.java:
##########
@@ -703,36 +748,51 @@ private String createCompleteSql(final String sql,
Map<Integer, String> paramete
return newSql.toString();
}
+ /**
+ * Splits the SQL at its parameter markers, skipping string literals, quoted
identifiers and
+ * comments as the table-model lexer does. Quotes are escaped only by
doubling them; a backslash
+ * is an ordinary character.
+ */
private List<String> splitSqlStatement(final String sql) {
List<String> parts = new ArrayList<>();
- int apCount = 0;
int off = 0;
- boolean skip = false;
-
- for (int i = 0; i < sql.length(); i++) {
+ int i = 0;
+ while (i < sql.length()) {
char c = sql.charAt(i);
- if (skip) {
- skip = false;
- continue;
- }
- switch (c) {
- case '\'':
- apCount++;
- break;
- case '\\':
- skip = true;
- break;
- case '?':
- if ((apCount & 1) == 0) {
- parts.add(sql.substring(off, i));
- off = i + 1;
- }
- break;
- default:
- break;
+ if (c == '\'' || c == '"' || c == '`') {
+ i = skipQuoted(sql, i, c);
+ } else if (sql.startsWith("--", i)) {
+ int end = sql.indexOf('\n', i);
+ i = end < 0 ? sql.length() : end + 1;
Review Comment:
[P2] Recognize carriage returns as line-comment terminators
The table-model lexer's `SIMPLE_COMMENT` rule ends a comment at either `\r`
or `\n`, but this scanner only searches for `\n`. For the Java string `"INSERT
-- comment\rINTO t(time, s1) VALUES(?, ?)\n"`, binding both parameters and
calling `executeUpdate()` still sends the two `?` markers unchanged because the
scanner treats the remainder of the INSERT as a comment. This substitution test
passes on the PR base and fails here. Please recognize lone CR as well as LF
and CRLF so the client and server agree on where parameter markers are visible.
##########
iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBTablePreparedStatement.java:
##########
@@ -446,10 +472,27 @@ public void setTime(int parameterIndex, Time x, Calendar
cal) throws SQLExceptio
@Override
public void setTimestamp(int parameterIndex, Timestamp x) throws
SQLException {
checkParameterIndex(parameterIndex);
- // Use millisecond value for SQL compatibility with TIMESTAMP columns
- long timestampMs = x.getTime();
- setPreparedParameterValue(parameterIndex, timestampMs, Types.BIGINT);
- this.parameters.put(parameterIndex, Long.toString(timestampMs));
+ // The server reads time values in its own precision (ms, us or ns)
+ long time = toServerTime(x);
+ setPreparedParameterValue(parameterIndex, time, Types.BIGINT);
+ this.parameters.put(parameterIndex, Long.toString(time));
+ }
+
+ private long toServerTime(Timestamp x) throws SQLException {
+ int timeFactor = getTimeFactor();
+ // getTime() carries the milliseconds of getNanos(), so only its whole
seconds are used
+ long seconds = Math.floorDiv(x.getTime(), 1_000L);
+ try {
+ return Math.addExact(
+ Math.multiplyExact(seconds, timeFactor), x.getNanos() /
(1_000_000_000 / timeFactor));
Review Comment:
[P3] Avoid intermediate underflow for valid nanosecond timestamps
With nanosecond precision, `setTimestamp(1,
Timestamp.from(Instant.parse("1677-09-21T00:12:43.145224193Z")))` throws the
new out-of-range exception, although the correct value is `Long.MIN_VALUE + 1`
and fits in a long. Flooring to whole seconds makes `seconds * timeFactor`
underflow before the positive fractional component can bring the final result
back into range. Please rearrange the negative-value arithmetic or check the
complete converted value without overflowing the intermediate product, and add
a lower-bound test alongside the existing far-future overflow test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]