-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements.  See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to You under the Apache License, Version 2.0
-- (the "License") you may not use this file except in compliance with
-- the License.  You may obtain a copy of the License at
--
--     http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
set hive.input.format=org.apache.hadoop.hive.ql.io.BucketizedHiveInputFormat;
set mapred.min.split.size = 64;

CREATE TABLE T1(name STRING) STORED AS TEXTFILE;

LOAD DATA LOCAL INPATH 'seed_data_files/kv1.txt' INTO TABLE T1;

CREATE TABLE T2(name STRING) STORED AS SEQUENCEFILE;

EXPLAIN INSERT OVERWRITE TABLE T2 SELECT * FROM (
SELECT tmp1.name as name FROM (
  SELECT name, 'MMM' AS n FROM T1) tmp1 
  JOIN (SELECT 'MMM' AS n FROM T1) tmp2
  JOIN (SELECT 'MMM' AS n FROM T1) tmp3
  ON tmp1.n = tmp2.n AND tmp1.n = tmp3.n) ttt LIMIT 5000000;


INSERT OVERWRITE TABLE T2 SELECT * FROM (
SELECT tmp1.name as name FROM (
  SELECT name, 'MMM' AS n FROM T1) tmp1 
  JOIN (SELECT 'MMM' AS n FROM T1) tmp2
  JOIN (SELECT 'MMM' AS n FROM T1) tmp3
  ON tmp1.n = tmp2.n AND tmp1.n = tmp3.n) ttt LIMIT 5000000;

EXPLAIN SELECT COUNT(1) FROM T2;
SELECT COUNT(1) FROM T2;

CREATE TABLE T3(name STRING) STORED AS TEXTFILE;
LOAD DATA LOCAL INPATH 'seed_data_files/kv1.txt' INTO TABLE T3;
LOAD DATA LOCAL INPATH 'seed_data_files/kv2.txt' INTO TABLE T3;

EXPLAIN SELECT COUNT(1) FROM T3;
SELECT COUNT(1) FROM T3;
