diff --git bin/ext/hiveburninclient.sh bin/ext/hiveburninclient.sh new file mode 100644 index 0000000..ccbe726 --- /dev/null +++ bin/ext/hiveburninclient.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# 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. + +THISSERVICE=hiveburninclient +export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} " + +hiveburninclient() { + echo "Starting hiveburninclient" + CLASS=org.apache.hive.testutils.jdbc.HiveBurnInClient + if $cygwin; then + HIVE_LIB=`cygpath -w "$HIVE_LIB"` + fi + JAR=${HIVE_LIB}/hive-service-*.jar + exec $HADOOP jar $JAR $CLASS $HIVE_OPTS "$@" +} + +hiveburninclient_help() { + hiveburninclient -H +} + diff --git testutils/src/java/org/apache/hive/testutils/jdbc/HiveBurnInClient.java testutils/src/java/org/apache/hive/testutils/jdbc/HiveBurnInClient.java new file mode 100644 index 0000000..e486343 --- /dev/null +++ testutils/src/java/org/apache/hive/testutils/jdbc/HiveBurnInClient.java @@ -0,0 +1,137 @@ +package org.apache.hive.testutils.jdbc; + + +import java.sql.SQLException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.DriverManager; + + +public class HiveBurnInClient { + private static String driverName = "org.apache.hive.jdbc.HiveDriver"; + + /** + * Creates 2 tables to query from + * + * @param num + */ + public static void createTables(Connection con) throws SQLException { + Statement stmt = con.createStatement(); + String tableName = "table1"; + stmt.execute("drop table if exists " + tableName); + stmt.execute("create table " + tableName + " (key int, value string)"); + + // load data into table + // NOTE: filepath has to be local to the hive server + String filepath = "./examples/files/kv1.txt"; + String sql = "load data local inpath '" + filepath + "' into table " + tableName; + System.out.println("Running: " + sql); + stmt.execute(sql); + + tableName = "table2"; + stmt.execute("drop table if exists " + tableName); + stmt.execute("create table " + tableName + " (key int, value string)"); + + filepath = "./examples/files/kv2.txt"; + sql = "load data local inpath '" + filepath + "' into table " + tableName; + System.out.println("Running: " + sql); + stmt.execute(sql); + } + + + + /** + * @param con + * @param numberOfQueryIterations + * @throws SQLException + */ + public static void runQueries(Connection con, int numberOfQueryIterations) throws SQLException { + Statement stmt = con.createStatement(); + + for (int i = 0; i < numberOfQueryIterations; i++) { + System.out.println("Iteration #" + i); + // select query + String sql = "from table1 SELECT * group by table1.key order by table1.key desc"; + System.out.println("Running: " + sql); + + long startTime = System.currentTimeMillis(); + ResultSet res = stmt.executeQuery(sql); + long endTime = System.currentTimeMillis(); + long msElapsedTime = endTime - startTime; + + while (res.next()) { + System.out.println(res.getInt(1)); + } + System.out.printf("Time taken for query = %d ms \n", msElapsedTime); + + + // count query + sql = "select count(*) from table1"; + + System.out.println("Running: " + sql); + startTime = System.currentTimeMillis(); + res = stmt.executeQuery(sql); + endTime = System.currentTimeMillis(); + msElapsedTime = endTime - startTime; + + while (res.next()) { + System.out.println(res.getInt(1)); + } + System.out.printf("Time taken for query = %d ms \n", msElapsedTime); + + + // join with group-by, having, order-by + sql = "select t1.key,count(t1.key) as cnt from table1 t1" + + " join table2 t2 on (t1.key = t2.key) group by t1.key having cnt > 5 order by cnt desc"; + + System.out.println("Running: " + sql); + startTime = System.currentTimeMillis(); + res = stmt.executeQuery(sql); + endTime = System.currentTimeMillis(); + msElapsedTime = endTime - startTime; + while (res.next()) { + System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2)); + } + System.out.printf("Time taken for query = %d ms \n", msElapsedTime); + + // full outer join + sql = "select table1.value, table2.value from table1 full outer join table2 " + + "on (table1.key = table2.key)"; + + + System.out.println("Running: " + sql); + startTime = System.currentTimeMillis(); + res = stmt.executeQuery(sql); + endTime = System.currentTimeMillis(); + msElapsedTime = endTime - startTime; + + while (res.next()) { + System.out.println(res.getString(1) + "\t" + res.getString(2)); + } + System.out.printf("Time taken for query = %d ms \n", msElapsedTime); + + } + + } + + /** + * @param args + * @throws SQLException + * @throws ClassNotFoundException + */ + public static void main(String[] args) throws SQLException, ClassNotFoundException { + Class.forName(driverName); + int numberOfQueryIterations = 80000; //default 80k (runs slightly over 1 day long) + + if (args.length > 0) { + numberOfQueryIterations = Integer.parseInt(args[0]); + } + if (numberOfQueryIterations < 0) { + numberOfQueryIterations = 80000; + } + Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "hive", ""); + createTables(con); + runQueries(con, numberOfQueryIterations); + } +}