2021-07-28 23:20:18 -04:00
|
|
|
CREATE DATABASE IF NOT EXISTS db1;
|
|
|
|
CREATE DATABASE IF NOT EXISTS db2;
|
2021-06-30 22:57:13 -07:00
|
|
|
-- Setup a "pokes" example table.
|
2021-07-28 23:20:18 -04:00
|
|
|
CREATE TABLE IF NOT EXISTS db1.pokes (foo INT, bar STRING);
|
|
|
|
LOAD DATA LOCAL INPATH '/opt/hive/examples/files/kv1.txt' OVERWRITE INTO TABLE db1.pokes;
|
|
|
|
|
2023-05-02 18:37:51 +05:30
|
|
|
CREATE TABLE IF NOT EXISTS db2.pokes (foo INT, bar STRING, CONSTRAINT pk_1173723383_1683022998392_0 primary key(foo) DISABLE NOVALIDATE NORELY);
|
2021-07-28 23:20:18 -04:00
|
|
|
LOAD DATA LOCAL INPATH '/opt/hive/examples/files/kv1.txt' OVERWRITE INTO TABLE db2.pokes;
|
2021-06-30 22:57:13 -07:00
|
|
|
|
|
|
|
-- Setup a table with a special character.
|
2021-07-28 23:20:18 -04:00
|
|
|
CREATE TABLE IF NOT EXISTS db1.`_test_table_underscore` (foo INT, bar STRING);
|
2021-06-30 22:57:13 -07:00
|
|
|
|
|
|
|
-- Create tables with struct and array types.
|
|
|
|
-- From https://stackoverflow.com/questions/57491644/correct-usage-of-a-struct-in-hive.
|
2021-07-28 23:20:18 -04:00
|
|
|
CREATE TABLE IF NOT EXISTS db1.struct_test
|
2021-06-30 22:57:13 -07:00
|
|
|
(
|
|
|
|
property_id INT,
|
|
|
|
service STRUCT<
|
|
|
|
type: STRING
|
|
|
|
,provider: ARRAY<INT>
|
|
|
|
>
|
|
|
|
);
|
|
|
|
|
2021-07-28 23:20:18 -04:00
|
|
|
CREATE TABLE IF NOT EXISTS db1.array_struct_test
|
2021-06-30 22:57:13 -07:00
|
|
|
(
|
|
|
|
property_id INT,
|
|
|
|
service array<STRUCT<
|
|
|
|
type: STRING
|
|
|
|
,provider: ARRAY<INT>
|
|
|
|
>>
|
|
|
|
);
|
|
|
|
|
|
|
|
WITH
|
|
|
|
test_data as (
|
|
|
|
SELECT 989 property_id, array(NAMED_STRUCT('type','Cleaning','provider', ARRAY(587, 887)),
|
|
|
|
NAMED_STRUCT('type','Pricing','provider', ARRAY(932))
|
|
|
|
) AS service
|
|
|
|
)
|
2021-07-28 23:20:18 -04:00
|
|
|
INSERT INTO TABLE db1.array_struct_test
|
2021-06-30 22:57:13 -07:00
|
|
|
select * from test_data;
|
2021-10-19 11:23:51 +05:30
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS db1.nested_struct_test
|
|
|
|
(
|
|
|
|
property_id INT,
|
|
|
|
service STRUCT<
|
|
|
|
type: STRING
|
|
|
|
,provider: STRUCT<name:VARCHAR(50), id:TINYINT>
|
|
|
|
>
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE db1.union_test(
|
|
|
|
foo UNIONTYPE<int, double, array<string>, struct<a:int,b:string>, struct<c:int,d:double>>
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE db1.map_test(
|
|
|
|
KeyValue String,
|
|
|
|
RecordId map<int,string>
|
|
|
|
);
|