I am trying to create a Hive table with partitions but getting the above error. What am I doing wrong?
CREATE TABLE IF NOT EXISTS schema.table_name
(
ID varchar(20),
name varchar(50)
)
PARTITIONED BY (part_dt varchar(8), system varchar(5));
The code works without the partitioning clause. Something gives up during partitioning.
Statement is working in hive. Pls find below screenshot.
Its possible that some of column names are reserved keywords and that is throwing error. if yes, you can use below SQL too.
CREATE TABLE IF NOT EXISTS schema.table_name
(
`ID` varchar(20),
`name` varchar(50)
)
PARTITIONED BY (`part_dt` varchar(8), `system` varchar(5));
Related
hey guys i am new to databricks and i have been trying to create tables using spark sql but i was unable to do so due to the error : Error in SQL statement: ParseException:
no viable alternative at input 'Create table offices(\n\tAreaCode VARCHAR(10) NOT NULL PRIMARY'(line 2, pos 31)
As i do not know what is wrong with the code as i am able to create the exact table using the below code. Do let me know if there is any suggestion or alternatives!.
Create table offices(
AreaCode VARCHAR(10) NOT NULL PRIMARY KEY,
city VARCHAR(50) NOT NULL
)
Take the primary key out
Create table offices(
AreaCode VARCHAR(10) NOT NULL,
city VARCHAR(50) NOT NULL
)
Advice on creating/inserting data into Hive's bucketed tables.
Did some reading (https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL+BucketedTables) and tested few options but with no success.
Currently I get following error while running insert:
Error while processing statement: FAILED: Execution Error, return code 3 from org.apache.hadoop.hive.ql.exec.spark.SparkTask
Create code:
CREATE test_in (
id VARCHAR(250),
field_1 VARCHAR(250),
field_2 VARCHAR(250),
field_3 VARCHAR(250),
field_4 VARCHAR(250),
field_5 VARCHAR(250)
)
PARTITIONED BY(ds STRING)
CLUSTERED BY(id) into 10 buckets
STORED AS orc
tblproperties("orc.compress"="NONE","transactional"="true");
Insert code:
INSERT INTO TABLE test_in
VALUES (
'9gD0xQxOYS',
'ZhQbTjUGLhz8KuQ',
'SmszyJHEqIVAeK8gAFVx',
'RvbRdU7ia1AMHhaXd9tOgLEzi',
'a010E000004uJt8QAE',
'yh6phK4ZG7W4JaOdoOhDJXNJgmcoZU'
)
Need help in creating proper syntax for create/insert statement and some explanation on bucketting in Hive.
CREATE STATEMENT - The word table is missing. (May be a typo)
INSERT STATEMENT - Partition details are missing. Partition value is required during INSERT operation since it is a partitioned table.
The correct and working queries are below,
CREATE STATEMENT:
CREATE TABLE test_in (
id VARCHAR(250),
field_1 VARCHAR(250),
field_2 VARCHAR(250),
field_3 VARCHAR(250),
field_4 VARCHAR(250),
field_5 VARCHAR(250)
)
PARTITIONED BY(ds STRING)
CLUSTERED BY(id) into 10 buckets
STORED AS orc
INSERT STATEMENT:
INSERT INTO test_in
PARTITION (ds='123')
VALUES (
'9gD0xQxOYS',
'ZhQbTjUGLhz8KuQ',
'SmszyJHEqIVAeK8gAFVx',
'RvbRdU7ia1AMHhaXd9tOgLEzi',
'a010E000004uJt8QAE',
'yh6phK4ZG7W4JaOdoOhDJXNJgmcoZU'
)
Hope this helps!
I am trying to create table by sqlyog
i want to use spaces in columns names but i still got errors
for example id number
i just can do it like this id_number
i searched in this website i found two ways
[id number] or "id number"
i tried it but i still have errors
this is the code
CREATE TABLE project(
ProjectID VARCHAR(10),
Project NAME VARCHAR(50),
Group_Name VARCHAR(20),
BeginDate VARCHAR(10),
EndDate VARCHAR(10)
);
and these are the errors that i got them
1 queries executed, 0 success, 1 errors, 0 warnings
Query: CREATE table project( ProjectID varchar(10), Project Name varchar(50), Group_Name varchar(20), BeginDate varchar(10), EndDate va...
Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Name varchar(50),
Group_Name varchar(20),
BeginDate varchar(10),
EndDate varc' at line 3
i hope some one helping me
The SQL Standard defines double quote character " to delimit identifiers.
Speaking of MariaDB and MySQL this requires that the sql_mode was set to ANSI:
mysql> set sql_mode=ANSI;
Query OK, 0 rows affected (0.00 sec)
mysql> create table project("project name" varchar(50));
Query OK, 0 rows affected (0.02 sec)
Another option (as mentioned in the previous answer) is to use backticks. However this solution will not be portable.
You can create tables and columns with spaces in the name using backticks (`)
Egg:
CREATE TABLE `project project`
(
`ProjectID` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`Project NAME` VARCHAR(255) NOT NULL
.
.
.
);
try like below
CREATE TABLE project(
ProjectID VARCHAR(10),
`Project NAME` VARCHAR(50),
Group_Name VARCHAR(20),
BeginDate VARCHAR(10),
EndDate VARCHAR(10)
);
i want to create a table in hive with NOT NULL property but i am not able to create it . it will says "ParseException line 1:44 mismatched input 'NOT' expecting ) near ')' in create table statement".
i have tried with primary key option but it will give same error
create table AGENTS(agent_code varchar(10) NOT NULL ,
agent_name varchar(40),
working_area varchar(30),
commission double(10,5),
phone_no int(15),
country varchar(25));
I don't think Hive supports double with scale and precision arguments. And, I don't think there is a length for int Perhaps you intend numeric:
create table AGENTS (
agent_code varchar(10) NOT NULL ,
agent_name varchar(40),
working_area varchar(30),
commission decimal(10, 5),
phone_no decimal(15),
country varchar(25)
);
NOT NULL constraints are only enforced relatively recently, so that might also be a problem.
Check your Hive version. Older versions of Hive do not support NOT NULL constraint like most databases. NOT NULL constraint was introduced from 3.0.0 version onwards.
Reference: https://issues.apache.org/jira/browse/HIVE-16575
I have this query
CREATE TABLE COSTUMER(
COSTUMER_ID INT,
TAXI_ID INT,
COSTUMER_PHONE_NUMBER BIGINT,
COSTUMER_NAME VARCHAR(40),
DESTINATION VARCHAR(40)
);
i'd like to change the DESTINATION data type to DATETIME rather than VARCHAR. or if you can suggest a better data type that can store a full address the please do.
I tried this query
ALTER TABLE COSTUMER ALTER DESTINATION DATETIME
but when executed I get this message :
102 stating expecting column
If it is a mySql database then the syntax should be as follows:
ALTER TABLE table_name
MODIFY COLUMN column_name datatype
ALTER TABLE COSTUMER MODIFY COLUMN DESTINATION DATETIME;