JackieTien97 commented on code in PR #14364:
URL: https://github.com/apache/iotdb/pull/14364#discussion_r1881346496
##########
library-udf/src/main/java/org/apache/iotdb/library/util/Util.java:
##########
@@ -300,26 +304,80 @@ public static long mode(long[] values) {
* @param s input string
* @return timestamp
*/
- public static long parseTime(String s) {
+ public static long parseTime(String s, UDFParameters parameters) {
long unit = 0;
+ String timestampPrecision =
+ parameters.getSystemStringOrDefault(TIMESTAMP_PRECISION, MS_PRECISION);
s = s.toLowerCase();
s = s.replace(" ", "");
- if (s.endsWith("ms")) {
- unit = 1;
- s = s.substring(0, s.length() - 2);
- } else if (s.endsWith("s")) {
- unit = 1000;
- s = s.substring(0, s.length() - 1);
- } else if (s.endsWith("m")) {
- unit = 60 * 1000L;
- s = s.substring(0, s.length() - 1);
- } else if (s.endsWith("h")) {
- unit = 60 * 60 * 1000L;
- s = s.substring(0, s.length() - 1);
- } else if (s.endsWith("d")) {
- unit = 24 * 60 * 60 * 1000L;
- s = s.substring(0, s.length() - 1);
+ if (timestampPrecision.equals("ms")) {
+ if (s.endsWith("ns") || s.endsWith("us")) {
+ throw new IllegalArgumentException(
+ "The provided time precision is lower than the system's minimum
precision (ms). Please check your input.");
+ } else if (s.endsWith("ms")) {
+ unit = 1;
+ s = s.substring(0, s.length() - 2);
+ } else if (s.endsWith("s")) {
+ unit = 1000;
+ s = s.substring(0, s.length() - 1);
+ } else if (s.endsWith("m")) {
+ unit = 60 * 1000L;
+ s = s.substring(0, s.length() - 1);
+ } else if (s.endsWith("h")) {
+ unit = 60 * 60 * 1000L;
+ s = s.substring(0, s.length() - 1);
+ } else if (s.endsWith("d")) {
+ unit = 24 * 60 * 60 * 1000L;
+ s = s.substring(0, s.length() - 1);
+ }
+ } else if (timestampPrecision.equals("us")) {
+ if (s.endsWith("ns")) {
+ throw new IllegalArgumentException(
+ "The provided time precision is lower than the system's minimum
precision (ms). Please check your input.");
Review Comment:
```suggestion
"The provided time precision is higher than the system's time
precision (us). Please check your input.");
```
##########
library-udf/src/main/java/org/apache/iotdb/library/util/Util.java:
##########
@@ -300,26 +304,80 @@ public static long mode(long[] values) {
* @param s input string
* @return timestamp
*/
- public static long parseTime(String s) {
+ public static long parseTime(String s, UDFParameters parameters) {
long unit = 0;
+ String timestampPrecision =
+ parameters.getSystemStringOrDefault(TIMESTAMP_PRECISION, MS_PRECISION);
s = s.toLowerCase();
s = s.replace(" ", "");
- if (s.endsWith("ms")) {
- unit = 1;
- s = s.substring(0, s.length() - 2);
- } else if (s.endsWith("s")) {
- unit = 1000;
- s = s.substring(0, s.length() - 1);
- } else if (s.endsWith("m")) {
- unit = 60 * 1000L;
- s = s.substring(0, s.length() - 1);
- } else if (s.endsWith("h")) {
- unit = 60 * 60 * 1000L;
- s = s.substring(0, s.length() - 1);
- } else if (s.endsWith("d")) {
- unit = 24 * 60 * 60 * 1000L;
- s = s.substring(0, s.length() - 1);
+ if (timestampPrecision.equals("ms")) {
+ if (s.endsWith("ns") || s.endsWith("us")) {
+ throw new IllegalArgumentException(
+ "The provided time precision is lower than the system's minimum
precision (ms). Please check your input.");
Review Comment:
```suggestion
"The provided time precision is higher than the system's time
precision (ms). Please check your input.");
```
--
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]