You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@phoenix.apache.org by "Dong-iL, Kim" <ki...@gmail.com> on 2016/08/05 14:27:00 UTC

ERROR 201 (22000) illegal data error, expected length at least 4 but had ...

Hi
I’ve create a table in phoenix. 

CREATE TABLE WINLOSS (
    dayNumber VARCHAR NOT NULL,
    type VARCHAR NOT NULL,
    historyId VARCHAR NOT NULL,
    seq INTEGER NOT NULL,
    timestamp BIGINT,
    name VARCHAR,
    gameType VARCHAR,
    playType VARCHAR,
    gameKind VARCHAR,
    onRitt BOOLEAN,
    contributedAmount BIGINT,
    payAmount BIGINT
    CONSTRAINT rowid PRIMARY KEY(dayNumber, type, historyId, seq)
) default_column_family = 'winloss';

insert data through hbase.

and I got an error when querying table.
just like this.

select * from WINLESS;

Error: ERROR 201 (22000): Illegal data. Expected length of at least 4 bytes, but had 1 (state=22000,code=201)
java.sql.SQLException: ERROR 201 (22000): Illegal data. Expected length of at least 4 bytes, but had 1
	at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:422)
	at org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:145)
	at org.apache.phoenix.schema.types.PDataType.checkForSufficientLength(PDataType.java:274)
	at org.apache.phoenix.schema.types.PInteger$IntCodec.decodeInt(PInteger.java:183)
	at org.apache.phoenix.schema.types.PInteger.toObject(PInteger.java:81)
	at org.apache.phoenix.schema.types.PInteger.toObject(PInteger.java:28)
	at org.apache.phoenix.schema.types.PDataType.toObject(PDataType.java:985)
	at org.apache.phoenix.compile.ExpressionProjector.getValue(ExpressionProjector.java:75)
	at org.apache.phoenix.jdbc.PhoenixResultSet.getObject(PhoenixResultSet.java:524)
	at sqlline.Rows$Row.<init>(Rows.java:157)
	at sqlline.BufferedRows.<init>(BufferedRows.java:38)
	at sqlline.SqlLine.print(SqlLine.java:1650)
	at sqlline.Commands.execute(Commands.java:833)
	at sqlline.Commands.sql(Commands.java:732)
	at sqlline.SqlLine.dispatch(SqlLine.java:808)
	at sqlline.SqlLine.begin(SqlLine.java:681)
	at sqlline.SqlLine.start(SqlLine.java:398)
	at sqlline.SqlLine.main(SqlLine.java:292)

what shall I do?

Thanks.

Re: ERROR 201 (22000) illegal data error, expected length at least 4 but had ...

Posted by vikashtalanki <vi...@gmail.com>.
I dont have a code snippet for composite key, but you can encode each field
in the composite key and then do an array concatenation.
http://stackoverflow.com/questions/80476/how-can-i-concatenate-two-arrays-in-java



--
View this message in context: http://apache-phoenix-user-list.1124778.n5.nabble.com/ERROR-201-22000-illegal-data-error-expected-length-at-least-4-but-had-tp2170p2249.html
Sent from the Apache Phoenix User List mailing list archive at Nabble.com.

Re: ERROR 201 (22000) illegal data error, expected length at least 4 but had ...

Posted by "Dong-iL, Kim" <ki...@gmail.com>.
Oh. Thanks a lot.

do you have a snippet for generating composite key?

I’m sorry for my laziness. 


