Index: jdbc/src/test/org/apache/hive/jdbc/TestUtils.java =================================================================== --- jdbc/src/test/org/apache/hive/jdbc/TestUtils.java (revision 0) +++ jdbc/src/test/org/apache/hive/jdbc/TestUtils.java (revision 0) @@ -0,0 +1,76 @@ +/** + * 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.hive.jdbc; + +import java.sql.SQLException; + +import junit.framework.Assert; +import org.apache.hive.service.cli.thrift.TStatus; +import org.apache.hive.service.cli.thrift.TStatusCode; + +import junit.framework.TestCase; + +public class TestUtils extends TestCase { + + public void testVerifySuccessWithInfo() { + TStatus status = new TStatus(); + + // Test successful cases + status.setStatusCode(TStatusCode.SUCCESS_STATUS); + try { + Utils.verifySuccessWithInfo(status); + status.setStatusCode(TStatusCode.SUCCESS_WITH_INFO_STATUS); + Utils.verifySuccessWithInfo(status); + } catch (SQLException e) { + fail("SQL exception should not be thrown for successful status"); + } + + // Test failure cases + status.setStatusCode(TStatusCode.ERROR_STATUS); + status.setErrorMessage("Test message for exception"); + try { + Utils.verifySuccessWithInfo(status); + fail("Exception will be thrown for a failed status code"); + } catch (SQLException e) { + Assert.assertEquals("Test message for exception", e.getMessage()); + } + } + + public void testVerifySuccess() throws Exception { + TStatus status = new TStatus(); + + // Test successful cases + try { + status.setStatusCode(TStatusCode.SUCCESS_STATUS); + Utils.verifySuccess(status); + } catch (SQLException e) { + fail("SQL exception should not be thrown for successful status"); + } + + // Test failure cases + status.setStatusCode(TStatusCode.ERROR_STATUS); + status.setErrorMessage("Test message for exception"); + try { + Utils.verifySuccess(status); + fail("Exception will be thrown for a failed status code"); + } catch (SQLException e) { + Assert.assertEquals("Test message for exception", e.getMessage()); + } + } +} Index: jdbc/src/java/org/apache/hive/jdbc/Utils.java =================================================================== --- jdbc/src/java/org/apache/hive/jdbc/Utils.java (revision 1477887) +++ jdbc/src/java/org/apache/hive/jdbc/Utils.java (working copy) @@ -146,21 +146,19 @@ // Verify success or success_with_info status, else throw SQLException public static void verifySuccessWithInfo(TStatus status) throws SQLException { - verifySuccess(status, true); + if (status.getStatusCode() != TStatusCode.SUCCESS_STATUS && + status.getStatusCode() != TStatusCode.SUCCESS_WITH_INFO_STATUS) { + throw new SQLException(status.getErrorMessage(), + status.getSqlState(), status.getErrorCode()); + } } // Verify success status, else throw SQLException public static void verifySuccess(TStatus status) throws SQLException { - verifySuccess(status, false); - } - - // Verify success and optionally with_info status, else throw SQLException - public static void verifySuccess(TStatus status, boolean withInfo) throws SQLException { - if ((status.getStatusCode() != TStatusCode.SUCCESS_STATUS) && - (withInfo && (status.getStatusCode() != TStatusCode.SUCCESS_WITH_INFO_STATUS))) { + if (status.getStatusCode() != TStatusCode.SUCCESS_STATUS) { throw new SQLException(status.getErrorMessage(), - status.getSqlState(), status.getErrorCode()); - } + status.getSqlState(), status.getErrorCode()); + } } /**