You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Niels Stevens <ni...@kabisa.nl> on 2011/12/19 10:24:44 UTC

Decimal Mapping problem

Hey everybody,

I'm having an issue importing Decimal numbers from my Mysql DB to Solr.
Is there anybody with some advise, I will start and try to explain my
problem.

According to my findings, I think the lack of a explicit mapping of a
Decimal value in the schema.xml
is causing some issues I'm experiencing.

The decimal numbers I'm trying to import look like this :

0.075000
7.500000
2.250000


but after the import statement the results for the equivalent Solr field
are returned as this:

[B@1413d20
[B@11c86ff
[B@1e2fd0d


The import statement for this particular field looks like:

.... IF(drt.discount IS NULL,'0',(drt.discount/100)) ...


Now I thought that using the Round functions from mysql to 3 numbers after
the dot.
In conjunction with a explicite mapping field in the schema.xml could solve
this issue.
Is there someone with some similar problems with decimal fields or anybody
with an expert view on this?

Thanks a lot in advance.

Regards,

Niels Stevens

Re: Decimal Mapping problem

Posted by Chris Hostetter <ho...@fucit.org>.
: Try to cast MySQL decimal data type to string, i.e.
: 
: CAST( IF(drt.discount IS NULL,'0',(drt.discount/100)) AS CHAR) as discount
: (or CAST AS TEXT)

...to clarify here, the values you are seeing are what happens when the DB 
returns to DIH a value in a type it doesn't udnerstand -- in this case 
it's a byte array.  DIH isn't sure what do do with this byte array, so it 
just calls the java "toString()" method on it.

casting that byte array to something DIH understands (like a string) is 
one way to solve the problem, but the other would be to use some SQL 
expression that always returns aconsistent type, so the SQL server knows 
what type to declare in it's response -- in your example you are sometimes 
returning a string (if NULL, you return the string '0') and sometimes 
returning a number (if not null, drt.discount/100) 

use SQL that alwasy returns a number, and this problem will also go away.


-Hoss

Re: Decimal Mapping problem

Posted by Alexey Serba <as...@gmail.com>.
Try to cast MySQL decimal data type to string, i.e.

CAST( IF(drt.discount IS NULL,'0',(drt.discount/100)) AS CHAR) as discount
(or CAST AS TEXT)

On Mon, Dec 19, 2011 at 1:24 PM, Niels Stevens <ni...@kabisa.nl> wrote:
> Hey everybody,
>
> I'm having an issue importing Decimal numbers from my Mysql DB to Solr.
> Is there anybody with some advise, I will start and try to explain my
> problem.
>
> According to my findings, I think the lack of a explicit mapping of a
> Decimal value in the schema.xml
> is causing some issues I'm experiencing.
>
> The decimal numbers I'm trying to import look like this :
>
> 0.075000
> 7.500000
> 2.250000
>
>
> but after the import statement the results for the equivalent Solr field
> are returned as this:
>
> [B@1413d20
> [B@11c86ff
> [B@1e2fd0d
>
>
> The import statement for this particular field looks like:
>
> .... IF(drt.discount IS NULL,'0',(drt.discount/100)) ...
>
>
> Now I thought that using the Round functions from mysql to 3 numbers after
> the dot.
> In conjunction with a explicite mapping field in the schema.xml could solve
> this issue.
> Is there someone with some similar problems with decimal fields or anybody
> with an expert view on this?
>
> Thanks a lot in advance.
>
> Regards,
>
> Niels Stevens