Exception in thread "main" java.lang.IllegalArgumentException: location.city is not a column defined in this metadata

761 views Asked by At

Here is my CQL tables

CREATE TYPE ks_demo.location (
lat float,
lon float,
locName text,
city text,
state text,
country text,
pin int
);    

create table publishMsg
(
    rowKey uuid,
    msgId timeuuid,
    postedBy text,
    postedById uuid,
    title text,
    details text,
    tags set<text>,
    location frozen<location>,
    blocked boolean,
    anonymous boolean,
    hasPhotos boolean,
    PRIMARY KEY(rowKey, msgId)      
)

create table publishMsg_by_user
(
    userId uuid,
    msgId timeuuid,
    postedBy text,
    title text,
    details text,
    tags set<text>,
    location frozen<location>,
    blocked boolean,
    anonymous boolean,
    hasPhotos boolean,
    PRIMARY KEY(rowKey, msgId)      
)

Here is datastax java query

Select.Where query = QueryBuilder.select().column("userId").column("msgId")
.column("location.city")
       .from(AppConstants.KEYSPACE, "publishMsg_by_user")
       .where(QueryBuilder.eq("userId",userId));

If I do

ResultSet  execute         = session.execute(query);
Iterator<Row> iterator        = execute.iterator();        
while(iterator.hasNext())
{
    Row row = iterator.next();
    row.getString("location.city")
}
row.getString("location.city")

it is showing

Exception in thread "main" java.lang.IllegalArgumentException: location.city is not a column defined in this metadata
1

There are 1 answers

0
dgofactory On

You could try:

String city = row.getUDTValue("location").getString("city")