Hi James,
I primarily was using getting the list of ColumnInfo from PhoenixRuntime
and then passing the list to QueryUtil to construct a select query. Since I
get the column name with the pattern "<column family>:<column name>" , the
SELECT query is failing. Below is how I am constructing the query.
/**
*
* @param tableName name of the table for which the select statement
needs to be created.
* @param columnInfos list of columns to be projected in the select
statement.
* @return Select Query
*/
public static String constructSelectStatement(String
tableName,List<ColumnInfo> columnInfos) {
if(columnInfos.isEmpty()) {
throw new IllegalArgumentException("At least one column must
be provided");
}
StringBuilder sb = new StringBuilder();
sb.append("SELECT ");
for (ColumnInfo cinfo : columnInfos) {
if (cinfo != null) {
sb.append(cinfo.getColumnName());
sb.append(",");
}
}
// Remove the trailing comma
sb.setLength(sb.length() - 1);
sb.append("\n");
sb.append(" FROM ");
sb.append(tableName);
return sb.toString();
}
I noticed even the UPSERT query failed due to the same issue.
Regards
Ravi
On Fri, Apr 4, 2014 at 11:42 AM, James Taylor <[email protected]>wrote:
> The default column name should not be necessary. Something is wrong with
> the column resolution logic being using. Can you see this[1] JIRA and use
> this same mechanism to do the column resolution?
>
> Thanks,
> James
>
> [1] https://issues.apache.org/jira/browse/PHOENIX-898
>
>
> On Thu, Apr 3, 2014 at 1:12 PM, Ravi Kiran <[email protected]
> >wrote:
>
> > Hi ,
> > Currently, while working on the Phoenix Pig support on
> > v3.0.0.incubating branch , I notice that we need to pass the default
> column
> > family with double quotes in the SELECT query.
> > A test case for it is
> >
> >
> > @Test
> > public void testSelectQueryWithDefaultCF() throws SQLException {
> > final Properties props = new Properties();
> > final Connection conn = DriverManager.getConnection(getUrl(),
> > props);
> > conn.createStatement().execute("CREATE TABLE HIRES (id integer
> not
> > null, name varchar, cf1.location varchar constraint pk primary
> key(id))");
> >
> > final String query = "select id,0.name from HIRES";
> > final Statement statement = conn.createStatement();
> > statement.executeQuery(query);
> >
> > }
> >
> > The above test fails with the following error.
> > org.apache.phoenix.exception.PhoenixParserException: ERROR 601
> (42P00):
> > Syntax error. Encountered "." at line 1, column 12.
> > at
> >
> >
> org.apache.phoenix.exception.PhoenixParserException.newException(PhoenixParserException.java:33)
> > at
> > org.apache.phoenix.parse.SQLParser.parseStatement(SQLParser.java:111)
> > at
> >
> >
> org.apache.phoenix.jdbc.PhoenixStatement$PhoenixStatementParser.parseStatement(PhoenixStatement.java:775)
> > at
> >
> >
> org.apache.phoenix.jdbc.PhoenixStatement.parseStatement(PhoenixStatement.java:856)
> > at
> >
> >
> org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:891)
> >
> > However , the following queries work.
> > String query = "select id,\"0\".name from HIRES";
> > String query = "select id,name from HIRES";
> >
> > Is the exception an expected behaviour with default column family or a
> bug?
> >
> > Any help appreciated.
> >
> > Regards
> > Ravi
> >
>