A set of records are to be selected from a cassandra table.
select a1,a2,a3 from tableB where solr_query='...';
Where some of a1 (int
type) are null.
- In Oracle, we could use
nvl(a1,0)
. - In MS SQL Server, we could use
isnull(a1,0)
.
I don't know the same to handle in cassandra way.
How I handle this in Java :
Create TableBObject
class , in which all attributes are mapped with tableB
(cassandra table).
Create Java accessor interface with the accessor method
@Accessor
public interface TableBAccessor
{
@Query(select a1,a2,a3 from tableB where solr_query='...';)
Result<TableBObject> getTableOnSolrQuery (@Param("solrQuery") String solrQuery);
}
In my calling method, I have created the mappingManager
and used :
TableBAccessor tableBAccessor = mappingManager.createAccessor();
List<TableBObject> tabBList = tableBAccessor.getTableOnSolrQuery("someSolrQuery").all();
for(TableBObject tabB : tabBList){
int a1 = tabB.getA1(); /*a1 column in cassandra table*/
if(a1!=null){
// replace a1 by some int value (zero / something else)
}
}
Above way, I am handling the same in Java.
It is consuming additional effort to me.
What's the solution in cassandra
other than handling the same in Java
Code ?
**Can I not write like : **
select isnull(a1,0),a2,a3 from tableB where solr_query='...';
or
select nvl(a1,0),a2,a3 from tableB where solr_query='...';
??
**My Question Is : **
If Yes, then how ? If not, then why ?