1
votes

Hi I am trying to create a hive table with some constraints using jdbc,which is giving me an error String sql1="CREATE TABLE sample_hive_table_2 (key1 int PRIMARY KEY ,value1 string)"; System.out.println(sql1); res = stmt.executeQuery(sql1); Exception in thread "main" java.sql.SQLException: Query returned non-zero code: 40000, cause: FAILED: ParseException line 1:43 mismatched input 'PRIMARY' expecting ) near 'int' in create table statement

at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:194)

I need to do two things 1) create a table with constraints 2)find the constraints on columns of a table using jdbc program. Thanks Hitz

3

3 Answers

1
votes

Hive table does not have constraints!

Hive is a data warehousing infrastructure based on Hadoop. Hadoop provides massive scale out and fault tolerance capabilities for data storage and processing (using the map-reduce programming paradigm) on commodity hardware.

Hive is designed to enable easy data summarization, ad-hoc querying and analysis of large volumes of data. It provides a simple query language called Hive QL, which is based on SQL and which enables users familiar with SQL to do ad-hoc querying, summarization and data analysis easily. At the same time, Hive QL also allows traditional map/reduce programmers to be able to plug in their custom mappers and reducers to do more sophisticated analysis that may not be supported by the built-in capabilities of the language.

refer https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-CreatingHiveTables for hive table DDL

1
votes

Hive, does not have the concept of primary keys.

0
votes

Hive actually has the concept of the primary key as you can see below, and you can see that, unfortunately, is not validate.

: [, PRIMARY KEY (col_name, ...) DISABLE NOVALIDATE ]
  [, CONSTRAINT constraint_name FOREIGN KEY (col_name, ...) REFERENCES
  table_name(col_name, ...) DISABLE NOVALIDATE 

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL