Support Questions
Find answers, ask questions, and share your expertise

Spring boot, phoenix hbase column return an array as a variable

Explorer

Hi All,

I have a phoenix table which there is a column which stores an array as the variable type.

The table is defined as below:

CREATE TABLE IF NOT EXISTS ENVI_DATA (
    PATIENT_ID	VARCHAR(50) NOT NULL,
    RECORD_DATE	TIMESTAMP NOT NULL,
    STEPS INTEGER NULL,
    STEPS_TIME	TIMESTAMP NULL,
    SPEED FLOAT	NULL,
    SPEED_TIME	TIMESTAMP NULL,
    USER_ROUTES	BIGINT[] NULL,
    LATITUDE  INTEGER	NULL,
    LONGITUDE INTEGER	NULL,
    LOCATION_RECORD_TIME TIMESTAMP NULL,
    CONSTRAINT PK PRIMARY KEY
    (
        PATIENT_ID,
        MOBILE_ID,
        RECORD_DATE
    )
) VERSIONS=3,SALT_BUCKETS=16;

The USER_ROUTES BIGINT[] NULL, is defined as long[] in the program.

And I have a method to query the data:

public EnviData query(String id){
		String querySql= "SELECT * FROM ENVI_DATA where PATIENT_ID=?";
		RowMapper<EnviData> rowMapper = new BeanPropertyRowMapper<EnviData>(EnviData.class);
		return jdbcTemplate.update(querySql, rowMapper, id);
	}

However, I got the following error:

"Failed to convert property value of type 'org.apache.phoenix.schema.types.PhoenixArray$PrimitiveLongPhoenixArray' to required type 'long[]' for property 'USER_ROUTES'

Which means the USER_ROUTES cann't convert to the type of long[].

I want to ask, do I need to write my own row mapper for this?

3 REPLIES 3

You likely need to share your application and the stack-trace to get help. It seems like this might be more of an issue with Spring and Phoenix.

Can you try something like this:-

String querySql= "SELECT * FROM ENVI_DATA where PATIENT_ID=?";
RowMapper<EnviData> rowMapper = newRowMapper<EnviData>(){
@Override
public EnviData mapRow(ResultSet rs,int rowNum) throwsSQLException{
		EnviData data =new EnviData();
        data.setPatientId(rs.getString(1));
        data.setUserRoutes(rs.getArray(7).getArray());
}
return jdbcTemplate.update(querySql, rowMapper, id);

Explorer

Hi Ankit,

Thanks for your information. I solved the problem by changing long[] to Long[].

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.