Skip to content

Commit 4e0ecc2

Browse files
authored
Add Date and Float data IT (apache#14892)
1 parent 7883265 commit 4e0ecc2

File tree

4 files changed

+82
-13
lines changed

4 files changed

+82
-13
lines changed

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFloatPrecisionIT.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,49 @@ public void selectAllSQLTest() {
169169
fail(e.getMessage());
170170
}
171171
}
172+
173+
@Test
174+
public void bigFloatNumberTest2() {
175+
try (Connection connection = EnvFactory.getEnv().getConnection();
176+
Statement statement = connection.createStatement()) {
177+
float[] floats = new float[] {6.5536403E8F, 3.123456768E20F, Float.NaN};
178+
double[] doubles = new double[] {9.223372036854E18, 9.223372036854E100, Double.NaN};
179+
180+
statement.execute("create timeseries root.sg.d1.s1 with datatype=float, encoding=rle");
181+
statement.execute("create timeseries root.sg.d1.s2 with datatype=double, encoding=rle");
182+
statement.execute(
183+
"insert into root.sg.d1(time, s1, s2) values (1, 6.5536403E8, 9.223372036854E18)");
184+
statement.execute(
185+
"insert into root.sg.d1(time, s1, s2) values (2, 3.123456768E20, 9.223372036854E100)");
186+
statement.execute("insert into root.sg.d1(time, s1, s2) values (3, NaN, NaN)");
187+
188+
int cnt;
189+
try (ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg.d1")) {
190+
assertNotNull(resultSet);
191+
cnt = 0;
192+
while (resultSet.next()) {
193+
assertEquals(floats[cnt], resultSet.getFloat("root.sg.d1.s1"), DELTA_FLOAT);
194+
assertEquals(doubles[cnt], resultSet.getDouble("root.sg.d1.s2"), DELTA_DOUBLE);
195+
cnt++;
196+
}
197+
assertEquals(3, cnt);
198+
}
199+
200+
statement.execute("flush");
201+
202+
try (ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg.d1")) {
203+
assertNotNull(resultSet);
204+
cnt = 0;
205+
while (resultSet.next()) {
206+
assertEquals(floats[cnt], resultSet.getFloat("root.sg.d1.s1"), DELTA_FLOAT);
207+
assertEquals(doubles[cnt], resultSet.getDouble("root.sg.d1.s2"), DELTA_DOUBLE);
208+
cnt++;
209+
}
210+
assertEquals(3, cnt);
211+
}
212+
} catch (Exception e) {
213+
e.printStackTrace();
214+
fail(e.getMessage());
215+
}
216+
}
172217
}

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,4 +1185,28 @@ public void testNewDataType() {
11851185
fail();
11861186
}
11871187
}
1188+
1189+
@Test
1190+
public void testIllegalDateType() {
1191+
try (Connection connection = EnvFactory.getEnv().getConnection();
1192+
Statement statement = connection.createStatement()) {
1193+
1194+
statement.execute("CREATE DATABASE root.sg1");
1195+
statement.execute(
1196+
"CREATE TIMESERIES root.sg1.d1.s4 WITH DATATYPE=DATE, ENCODING=PLAIN, COMPRESSOR=SNAPPY");
1197+
try {
1198+
statement.execute("insert into root.sg1.d1(timestamp, s4) values(1, '2022-04-31')");
1199+
fail();
1200+
} catch (Exception e) {
1201+
assertEquals(
1202+
TSStatusCode.METADATA_ERROR.getStatusCode()
1203+
+ ": Fail to insert measurements [s4] caused by [data type is not consistent, "
1204+
+ "input '2022-04-31', registered DATE because Invalid date format. "
1205+
+ "Please use YYYY-MM-DD format.]",
1206+
e.getMessage());
1207+
}
1208+
} catch (SQLException e) {
1209+
fail();
1210+
}
1211+
}
11881212
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/MathUtils.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ private MathUtils() {
2929
throw new IllegalStateException("Utility class");
3030
}
3131

32-
/**
33-
* @param data data should be less than Long.MAX_VALUE. otherwise Math.round() will return wrong
34-
* value.
35-
*/
3632
public static float roundWithGivenPrecision(float data, int size) {
33+
if (Float.isNaN(data) || data > Integer.MAX_VALUE || data < Integer.MIN_VALUE) {
34+
return data;
35+
}
3736
if (size == 0) {
3837
return Math.round(data);
3938
}
@@ -42,6 +41,9 @@ public static float roundWithGivenPrecision(float data, int size) {
4241
}
4342

4443
public static float roundWithGivenPrecision(float data) {
44+
if (Float.isNaN(data) || data > Integer.MAX_VALUE || data < Integer.MIN_VALUE) {
45+
return data;
46+
}
4547
if (TSFileDescriptor.getInstance().getConfig().getFloatPrecision() == 0) {
4648
return Math.round(data);
4749
}
@@ -54,23 +56,21 @@ public static float roundWithGivenPrecision(float data) {
5456
/ (float) Math.pow(10, TSFileDescriptor.getInstance().getConfig().getFloatPrecision());
5557
}
5658

57-
/**
58-
* @param data data should be less than Long.MAX_VALUE. otherwise Math.round() will return wrong
59-
* value.
60-
*/
6159
public static double roundWithGivenPrecision(double data, int size) {
60+
if (Double.isNaN(data) || data > Long.MAX_VALUE || data < Long.MIN_VALUE) {
61+
return data;
62+
}
6263
if (size == 0) {
6364
return Math.round(data);
6465
}
6566
return Math.round(data)
6667
+ Math.round(((data - Math.round(data)) * Math.pow(10, size))) / Math.pow(10, size);
6768
}
6869

69-
/**
70-
* @param data data should be less than Long.MAX_VALUE. otherwise Math.round() will return wrong
71-
* value.
72-
*/
7370
public static double roundWithGivenPrecision(double data) {
71+
if (Double.isNaN(data) || data > Long.MAX_VALUE || data < Long.MIN_VALUE) {
72+
return data;
73+
}
7474
if (TSFileDescriptor.getInstance().getConfig().getFloatPrecision() == 0) {
7575
return Math.round(data);
7676
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
<thrift.version>0.14.1</thrift.version>
168168
<xz.version>1.9</xz.version>
169169
<zstd-jni.version>1.5.6-3</zstd-jni.version>
170-
<tsfile.version>2.1.0-250207-SNAPSHOT</tsfile.version>
170+
<tsfile.version>2.1.0-250219-SNAPSHOT</tsfile.version>
171171
</properties>
172172
<!--
173173
if we claim dependencies in dependencyManagement, then we do not claim

0 commit comments

Comments
 (0)