Skip to content
Snippets Groups Projects

Fix large integer queries

Merged Daniel Hornung requested to merge f-fix-145-large-integer into dev
All threads resolved!
Files
3
@@ -63,6 +63,7 @@ public class POV implements EntityFilterInterface {
private DateTimeInterface vDatetime;
private final String aggregate;
private String targetSet = null;
private String unitStr = null;
private Unit unit = null;
private Long stdUnitSig = null;
private Double vDoubleConvertedToStdUnit = null;
@@ -112,7 +113,6 @@ public class POV implements EntityFilterInterface {
// parse value to int/double/datetime
if (this.value != null) {
String unitStr = null;
// try and parse as integer
try {
@@ -122,44 +122,41 @@ public class POV implements EntityFilterInterface {
throw new NumberFormatException();
}
final String vIntStr = m.group(1);
unitStr = m.group(2);
this.unitStr = m.group(2);
this.vInt = Integer.parseInt(vIntStr);
} catch (final NumberFormatException e) {
this.vInt = null;
}
// try and parse as double
if (this.vInt != null) {
this.vDouble = (double) this.vInt;
} else {
// Try and parse as double, if integer parsing was unsuccessful.
if (this.vInt == null) {
try {
final Pattern dp = Pattern.compile("^(-?[0-9]+(?:\\.[0-9]+))\\s*([^-]*)$");
// Doubles are allowed without dots, for example when the integer overflows.
final Pattern dp = Pattern.compile("^(-?[0-9]+(?:\\.)?(?:[0-9]+))\\s*([^-]*)$");
final Matcher m = dp.matcher(value);
if (!m.matches()) {
throw new NumberFormatException();
}
final String vDoubleStr = m.group(1);
unitStr = m.group(2);
this.unitStr = m.group(2);
this.vDouble = Double.parseDouble(vDoubleStr);
if (this.vDouble % 1 == 0) {
this.vInt = (int) Math.floor(this.vDouble);
}
} catch (final NumberFormatException e) {
this.vDouble = null;
}
}
if (this.vDouble != null && unitStr != null && unitStr.length() > 0) {
if ((this.vDouble != null || this.vInt != null)
&& this.unitStr != null
&& this.unitStr.length() > 0) {
try {
this.unit = getUnit(unitStr);
this.unit = getUnit(this.unitStr);
} catch (final ParserException e) {
e.printStackTrace();
throw new UnsupportedOperationException("Could not parse the unit.");
}
this.stdUnitSig = this.unit.normalize().getSignature();
this.vDoubleConvertedToStdUnit = this.unit.convert(this.vDouble);
}
// try and parse as datetime
try {
@@ -219,6 +216,11 @@ public class POV implements EntityFilterInterface {
"Versioned queries are not supported for subqueries yet. Please file a feature request.");
}
final long t1 = System.currentTimeMillis();
// Add type-converted substitutes for ints/doubles.
final Integer vIntSubst =
(this.vDouble != null && this.vDouble % 1 == 0) ? (int) Math.rint(this.vDouble) : null;
final Double vDoubleSubst = (this.vInt != null) ? (double) this.vInt : null;
try {
this.connection = query.getConnection();
this.targetSet = query.getTargetSet();
@@ -272,14 +274,25 @@ public class POV implements EntityFilterInterface {
} else {
callPOV.setNull(6, VARCHAR);
}
if (this.vInt != null) { // vInt
callPOV.setInt(7, this.vInt);
if (this.vInt != null || this.vDouble != null) { // Some numeric
if (this.vInt != null) {
callPOV.setInt(7, this.vInt);
callPOV.setDouble(8, vDoubleSubst);
} else {
if (vIntSubst == null) {
callPOV.setNull(7, INTEGER);
} else {
callPOV.setInt(7, vIntSubst);
}
callPOV.setDouble(8, this.vDouble);
}
// finally: do unit conversion
if (this.unitStr != null && this.unitStr.length() > 0) {
this.vDoubleConvertedToStdUnit =
this.unit.convert(this.vDouble != null ? this.vDouble : vDoubleSubst);
}
} else {
callPOV.setNull(7, INTEGER);
}
if (this.vDouble != null) { // vDouble
callPOV.setDouble(8, this.vDouble);
} else {
callPOV.setNull(8, DOUBLE);
}
if (this.unit != null) {
@@ -505,6 +518,27 @@ public class POV implements EntityFilterInterface {
return ret;
}
/** Return the Int value, which may be null. */
public Integer getVInt() {
if (this.vInt != null) {
return Integer.valueOf(vInt);
}
return null;
}
/** Return the Double value, which may be null. */
public Double getVDouble() {
if (this.vDouble != null) {
return Double.valueOf(vDouble);
}
return null;
}
/** Return the Datetime value, which may be null. */
public DateTimeInterface getVDatetime() {
return this.vDatetime;
}
public String getAggregate() {
return this.aggregate;
}
Loading