You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Mohammad Tariq <do...@gmail.com> on 2013/06/05 08:00:10 UTC

Correct way to use Hive Java API

Hello list,

     I am trying to access data stored in my Hive table through the Java
API but looks like I am not using it in the correct manner. Would really
appreciate some help. Here is the small piece of code I am trying to use :

public static void main(String[] args) throws HiveMetaException {
// TODO Auto-generated method stub

Table table = new Table("default", "pokes");
 System.out.println("DBNAME : " + table.getDbName());
List<FieldSchema> cols = new ArrayList<FieldSchema>();
 cols = table.getCols();
System.out.println("SIZE : " + cols.size());
 for(FieldSchema fs : cols) {
System.out.println(fs.getFieldValue(_Fields.findByName("foo VALUE : " +
"foo")));
 }
}

The problem here is that *table.getCols() *is not returning anything. I
tried to print the size of the list, but it's zero. Looks like i'm missing
out something obvious or the approach itself is wrong. Need some help.
Pardon my ignorance.

Thank you so much for your valuable time.

Warm Regards,
Tariq
cloudfront.blogspot.com

Re: Correct way to use Hive Java API

Posted by Mohammad Tariq <do...@gmail.com>.
Hello Prasad,

    Thank you for the reply. I was actually trying to achieve this without
JDBC. Is it possible by any means?

Thanks again.

On Friday, June 7, 2013, Prasad Mujumdar <pr...@cloudera.com> wrote:
>
>    I think the new Table("default", "pokes")will create a dummy table
object with only the db name and table name set. It will not retrieve the
table information from metastore.
> If you are looking for the schema information and retrieve the data, you
might want to consider using the JDBC interface. The JDBC driver can be
used with a remote hiveserver as well embedded hive.
> thanks
> Prasad
>
>
>
> On Fri, Jun 7, 2013 at 7:59 AM, Haidar Hadi <ha...@yahoo.com>
wrote:
>>
>> Hello all,
>> I have similar issue, any idea?
>>
>> On Jun 4, 2013, at 11:00 PM, Mohammad Tariq <do...@gmail.com> wrote:
>>
>> Hello list,
>>      I am trying to access data stored in my Hive table through the Java
API but looks like I am not using it in the correct manner. Would really
appreciate some help. Here is the small piece of code I am trying to use :
>> public static void main(String[] args) throws HiveMetaException {
>> // TODO Auto-generated method stub
>> Table table = new Table("default", "pokes");
>> System.out.println("DBNAME : " + table.getDbName());
>> List<FieldSchema> cols = new ArrayList<FieldSchema>();
>> cols = table.getCols();
>> System.out.println("SIZE : " + cols.size());
>> for(FieldSchema fs : cols) {
>> System.out.println(fs.getFieldValue(_Fields.findByName("foo VALUE : " +
"foo")));
>> }
>> }
>> The problem here is that table.getCols() is not returning anything. I
tried to print the size of the list, but it's zero. Looks like i'm missing
out something obvious or the approach itself is wrong. Need some help.
Pardon my ignorance.
>> Thank you so much for your valuable time.
>> Warm Regards,
>> Tariq
>> cloudfront.blogspot.com
>
>

-- 
Warm Regards,
Tariq
cloudfront.blogspot.com

Re: Correct way to use Hive Java API

Posted by Prasad Mujumdar <pr...@cloudera.com>.
   I think the new Table("default", "pokes")will create a dummy table
object with only the db name and table name set. It will not retrieve the
table information from metastore.

If you are looking for the schema information and retrieve the data, you
might want to consider using the JDBC interface. The JDBC driver can be
used with a remote hiveserver as well embedded hive.

thanks
Prasad




On Fri, Jun 7, 2013 at 7:59 AM, Haidar Hadi <ha...@yahoo.com>wrote:

> Hello all,
> I have similar issue, any idea?
>
>
> On Jun 4, 2013, at 11:00 PM, Mohammad Tariq <do...@gmail.com> wrote:
>
> Hello list,
>
>      I am trying to access data stored in my Hive table through the Java
> API but looks like I am not using it in the correct manner. Would really
> appreciate some help. Here is the small piece of code I am trying to use :
>
> public static void main(String[] args) throws HiveMetaException {
> // TODO Auto-generated method stub
>
> Table table = new Table("default", "pokes");
>  System.out.println("DBNAME : " + table.getDbName());
> List<FieldSchema> cols = new ArrayList<FieldSchema>();
>  cols = table.getCols();
> System.out.println("SIZE : " + cols.size());
>  for(FieldSchema fs : cols) {
> System.out.println(fs.getFieldValue(_Fields.findByName("foo VALUE : " +
> "foo")));
>  }
> }
>
> The problem here is that *table.getCols() *is not returning anything. I
> tried to print the size of the list, but it's zero. Looks like i'm missing
> out something obvious or the approach itself is wrong. Need some help.
> Pardon my ignorance.
>
> Thank you so much for your valuable time.
>
> Warm Regards,
> Tariq
> cloudfront.blogspot.com
>
>

Re: Correct way to use Hive Java API

Posted by Haidar Hadi <ha...@yahoo.com>.
Hello all,
I have similar issue, any idea?

On Jun 4, 2013, at 11:00 PM, Mohammad Tariq <do...@gmail.com> wrote:

> Hello list,
> 
>      I am trying to access data stored in my Hive table through the Java API but looks like I am not using it in the correct manner. Would really appreciate some help. Here is the small piece of code I am trying to use :
> 
> public static void main(String[] args) throws HiveMetaException {
> 		// TODO Auto-generated method stub
> 
> 		Table table = new Table("default", "pokes");
> 		System.out.println("DBNAME : " + table.getDbName());
> 		List<FieldSchema> cols = new ArrayList<FieldSchema>();
> 		cols = table.getCols();
> 		System.out.println("SIZE : " + cols.size());		
> 		for(FieldSchema fs : cols) {
> 			System.out.println(fs.getFieldValue(_Fields.findByName("foo VALUE : " + "foo")));
> 		}
> }
> 
> The problem here is that table.getCols() is not returning anything. I tried to print the size of the list, but it's zero. Looks like i'm missing out something obvious or the approach itself is wrong. Need some help. Pardon my ignorance.
> 
> Thank you so much for your valuable time.
> 
> Warm Regards,
> Tariq
> cloudfront.blogspot.com