> On Aug 12, 2016, at 3:24 PM, vikashtalanki <vi...@gmail.com> wrote:
> 
> Hi Dong,
> 
> If you still want to insert through hbase, you can use the below snippets
> for encoding values as per phoenix. ---> import
> org.apache.phoenix.schema.types.*;
> 
> public static byte[] encodeDecimal(String value)
> 	{
> 		BigDecimal bigDecValue = new BigDecimal(value);
> 		byte[] pDecimalByteArray = PDecimal.INSTANCE.toBytes(bigDecValue);
> 		return pDecimalByteArray;
> 	}
> 	
> 	public static byte[] encodeDate(java.util.Date utilDate)
> 	{
> 		java.sql.Date sqlDate = new Date(utilDate.getTime());
> 		byte[] pDateByteArray = PDate.INSTANCE.toBytes(sqlDate);
> 		return pDateByteArray;
> 	}
> 	
> 	public static byte[] encodeTimestamp(String utilTS)
> 	{
> 		java.sql.Timestamp sqlDate = Timestamp.valueOf(utilTS);
> 		byte[] pTSByteArray = PTimestamp.INSTANCE.toBytes(sqlDate);
> 		return pTSByteArray;
> 	}
> 	
> 	public static byte[] encodeLong(String value)
> 	{
> 		byte[] pLongByteArray = PLong.INSTANCE.toBytes(value);
> 		return pLongByteArray;
> 	}
> 	
> 	public static byte[] encodeChar(String value)
> 	{
> 		byte[] pCharByteArray = PChar.INSTANCE.toBytes(value);
> 		return pCharByteArray;
> 	}
> 	
> 	public static byte[] encodeVarchar(String value)
> 	{
> 		byte[] pVarcharByteArray = PVarchar.INSTANCE.toBytes(value);
> 		return pVarcharByteArray;
> 	}
> 	
> 	public static byte[] encodeShort(String value)
> 	{
> 		Short shortValue = Short.parseShort(value);
> 		byte[] pShortByteArray = PSmallint.INSTANCE.toBytes(shortValue);
> 		return pShortByteArray;
> 	}
> 	
> 	public static byte[] encodeInteger(String value)
> 	{
> 		int intValue = Integer.parseInt(value);
> 		byte[] pIntByteArray = PInteger.INSTANCE.toBytes(intValue);
> 		return pIntByteArray;
> 	} 
> 
> 
> 
> --
> View this message in context: http://apache-phoenix-user-list.1124778.n5.nabble.com/ERROR-201-22000-illegal-data-error-expected-length-at-least-4-but-had-tp2170p2202.html
> Sent from the Apache Phoenix User List mailing list archive at Nabble.com.


Re: ERROR 201 (22000) illegal data error, expected length at least 4 but had ...

Posted by vikashtalanki <vi...@gmail.com>.
Hi Dong,

If you still want to insert through hbase, you can use the below snippets
for encoding values as per phoenix. ---> import
org.apache.phoenix.schema.types.*;

public static byte[] encodeDecimal(String value)
	{
		BigDecimal bigDecValue = new BigDecimal(value);
		byte[] pDecimalByteArray = PDecimal.INSTANCE.toBytes(bigDecValue);
		return pDecimalByteArray;
	}
	
	public static byte[] encodeDate(java.util.Date utilDate)
	{
		java.sql.Date sqlDate = new Date(utilDate.getTime());
		byte[] pDateByteArray = PDate.INSTANCE.toBytes(sqlDate);
		return pDateByteArray;
	}
	
	public static byte[] encodeTimestamp(String utilTS)
	{
		java.sql.Timestamp sqlDate = Timestamp.valueOf(utilTS);
		byte[] pTSByteArray = PTimestamp.INSTANCE.toBytes(sqlDate);
		return pTSByteArray;
	}
	
	public static byte[] encodeLong(String value)
	{
		byte[] pLongByteArray = PLong.INSTANCE.toBytes(value);
		return pLongByteArray;
	}
	
	public static byte[] encodeChar(String value)
	{
		byte[] pCharByteArray = PChar.INSTANCE.toBytes(value);
		return pCharByteArray;
	}
	
	public static byte[] encodeVarchar(String value)
	{
		byte[] pVarcharByteArray = PVarchar.INSTANCE.toBytes(value);
		return pVarcharByteArray;
	}
	
	public static byte[] encodeShort(String value)
	{
		Short shortValue = Short.parseShort(value);
		byte[] pShortByteArray = PSmallint.INSTANCE.toBytes(shortValue);
		return pShortByteArray;
	}
	
	public static byte[] encodeInteger(String value)
	{
		int intValue = Integer.parseInt(value);
		byte[] pIntByteArray = PInteger.INSTANCE.toBytes(intValue);
		return pIntByteArray;
	} 



--
View this message in context: http://apache-phoenix-user-list.1124778.n5.nabble.com/ERROR-201-22000-illegal-data-error-expected-length-at-least-4-but-had-tp2170p2202.html
Sent from the Apache Phoenix User List mailing list archive at Nabble.com.

Re: ERROR 201 (22000) illegal data error, expected length at least 4 but had ...

Posted by "Dong-iL, Kim" <ki...@gmail.com>.
Thank you so much.

