Hi
I’m trying to access a Phoenix table from Datameer. Datameer can read HBase,
but doesn’t support using the Phoenix JDBC driver, as the Phoenix JDBC driver
only does a partial implementation of the JDBC standard.
To get around this I’m using the Datameer SDK to write a function that will
encode columns of type double. Unfortunately the decoding isn’t going well. Let
me give you a little test case. All of the following is done with Phoenix 4.4
on HDP 2.3.4
Here’s the table DDL:-
create table MCALLISTERM.TEST
( FIRSTNAME VARCHAR NOT NULL
, LASTNAME VARCHAR NOT NULL
, CITY VARCHAR NULL
, RATE DOUBLE NULL
, CONSTRAINT TEST_PK PRIMARY KEY (FIRSTNAME, LASTNAME)
);
Here’s a row of test data:-
UPSERT INTO MCALLISTERM.TEST( FIRSTNAME, LASTNAME, CITY, RATE )
VALUES ('Richard', 'Jones', 'San Diego', 137.47 );
When you view this table in Datameer via the HBase driver, it shows up as
follows:-
[cid:[email protected]]
The rowkey is fairly easing separated by tokenizing via the null byte
character. The rate column shows up as it does due to the encoding Phoenix has
done.
Here is the guts of the conversion function I’m writing …
package com.datameer.sdk;
import datameer.dap.sdk.function.BaseSimpleFunctionType;
import datameer.dap.sdk.function.FieldType;
import datameer.dap.sdk.function.FunctionGroup;
import datameer.dap.sdk.function.argument.ArgumentType;
import datameer.dap.sdk.schema.ValueTypeId;
import org.apache.phoenix.schema.types.PDouble;
import org.apache.phoenix.schema.SortOrder;
public class ApachePhoenixDoubleDecode extends BaseSimpleFunctionType {
public ApachePhoenixDoubleDecode()
{
super( FunctionGroup.ENCODING
, "ApachePhoenixDoubleDecode"
, "Converts Apache Phoenix double encoded bytestream into float"
, new ArgumentType[]{ new ArgumentType("Input", ValueTypeId.STRING)
}
);
}
@Override
protected Object compute(Object... arg0) {
byte[] bytes = ((String)arg0[0]).getBytes();
int offset = 0;
return PDouble.INSTANCE.getCodec().decodeDouble(bytes, offset,
SortOrder.ASC );
}
@Override
public FieldType computeReturnType(FieldType... arg0) {
return FieldType.FLOAT;
}
}
As you probably suspect, I’m having to guess at the offset and the sortorder.
Here’s what shows up when I use this function in datameer on the single row in
the table, which should be returning 137.47:-
[cid:[email protected]]
Any pointers on where I’ve gone wrong, and how to correct my plugin?
Regards
Mike