You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metamodel.apache.org by "Kasper Sørensen (JIRA)" <ji...@apache.org> on 2017/10/03 03:41:00 UTC
[jira] [Resolved] (METAMODEL-1164) How to cast result of a query
containing an aggregate function using apache metamodel
[ https://issues.apache.org/jira/browse/METAMODEL-1164?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Kasper Sørensen resolved METAMODEL-1164.
----------------------------------------
Resolution: Fixed
I always cast to Number and then get long value, like this:
{code}
Number n = (Number) dataSet.getRow().getValue(0);
long count = n.longValue();
{code}
> How to cast result of a query containing an aggregate function using apache metamodel
> -------------------------------------------------------------------------------------
>
> Key: METAMODEL-1164
> URL: https://issues.apache.org/jira/browse/METAMODEL-1164
> Project: Apache MetaModel
> Issue Type: Bug
> Affects Versions: 4.5.4
> Reporter: santoshnagda
>
> I am new to apache metamodel. And I need to run following query using apache metamodel.
> {code:java}
> select sum(cast(columnName as decimal)) from table;"
> {code}
> I know that a query containing simple sum function looks like the one given below:
> {code:java}
> Query query = dataContext.query().from(table).select(FunctionType.SUM, table.getColumnByName(columnName)).toQuery();
> {code}
> But I need to use a cast function because depending on the number of records in particular table the result of the sum can be too big than a value which an integer can hold. Thus causing an exception "Arithmetic overflow error converting expression to data type int." to be thrown when there are millions of records in a table. Can anyone tell me how to apply a cast function when composing a query to be executed with apache metamodel.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)