/** * 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. */ package org.apache.drill.jdbc.test; import java.nio.file.Paths; import java.sql.Connection; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; import java.util.concurrent.TimeUnit; import org.apache.drill.common.util.TestTools; import org.apache.drill.jdbc.DrillResultSet; import org.apache.drill.jdbc.Driver; import org.apache.drill.jdbc.JdbcTestBase; import org.junit.Rule; import org.junit.rules.TestRule; import com.google.common.base.Stopwatch; public class JdbcTestQueryBase extends JdbcTestBase { // Set a timeout unless we're debugging. @Rule public TestRule TIMEOUT = TestTools.getTimeoutRule(40000); protected static final String WORKING_PATH; static{ Driver.load(); WORKING_PATH = Paths.get("").toAbsolutePath().toString(); } protected static void testQuery(String sql) throws Exception{ boolean success = false; try (Connection conn = connect("jdbc:drill:zk=local")) { for (int x = 0; x < 1; x++) { Stopwatch watch = Stopwatch.createStarted(); Statement s = conn.createStatement(); ResultSet r = s.executeQuery(sql); System.out.println(String.format("QueryId: %s", r.unwrap(DrillResultSet.class).getQueryId())); boolean first = true; while (r.next()) { ResultSetMetaData md = r.getMetaData(); if (first == true) { for (int i = 1; i <= md.getColumnCount(); i++) { System.out.print(md.getColumnName(i)); System.out.print('\t'); } System.out.println(); first = false; } for (int i = 1; i <= md.getColumnCount(); i++) { System.out.print(r.getObject(i)); System.out.print('\t'); } System.out.println(); } System.out.println(String.format("Query completed in %d millis.", watch.elapsed(TimeUnit.MILLISECONDS))); } System.out.println("\n\n\n"); success = true; } finally { if (!success) { Thread.sleep(2000); } } } }