> On Aug 9, 2016, at 6:27 PM, Ankit Singhal <an...@gmail.com> wrote:
> 
> Hi Dong-iL Kim,
> 
> As you said , you are inserting data from hbase, so the exception can be seen if the primary key and columns are not properly represented or encoded as per Phoenix.
> 
> Please see for more details:-
> https://phoenix.apache.org/faq.html#How_I_map_Phoenix_table_to_an_existing_HBase_table <https://phoenix.apache.org/faq.html#How_I_map_Phoenix_table_to_an_existing_HBase_table>
> 
> If you have a composite key , it is always better to insert data from phoenix only.
> 
> Regards,
> Ankit Singhal
> 
> On Fri, Aug 5, 2016 at 8:00 PM, Dong-iL, Kim <kim.same@gmail.com <ma...@gmail.com>> wrote:
> oh.  phoenix version is 4.7.0 and on EMR.
> Thx.
> 
> > On Aug 5, 2016, at 11:27 PM, Dong-iL, Kim <kim.same@gmail.com <ma...@gmail.com>> wrote:
> >
> > Hi
> > I’ve create a table in phoenix.
> >
> > CREATE TABLE WINLOSS (
> >    dayNumber VARCHAR NOT NULL,
> >    type VARCHAR NOT NULL,
> >    historyId VARCHAR NOT NULL,
> >    seq INTEGER NOT NULL,
> >    timestamp BIGINT,
> >    name VARCHAR,
> >    gameType VARCHAR,
> >    playType VARCHAR,
> >    gameKind VARCHAR,
> >    onRitt BOOLEAN,
> >    contributedAmount BIGINT,
> >    payAmount BIGINT
> >    CONSTRAINT rowid PRIMARY KEY(dayNumber, type, historyId, seq)
> > ) default_column_family = 'winloss';
> >
> > insert data through hbase.
> >
> > and I got an error when querying table.
> > just like this.
> >
> > select * from WINLESS;
> >
> > Error: ERROR 201 (22000): Illegal data. Expected length of at least 4 bytes, but had 1 (state=22000,code=201)
> > java.sql.SQLException: ERROR 201 (22000): Illegal data. Expected length of at least 4 bytes, but had 1
> >       at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:422)
> >       at org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:145)
> >       at org.apache.phoenix.schema.types.PDataType.checkForSufficientLength(PDataType.java:274)
> >       at org.apache.phoenix.schema.types.PInteger$IntCodec.decodeInt(PInteger.java:183)
> >       at org.apache.phoenix.schema.types.PInteger.toObject(PInteger.java:81)
> >       at org.apache.phoenix.schema.types.PInteger.toObject(PInteger.java:28)
> >       at org.apache.phoenix.schema.types.PDataType.toObject(PDataType.java:985)
> >       at org.apache.phoenix.compile.ExpressionProjector.getValue(ExpressionProjector.java:75)
> >       at org.apache.phoenix.jdbc.PhoenixResultSet.getObject(PhoenixResultSet.java:524)
> >       at sqlline.Rows$Row.<init>(Rows.java:157)
> >       at sqlline.BufferedRows.<init>(BufferedRows.java:38)
> >       at sqlline.SqlLine.print(SqlLine.java:1650)
> >       at sqlline.Commands.execute(Commands.java:833)
> >       at sqlline.Commands.sql(Commands.java:732)
> >       at sqlline.SqlLine.dispatch(SqlLine.java:808)
> >       at sqlline.SqlLine.begin(SqlLine.java:681)
> >       at sqlline.SqlLine.start(SqlLine.java:398)
> >       at sqlline.SqlLine.main(SqlLine.java:292)
> >
> > what shall I do?
> >
> > Thanks.
> 
> 


Re: ERROR 201 (22000) illegal data error, expected length at least 4 but had ...

Posted by Ankit Singhal <an...@gmail.com>.
Hi Dong-iL Kim,

As you said , you are inserting data from hbase, so the exception can be
seen if the primary key and columns are not properly represented or encoded
as per Phoenix.

Please see for more details:-
https://phoenix.apache.org/faq.html#How_I_map_Phoenix_table_to_an_existing_HBase_table

If you have a composite key , it is always better to insert data from
phoenix only.

Regards,
Ankit Singhal

On Fri, Aug 5, 2016 at 8:00 PM, Dong-iL, Kim <ki...@gmail.com> wrote:

