-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3.1 driver broke float handling for nan/inf
ResultSet.getFloat and ResultSet.getObject(Float.class) did not agree with each other
- Loading branch information
1 parent
272d9c4
commit 6cc8b68
Showing
4 changed files
with
212 additions
and
7 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...khouse-jdbc/src/main/java/ru/yandex/clickhouse/response/parser/ClickHouseFloatParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ru.yandex.clickhouse.response.parser; | ||
|
||
import java.sql.SQLException; | ||
import java.util.TimeZone; | ||
|
||
import ru.yandex.clickhouse.except.ClickHouseUnknownException; | ||
import ru.yandex.clickhouse.response.ByteFragment; | ||
import ru.yandex.clickhouse.response.ClickHouseColumnInfo; | ||
|
||
final class ClickHouseFloatParser extends ClickHouseValueParser<Float> { | ||
|
||
private static ClickHouseFloatParser instance; | ||
|
||
static ClickHouseFloatParser getInstance() { | ||
if (instance == null) { | ||
instance = new ClickHouseFloatParser(); | ||
} | ||
return instance; | ||
} | ||
|
||
private ClickHouseFloatParser() { | ||
// prevent instantiation | ||
} | ||
|
||
@Override | ||
public Float parse(ByteFragment value, ClickHouseColumnInfo columnInfo, | ||
TimeZone resultTimeZone) throws SQLException | ||
{ | ||
if (value.isNull()) { | ||
return null; | ||
} | ||
if (value.isNaN()) { | ||
return Float.valueOf(Float.NaN); | ||
} | ||
String s = value.asString(); | ||
switch (s) { | ||
case "+inf": | ||
case "inf": | ||
return Float.valueOf(Float.POSITIVE_INFINITY); | ||
case "-inf": | ||
return Float.valueOf(Float.NEGATIVE_INFINITY); | ||
default: | ||
try { | ||
return Float.valueOf(s); | ||
} catch (NumberFormatException nfe) { | ||
throw new ClickHouseUnknownException( | ||
"Error parsing '" + s + "' as Float", | ||
nfe); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected Float getDefaultValue() { | ||
return Float.valueOf(0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters