fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. return 0;
  7. }
Success #stdin #stdout 0s 5316KB
stdin
-- (1) Create a Database
CREATE DATABASE sales_db;
USE sales_db;

-- (2) Create a Table
CREATE TABLE sales (
    id INT,
    product STRING,
    price FLOAT,
    quantity INT
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS TEXTFILE;

-- (3) Load Data from Local File (Example)
LOAD DATA LOCAL INPATH '/home/hadoop/salesdata.txt' INTO TABLE sales;

-- (4) Insert Data Manually
INSERT INTO TABLE sales VALUES 
(1, 'Laptop', 55000.0, 2),
(2, 'Mouse', 500.0, 5),
(3, 'Keyboard', 800.0, 3);

-- (5) View Data
SELECT * FROM sales;

-- (6) Filter Records
SELECT * FROM sales WHERE price > 1000;

-- (7) Update Data (Hive supports update from v0.14+ with ORC format)
-- First, convert table to transactional
ALTER TABLE sales SET TBLPROPERTIES ('transactional'='true');
SET hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
SET hive.support.concurrency=true;

UPDATE sales SET price = 60000.0 WHERE id = 1;

-- (8) Delete a Record
DELETE FROM sales WHERE id = 2;

-- (9) Truncate Table (Remove all rows)
TRUNCATE TABLE sales;

-- (10) Drop Table
DROP TABLE sales;
stdout
Standard output is empty