> oh.  phoenix version is 4.7.0 and on EMR.
> Thx.
>
> > On Aug 5, 2016, at 11:27 PM, Dong-iL, Kim <ki...@gmail.com> wrote:
> >
> > Hi
> > I’ve create a table in phoenix.
> >
> > CREATE TABLE WINLOSS (
> >    dayNumber VARCHAR NOT NULL,
> >    type VARCHAR NOT NULL,
> >    historyId VARCHAR NOT NULL,
> >    seq INTEGER NOT NULL,
> >    timestamp BIGINT,
> >    name VARCHAR,
> >    gameType VARCHAR,
> >    playType VARCHAR,
> >    gameKind VARCHAR,
> >    onRitt BOOLEAN,
> >    contributedAmount BIGINT,
> >    payAmount BIGINT
> >    CONSTRAINT rowid PRIMARY KEY(dayNumber, type, historyId, seq)
> > ) default_column_family = 'winloss';
> >
> > insert data through hbase.
> >
> > and I got an error when querying table.
> > just like this.
> >
> > select * from WINLESS;
> >
> > Error: ERROR 201 (22000): Illegal data. Expected length of at least 4
> bytes, but had 1 (state=22000,code=201)
> > java.sql.SQLException: ERROR 201 (22000): Illegal data. Expected length
> of at least 4 bytes, but had 1
> >       at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.
> newException(SQLExceptionCode.java:422)
> >       at org.apache.phoenix.exception.SQLExceptionInfo.buildException(
> SQLExceptionInfo.java:145)
> >       at org.apache.phoenix.schema.types.PDataType.
> checkForSufficientLength(PDataType.java:274)
> >       at org.apache.phoenix.schema.types.PInteger$IntCodec.
> decodeInt(PInteger.java:183)
> >       at org.apache.phoenix.schema.types.PInteger.toObject(
> PInteger.java:81)
> >       at org.apache.phoenix.schema.types.PInteger.toObject(
> PInteger.java:28)
> >       at org.apache.phoenix.schema.types.PDataType.toObject(
> PDataType.java:985)
> >       at org.apache.phoenix.compile.ExpressionProjector.getValue(
> ExpressionProjector.java:75)
> >       at org.apache.phoenix.jdbc.PhoenixResultSet.getObject(
> PhoenixResultSet.java:524)
> >       at sqlline.Rows$Row.<init>(Rows.java:157)
> >       at sqlline.BufferedRows.<init>(BufferedRows.java:38)
> >       at sqlline.SqlLine.print(SqlLine.java:1650)
> >       at sqlline.Commands.execute(Commands.java:833)
> >       at sqlline.Commands.sql(Commands.java:732)
> >       at sqlline.SqlLine.dispatch(SqlLine.java:808)
> >       at sqlline.SqlLine.begin(SqlLine.java:681)
> >       at sqlline.SqlLine.start(SqlLine.java:398)
> >       at sqlline.SqlLine.main(SqlLine.java:292)
> >
> > what shall I do?
> >
> > Thanks.
>
>

Re: ERROR 201 (22000) illegal data error, expected length at least 4 but had ...

Posted by "Dong-iL, Kim" <ki...@gmail.com>.
oh.  phoenix version is 4.7.0 and on EMR.
Thx.

> On Aug 5, 2016, at 11:27 PM, Dong-iL, Kim <ki...@gmail.com> wrote:
> 
> Hi
> I’ve create a table in phoenix. 
> 
> CREATE TABLE WINLOSS (
>    dayNumber VARCHAR NOT NULL,
>    type VARCHAR NOT NULL,
>    historyId VARCHAR NOT NULL,
>    seq INTEGER NOT NULL,
>    timestamp BIGINT,
>    name VARCHAR,
>    gameType VARCHAR,
>    playType VARCHAR,
>    gameKind VARCHAR,
>    onRitt BOOLEAN,
>    contributedAmount BIGINT,
>    payAmount BIGINT
>    CONSTRAINT rowid PRIMARY KEY(dayNumber, type, historyId, seq)
> ) default_column_family = 'winloss';
> 
> insert data through hbase.
> 
> and I got an error when querying table.
> just like this.
> 
> select * from WINLESS;
> 
> Error: ERROR 201 (22000): Illegal data. Expected length of at least 4 bytes, but had 1 (state=22000,code=201)
> java.sql.SQLException: ERROR 201 (22000): Illegal data. Expected length of at least 4 bytes, but had 1
> 	at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:422)
> 	at org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:145)
> 	at org.apache.phoenix.schema.types.PDataType.checkForSufficientLength(PDataType.java:274)
> 	at org.apache.phoenix.schema.types.PInteger$IntCodec.decodeInt(PInteger.java:183)
> 	at org.apache.phoenix.schema.types.PInteger.toObject(PInteger.java:81)
> 	at org.apache.phoenix.schema.types.PInteger.toObject(PInteger.java:28)
> 	at org.apache.phoenix.schema.types.PDataType.toObject(PDataType.java:985)
> 	at org.apache.phoenix.compile.ExpressionProjector.getValue(ExpressionProjector.java:75)
> 	at org.apache.phoenix.jdbc.PhoenixResultSet.getObject(PhoenixResultSet.java:524)
> 	at sqlline.Rows$Row.<init>(Rows.java:157)
> 	at sqlline.BufferedRows.<init>(BufferedRows.java:38)
> 	at sqlline.SqlLine.print(SqlLine.java:1650)
> 	at sqlline.Commands.execute(Commands.java:833)
> 	at sqlline.Commands.sql(Commands.java:732)
> 	at sqlline.SqlLine.dispatch(SqlLine.java:808)
> 	at sqlline.SqlLine.begin(SqlLine.java:681)
> 	at sqlline.SqlLine.start(SqlLine.java:398)
> 	at sqlline.SqlLine.main(SqlLine.java:292)
> 
> what shall I do?
> 
> Thanks.