GemFire Error "unable to parse integer" Running Query on BigDecimal Field
search cancel

GemFire Error "unable to parse integer" Running Query on BigDecimal Field

book

Article ID: 294131

calendar_today

Updated On:

Products

VMware Tanzu Gemfire

Issue/Introduction

Symptoms:

When attempting to run a query with a "Where" clause on a BigDecimal field, it throws the below exception and fails to return a result.

Example:

The Domain class has a BigDecimal field like the one below:

private BigDecimal SampleID;

public BigDecimal getSampleID()
{
return SampleID;
}

public void setSampleID( BigDecimal SampleID )
{
SampleID = SampleID;
}

public String toString() {
return "Id [SampleID=" + SampleID + "]";
}

gfsh>query --query='SELECT * FROM /ID_Region t WHERE t.SampleID=9111221001';

Result : false
startCount : 0
endCount : 20
Message : Query is invalid due for error :<Syntax error in query:  unable to parse integer:  9111221001>

Environment


Cause

When the OQL parser gets a value of 9111221001 from a WHERE clause, it decides that the number is an integer by default like Java does. Since this value of 9111221001 is over the integer's maximum value of 2147483647, the OQL parser returns this error.

Resolution

To work around this error, there are several solutions.

Solution 1

Add suffix "L" like Java to the number to convert the number to Long type.

Example:
SELECT * FROM /ID_Region t WHERE t.SampleID=9111221001L

Solution 2

Use method in domain class to convert the number into String.
Example:
SELECT * FROM /ID_Regionn t WHERE t.SampleID. toString()='9111221001'

Solution 3

Add suffix "." or ".0" to convert the number into double type.
Example:
SELECT * FROM /ID_Region t WHERE t.SampleID=9111221001.
SELECT * FROM /ID_Region t WHERE t.SampleID=9111221001.0