[ 
https://issues.apache.org/jira/browse/PHOENIX-939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13981872#comment-13981872
 ] 

James Taylor commented on PHOENIX-939:
--------------------------------------

Everything listed in the SELECT clause is considered an expression, but the 
only kind we're handling is when the expression is a reference to a column. For 
example:
{code}
A = load 'hbase://query/SELECT ID,NAME FROM HIRES WHERE AGE > 50' using 
org.apache.phoenix.pig.PhoenixHBaseLoader('localhost');
{code}
In this case, ID and NAME are expressions in the SELECT clause and this works 
fine.  However, the following will not currently work:
{code}
A = load 'hbase://query/SELECT ID,UPPER(NAME),NEXT VALUE FOR my_seq,MY_NUM+1 
FROM HIRES WHERE AGE > 50' using 
org.apache.phoenix.pig.PhoenixHBaseLoader('localhost');
{code}
Phoenix treats these the same, so you could generate a "schema" for the above 
as:
{code}
<NAME>                                   <DATA TYPE>
ID                                              VARCHAR
"UPPER(NAME)"                       VARCHAR
"NEXT VALUE FOR my_seq"    BIGINT
"MY_NUM+1"                            INTEGER
{code}
If Pig cares about the characters used as the <NAME> for a schema, then aliases 
could be generated for the SELECT expressions or required to be present. For 
example:
{code}
A = load 'hbase://query/SELECT ID a,UPPER(NAME) b,NEXT VALUE FOR my_seq 
c,MY_NUM+1 d FROM HIRES WHERE AGE > 50' using 
org.apache.phoenix.pig.PhoenixHBaseLoader('localhost');
{code}
in which case the "schema" would look like this:
{code}
<NAME>   <DATA TYPE>
a               VARCHAR
b               VARCHAR
c               BIGINT
d               INTEGER
{code}
So this JIRA is about allowing any expression in the SELECT clause. Not sure 
what restrictions Pig would put on this, but I suspect it wouldn't know/care as 
long as a String <NAME> is used and we do the same data type mapping that we do 
now.






> Generalize SELECT expressions for Pig Loader
> --------------------------------------------
>
>                 Key: PHOENIX-939
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-939
>             Project: Phoenix
>          Issue Type: Improvement
>    Affects Versions: 5.0.0, 3.1, 4.1
>            Reporter: James Taylor
>            Assignee: maghamravikiran
>             Fix For: 5.0.0, 3.1, 4.1
>
>
> The current Pig Loader requires that the query contain only column references 
> in the SELECT expressions. Instead, we should allow any expression as that 
> will provide more general utility. For example, built-in functions, sequence 
> references, etc. could be used then.
> Validation can be done by simply compiling the query. This does all the 
> validation required. It's ok if it's compiled twice if need be too.
> Pig doesn't know and likely wouldn't care if the expressions in the SELECT 
> correspond to columns in Phoenix or general expressions. You can use the 
> ColumnProjection.getName() method to get back an alias of the SELECT 
> expression. If no alias is provided, then the String of the expression is 
> returned. [~prkommireddi] - can you weigh in here? You can use the Phoenix 
> RowProjector to iterate through each ColumnProjector you get back after the 
> compile to get the alias of the select expression (i.e. you'd give this to 
> Pig as the "column" name) plus the data type. Note that if this is 
> problemattic, then you could likely generate an alias name if one is not 
> present.
> For example:
> {code}
>     RowProjector rowProj = queryPlan.getProjector();
>     for (ColumnProjector colProj : rowProj.getColumnProjectors()) {
>         String columnName = colProj.getName();
>         PDataType dataType = colProj.getExpression().getDataType();
>     }
> {code}
> If the SELECT expressions are simple column references, this would be exactly 
> the same as is being done now. If the SELECT expressions are more complex 
> expressions, this would work as well.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to