线程“main”中的异常java.lang.IllegalArgumentException:location.city不是此元数据中定义的列

时间:2015-06-24 15:05:39

标签: java cassandra datastax cql3 datastax-java-driver

这是我的CQL表

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)      
)

这是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));

如果我这样做

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")

显示

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

1 个答案:

答案 0 :(得分:0)

你可以尝试:

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