Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate Hive HQL syntax?

Is there a programmatic way to validate HiveQL statements for errors like basic syntax mistakes? I'd like to check statements before sending them off to Elastic Map Reduce in order to save debugging time.

like image 976
Matt Hampel Avatar asked Nov 16 '11 17:11

Matt Hampel


People also ask

What is Hql in Hive?

HQL or Hive Query Language is a simple yet powerful SQL like querying language which provides the users with the ability to perform data analytics on big datasets.

What is Hive SQL or HQL?

What is HQL? Hive defines a simple SQL-like query language to querying and managing large datasets called Hive-QL ( HQL ). It's easy to use if you're familiar with SQL Language. Hive allows programmers who are familiar with the language to write the custom MapReduce framework to perform more sophisticated analysis.

How do I check if a SQL query is correct?

Check - The check is a way for you to check if you have written a legal SQL query. Arrow - This is the execute command button. This will send the query to the server and the server will write back the result to you. Square - This is the stop execution command.


1 Answers

Yes there is!

It's pretty easy actually.

Steps:

1. Get a hive thrift client in your language.

I'm in ruby so I use this wrapper - https://github.com/forward/rbhive (gem install rbhive)

If you're not in ruby, you can download the hive source and run thrift on the included thrift configuration files to generate client code in most languages.

2. Connect to hive on port 10001 and run a describe query

In ruby this looks like this:

RBHive.connect(host, port) do |connection|
    connection.fetch("describe select * from categories limit 10")
end

If the query is invalid the client will throw an exception with details of why the syntax is invalid. Describe will return you a query tree if the syntax IS valid (which you can ignore in this case)

Hope that helps.

like image 140
Matthew Rathbone Avatar answered Oct 22 '22 03:10

Matthew Rathbone