Reply
Contributor
Posts: 33
Registered: ‎07-27-2015

Using PreparedStatement with Phoenix

[ Edited ]

I want to use PreparedStatement when setting a query to Phoenix record reader/ calculating input splits. I am not able to find other means than this -

 

PhoenixConfigurationUtil.setInputQuery(conf, query);

 

which takes in a raw String sql query. How do I change this to PreparedStatement rather than a hard coded Statement?

 

Thanks,
Sumit

Contributor
Posts: 33
Registered: ‎07-27-2015

Re: Using PreparedStatement with Phoenix

I researched a bit more. However, I am unable to find any means to use Prep Statements with phoenix input format.

Anyone has contrary comments?

uzi
Explorer
Posts: 13
Registered: ‎05-27-2016

Re: Using PreparedStatement with Phoenix

You can use prepared statement. For example something like this works pretty well. 

 

Connection con = DriverManager.getConnection("jdbc:phoenix:localhost");
PreparedStatement statement = con.prepareStatement("select * from TABLE");
rset = statement.executeQuery();
while (rset.next()) {
System.out.println(rset.getString("COLUMN_A"));
}
statement.close();
con.close();

 

However, this is limited. I want to run '!columns TABLE' from java, but it gives unexpected character '!'. Please let me know anyone has figured out a way to do this.

Contributor
Posts: 33
Registered: ‎07-27-2015

Re: Using PreparedStatement with Phoenix

If you are only looking to get the list of columns, you can use a degenerate query like -

SELECT * FROM TBL WHERE 1 = 0

 

And then use java.sql.ResultSetMetaData to iterate over the columns.

Announcements

Currently incubating in Cloudera Labs:

Envelope
HTrace
Ibis
Impyla
Livy
Oryx
Phoenix
Spark Runner for Beam SDK
Time Series for Spark
YCSB