Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveCallableStatement.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveCallableStatement.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveCallableStatement.java (working copy) @@ -1,2464 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Array; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Connection; -import java.sql.Date; -import java.sql.NClob; -import java.sql.ParameterMetaData; -import java.sql.Ref; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.RowId; -import java.sql.SQLException; -import java.sql.SQLWarning; -import java.sql.SQLXML; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Map; - -/** - * HiveCallableStatement. - * - */ -public class HiveCallableStatement implements java.sql.CallableStatement { - - /** - * - */ - public HiveCallableStatement() { - // TODO Auto-generated constructor stub - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getArray(int) - */ - - public Array getArray(int i) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getArray(java.lang.String) - */ - - public Array getArray(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getBigDecimal(int) - */ - - public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getBigDecimal(java.lang.String) - */ - - public BigDecimal getBigDecimal(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getBigDecimal(int, int) - */ - - public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getBlob(int) - */ - - public Blob getBlob(int i) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getBlob(java.lang.String) - */ - - public Blob getBlob(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getBoolean(int) - */ - - public boolean getBoolean(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getBoolean(java.lang.String) - */ - - public boolean getBoolean(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getByte(int) - */ - - public byte getByte(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getByte(java.lang.String) - */ - - public byte getByte(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getBytes(int) - */ - - public byte[] getBytes(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getBytes(java.lang.String) - */ - - public byte[] getBytes(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getCharacterStream(int) - */ - - public Reader getCharacterStream(int arg0) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getCharacterStream(java.lang.String) - */ - - public Reader getCharacterStream(String arg0) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getClob(int) - */ - - public Clob getClob(int i) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getClob(java.lang.String) - */ - - public Clob getClob(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getDate(int) - */ - - public Date getDate(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getDate(java.lang.String) - */ - - public Date getDate(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getDate(int, java.util.Calendar) - */ - - public Date getDate(int parameterIndex, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getDate(java.lang.String, - * java.util.Calendar) - */ - - public Date getDate(String parameterName, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getDouble(int) - */ - - public double getDouble(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getDouble(java.lang.String) - */ - - public double getDouble(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getFloat(int) - */ - - public float getFloat(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getFloat(java.lang.String) - */ - - public float getFloat(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getInt(int) - */ - - public int getInt(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getInt(java.lang.String) - */ - - public int getInt(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getLong(int) - */ - - public long getLong(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getLong(java.lang.String) - */ - - public long getLong(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getNCharacterStream(int) - */ - - public Reader getNCharacterStream(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getNCharacterStream(java.lang.String) - */ - - public Reader getNCharacterStream(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getNClob(int) - */ - - public NClob getNClob(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getNClob(java.lang.String) - */ - - public NClob getNClob(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getNString(int) - */ - - public String getNString(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getNString(java.lang.String) - */ - - public String getNString(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getObject(int) - */ - - public Object getObject(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getObject(java.lang.String) - */ - - public Object getObject(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - public T getObject(int parameterIndex, Class type) throws SQLException { - // TODO JDK 1.7 - throw new SQLException("Method not supported"); - } - - public T getObject(String parameterName, Class type) throws SQLException { - // TODO JDK 1.7 - throw new SQLException("Method not supported"); - } - - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getObject(int, java.util.Map) - */ - - public Object getObject(int i, Map> map) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getObject(java.lang.String, java.util.Map) - */ - - public Object getObject(String parameterName, Map> map) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getRef(int) - */ - - public Ref getRef(int i) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getRef(java.lang.String) - */ - - public Ref getRef(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getRowId(int) - */ - - public RowId getRowId(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getRowId(java.lang.String) - */ - - public RowId getRowId(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getSQLXML(int) - */ - - public SQLXML getSQLXML(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getSQLXML(java.lang.String) - */ - - public SQLXML getSQLXML(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getShort(int) - */ - - public short getShort(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getShort(java.lang.String) - */ - - public short getShort(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getString(int) - */ - - public String getString(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getString(java.lang.String) - */ - - public String getString(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getTime(int) - */ - - public Time getTime(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getTime(java.lang.String) - */ - - public Time getTime(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getTime(int, java.util.Calendar) - */ - - public Time getTime(int parameterIndex, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getTime(java.lang.String, - * java.util.Calendar) - */ - - public Time getTime(String parameterName, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getTimestamp(int) - */ - - public Timestamp getTimestamp(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getTimestamp(java.lang.String) - */ - - public Timestamp getTimestamp(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getTimestamp(int, java.util.Calendar) - */ - - public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getTimestamp(java.lang.String, - * java.util.Calendar) - */ - - public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getURL(int) - */ - - public URL getURL(int parameterIndex) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#getURL(java.lang.String) - */ - - public URL getURL(String parameterName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#registerOutParameter(int, int) - */ - - public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#registerOutParameter(java.lang.String, int) - */ - - public void registerOutParameter(String parameterName, int sqlType) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#registerOutParameter(int, int, int) - */ - - public void registerOutParameter(int parameterIndex, int sqlType, int scale) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#registerOutParameter(int, int, - * java.lang.String) - */ - - public void registerOutParameter(int paramIndex, int sqlType, String typeName) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#registerOutParameter(java.lang.String, int, - * int) - */ - - public void registerOutParameter(String parameterName, int sqlType, int scale) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#registerOutParameter(java.lang.String, int, - * java.lang.String) - */ - - public void registerOutParameter(String parameterName, int sqlType, - String typeName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setAsciiStream(java.lang.String, - * java.io.InputStream) - */ - - public void setAsciiStream(String parameterName, InputStream x) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setAsciiStream(java.lang.String, - * java.io.InputStream, int) - */ - - public void setAsciiStream(String parameterName, InputStream x, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setAsciiStream(java.lang.String, - * java.io.InputStream, long) - */ - - public void setAsciiStream(String parameterName, InputStream x, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setBigDecimal(java.lang.String, - * java.math.BigDecimal) - */ - - public void setBigDecimal(String parameterName, BigDecimal x) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setBinaryStream(java.lang.String, - * java.io.InputStream) - */ - - public void setBinaryStream(String parameterName, InputStream x) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setBinaryStream(java.lang.String, - * java.io.InputStream, int) - */ - - public void setBinaryStream(String parameterName, InputStream x, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setBinaryStream(java.lang.String, - * java.io.InputStream, long) - */ - - public void setBinaryStream(String parameterName, InputStream x, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setBlob(java.lang.String, java.sql.Blob) - */ - - public void setBlob(String parameterName, Blob x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setBlob(java.lang.String, - * java.io.InputStream) - */ - - public void setBlob(String parameterName, InputStream inputStream) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setBlob(java.lang.String, - * java.io.InputStream, long) - */ - - public void setBlob(String parameterName, InputStream inputStream, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setBoolean(java.lang.String, boolean) - */ - - public void setBoolean(String parameterName, boolean x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setByte(java.lang.String, byte) - */ - - public void setByte(String parameterName, byte x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setBytes(java.lang.String, byte[]) - */ - - public void setBytes(String parameterName, byte[] x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setCharacterStream(java.lang.String, - * java.io.Reader) - */ - - public void setCharacterStream(String parameterName, Reader reader) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setCharacterStream(java.lang.String, - * java.io.Reader, int) - */ - - public void setCharacterStream(String parameterName, Reader reader, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setCharacterStream(java.lang.String, - * java.io.Reader, long) - */ - - public void setCharacterStream(String parameterName, Reader reader, - long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setClob(java.lang.String, java.sql.Clob) - */ - - public void setClob(String parameterName, Clob x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setClob(java.lang.String, java.io.Reader) - */ - - public void setClob(String parameterName, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setClob(java.lang.String, java.io.Reader, - * long) - */ - - public void setClob(String parameterName, Reader reader, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setDate(java.lang.String, java.sql.Date) - */ - - public void setDate(String parameterName, Date x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setDate(java.lang.String, java.sql.Date, - * java.util.Calendar) - */ - - public void setDate(String parameterName, Date x, Calendar cal) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setDouble(java.lang.String, double) - */ - - public void setDouble(String parameterName, double x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setFloat(java.lang.String, float) - */ - - public void setFloat(String parameterName, float x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setInt(java.lang.String, int) - */ - - public void setInt(String parameterName, int x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setLong(java.lang.String, long) - */ - - public void setLong(String parameterName, long x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setNCharacterStream(java.lang.String, - * java.io.Reader) - */ - - public void setNCharacterStream(String parameterName, Reader value) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setNCharacterStream(java.lang.String, - * java.io.Reader, long) - */ - - public void setNCharacterStream(String parameterName, Reader value, - long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setNClob(java.lang.String, java.sql.NClob) - */ - - public void setNClob(String parameterName, NClob value) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setNClob(java.lang.String, java.io.Reader) - */ - - public void setNClob(String parameterName, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setNClob(java.lang.String, java.io.Reader, - * long) - */ - - public void setNClob(String parameterName, Reader reader, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setNString(java.lang.String, - * java.lang.String) - */ - - public void setNString(String parameterName, String value) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setNull(java.lang.String, int) - */ - - public void setNull(String parameterName, int sqlType) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setNull(java.lang.String, int, - * java.lang.String) - */ - - public void setNull(String parameterName, int sqlType, String typeName) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setObject(java.lang.String, - * java.lang.Object) - */ - - public void setObject(String parameterName, Object x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setObject(java.lang.String, - * java.lang.Object, int) - */ - - public void setObject(String parameterName, Object x, int targetSqlType) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setObject(java.lang.String, - * java.lang.Object, int, int) - */ - - public void setObject(String parameterName, Object x, int targetSqlType, - int scale) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setRowId(java.lang.String, java.sql.RowId) - */ - - public void setRowId(String parameterName, RowId x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setSQLXML(java.lang.String, - * java.sql.SQLXML) - */ - - public void setSQLXML(String parameterName, SQLXML xmlObject) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setShort(java.lang.String, short) - */ - - public void setShort(String parameterName, short x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setString(java.lang.String, - * java.lang.String) - */ - - public void setString(String parameterName, String x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setTime(java.lang.String, java.sql.Time) - */ - - public void setTime(String parameterName, Time x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setTime(java.lang.String, java.sql.Time, - * java.util.Calendar) - */ - - public void setTime(String parameterName, Time x, Calendar cal) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setTimestamp(java.lang.String, - * java.sql.Timestamp) - */ - - public void setTimestamp(String parameterName, Timestamp x) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setTimestamp(java.lang.String, - * java.sql.Timestamp, java.util.Calendar) - */ - - public void setTimestamp(String parameterName, Timestamp x, Calendar cal) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#setURL(java.lang.String, java.net.URL) - */ - - public void setURL(String parameterName, URL val) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.CallableStatement#wasNull() - */ - - public boolean wasNull() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#addBatch() - */ - - public void addBatch() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#clearParameters() - */ - - public void clearParameters() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#execute() - */ - - public boolean execute() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#executeQuery() - */ - - public ResultSet executeQuery() throws SQLException { - // TODO Auto-generated method stub - return new HiveQueryResultSet(null); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#executeUpdate() - */ - - public int executeUpdate() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#getMetaData() - */ - - public ResultSetMetaData getMetaData() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#getParameterMetaData() - */ - - public ParameterMetaData getParameterMetaData() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setArray(int, java.sql.Array) - */ - - public void setArray(int i, Array x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream) - */ - - public void setAsciiStream(int arg0, InputStream arg1) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream, - * int) - */ - - public void setAsciiStream(int parameterIndex, InputStream x, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream, - * long) - */ - - public void setAsciiStream(int arg0, InputStream arg1, long arg2) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBigDecimal(int, java.math.BigDecimal) - */ - - public void setBigDecimal(int parameterIndex, BigDecimal x) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream) - */ - - public void setBinaryStream(int parameterIndex, InputStream x) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, - * int) - */ - - public void setBinaryStream(int parameterIndex, InputStream x, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, - * long) - */ - - public void setBinaryStream(int parameterIndex, InputStream x, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBlob(int, java.sql.Blob) - */ - - public void setBlob(int i, Blob x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBlob(int, java.io.InputStream) - */ - - public void setBlob(int parameterIndex, InputStream inputStream) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBlob(int, java.io.InputStream, long) - */ - - public void setBlob(int parameterIndex, InputStream inputStream, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBoolean(int, boolean) - */ - - public void setBoolean(int parameterIndex, boolean x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setByte(int, byte) - */ - - public void setByte(int parameterIndex, byte x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBytes(int, byte[]) - */ - - public void setBytes(int parameterIndex, byte[] x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader) - */ - - public void setCharacterStream(int parameterIndex, Reader reader) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader, - * int) - */ - - public void setCharacterStream(int parameterIndex, Reader reader, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader, - * long) - */ - - public void setCharacterStream(int parameterIndex, Reader reader, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setClob(int, java.sql.Clob) - */ - - public void setClob(int i, Clob x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setClob(int, java.io.Reader) - */ - - public void setClob(int parameterIndex, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setClob(int, java.io.Reader, long) - */ - - public void setClob(int parameterIndex, Reader reader, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setDate(int, java.sql.Date) - */ - - public void setDate(int parameterIndex, Date x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setDate(int, java.sql.Date, - * java.util.Calendar) - */ - - public void setDate(int parameterIndex, Date x, Calendar cal) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setDouble(int, double) - */ - - public void setDouble(int parameterIndex, double x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setFloat(int, float) - */ - - public void setFloat(int parameterIndex, float x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setInt(int, int) - */ - - public void setInt(int parameterIndex, int x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setLong(int, long) - */ - - public void setLong(int parameterIndex, long x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader) - */ - - public void setNCharacterStream(int parameterIndex, Reader value) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader, - * long) - */ - - public void setNCharacterStream(int parameterIndex, Reader value, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNClob(int, java.sql.NClob) - */ - - public void setNClob(int parameterIndex, NClob value) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNClob(int, java.io.Reader) - */ - - public void setNClob(int parameterIndex, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNClob(int, java.io.Reader, long) - */ - - public void setNClob(int parameterIndex, Reader reader, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNString(int, java.lang.String) - */ - - public void setNString(int parameterIndex, String value) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNull(int, int) - */ - - public void setNull(int parameterIndex, int sqlType) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNull(int, int, java.lang.String) - */ - - public void setNull(int paramIndex, int sqlType, String typeName) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setObject(int, java.lang.Object) - */ - - public void setObject(int parameterIndex, Object x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setObject(int, java.lang.Object, int) - */ - - public void setObject(int parameterIndex, Object x, int targetSqlType) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setObject(int, java.lang.Object, int, int) - */ - - public void setObject(int parameterIndex, Object x, int targetSqlType, - int scale) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setRef(int, java.sql.Ref) - */ - - public void setRef(int i, Ref x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setRowId(int, java.sql.RowId) - */ - - public void setRowId(int parameterIndex, RowId x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setSQLXML(int, java.sql.SQLXML) - */ - - public void setSQLXML(int parameterIndex, SQLXML xmlObject) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setShort(int, short) - */ - - public void setShort(int parameterIndex, short x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setString(int, java.lang.String) - */ - - public void setString(int parameterIndex, String x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setTime(int, java.sql.Time) - */ - - public void setTime(int parameterIndex, Time x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setTime(int, java.sql.Time, - * java.util.Calendar) - */ - - public void setTime(int parameterIndex, Time x, Calendar cal) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setTimestamp(int, java.sql.Timestamp) - */ - - public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setTimestamp(int, java.sql.Timestamp, - * java.util.Calendar) - */ - - public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setURL(int, java.net.URL) - */ - - public void setURL(int parameterIndex, URL x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setUnicodeStream(int, java.io.InputStream, - * int) - */ - - public void setUnicodeStream(int parameterIndex, InputStream x, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#addBatch(java.lang.String) - */ - - public void addBatch(String sql) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#cancel() - */ - - public void cancel() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#clearBatch() - */ - - public void clearBatch() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#clearWarnings() - */ - - public void clearWarnings() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#close() - */ - - public void close() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - public void closeOnCompletion() throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - public boolean isCloseOnCompletion() throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String) - */ - - public boolean execute(String sql) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String, int) - */ - - public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String, int[]) - */ - - public boolean execute(String sql, int[] columnIndexes) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String, java.lang.String[]) - */ - - public boolean execute(String sql, String[] columnNames) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeBatch() - */ - - public int[] executeBatch() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeQuery(java.lang.String) - */ - - public ResultSet executeQuery(String sql) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String) - */ - - public int executeUpdate(String sql) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String, int) - */ - - public int executeUpdate(String sql, int autoGeneratedKeys) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String, int[]) - */ - - public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String, java.lang.String[]) - */ - - public int executeUpdate(String sql, String[] columnNames) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getConnection() - */ - - public Connection getConnection() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getFetchDirection() - */ - - public int getFetchDirection() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getFetchSize() - */ - - public int getFetchSize() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getGeneratedKeys() - */ - - public ResultSet getGeneratedKeys() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMaxFieldSize() - */ - - public int getMaxFieldSize() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMaxRows() - */ - - public int getMaxRows() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMoreResults() - */ - - public boolean getMoreResults() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMoreResults(int) - */ - - public boolean getMoreResults(int current) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getQueryTimeout() - */ - - public int getQueryTimeout() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSet() - */ - - public ResultSet getResultSet() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSetConcurrency() - */ - - public int getResultSetConcurrency() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSetHoldability() - */ - - public int getResultSetHoldability() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSetType() - */ - - public int getResultSetType() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getUpdateCount() - */ - - public int getUpdateCount() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getWarnings() - */ - - public SQLWarning getWarnings() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#isClosed() - */ - - public boolean isClosed() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#isPoolable() - */ - - public boolean isPoolable() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setCursorName(java.lang.String) - */ - - public void setCursorName(String name) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setEscapeProcessing(boolean) - */ - - public void setEscapeProcessing(boolean enable) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setFetchDirection(int) - */ - - public void setFetchDirection(int direction) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setFetchSize(int) - */ - - public void setFetchSize(int rows) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setMaxFieldSize(int) - */ - - public void setMaxFieldSize(int max) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setMaxRows(int) - */ - - public void setMaxRows(int max) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setPoolable(boolean) - */ - - public void setPoolable(boolean arg0) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setQueryTimeout(int) - */ - - public void setQueryTimeout(int seconds) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#isWrapperFor(java.lang.Class) - */ - - public boolean isWrapperFor(Class iface) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#unwrap(java.lang.Class) - */ - - public T unwrap(Class iface) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - -} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveStatement.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveStatement.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveStatement.java (working copy) @@ -1,526 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.SQLWarning; - -import org.apache.hadoop.hive.service.HiveInterface; -import org.apache.hadoop.hive.service.HiveServerException; - -/** - * HiveStatement. - * - */ -public class HiveStatement implements java.sql.Statement { - private HiveInterface client; - private int fetchSize = 50; - - /** - * We need to keep a reference to the result set to support the following: - * - * statement.execute(String sql); - * statement.getResultSet(); - * . - */ - private ResultSet resultSet = null; - - /** - * The maximum number of rows this statement should return (0 => all rows). - */ - private int maxRows = 0; - - /** - * Add SQLWarnings to the warningChain if needed. - */ - private SQLWarning warningChain = null; - - /** - * Keep state so we can fail certain calls made after close(). - */ - private boolean isClosed = false; - - /** - * - */ - public HiveStatement(HiveInterface client) { - this.client = client; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#addBatch(java.lang.String) - */ - - public void addBatch(String sql) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#cancel() - */ - - public void cancel() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#clearBatch() - */ - - public void clearBatch() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#clearWarnings() - */ - - public void clearWarnings() throws SQLException { - warningChain = null; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#close() - */ - - public void close() throws SQLException { - client = null; - resultSet = null; - isClosed = true; - } - - public void closeOnCompletion() throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String) - */ - - public boolean execute(String sql) throws SQLException { - ResultSet rs = executeQuery(sql); - - // TODO: this should really check if there are results, but there's no easy - // way to do that without calling rs.next(); - return rs != null; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String, int) - */ - - public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String, int[]) - */ - - public boolean execute(String sql, int[] columnIndexes) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String, java.lang.String[]) - */ - - public boolean execute(String sql, String[] columnNames) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeBatch() - */ - - public int[] executeBatch() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeQuery(java.lang.String) - */ - - public ResultSet executeQuery(String sql) throws SQLException { - if (isClosed) { - throw new SQLException("Can't execute after statement has been closed"); - } - - try { - resultSet = null; - client.execute(sql); - } catch (HiveServerException e) { - throw new SQLException(e.getMessage(), e.getSQLState(), e.getErrorCode()); - } catch (Exception ex) { - throw new SQLException(ex.toString(), "08S01"); - } - resultSet = new HiveQueryResultSet(client, maxRows); - resultSet.setFetchSize(fetchSize); - return resultSet; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String) - */ - - public int executeUpdate(String sql) throws SQLException { - try { - client.execute(sql); - } catch (Exception ex) { - throw new SQLException(ex.toString()); - } - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String, int) - */ - - public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String, int[]) - */ - - public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String, java.lang.String[]) - */ - - public int executeUpdate(String sql, String[] columnNames) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getConnection() - */ - - public Connection getConnection() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getFetchDirection() - */ - - public int getFetchDirection() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getFetchSize() - */ - - public int getFetchSize() throws SQLException { - return fetchSize; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getGeneratedKeys() - */ - - public ResultSet getGeneratedKeys() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMaxFieldSize() - */ - - public int getMaxFieldSize() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMaxRows() - */ - - public int getMaxRows() throws SQLException { - return maxRows; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMoreResults() - */ - - public boolean getMoreResults() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMoreResults(int) - */ - - public boolean getMoreResults(int current) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getQueryTimeout() - */ - - public int getQueryTimeout() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSet() - */ - - public ResultSet getResultSet() throws SQLException { - return resultSet; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSetConcurrency() - */ - - public int getResultSetConcurrency() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSetHoldability() - */ - - public int getResultSetHoldability() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSetType() - */ - - public int getResultSetType() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getUpdateCount() - */ - - public int getUpdateCount() throws SQLException { - return 0; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getWarnings() - */ - - public SQLWarning getWarnings() throws SQLException { - return warningChain; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#isClosed() - */ - - public boolean isClosed() throws SQLException { - return isClosed; - } - - public boolean isCloseOnCompletion() throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#isPoolable() - */ - - public boolean isPoolable() throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setCursorName(java.lang.String) - */ - - public void setCursorName(String name) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setEscapeProcessing(boolean) - */ - - public void setEscapeProcessing(boolean enable) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setFetchDirection(int) - */ - - public void setFetchDirection(int direction) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setFetchSize(int) - */ - - public void setFetchSize(int rows) throws SQLException { - fetchSize = rows; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setMaxFieldSize(int) - */ - - public void setMaxFieldSize(int max) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setMaxRows(int) - */ - - public void setMaxRows(int max) throws SQLException { - if (max < 0) { - throw new SQLException("max must be >= 0"); - } - maxRows = max; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setPoolable(boolean) - */ - - public void setPoolable(boolean poolable) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setQueryTimeout(int) - */ - - public void setQueryTimeout(int seconds) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#isWrapperFor(java.lang.Class) - */ - - public boolean isWrapperFor(Class iface) throws SQLException { - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#unwrap(java.lang.Class) - */ - - public T unwrap(Class iface) throws SQLException { - throw new SQLException("Method not supported"); - } - -} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcColumn.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcColumn.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcColumn.java (working copy) @@ -1,185 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.sql.SQLException; -import java.sql.Types; - -/** - * Column metadata. - */ -public class JdbcColumn { - private final String columnName; - private final String tableName; - private final String tableCatalog; - private final String type; - private final String comment; - private final int ordinalPos; - - JdbcColumn(String columnName, String tableName, String tableCatalog - , String type, String comment, int ordinalPos) { - this.columnName = columnName; - this.tableName = tableName; - this.tableCatalog = tableCatalog; - this.type = type; - this.comment = comment; - this.ordinalPos = ordinalPos; - } - - public String getColumnName() { - return columnName; - } - - public String getTableName() { - return tableName; - } - - public String getTableCatalog() { - return tableCatalog; - } - - public String getType() { - return type; - } - - public Integer getSqlType() throws SQLException { - return Utils.hiveTypeToSqlType(type); - } - - static int columnDisplaySize(int columnType) throws SQLException { - // according to hiveTypeToSqlType possible options are: - switch(columnType) { - case Types.BOOLEAN: - return columnPrecision(columnType); - case Types.VARCHAR: - return Integer.MAX_VALUE; // hive has no max limit for strings - case Types.TINYINT: - case Types.SMALLINT: - case Types.INTEGER: - case Types.BIGINT: - return columnPrecision(columnType) + 1; // allow +/- - case Types.DATE: - return 10; - case Types.TIMESTAMP: - return columnPrecision(columnType); - // see http://download.oracle.com/javase/6/docs/api/constant-values.html#java.lang.Float.MAX_EXPONENT - case Types.FLOAT: - return 24; // e.g. -(17#).e-### - // see http://download.oracle.com/javase/6/docs/api/constant-values.html#java.lang.Double.MAX_EXPONENT - case Types.DOUBLE: - return 25; // e.g. -(17#).e-#### - case Types.DECIMAL: - return Integer.MAX_VALUE; - default: - throw new SQLException("Invalid column type: " + columnType); - } - } - - static int columnPrecision(int columnType) throws SQLException { - // according to hiveTypeToSqlType possible options are: - switch(columnType) { - case Types.BOOLEAN: - return 1; - case Types.VARCHAR: - return Integer.MAX_VALUE; // hive has no max limit for strings - case Types.TINYINT: - return 3; - case Types.SMALLINT: - return 5; - case Types.INTEGER: - return 10; - case Types.BIGINT: - return 19; - case Types.FLOAT: - return 7; - case Types.DOUBLE: - return 15; - case Types.DATE: - return 10; - case Types.TIMESTAMP: - return 29; - case Types.DECIMAL: - return Integer.MAX_VALUE; - default: - throw new SQLException("Invalid column type: " + columnType); - } - } - - static int columnScale(int columnType) throws SQLException { - // according to hiveTypeToSqlType possible options are: - switch(columnType) { - case Types.BOOLEAN: - case Types.VARCHAR: - case Types.TINYINT: - case Types.SMALLINT: - case Types.INTEGER: - case Types.BIGINT: - case Types.DATE: - return 0; - case Types.FLOAT: - return 7; - case Types.DOUBLE: - return 15; - case Types.TIMESTAMP: - return 9; - case Types.DECIMAL: - return Integer.MAX_VALUE; - default: - throw new SQLException("Invalid column type: " + columnType); - } - } - - public Integer getColumnSize() throws SQLException { - int precision = columnPrecision(Utils.hiveTypeToSqlType(type)); - - return precision == 0 ? null : precision; - } - - public Integer getDecimalDigits() throws SQLException { - return columnScale(Utils.hiveTypeToSqlType(type)); - } - - public Integer getNumPrecRadix() { - if (type.equalsIgnoreCase("tinyint")) { - return 10; - } else if (type.equalsIgnoreCase("smallint")) { - return 10; - } else if (type.equalsIgnoreCase("int")) { - return 10; - } else if (type.equalsIgnoreCase("bigint")) { - return 10; - } else if (type.equalsIgnoreCase("decimal")) { - return 10; - } else if (type.equalsIgnoreCase("float")) { - return 2; - } else if (type.equalsIgnoreCase("double")) { - return 2; - } else { // anything else including boolean and string is null - return null; - } - } - - public String getComment() { - return comment; - } - - public int getOrdinalPos() { - return ordinalPos; - } -} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/Utils.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/Utils.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/Utils.java (working copy) @@ -1,65 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.sql.SQLException; -import java.sql.Types; - -public class Utils { - - /** - * Convert hive types to sql types. - * @param type - * @return Integer java.sql.Types values - * @throws SQLException - */ - public static int hiveTypeToSqlType(String type) throws SQLException { - if ("string".equalsIgnoreCase(type)) { - return Types.VARCHAR; - } else if ("float".equalsIgnoreCase(type)) { - return Types.FLOAT; - } else if ("double".equalsIgnoreCase(type)) { - return Types.DOUBLE; - } else if ("boolean".equalsIgnoreCase(type)) { - return Types.BOOLEAN; - } else if ("tinyint".equalsIgnoreCase(type)) { - return Types.TINYINT; - } else if ("smallint".equalsIgnoreCase(type)) { - return Types.SMALLINT; - } else if ("int".equalsIgnoreCase(type)) { - return Types.INTEGER; - } else if ("bigint".equalsIgnoreCase(type)) { - return Types.BIGINT; - } else if ("date".equalsIgnoreCase(type)) { - return Types.DATE; - } else if ("timestamp".equalsIgnoreCase(type)) { - return Types.TIMESTAMP; - } else if (type.startsWith("decimal")) { - return Types.DECIMAL; - } else if (type.startsWith("map<")) { - return Types.VARCHAR; - } else if (type.startsWith("array<")) { - return Types.VARCHAR; - } else if (type.startsWith("struct<")) { - return Types.VARCHAR; - } - throw new SQLException("Unrecognized column type: " + type); - } - -} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveBaseResultSet.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveBaseResultSet.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveBaseResultSet.java (working copy) @@ -1,987 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.math.MathContext; -import java.net.URL; -import java.sql.Array; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Date; -import java.sql.NClob; -import java.sql.Ref; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.RowId; -import java.sql.SQLException; -import java.sql.SQLWarning; -import java.sql.SQLXML; -import java.sql.Statement; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.List; -import java.util.Map; - -import org.apache.hadoop.hive.common.type.HiveDecimal; - -/** - * Data independed base class which implements the common part of - * all hive resultsets. - */ -public abstract class HiveBaseResultSet implements ResultSet{ - protected SQLWarning warningChain = null; - protected boolean wasNull = false; - protected List row; - protected List columnNames; - protected List columnTypes; - - public boolean absolute(int row) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void afterLast() throws SQLException { - throw new SQLException("Method not supported"); - } - - public void beforeFirst() throws SQLException { - throw new SQLException("Method not supported"); - } - - public void cancelRowUpdates() throws SQLException { - throw new SQLException("Method not supported"); - } - - public void deleteRow() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int findColumn(String columnName) throws SQLException { - int columnIndex = columnNames.indexOf(columnName); - if (columnIndex==-1) { - throw new SQLException(); - } else { - return ++columnIndex; - } - } - - public boolean first() throws SQLException { - throw new SQLException("Method not supported"); - } - - public Array getArray(int i) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Array getArray(String colName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public InputStream getAsciiStream(int columnIndex) throws SQLException { - throw new SQLException("Method not supported"); - } - - public InputStream getAsciiStream(String columnName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - Object obj = getObject(columnIndex); - if (obj == null) { - return null; - } - if (obj instanceof BigDecimal) { - return ((BigDecimal) obj); - } - if (obj instanceof HiveDecimal) { - return ((HiveDecimal) obj).bigDecimalValue(); - } - throw new SQLException("Cannot convert column " + columnIndex - + " to BigDecimal. Found data of type: " - + obj.getClass()+", value: " + obj.toString()); - } - - public BigDecimal getBigDecimal(String columnName) throws SQLException { - return getBigDecimal(findColumn(columnName)); - } - - public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { - MathContext mc = new MathContext(scale); - return getBigDecimal(columnIndex).round(mc); - } - - public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { - return getBigDecimal(findColumn(columnName), scale); - } - - public InputStream getBinaryStream(int columnIndex) throws SQLException { - throw new SQLException("Method not supported"); - } - - public InputStream getBinaryStream(String columnName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Blob getBlob(int i) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Blob getBlob(String colName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean getBoolean(int columnIndex) throws SQLException { - Object obj = getObject(columnIndex); - if (Boolean.class.isInstance(obj)) { - return (Boolean) obj; - } else if (obj == null) { - return false; - } else if (Number.class.isInstance(obj)) { - return ((Number) obj).intValue() != 0; - } else if (String.class.isInstance(obj)) { - return !((String) obj).equals("0"); - } - throw new SQLException("Cannot convert column " + columnIndex + " to boolean"); - } - - public boolean getBoolean(String columnName) throws SQLException { - return getBoolean(findColumn(columnName)); - } - - public byte getByte(int columnIndex) throws SQLException { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).byteValue(); - } else if (obj == null) { - return 0; - } - throw new SQLException("Cannot convert column " + columnIndex + " to byte"); - } - - public byte getByte(String columnName) throws SQLException { - return getByte(findColumn(columnName)); - } - - public byte[] getBytes(int columnIndex) throws SQLException { - throw new SQLException("Method not supported"); - } - - public byte[] getBytes(String columnName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Reader getCharacterStream(int columnIndex) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Reader getCharacterStream(String columnName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Clob getClob(int i) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Clob getClob(String colName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getConcurrency() throws SQLException { - return ResultSet.CONCUR_READ_ONLY; - } - - public String getCursorName() throws SQLException { - throw new SQLException("Method not supported"); - } - - public Date getDate(int columnIndex) throws SQLException { - Object obj = getObject(columnIndex); - if (obj == null) { - return null; - } - - if (obj instanceof Date) { - return (Date) obj; - } - - try { - if (obj instanceof String) { - return Date.valueOf((String)obj); - } - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex - + " to date: " + e.toString()); - } - - throw new SQLException("Illegal conversion"); - } - - public Date getDate(String columnName) throws SQLException { - return getDate(findColumn(columnName)); - } - - public Date getDate(int columnIndex, Calendar cal) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Date getDate(String columnName, Calendar cal) throws SQLException { - throw new SQLException("Method not supported"); - } - - public double getDouble(int columnIndex) throws SQLException { - try { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).doubleValue(); - } else if (obj == null) { - return 0; - } else if (String.class.isInstance(obj)) { - return Double.valueOf((String)obj); - } - throw new Exception("Illegal conversion"); - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex - + " to double: " + e.toString()); - } - } - - public double getDouble(String columnName) throws SQLException { - return getDouble(findColumn(columnName)); - } - - public int getFetchDirection() throws SQLException { - return ResultSet.FETCH_FORWARD; - } - - public int getFetchSize() throws SQLException { - throw new SQLException("Method not supported"); - } - - public float getFloat(int columnIndex) throws SQLException { - try { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).floatValue(); - } else if (obj == null) { - return 0; - } else if (String.class.isInstance(obj)) { - return Float.valueOf((String)obj); - } - throw new Exception("Illegal conversion"); - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex - + " to float: " + e.toString()); - } - } - - public float getFloat(String columnName) throws SQLException { - return getFloat(findColumn(columnName)); - } - - public int getHoldability() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getInt(int columnIndex) throws SQLException { - try { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).intValue(); - } else if (obj == null) { - return 0; - } else if (String.class.isInstance(obj)) { - return Integer.valueOf((String)obj); - } - throw new Exception("Illegal conversion"); - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex + " to integer" + e.toString()); - } - } - - public int getInt(String columnName) throws SQLException { - return getInt(findColumn(columnName)); - } - - public long getLong(int columnIndex) throws SQLException { - try { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).longValue(); - } else if (obj == null) { - return 0; - } else if (String.class.isInstance(obj)) { - return Long.valueOf((String)obj); - } - throw new Exception("Illegal conversion"); - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex + " to long: " + e.toString()); - } - } - - public long getLong(String columnName) throws SQLException { - return getLong(findColumn(columnName)); - } - - public ResultSetMetaData getMetaData() throws SQLException { - return new HiveResultSetMetaData(columnNames, columnTypes); - } - - public Reader getNCharacterStream(int arg0) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Reader getNCharacterStream(String arg0) throws SQLException { - throw new SQLException("Method not supported"); - } - - public NClob getNClob(int arg0) throws SQLException { - throw new SQLException("Method not supported"); - } - - public NClob getNClob(String columnLabel) throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getNString(int columnIndex) throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getNString(String columnLabel) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Object getObject(int columnIndex) throws SQLException { - if (row == null) { - throw new SQLException("No row found."); - } - - if (columnIndex > row.size()) { - throw new SQLException("Invalid columnIndex: " + columnIndex); - } - - try { - wasNull = false; - if (row.get(columnIndex - 1) == null) { - wasNull = true; - } - - return row.get(columnIndex - 1); - } catch (Exception e) { - throw new SQLException(e.toString()); - } - } - - public Object getObject(String columnName) throws SQLException { - return getObject(findColumn(columnName)); - } - - public T getObject(int columnIndex, Class type) throws SQLException { - // TODO method required by JDK 1.7 - throw new SQLException("Method not supported"); - } - - public T getObject(String columnLabel, Class type) throws SQLException { - // TODO method required by JDK 1.7 - throw new SQLException("Method not supported"); - } - - public Object getObject(int i, Map> map) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Object getObject(String colName, Map> map) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Ref getRef(int i) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Ref getRef(String colName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getRow() throws SQLException { - throw new SQLException("Method not supported"); - } - - public RowId getRowId(int columnIndex) throws SQLException { - throw new SQLException("Method not supported"); - } - - public RowId getRowId(String columnLabel) throws SQLException { - throw new SQLException("Method not supported"); - } - - public SQLXML getSQLXML(int columnIndex) throws SQLException { - throw new SQLException("Method not supported"); - } - - public SQLXML getSQLXML(String columnLabel) throws SQLException { - throw new SQLException("Method not supported"); - } - - public short getShort(int columnIndex) throws SQLException { - try { - Object obj = getObject(columnIndex); - if (Number.class.isInstance(obj)) { - return ((Number) obj).shortValue(); - } else if (obj == null) { - return 0; - } else if (String.class.isInstance(obj)) { - return Short.valueOf((String)obj); - } - throw new Exception("Illegal conversion"); - } catch (Exception e) { - throw new SQLException("Cannot convert column " + columnIndex - + " to short: " + e.toString()); - } - } - - public short getShort(String columnName) throws SQLException { - return getShort(findColumn(columnName)); - } - - public Statement getStatement() throws SQLException { - throw new SQLException("Method not supported"); - } - - /** - * @param columnIndex - the first column is 1, the second is 2, ... - * @see java.sql.ResultSet#getString(int) - */ - - public String getString(int columnIndex) throws SQLException { - // Column index starts from 1, not 0. - Object obj = getObject(columnIndex); - if (obj == null) { - return null; - } - - return obj.toString(); - } - - public String getString(String columnName) throws SQLException { - return getString(findColumn(columnName)); - } - - public Time getTime(int columnIndex) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Time getTime(String columnName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Time getTime(int columnIndex, Calendar cal) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Time getTime(String columnName, Calendar cal) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Timestamp getTimestamp(int columnIndex) throws SQLException { - Object obj = getObject(columnIndex); - if (obj == null) { - return null; - } - if (obj instanceof Timestamp) { - return (Timestamp) obj; - } - if (obj instanceof String) { - return Timestamp.valueOf((String)obj); - } - throw new SQLException("Illegal conversion"); - } - - public Timestamp getTimestamp(String columnName) throws SQLException { - return getTimestamp(findColumn(columnName)); - } - - public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { - throw new SQLException("Method not supported"); - } - - public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getType() throws SQLException { - return ResultSet.TYPE_FORWARD_ONLY; - } - - public URL getURL(int columnIndex) throws SQLException { - throw new SQLException("Method not supported"); - } - - public URL getURL(String columnName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public InputStream getUnicodeStream(int columnIndex) throws SQLException { - throw new SQLException("Method not supported"); - } - - public InputStream getUnicodeStream(String columnName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void insertRow() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isAfterLast() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isBeforeFirst() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isClosed() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isFirst() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isLast() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean last() throws SQLException { - throw new SQLException("Method not supported"); - } - - public void moveToCurrentRow() throws SQLException { - throw new SQLException("Method not supported"); - } - - public void moveToInsertRow() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean previous() throws SQLException { - throw new SQLException("Method not supported"); - } - - public void refreshRow() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean relative(int rows) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean rowDeleted() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean rowInserted() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean rowUpdated() throws SQLException { - throw new SQLException("Method not supported"); - } - - public void setFetchDirection(int direction) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void setFetchSize(int rows) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateArray(int columnIndex, Array x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateArray(String columnName, Array x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateAsciiStream(int columnIndex, InputStream x, int length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateAsciiStream(String columnName, InputStream x, int length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateAsciiStream(int columnIndex, InputStream x, long length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateAsciiStream(String columnLabel, InputStream x, long length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBinaryStream(int columnIndex, InputStream x, int length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBinaryStream(String columnName, InputStream x, int length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBinaryStream(int columnIndex, InputStream x, long length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBinaryStream(String columnLabel, InputStream x, long length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBlob(int columnIndex, Blob x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBlob(String columnName, Blob x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBlob(int columnIndex, InputStream inputStream, long length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBlob(String columnLabel, InputStream inputStream, - long length) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBoolean(int columnIndex, boolean x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBoolean(String columnName, boolean x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateByte(int columnIndex, byte x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateByte(String columnName, byte x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBytes(int columnIndex, byte[] x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateBytes(String columnName, byte[] x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateCharacterStream(int columnIndex, Reader x, int length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateCharacterStream(String columnName, Reader reader, int length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateCharacterStream(int columnIndex, Reader x, long length) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateCharacterStream(String columnLabel, Reader reader, - long length) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateClob(int columnIndex, Clob x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateClob(String columnName, Clob x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateClob(int columnIndex, Reader reader) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateClob(String columnLabel, Reader reader) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateDate(int columnIndex, Date x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateDate(String columnName, Date x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateDouble(int columnIndex, double x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateDouble(String columnName, double x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateFloat(int columnIndex, float x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateFloat(String columnName, float x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateInt(int columnIndex, int x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateInt(String columnName, int x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateLong(int columnIndex, long x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateLong(String columnName, long x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNCharacterStream(String columnLabel, Reader reader, - long length) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNClob(int columnIndex, NClob clob) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNClob(String columnLabel, NClob clob) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNClob(int columnIndex, Reader reader) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNClob(String columnLabel, Reader reader) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNString(int columnIndex, String string) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNString(String columnLabel, String string) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNull(int columnIndex) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateNull(String columnName) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateObject(int columnIndex, Object x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateObject(String columnName, Object x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateObject(int columnIndex, Object x, int scale) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateObject(String columnName, Object x, int scale) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateRef(int columnIndex, Ref x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateRef(String columnName, Ref x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateRow() throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateRowId(int columnIndex, RowId x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateRowId(String columnLabel, RowId x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateShort(int columnIndex, short x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateShort(String columnName, short x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateString(int columnIndex, String x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateString(String columnName, String x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateTime(int columnIndex, Time x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateTime(String columnName, Time x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public void updateTimestamp(String columnName, Timestamp x) throws SQLException { - throw new SQLException("Method not supported"); - } - - public SQLWarning getWarnings() throws SQLException { - return warningChain; - } - - public void clearWarnings() throws SQLException { - warningChain = null; - } - - public void close() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean wasNull() throws SQLException { - return wasNull; - } - - public boolean isWrapperFor(Class iface) throws SQLException { - throw new SQLException("Method not supported"); - } - - public T unwrap(Class iface) throws SQLException { - throw new SQLException("Method not supported"); - } -} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java (working copy) @@ -1,1174 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.RowIdLifetime; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.jar.Attributes; - -import org.apache.hadoop.hive.metastore.TableType; -import org.apache.hadoop.hive.metastore.api.FieldSchema; -import org.apache.hadoop.hive.metastore.api.Table; -import org.apache.hadoop.hive.service.HiveInterface; -import org.apache.thrift.TException; - -/** - * HiveDatabaseMetaData. - * - */ -public class HiveDatabaseMetaData implements java.sql.DatabaseMetaData { - - private final HiveInterface client; - private static final String CATALOG_SEPARATOR = "."; - - private static final char SEARCH_STRING_ESCAPE = '\\'; - - // The maximum column length = MFieldSchema.FNAME in metastore/src/model/package.jdo - private static final int maxColumnNameLength = 128; - - /** - * - */ - public HiveDatabaseMetaData(HiveInterface client) { - this.client = client; - } - - public boolean allProceduresAreCallable() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean allTablesAreSelectable() throws SQLException { - return true; - } - - public boolean autoCommitFailureClosesAllResultSets() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean dataDefinitionCausesTransactionCommit() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean dataDefinitionIgnoredInTransactions() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean deletesAreDetected(int type) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getAttributes(String catalog, String schemaPattern, - String typeNamePattern, String attributeNamePattern) throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getBestRowIdentifier(String catalog, String schema, - String table, int scope, boolean nullable) throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getCatalogSeparator() throws SQLException { - return CATALOG_SEPARATOR; - } - - public String getCatalogTerm() throws SQLException { - return "database"; - } - - public ResultSet getCatalogs() throws SQLException { - try { - // TODO a client call to get the schema's after HIVE-675 is implemented - final List catalogs = new ArrayList(); - catalogs.add("default"); - return new HiveMetaDataResultSet(Arrays.asList("TABLE_CAT") - , Arrays.asList("STRING") - , catalogs) { - private int cnt = 0; - - public boolean next() throws SQLException { - if (cnt a = new ArrayList(1); - a.add(data.get(cnt)); // TABLE_CAT String => table catalog (may be null) - row = a; - cnt++; - return true; - } else { - return false; - } - } - - public T getObject(String columnLabel, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - public T getObject(int columnIndex, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - }; - } catch (Exception e) { - throw new SQLException(e); - } - } - - public ResultSet getClientInfoProperties() throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getColumnPrivileges(String catalog, String schema, - String table, String columnNamePattern) throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getPseudoColumns(String catalog, String schemaPattern, - String tableNamePattern, String columnNamePattern) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean generatedKeyAlwaysReturned() throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - - /** - * Convert a pattern containing JDBC catalog search wildcards into - * Java regex patterns. - * - * @param pattern input which may contain '%' or '_' wildcard characters, or - * these characters escaped using {@link #getSearchStringEscape()}. - * @return replace %/_ with regex search characters, also handle escaped - * characters. - */ - private String convertPattern(final String pattern) { - if (pattern==null) { - return ".*"; - } else { - StringBuilder result = new StringBuilder(pattern.length()); - - boolean escaped = false; - for (int i = 0, len = pattern.length(); i < len; i++) { - char c = pattern.charAt(i); - if (escaped) { - if (c != SEARCH_STRING_ESCAPE) { - escaped = false; - } - result.append(c); - } else { - if (c == SEARCH_STRING_ESCAPE) { - escaped = true; - continue; - } else if (c == '%') { - result.append(".*"); - } else if (c == '_') { - result.append('.'); - } else { - result.append(Character.toLowerCase(c)); - } - } - } - - return result.toString(); - } - } - - public ResultSet getColumns(String catalog, final String schemaPattern - , final String tableNamePattern - , final String columnNamePattern) throws SQLException { - List columns = new ArrayList(); - try { - if (catalog==null) { - catalog = "default"; - } - - String regtableNamePattern = convertPattern(tableNamePattern); - String regcolumnNamePattern = convertPattern(columnNamePattern); - - List tables = client.get_tables(catalog, "*"); - for (String table: tables) { - if (table.matches(regtableNamePattern)) { - List fields = client.get_schema(catalog, table); - int ordinalPos = 1; - for (FieldSchema field: fields) { - if (field.getName().matches(regcolumnNamePattern)) { - columns.add(new JdbcColumn(field.getName(), table, catalog - , field.getType(), field.getComment(), ordinalPos)); - ordinalPos++; - } - } - } - } - Collections.sort(columns, new GetColumnsComparator()); - - return new HiveMetaDataResultSet( - Arrays.asList("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE" - , "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS" - , "NUM_PREC_RADIX", "NULLABLE", "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE" - , "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION" - , "IS_NULLABLE", "SCOPE_CATLOG", "SCOPE_SCHEMA", "SCOPE_TABLE" - , "SOURCE_DATA_TYPE") - , Arrays.asList("STRING", "STRING", "STRING", "STRING", "INT", "STRING" - , "INT", "INT", "INT", "INT", "INT", "STRING" - , "STRING", "INT", "INT", "INT", "INT" - , "STRING", "STRING", "STRING", "STRING", "INT") - , columns) { - - private int cnt = 0; - - public boolean next() throws SQLException { - if (cnt a = new ArrayList(20); - JdbcColumn column = data.get(cnt); - a.add(column.getTableCatalog()); // TABLE_CAT String => table catalog (may be null) - a.add(null); // TABLE_SCHEM String => table schema (may be null) - a.add(column.getTableName()); // TABLE_NAME String => table name - a.add(column.getColumnName()); // COLUMN_NAME String => column name - a.add(column.getSqlType()); // DATA_TYPE short => SQL type from java.sql.Types - a.add(column.getType()); // TYPE_NAME String => Data source dependent type name. - a.add(column.getColumnSize()); // COLUMN_SIZE int => column size. - a.add(null); // BUFFER_LENGTH is not used. - a.add(column.getDecimalDigits()); // DECIMAL_DIGITS int => number of fractional digits - a.add(column.getNumPrecRadix()); // NUM_PREC_RADIX int => typically either 10 or 2 - a.add(DatabaseMetaData.columnNullable); // NULLABLE int => is NULL allowed? - a.add(column.getComment()); // REMARKS String => comment describing column (may be null) - a.add(null); // COLUMN_DEF String => default value (may be null) - a.add(null); // SQL_DATA_TYPE int => unused - a.add(null); // SQL_DATETIME_SUB int => unused - a.add(null); // CHAR_OCTET_LENGTH int - a.add(column.getOrdinalPos()); // ORDINAL_POSITION int - a.add("YES"); // IS_NULLABLE String - a.add(null); // SCOPE_CATLOG String - a.add(null); // SCOPE_SCHEMA String - a.add(null); // SCOPE_TABLE String - a.add(null); // SOURCE_DATA_TYPE short - row = a; - cnt++; - return true; - } else { - return false; - } - } - - public T getObject(String columnLabel, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - public T getObject(int columnIndex, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - }; - } catch (Exception e) { - throw new SQLException(e); - } - } - - /** - * We sort the output of getColumns to guarantee jdbc compliance. - * First check by table name then by ordinal position - */ - private class GetColumnsComparator implements Comparator { - - public int compare(JdbcColumn o1, JdbcColumn o2) { - int compareName = o1.getTableName().compareTo(o2.getTableName()); - if (compareName==0) { - if (o1.getOrdinalPos() > o2.getOrdinalPos()) { - return 1; - } else if (o1.getOrdinalPos() < o2.getOrdinalPos()) { - return -1; - } - return 0; - } else { - return compareName; - } - } - } - - public Connection getConnection() throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getCrossReference(String primaryCatalog, - String primarySchema, String primaryTable, String foreignCatalog, - String foreignSchema, String foreignTable) throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getDatabaseMajorVersion() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getDatabaseMinorVersion() throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getDatabaseProductName() throws SQLException { - return "Hive"; - } - - public String getDatabaseProductVersion() throws SQLException { - try { - return client.getVersion(); - } catch (TException e) { - throw new SQLException(e); - } - } - - public int getDefaultTransactionIsolation() throws SQLException { - return Connection.TRANSACTION_NONE; - } - - public int getDriverMajorVersion() { - return HiveDriver.getMajorDriverVersion(); - } - - public int getDriverMinorVersion() { - return HiveDriver.getMinorDriverVersion(); - } - - public String getDriverName() throws SQLException { - return HiveDriver.fetchManifestAttribute(Attributes.Name.IMPLEMENTATION_TITLE); - } - - public String getDriverVersion() throws SQLException { - return HiveDriver.fetchManifestAttribute(Attributes.Name.IMPLEMENTATION_VERSION); - } - - public ResultSet getExportedKeys(String catalog, String schema, String table) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getExtraNameCharacters() throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getFunctionColumns(String arg0, String arg1, String arg2, - String arg3) throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getFunctions(String arg0, String arg1, String arg2) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getIdentifierQuoteString() throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getImportedKeys(String catalog, String schema, String table) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getIndexInfo(String catalog, String schema, String table, - boolean unique, boolean approximate) throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getJDBCMajorVersion() throws SQLException { - return 3; - } - - public int getJDBCMinorVersion() throws SQLException { - return 0; - } - - public int getMaxBinaryLiteralLength() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxCatalogNameLength() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxCharLiteralLength() throws SQLException { - throw new SQLException("Method not supported"); - } - - /** - * Returns the value of maxColumnNameLength. - * - */ - public int getMaxColumnNameLength() throws SQLException { - return maxColumnNameLength; - } - - public int getMaxColumnsInGroupBy() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxColumnsInIndex() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxColumnsInOrderBy() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxColumnsInSelect() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxColumnsInTable() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxConnections() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxCursorNameLength() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxIndexLength() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxProcedureNameLength() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxRowSize() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxSchemaNameLength() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxStatementLength() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxStatements() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxTableNameLength() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxTablesInSelect() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getMaxUserNameLength() throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getNumericFunctions() throws SQLException { - return ""; - } - - public ResultSet getPrimaryKeys(String catalog, String schema, String table) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getProcedureColumns(String catalog, String schemaPattern, - String procedureNamePattern, String columnNamePattern) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getProcedureTerm() throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getProcedures(String catalog, String schemaPattern, - String procedureNamePattern) throws SQLException { - return null; - } - - public int getResultSetHoldability() throws SQLException { - throw new SQLException("Method not supported"); - } - - public RowIdLifetime getRowIdLifetime() throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getSQLKeywords() throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getSQLStateType() throws SQLException { - return DatabaseMetaData.sqlStateSQL99; - } - - public String getSchemaTerm() throws SQLException { - return ""; - } - - public ResultSet getSchemas() throws SQLException { - return getSchemas(null, null); - } - - public ResultSet getSchemas(String catalog, String schemaPattern) - throws SQLException { - return new HiveMetaDataResultSet(Arrays.asList("TABLE_SCHEM", "TABLE_CATALOG") - , Arrays.asList("STRING", "STRING"), null) { - - public boolean next() throws SQLException { - return false; - } - - public T getObject(String columnLabel, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - public T getObject(int columnIndex, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - }; - - } - - public String getSearchStringEscape() throws SQLException { - return String.valueOf(SEARCH_STRING_ESCAPE); - } - - public String getStringFunctions() throws SQLException { - return ""; - } - - public ResultSet getSuperTables(String catalog, String schemaPattern, - String tableNamePattern) throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getSuperTypes(String catalog, String schemaPattern, - String typeNamePattern) throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getSystemFunctions() throws SQLException { - return ""; - } - - public ResultSet getTablePrivileges(String catalog, String schemaPattern, - String tableNamePattern) throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getTableTypes() throws SQLException { - final TableType[] tt = TableType.values(); - ResultSet result = new HiveMetaDataResultSet( - Arrays.asList("TABLE_TYPE") - , Arrays.asList("STRING"), new ArrayList(Arrays.asList(tt))) { - private int cnt = 0; - - public boolean next() throws SQLException { - if (cnt a = new ArrayList(1); - a.add(toJdbcTableType(data.get(cnt).name())); - row = a; - cnt++; - return true; - } else { - return false; - } - } - - public T getObject(String columnLabel, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - public T getObject(int columnIndex, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - }; - return result; - } - - public ResultSet getTables(String catalog, String schemaPattern, - String tableNamePattern, String[] types) throws SQLException { - final List tablesstr; - final List resultTables = new ArrayList(); - final String resultCatalog; - if (catalog==null) { // On jdbc the default catalog is null but on hive it's "default" - resultCatalog = "default"; - } else { - resultCatalog = catalog; - } - - String regtableNamePattern = convertPattern(tableNamePattern); - try { - tablesstr = client.get_tables(resultCatalog, "*"); - for (String tablestr: tablesstr) { - if (tablestr.matches(regtableNamePattern)) { - Table tbl = client.get_table(resultCatalog, tablestr); - if (types == null) { - resultTables.add(new JdbcTable(resultCatalog, tbl.getTableName(), tbl.getTableType() - , tbl.getParameters().get("comment"))); - } else { - String tableType = toJdbcTableType(tbl.getTableType()); - for(String type : types) { - if (type.equalsIgnoreCase(tableType)) { - resultTables.add(new JdbcTable(resultCatalog, tbl.getTableName(), tbl.getTableType() - , tbl.getParameters().get("comment"))); - break; - } - } - } - } - } - Collections.sort(resultTables, new GetTablesComparator()); - } catch (Exception e) { - throw new SQLException(e); - } - ResultSet result = new HiveMetaDataResultSet( - Arrays.asList("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "TABLE_TYPE", "REMARKS") - , Arrays.asList("STRING", "STRING", "STRING", "STRING", "STRING") - , resultTables) { - private int cnt = 0; - - public boolean next() throws SQLException { - if (cnt a = new ArrayList(5); - JdbcTable table = data.get(cnt); - a.add(table.getTableCatalog()); // TABLE_CAT String => table catalog (may be null) - a.add(null); // TABLE_SCHEM String => table schema (may be null) - a.add(table.getTableName()); // TABLE_NAME String => table name - try { - a.add(table.getSqlTableType()); // TABLE_TYPE String => "TABLE","VIEW" - } catch (Exception e) { - throw new SQLException(e); - } - a.add(table.getComment()); // REMARKS String => explanatory comment on the table - row = a; - cnt++; - return true; - } else { - return false; - } - } - - public T getObject(String columnLabel, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - public T getObject(int columnIndex, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - }; - return result; - } - - /** - * We sort the output of getTables to guarantee jdbc compliance. - * First check by table type then by table name - */ - private class GetTablesComparator implements Comparator { - - public int compare(JdbcTable o1, JdbcTable o2) { - int compareType = o1.getType().compareTo(o2.getType()); - if (compareType==0) { - return o1.getTableName().compareTo(o2.getTableName()); - } else { - return compareType; - } - } - } - - /** - * Translate hive table types into jdbc table types. - * @param hivetabletype - * @return the type of the table - */ - public static String toJdbcTableType(String hivetabletype) { - if (hivetabletype==null) { - return null; - } else if (hivetabletype.equals(TableType.MANAGED_TABLE.toString())) { - return "TABLE"; - } else if (hivetabletype.equals(TableType.VIRTUAL_VIEW.toString())) { - return "VIEW"; - } else if (hivetabletype.equals(TableType.EXTERNAL_TABLE.toString())) { - return "EXTERNAL TABLE"; - } else { - return hivetabletype; - } - } - - public String getTimeDateFunctions() throws SQLException { - return ""; - } - - public ResultSet getTypeInfo() throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getUDTs(String catalog, String schemaPattern, - String typeNamePattern, int[] types) throws SQLException { - - return new HiveMetaDataResultSet( - Arrays.asList("TYPE_CAT", "TYPE_SCHEM", "TYPE_NAME", "CLASS_NAME", "DATA_TYPE" - , "REMARKS", "BASE_TYPE") - , Arrays.asList("STRING", "STRING", "STRING", "STRING", "INT", "STRING", "INT") - , null) { - - public boolean next() throws SQLException { - return false; - } - - public T getObject(String columnLabel, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - public T getObject(int columnIndex, Class type) - throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - }; - } - - public String getURL() throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getUserName() throws SQLException { - throw new SQLException("Method not supported"); - } - - public ResultSet getVersionColumns(String catalog, String schema, String table) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean insertsAreDetected(int type) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isCatalogAtStart() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isReadOnly() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean locatorsUpdateCopy() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean nullPlusNonNullIsNull() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean nullsAreSortedAtEnd() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean nullsAreSortedAtStart() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean nullsAreSortedHigh() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean nullsAreSortedLow() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean othersDeletesAreVisible(int type) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean othersInsertsAreVisible(int type) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean othersUpdatesAreVisible(int type) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean ownDeletesAreVisible(int type) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean ownInsertsAreVisible(int type) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean ownUpdatesAreVisible(int type) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean storesLowerCaseIdentifiers() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean storesMixedCaseIdentifiers() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean storesUpperCaseIdentifiers() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsANSI92EntryLevelSQL() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsANSI92FullSQL() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsANSI92IntermediateSQL() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsAlterTableWithAddColumn() throws SQLException { - return true; - } - - public boolean supportsAlterTableWithDropColumn() throws SQLException { - return false; - } - - public boolean supportsBatchUpdates() throws SQLException { - return false; - } - - public boolean supportsCatalogsInDataManipulation() throws SQLException { - return false; - } - - public boolean supportsCatalogsInIndexDefinitions() throws SQLException { - return false; - } - - public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { - return false; - } - - public boolean supportsCatalogsInProcedureCalls() throws SQLException { - return false; - } - - public boolean supportsCatalogsInTableDefinitions() throws SQLException { - return false; - } - - public boolean supportsColumnAliasing() throws SQLException { - return true; - } - - public boolean supportsConvert() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsConvert(int fromType, int toType) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsCoreSQLGrammar() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsCorrelatedSubqueries() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsDataDefinitionAndDataManipulationTransactions() - throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsDataManipulationTransactionsOnly() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsDifferentTableCorrelationNames() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsExpressionsInOrderBy() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsExtendedSQLGrammar() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsFullOuterJoins() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsGetGeneratedKeys() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsGroupBy() throws SQLException { - return true; - } - - public boolean supportsGroupByBeyondSelect() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsGroupByUnrelated() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsIntegrityEnhancementFacility() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsLikeEscapeClause() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsLimitedOuterJoins() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsMinimumSQLGrammar() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsMixedCaseIdentifiers() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsMultipleOpenResults() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsMultipleResultSets() throws SQLException { - return false; - } - - public boolean supportsMultipleTransactions() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsNamedParameters() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsNonNullableColumns() throws SQLException { - return false; - } - - public boolean supportsOpenCursorsAcrossCommit() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsOpenCursorsAcrossRollback() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsOpenStatementsAcrossCommit() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsOpenStatementsAcrossRollback() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsOrderByUnrelated() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsOuterJoins() throws SQLException { - return true; - } - - public boolean supportsPositionedDelete() throws SQLException { - return false; - } - - public boolean supportsPositionedUpdate() throws SQLException { - return false; - } - - public boolean supportsResultSetConcurrency(int type, int concurrency) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsResultSetHoldability(int holdability) - throws SQLException { - return false; - } - - public boolean supportsResultSetType(int type) throws SQLException { - return true; - } - - public boolean supportsSavepoints() throws SQLException { - return false; - } - - public boolean supportsSchemasInDataManipulation() throws SQLException { - return false; - } - - public boolean supportsSchemasInIndexDefinitions() throws SQLException { - return false; - } - - public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { - return false; - } - - public boolean supportsSchemasInProcedureCalls() throws SQLException { - return false; - } - - public boolean supportsSchemasInTableDefinitions() throws SQLException { - return false; - } - - public boolean supportsSelectForUpdate() throws SQLException { - return false; - } - - public boolean supportsStatementPooling() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsStoredProcedures() throws SQLException { - return false; - } - - public boolean supportsSubqueriesInComparisons() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsSubqueriesInExists() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsSubqueriesInIns() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsSubqueriesInQuantifieds() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsTableCorrelationNames() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsTransactionIsolationLevel(int level) - throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsTransactions() throws SQLException { - return false; - } - - public boolean supportsUnion() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean supportsUnionAll() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean updatesAreDetected(int type) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean usesLocalFilePerTable() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean usesLocalFiles() throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - throw new SQLException("Method not supported"); - } - - public T unwrap(Class iface) throws SQLException { - throw new SQLException("Method not supported"); - } - - public static void main(String[] args) throws SQLException { - HiveDatabaseMetaData meta = new HiveDatabaseMetaData(null); - System.out.println("DriverName: " + meta.getDriverName()); - System.out.println("DriverVersion: " + meta.getDriverVersion()); - } - -} - Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java (working copy) @@ -1,1300 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Array; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Connection; -import java.sql.Date; -import java.sql.NClob; -import java.sql.ParameterMetaData; -import java.sql.PreparedStatement; -import java.sql.Ref; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.RowId; -import java.sql.SQLException; -import java.sql.SQLWarning; -import java.sql.SQLXML; -import java.sql.Time; -import java.sql.Timestamp; -import java.text.MessageFormat; -import java.util.Calendar; -import java.util.HashMap; - -import org.apache.hadoop.hive.service.HiveInterface; -import org.apache.hadoop.hive.service.HiveServerException; - -/** - * HivePreparedStatement. - * - */ -public class HivePreparedStatement implements PreparedStatement { - private final String sql; - private HiveInterface client; - /** - * save the SQL parameters {paramLoc:paramValue} - */ - private final HashMap parameters=new HashMap(); - - /** - * We need to keep a reference to the result set to support the following: - * - * statement.execute(String sql); - * statement.getResultSet(); - * . - */ - private ResultSet resultSet = null; - /** - * The maximum number of rows this statement should return (0 => all rows). - */ - private int maxRows = 0; - - /** - * Add SQLWarnings to the warningChain if needed. - */ - private SQLWarning warningChain = null; - - /** - * Keep state so we can fail certain calls made after close(). - */ - private boolean isClosed = false; - - /** - * keep the current ResultRet update count - */ - private final int updateCount=0; - - /** - * - */ - public HivePreparedStatement(HiveInterface client, - String sql) { - this.client = client; - this.sql = sql; - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#addBatch() - */ - - public void addBatch() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#clearParameters() - */ - - public void clearParameters() throws SQLException { - this.parameters.clear(); - } - - /** - * Invokes executeQuery(sql) using the sql provided to the constructor. - * - * @return boolean Returns true if a resultSet is created, false if not. - * Note: If the result set is empty a true is returned. - * - * @throws SQLException - */ - - public boolean execute() throws SQLException { - ResultSet rs = executeImmediate(sql); - return rs != null; - } - - /** - * Invokes executeQuery(sql) using the sql provided to the constructor. - * - * @return ResultSet - * @throws SQLException - */ - - public ResultSet executeQuery() throws SQLException { - return executeImmediate(sql); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#executeUpdate() - */ - - public int executeUpdate() throws SQLException { - executeImmediate(sql); - return updateCount; - } - - /** - * Executes the SQL statement. - * - * @param sql The sql, as a string, to execute - * @return ResultSet - * @throws SQLException if the prepared statement is closed or there is a database error. - * caught Exceptions are thrown as SQLExceptions with the description - * "08S01". - */ - - protected ResultSet executeImmediate(String sql) throws SQLException { - if (isClosed) { - throw new SQLException("Can't execute after statement has been closed"); - } - - try { - clearWarnings(); - resultSet = null; - if (sql.contains("?")) { - sql = updateSql(sql, parameters); - } - client.execute(sql); - } catch (HiveServerException e) { - throw new SQLException(e.getMessage(), e.getSQLState(), e.getErrorCode(), e); - } catch (Exception ex) { - throw new SQLException(ex.toString(), "08S01", ex); - } - resultSet = new HiveQueryResultSet(client, maxRows); - return resultSet; - } - - /** - * update the SQL string with parameters set by setXXX methods of {@link PreparedStatement} - * - * @param sql - * @param parameters - * @return updated SQL string - */ - private String updateSql(final String sql, HashMap parameters) { - - StringBuffer newSql = new StringBuffer(sql); - - int paramLoc = 1; - while (getCharIndexFromSqlByParamLocation(sql, '?', paramLoc) > 0) { - // check the user has set the needs parameters - if (parameters.containsKey(paramLoc)) { - int tt = getCharIndexFromSqlByParamLocation(newSql.toString(), '?', 1); - newSql.deleteCharAt(tt); - newSql.insert(tt, parameters.get(paramLoc)); - } - paramLoc++; - } - - return newSql.toString(); - - } - - /** - * Get the index of given char from the SQL string by parameter location - *
The -1 will be return, if nothing found - * - * @param sql - * @param cchar - * @param paramLoc - * @return - */ - private int getCharIndexFromSqlByParamLocation(final String sql, final char cchar, final int paramLoc) { - int signalCount = 0; - int charIndex = -1; - int num = 0; - for (int i = 0; i < sql.length(); i++) { - char c = sql.charAt(i); - if (c == '\'' || c == '\\')// record the count of char "'" and char "\" - { - signalCount++; - } else if (c == cchar && signalCount % 2 == 0) {// check if the ? is really the parameter - num++; - if (num == paramLoc) { - charIndex = i; - break; - } - } - } - return charIndex; - } - - - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#getMetaData() - */ - - public ResultSetMetaData getMetaData() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#getParameterMetaData() - */ - - public ParameterMetaData getParameterMetaData() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setArray(int, java.sql.Array) - */ - - public void setArray(int i, Array x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream) - */ - - public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream, - * int) - */ - - public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream, - * long) - */ - - public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBigDecimal(int, java.math.BigDecimal) - */ - - public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream) - */ - - public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, - * int) - */ - - public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, - * long) - */ - - public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBlob(int, java.sql.Blob) - */ - - public void setBlob(int i, Blob x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBlob(int, java.io.InputStream) - */ - - public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBlob(int, java.io.InputStream, long) - */ - - public void setBlob(int parameterIndex, InputStream inputStream, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBoolean(int, boolean) - */ - - public void setBoolean(int parameterIndex, boolean x) throws SQLException { - this.parameters.put(parameterIndex, ""+x); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setByte(int, byte) - */ - - public void setByte(int parameterIndex, byte x) throws SQLException { - this.parameters.put(parameterIndex, ""+x); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setBytes(int, byte[]) - */ - - public void setBytes(int parameterIndex, byte[] x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader) - */ - - public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader, - * int) - */ - - public void setCharacterStream(int parameterIndex, Reader reader, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader, - * long) - */ - - public void setCharacterStream(int parameterIndex, Reader reader, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setClob(int, java.sql.Clob) - */ - - public void setClob(int i, Clob x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setClob(int, java.io.Reader) - */ - - public void setClob(int parameterIndex, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setClob(int, java.io.Reader, long) - */ - - public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setDate(int, java.sql.Date) - */ - - public void setDate(int parameterIndex, Date x) throws SQLException { - this.parameters.put(parameterIndex, x.toString()); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setDate(int, java.sql.Date, - * java.util.Calendar) - */ - - public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setDouble(int, double) - */ - - public void setDouble(int parameterIndex, double x) throws SQLException { - this.parameters.put(parameterIndex,""+x); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setFloat(int, float) - */ - - public void setFloat(int parameterIndex, float x) throws SQLException { - this.parameters.put(parameterIndex,""+x); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setInt(int, int) - */ - - public void setInt(int parameterIndex, int x) throws SQLException { - this.parameters.put(parameterIndex,""+x); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setLong(int, long) - */ - - public void setLong(int parameterIndex, long x) throws SQLException { - this.parameters.put(parameterIndex,""+x); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader) - */ - - public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader, - * long) - */ - - public void setNCharacterStream(int parameterIndex, Reader value, long length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNClob(int, java.sql.NClob) - */ - - public void setNClob(int parameterIndex, NClob value) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNClob(int, java.io.Reader) - */ - - public void setNClob(int parameterIndex, Reader reader) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNClob(int, java.io.Reader, long) - */ - - public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNString(int, java.lang.String) - */ - - public void setNString(int parameterIndex, String value) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNull(int, int) - */ - - public void setNull(int parameterIndex, int sqlType) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setNull(int, int, java.lang.String) - */ - - public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setObject(int, java.lang.Object) - */ - - public void setObject(int parameterIndex, Object x) throws SQLException { - if (x instanceof String) { - setString(parameterIndex, (String) x); - } else if (x instanceof Short) { - setShort(parameterIndex, ((Short) x).shortValue()); - } else if (x instanceof Integer) { - setInt(parameterIndex, ((Integer) x).intValue()); - } else if (x instanceof Long) { - setLong(parameterIndex, ((Long) x).longValue()); - } else if (x instanceof Float) { - setFloat(parameterIndex, ((Float) x).floatValue()); - } else if (x instanceof Double) { - setDouble(parameterIndex, ((Double) x).doubleValue()); - } else if (x instanceof Boolean) { - setBoolean(parameterIndex, ((Boolean) x).booleanValue()); - } else if (x instanceof Byte) { - setByte(parameterIndex, ((Byte) x).byteValue()); - } else if (x instanceof Character) { - setString(parameterIndex, ((Character) x).toString()); - } else { - // Can't infer a type. - throw new SQLException( - MessageFormat - .format( - "Can''t infer the SQL type to use for an instance of {0}. Use setObject() with an explicit Types value to specify the type to use.", - x.getClass().getName())); - } - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setObject(int, java.lang.Object, int) - */ - - public void setObject(int parameterIndex, Object x, int targetSqlType) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setObject(int, java.lang.Object, int, int) - */ - - public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setRef(int, java.sql.Ref) - */ - - public void setRef(int i, Ref x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setRowId(int, java.sql.RowId) - */ - - public void setRowId(int parameterIndex, RowId x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setSQLXML(int, java.sql.SQLXML) - */ - - public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setShort(int, short) - */ - - public void setShort(int parameterIndex, short x) throws SQLException { - this.parameters.put(parameterIndex,""+x); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setString(int, java.lang.String) - */ - - public void setString(int parameterIndex, String x) throws SQLException { - x=x.replace("'", "\\'"); - this.parameters.put(parameterIndex,"'"+x+"'"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setTime(int, java.sql.Time) - */ - - public void setTime(int parameterIndex, Time x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setTime(int, java.sql.Time, - * java.util.Calendar) - */ - - public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setTimestamp(int, java.sql.Timestamp) - */ - - public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { - this.parameters.put(parameterIndex, x.toString()); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setTimestamp(int, java.sql.Timestamp, - * java.util.Calendar) - */ - - public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setURL(int, java.net.URL) - */ - - public void setURL(int parameterIndex, URL x) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.PreparedStatement#setUnicodeStream(int, java.io.InputStream, - * int) - */ - - public void setUnicodeStream(int parameterIndex, InputStream x, int length) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#addBatch(java.lang.String) - */ - - public void addBatch(String sql) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#cancel() - */ - - public void cancel() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#clearBatch() - */ - - public void clearBatch() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#clearWarnings() - */ - - public void clearWarnings() throws SQLException { - warningChain=null; - } - - - public void closeOnCompletion() throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - /** - * Closes the prepared statement. - * - * @throws SQLException - */ - - public void close() throws SQLException { - client = null; - if (resultSet!=null) { - resultSet.close(); - resultSet = null; - } - isClosed = true; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String) - */ - - public boolean execute(String sql) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String, int) - */ - - public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String, int[]) - */ - - public boolean execute(String sql, int[] columnIndexes) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#execute(java.lang.String, java.lang.String[]) - */ - - public boolean execute(String sql, String[] columnNames) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeBatch() - */ - - public int[] executeBatch() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeQuery(java.lang.String) - */ - - public ResultSet executeQuery(String sql) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String) - */ - - public int executeUpdate(String sql) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String, int) - */ - - public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String, int[]) - */ - - public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#executeUpdate(java.lang.String, java.lang.String[]) - */ - - public int executeUpdate(String sql, String[] columnNames) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getConnection() - */ - - public Connection getConnection() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getFetchDirection() - */ - - public int getFetchDirection() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getFetchSize() - */ - - public int getFetchSize() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getGeneratedKeys() - */ - - public ResultSet getGeneratedKeys() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMaxFieldSize() - */ - - public int getMaxFieldSize() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMaxRows() - */ - - public int getMaxRows() throws SQLException { - return this.maxRows; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMoreResults() - */ - - public boolean getMoreResults() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getMoreResults(int) - */ - - public boolean getMoreResults(int current) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getQueryTimeout() - */ - - public int getQueryTimeout() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSet() - */ - - public ResultSet getResultSet() throws SQLException { - return this.resultSet; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSetConcurrency() - */ - - public int getResultSetConcurrency() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSetHoldability() - */ - - public int getResultSetHoldability() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getResultSetType() - */ - - public int getResultSetType() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getUpdateCount() - */ - - public int getUpdateCount() throws SQLException { - return updateCount; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#getWarnings() - */ - - public SQLWarning getWarnings() throws SQLException { - return warningChain; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#isClosed() - */ - - public boolean isClosed() throws SQLException { - return isClosed; - } - - public boolean isCloseOnCompletion() throws SQLException { - //JDK 1.7 - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#isPoolable() - */ - - public boolean isPoolable() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setCursorName(java.lang.String) - */ - - public void setCursorName(String name) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setEscapeProcessing(boolean) - */ - - public void setEscapeProcessing(boolean enable) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setFetchDirection(int) - */ - - public void setFetchDirection(int direction) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setFetchSize(int) - */ - - public void setFetchSize(int rows) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setMaxFieldSize(int) - */ - - public void setMaxFieldSize(int max) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setMaxRows(int) - */ - - public void setMaxRows(int max) throws SQLException { - if (max < 0) { - throw new SQLException("max must be >= 0"); - } - this.maxRows = max; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setPoolable(boolean) - */ - - public void setPoolable(boolean poolable) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Statement#setQueryTimeout(int) - */ - - public void setQueryTimeout(int seconds) throws SQLException { - // TODO Auto-generated method stub - // throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#isWrapperFor(java.lang.Class) - */ - - public boolean isWrapperFor(Class iface) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#unwrap(java.lang.Class) - */ - - public T unwrap(Class iface) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - -} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDataSource.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDataSource.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDataSource.java (working copy) @@ -1,140 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.logging.Logger; - -import javax.sql.DataSource; - -/** - * HiveDataSource. - * - */ -public class HiveDataSource implements DataSource { - - /** - * - */ - public HiveDataSource() { - // TODO Auto-generated constructor stub - } - - /* - * (non-Javadoc) - * - * @see javax.sql.DataSource#getConnection() - */ - - public Connection getConnection() throws SQLException { - return getConnection("", ""); - } - - /* - * (non-Javadoc) - * - * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String) - */ - - public Connection getConnection(String username, String password) - throws SQLException { - try { - return new HiveConnection("", null); - } catch (Exception ex) { - throw new SQLException("Error in getting HiveConnection",ex); - } - } - - /* - * (non-Javadoc) - * - * @see javax.sql.CommonDataSource#getLogWriter() - */ - - public PrintWriter getLogWriter() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see javax.sql.CommonDataSource#getLoginTimeout() - */ - - public int getLoginTimeout() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see javax.sql.CommonDataSource#setLogWriter(java.io.PrintWriter) - */ - - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - // JDK 1.7 - throw new SQLFeatureNotSupportedException("Method not supported"); - } - - - public void setLogWriter(PrintWriter arg0) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see javax.sql.CommonDataSource#setLoginTimeout(int) - */ - - public void setLoginTimeout(int arg0) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#isWrapperFor(java.lang.Class) - */ - - public boolean isWrapperFor(Class arg0) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#unwrap(java.lang.Class) - */ - - public T unwrap(Class arg0) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - -} - Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDriver.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDriver.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDriver.java (working copy) @@ -1,307 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.io.IOException; -import java.net.URL; -import java.sql.Connection; -import java.sql.Driver; -import java.sql.DriverPropertyInfo; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.Properties; -import java.util.jar.Attributes; -import java.util.jar.Manifest; -import java.util.logging.Logger; -import java.util.regex.Pattern; - -/** - * HiveDriver. - * - */ -public class HiveDriver implements Driver { - static { - try { - java.sql.DriverManager.registerDriver(new HiveDriver()); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * Is this driver JDBC compliant? - */ - private static final boolean JDBC_COMPLIANT = false; - - /** - * The required prefix for the connection URL. - */ - private static final String URL_PREFIX = "jdbc:hive://"; - - /** - * If host is provided, without a port. - */ - private static final String DEFAULT_PORT = "10000"; - - /** - * Property key for the database name. - */ - private static final String DBNAME_PROPERTY_KEY = "DBNAME"; - - /** - * Property key for the Hive Server host. - */ - private static final String HOST_PROPERTY_KEY = "HOST"; - - /** - * Property key for the Hive Server port. - */ - private static final String PORT_PROPERTY_KEY = "PORT"; - - /** - * - */ - public HiveDriver() { - // TODO Auto-generated constructor stub - SecurityManager security = System.getSecurityManager(); - if (security != null) { - security.checkWrite("foobah"); - } - } - - /** - * Checks whether a given url is in a valid format. - * - * The current uri format is: jdbc:hive://[host[:port]] - * - * jdbc:hive:// - run in embedded mode jdbc:hive://localhost - connect to - * localhost default port (10000) jdbc:hive://localhost:5050 - connect to - * localhost port 5050 - * - * TODO: - write a better regex. - decide on uri format - */ - - public boolean acceptsURL(String url) throws SQLException { - return Pattern.matches(URL_PREFIX + ".*", url); - } - - @Override - public Connection connect(String url, Properties info) throws SQLException { - return acceptsURL(url) ? new HiveConnection(url, info) : null; - } - - /** - * Package scoped access to the Driver's Major Version - * @return The Major version number of the driver. -1 if it cannot be determined from the - * manifest.mf file. - */ - static int getMajorDriverVersion() { - int version = -1; - try { - String fullVersion = HiveDriver.fetchManifestAttribute( - Attributes.Name.IMPLEMENTATION_VERSION); - String[] tokens = fullVersion.split("\\."); //$NON-NLS-1$ - - if(tokens != null && tokens.length > 0 && tokens[0] != null) { - version = Integer.parseInt(tokens[0]); - } - } catch (Exception e) { - // Possible reasons to end up here: - // - Unable to read version from manifest.mf - // - Version string is not in the proper X.x.xxx format - version = -1; - } - return version; - } - - /** - * Package scoped access to the Driver's Minor Version - * @return The Minor version number of the driver. -1 if it cannot be determined from the - * manifest.mf file. - */ - static int getMinorDriverVersion() { - int version = -1; - try { - String fullVersion = HiveDriver.fetchManifestAttribute( - Attributes.Name.IMPLEMENTATION_VERSION); - String[] tokens = fullVersion.split("\\."); //$NON-NLS-1$ - - if(tokens != null && tokens.length > 1 && tokens[1] != null) { - version = Integer.parseInt(tokens[1]); - } - } catch (Exception e) { - // Possible reasons to end up here: - // - Unable to read version from manifest.mf - // - Version string is not in the proper X.x.xxx format - version = -1; - } - return version; - } - - /** - * Returns the major version of this driver. - */ - public int getMajorVersion() { - return HiveDriver.getMajorDriverVersion(); - } - - /** - * Returns the minor version of this driver. - */ - public int getMinorVersion() { - return HiveDriver.getMinorDriverVersion(); - } - - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - // JDK 1.7 - throw new SQLFeatureNotSupportedException("Method not supported"); - } - - public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { - if (info == null) { - info = new Properties(); - } - - if ((url != null) && url.startsWith(URL_PREFIX)) { - info = parseURL(url, info); - } - - DriverPropertyInfo hostProp = new DriverPropertyInfo(HOST_PROPERTY_KEY, - info.getProperty(HOST_PROPERTY_KEY, "")); - hostProp.required = false; - hostProp.description = "Hostname of Hive Server"; - - DriverPropertyInfo portProp = new DriverPropertyInfo(PORT_PROPERTY_KEY, - info.getProperty(PORT_PROPERTY_KEY, "")); - portProp.required = false; - portProp.description = "Port number of Hive Server"; - - DriverPropertyInfo dbProp = new DriverPropertyInfo(DBNAME_PROPERTY_KEY, - info.getProperty(DBNAME_PROPERTY_KEY, "default")); - dbProp.required = false; - dbProp.description = "Database name"; - - DriverPropertyInfo[] dpi = new DriverPropertyInfo[3]; - - dpi[0] = hostProp; - dpi[1] = portProp; - dpi[2] = dbProp; - - return dpi; - } - - /** - * Returns whether the driver is JDBC compliant. - */ - - public boolean jdbcCompliant() { - return JDBC_COMPLIANT; - } - - /** - * Takes a url in the form of jdbc:hive://[hostname]:[port]/[db_name] and - * parses it. Everything after jdbc:hive// is optional. - * - * @param url - * @param defaults - * @return - * @throws java.sql.SQLException - */ - private Properties parseURL(String url, Properties defaults) throws SQLException { - Properties urlProps = (defaults != null) ? new Properties(defaults) - : new Properties(); - - if (url == null || !url.startsWith(URL_PREFIX)) { - throw new SQLException("Invalid connection url: " + url); - } - - if (url.length() <= URL_PREFIX.length()) { - return urlProps; - } - - // [hostname]:[port]/[db_name] - String connectionInfo = url.substring(URL_PREFIX.length()); - - // [hostname]:[port] [db_name] - String[] hostPortAndDatabase = connectionInfo.split("/", 2); - - // [hostname]:[port] - if (hostPortAndDatabase[0].length() > 0) { - String[] hostAndPort = hostPortAndDatabase[0].split(":", 2); - urlProps.put(HOST_PROPERTY_KEY, hostAndPort[0]); - if (hostAndPort.length > 1) { - urlProps.put(PORT_PROPERTY_KEY, hostAndPort[1]); - } else { - urlProps.put(PORT_PROPERTY_KEY, DEFAULT_PORT); - } - } - - // [db_name] - if (hostPortAndDatabase.length > 1) { - urlProps.put(DBNAME_PROPERTY_KEY, hostPortAndDatabase[1]); - } - - return urlProps; - } - - /** - * Lazy-load manifest attributes as needed. - */ - private static Attributes manifestAttributes = null; - - /** - * Loads the manifest attributes from the jar. - * - * @throws java.net.MalformedURLException - * @throws IOException - */ - private static synchronized void loadManifestAttributes() throws IOException { - if (manifestAttributes != null) { - return; - } - Class clazz = HiveDriver.class; - String classContainer = clazz.getProtectionDomain().getCodeSource() - .getLocation().toString(); - URL manifestUrl = new URL("jar:" + classContainer - + "!/META-INF/MANIFEST.MF"); - Manifest manifest = new Manifest(manifestUrl.openStream()); - manifestAttributes = manifest.getMainAttributes(); - } - - /** - * Package scoped to allow manifest fetching from other HiveDriver classes - * Helper to initialize attributes and return one. - * - * @param attributeName - * @return - * @throws SQLException - */ - static String fetchManifestAttribute(Attributes.Name attributeName) - throws SQLException { - try { - loadManifestAttributes(); - } catch (IOException e) { - throw new SQLException("Couldn't load manifest attributes.", e); - } - return manifestAttributes.getValue(attributeName); - } - -} - Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveMetaDataResultSet.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveMetaDataResultSet.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveMetaDataResultSet.java (working copy) @@ -1,53 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public abstract class HiveMetaDataResultSet extends HiveBaseResultSet { - protected final List data; - - @SuppressWarnings("unchecked") - public HiveMetaDataResultSet(final List columnNames - , final List columnTypes - , final List data) throws SQLException { - if (data!=null) { - this.data = new ArrayList(data); - } else { - this.data = new ArrayList(); - } - if (columnNames!=null) { - this.columnNames = new ArrayList(columnNames); - } else { - this.columnNames = new ArrayList(); - } - if (columnTypes!=null) { - this.columnTypes = new ArrayList(columnTypes); - } else { - this.columnTypes = new ArrayList(); - } - } - - @Override - public void close() throws SQLException { - } - -} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSetMetaData.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSetMetaData.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveResultSetMetaData.java (working copy) @@ -1,197 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.util.List; - -import org.apache.hadoop.hive.serde.serdeConstants; - -/** - * HiveResultSetMetaData. - * - */ -public class HiveResultSetMetaData implements java.sql.ResultSetMetaData { - private final List columnNames; - private final List columnTypes; - - public HiveResultSetMetaData(List columnNames, - List columnTypes) { - this.columnNames = columnNames; - this.columnTypes = columnTypes; - } - - public String getCatalogName(int column) throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getColumnClassName(int column) throws SQLException { - throw new SQLException("Method not supported"); - } - - public int getColumnCount() throws SQLException { - return columnNames.size(); - } - - public int getColumnDisplaySize(int column) throws SQLException { - int columnType = getColumnType(column); - - return JdbcColumn.columnDisplaySize(columnType); - } - - public String getColumnLabel(int column) throws SQLException { - return columnNames.get(column - 1); - } - - public String getColumnName(int column) throws SQLException { - return columnNames.get(column - 1); - } - - public int getColumnType(int column) throws SQLException { - if (columnTypes == null) { - throw new SQLException( - "Could not determine column type name for ResultSet"); - } - - if (column < 1 || column > columnTypes.size()) { - throw new SQLException("Invalid column value: " + column); - } - - // we need to convert the thrift type to the SQL type - String type = columnTypes.get(column - 1); - - // we need to convert the thrift type to the SQL type - return Utils.hiveTypeToSqlType(type); - } - - public String getColumnTypeName(int column) throws SQLException { - if (columnTypes == null) { - throw new SQLException( - "Could not determine column type name for ResultSet"); - } - - if (column < 1 || column > columnTypes.size()) { - throw new SQLException("Invalid column value: " + column); - } - - // we need to convert the Hive type to the SQL type name - // TODO: this would be better handled in an enum - String type = columnTypes.get(column - 1); - if ("string".equalsIgnoreCase(type)) { - return serdeConstants.STRING_TYPE_NAME; - } else if ("float".equalsIgnoreCase(type)) { - return serdeConstants.FLOAT_TYPE_NAME; - } else if ("double".equalsIgnoreCase(type)) { - return serdeConstants.DOUBLE_TYPE_NAME; - } else if ("boolean".equalsIgnoreCase(type)) { - return serdeConstants.BOOLEAN_TYPE_NAME; - } else if ("tinyint".equalsIgnoreCase(type)) { - return serdeConstants.TINYINT_TYPE_NAME; - } else if ("smallint".equalsIgnoreCase(type)) { - return serdeConstants.SMALLINT_TYPE_NAME; - } else if ("int".equalsIgnoreCase(type)) { - return serdeConstants.INT_TYPE_NAME; - } else if ("bigint".equalsIgnoreCase(type)) { - return serdeConstants.BIGINT_TYPE_NAME; - } else if ("date".equalsIgnoreCase(type)) { - return serdeConstants.DATE_TYPE_NAME; - } else if ("timestamp".equalsIgnoreCase(type)) { - return serdeConstants.TIMESTAMP_TYPE_NAME; - } else if (type.startsWith("decimal")) { - return serdeConstants.DECIMAL_TYPE_NAME; - } else if (type.startsWith("map<")) { - return serdeConstants.STRING_TYPE_NAME; - } else if (type.startsWith("array<")) { - return serdeConstants.STRING_TYPE_NAME; - } else if (type.startsWith("struct<")) { - return serdeConstants.STRING_TYPE_NAME; - } - - throw new SQLException("Unrecognized column type: " + type); - } - - public int getPrecision(int column) throws SQLException { - int columnType = getColumnType(column); - - return JdbcColumn.columnPrecision(columnType); - } - - public int getScale(int column) throws SQLException { - int columnType = getColumnType(column); - - return JdbcColumn.columnScale(columnType); - } - - public String getSchemaName(int column) throws SQLException { - throw new SQLException("Method not supported"); - } - - public String getTableName(int column) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isAutoIncrement(int column) throws SQLException { - // Hive doesn't have an auto-increment concept - return false; - } - - public boolean isCaseSensitive(int column) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isCurrency(int column) throws SQLException { - // Hive doesn't support a currency type - return false; - } - - public boolean isDefinitelyWritable(int column) throws SQLException { - throw new SQLException("Method not supported"); - } - - public int isNullable(int column) throws SQLException { - // Hive doesn't have the concept of not-null - return ResultSetMetaData.columnNullable; - } - - public boolean isReadOnly(int column) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isSearchable(int column) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isSigned(int column) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isWritable(int column) throws SQLException { - throw new SQLException("Method not supported"); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - throw new SQLException("Method not supported"); - } - - public T unwrap(Class iface) throws SQLException { - throw new SQLException("Method not supported"); - } - -} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcTable.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcTable.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/JdbcTable.java (working copy) @@ -1,58 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.sql.SQLException; - -/** - * Table metadata. - */ -public class JdbcTable { - private String tableCatalog; - private String tableName; - private String type; - private String comment; - - public JdbcTable(String tableCatalog, String tableName, String type, String comment) { - this.tableCatalog = tableCatalog; - this.tableName = tableName; - this.type = type; - this.comment = comment; - } - - public String getTableCatalog() { - return tableCatalog; - } - - public String getTableName() { - return tableName; - } - - public String getType() { - return type; - } - - public String getSqlTableType() throws SQLException { - return HiveDatabaseMetaData.toJdbcTableType(type); - } - - public String getComment() { - return comment; - } -} Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java (working copy) @@ -1,708 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import org.apache.hadoop.hive.conf.HiveConf; -import org.apache.hadoop.hive.metastore.api.MetaException; -import org.apache.hadoop.hive.service.HiveClient; -import org.apache.hadoop.hive.service.HiveInterface; -import org.apache.hadoop.hive.service.HiveServer; -import org.apache.thrift.TException; -import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.protocol.TProtocol; -import org.apache.thrift.transport.TSocket; -import org.apache.thrift.transport.TTransport; -import org.apache.thrift.transport.TTransportException; -import java.util.concurrent.Executor; - -import java.sql.Array; -import java.sql.Blob; -import java.sql.CallableStatement; -import java.sql.Clob; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.NClob; -import java.sql.PreparedStatement; -import java.sql.SQLClientInfoException; -import java.sql.SQLException; -import java.sql.SQLWarning; -import java.sql.SQLXML; -import java.sql.Savepoint; -import java.sql.Statement; -import java.sql.Struct; -import java.util.Map; -import java.util.Properties; - -/** - * HiveConnection. - * - */ -public class HiveConnection implements java.sql.Connection { - private TTransport transport; - private HiveInterface client; - private boolean isClosed = true; - private SQLWarning warningChain = null; - - private static final String URI_PREFIX = "jdbc:hive://"; - - /** - * Create a connection to a local Hive - * - * @param hiveConf - * @throws SQLException - */ - public HiveConnection(HiveConf hiveConf) throws SQLException { - try { - client = new HiveServer.HiveServerHandler(hiveConf); - } catch (MetaException e) { - throw new SQLException("Error accessing Hive metastore: " - + e.getMessage(), "08S01",e); - } - isClosed = false; - configureConnection(); - } - - /** - * TODO: - parse uri (use java.net.URI?). - */ - public HiveConnection(String uri, Properties info) throws SQLException { - if (!uri.startsWith(URI_PREFIX)) { - throw new SQLException("Invalid URL: " + uri, "08S01"); - } - - // remove prefix - uri = uri.substring(URI_PREFIX.length()); - - // If uri is not specified, use local mode. - if (uri.isEmpty()) { - try { - client = new HiveServer.HiveServerHandler(); - } catch (MetaException e) { - throw new SQLException("Error accessing Hive metastore: " - + e.getMessage(), "08S01",e); - } - } else { - // parse uri - // form: hostname:port/databasename - String[] parts = uri.split("/"); - String[] hostport = parts[0].split(":"); - int port = 10000; - String host = hostport[0]; - try { - port = Integer.parseInt(hostport[1]); - } catch (Exception e) { - } - transport = new TSocket(host, port); - TProtocol protocol = new TBinaryProtocol(transport); - client = new HiveClient(protocol); - try { - transport.open(); - } catch (TTransportException e) { - throw new SQLException("Could not establish connection to " - + uri + ": " + e.getMessage(), "08S01"); - } - } - isClosed = false; - configureConnection(); - } - - public void abort(Executor executor) throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - private void configureConnection() throws SQLException { - Statement stmt = createStatement(); - stmt.execute( - "set hive.fetch.output.serde = org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"); - stmt.close(); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#clearWarnings() - */ - - public void clearWarnings() throws SQLException { - warningChain = null; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#close() - */ - - public void close() throws SQLException { - if (!isClosed) { - try { - client.clean(); - } catch (TException e) { - throw new SQLException("Error while cleaning up the server resources", e); - } finally { - isClosed = true; - if (transport != null) { - transport.close(); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#commit() - */ - - public void commit() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#createArrayOf(java.lang.String, - * java.lang.Object[]) - */ - - public Array createArrayOf(String arg0, Object[] arg1) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#createBlob() - */ - - public Blob createBlob() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#createClob() - */ - - public Clob createClob() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#createNClob() - */ - - public NClob createNClob() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#createSQLXML() - */ - - public SQLXML createSQLXML() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /** - * Creates a Statement object for sending SQL statements to the database. - * - * @throws SQLException - * if a database access error occurs. - * @see java.sql.Connection#createStatement() - */ - - public Statement createStatement() throws SQLException { - if (isClosed) { - throw new SQLException("Can't create Statement, connection is closed"); - } - return new HiveStatement(client); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#createStatement(int, int) - */ - - public Statement createStatement(int resultSetType, int resultSetConcurrency) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#createStatement(int, int, int) - */ - - public Statement createStatement(int resultSetType, int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#createStruct(java.lang.String, java.lang.Object[]) - */ - - public Struct createStruct(String typeName, Object[] attributes) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#getAutoCommit() - */ - - public boolean getAutoCommit() throws SQLException { - return true; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#getCatalog() - */ - - public String getCatalog() throws SQLException { - return ""; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#getClientInfo() - */ - - public Properties getClientInfo() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#getClientInfo(java.lang.String) - */ - - public String getClientInfo(String name) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#getHoldability() - */ - - public int getHoldability() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#getMetaData() - */ - - public DatabaseMetaData getMetaData() throws SQLException { - return new HiveDatabaseMetaData(client); - } - - - public int getNetworkTimeout() throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - - public String getSchema() throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - /* - * (non-Javadoc) - * - * @see java.sql.Connection#getTransactionIsolation() - */ - - public int getTransactionIsolation() throws SQLException { - return Connection.TRANSACTION_NONE; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#getTypeMap() - */ - - public Map> getTypeMap() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#getWarnings() - */ - - public SQLWarning getWarnings() throws SQLException { - return warningChain; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#isClosed() - */ - - public boolean isClosed() throws SQLException { - return isClosed; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#isReadOnly() - */ - - public boolean isReadOnly() throws SQLException { - return false; - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#isValid(int) - */ - - public boolean isValid(int timeout) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#nativeSQL(java.lang.String) - */ - - public String nativeSQL(String sql) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#prepareCall(java.lang.String) - */ - - public CallableStatement prepareCall(String sql) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#prepareCall(java.lang.String, int, int) - */ - - public CallableStatement prepareCall(String sql, int resultSetType, - int resultSetConcurrency) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#prepareCall(java.lang.String, int, int, int) - */ - - public CallableStatement prepareCall(String sql, int resultSetType, - int resultSetConcurrency, int resultSetHoldability) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#prepareStatement(java.lang.String) - */ - - public PreparedStatement prepareStatement(String sql) throws SQLException { - return new HivePreparedStatement(client, sql); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#prepareStatement(java.lang.String, int) - */ - - public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) - throws SQLException { - return new HivePreparedStatement(client, sql); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#prepareStatement(java.lang.String, int[]) - */ - - public PreparedStatement prepareStatement(String sql, int[] columnIndexes) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#prepareStatement(java.lang.String, - * java.lang.String[]) - */ - - public PreparedStatement prepareStatement(String sql, String[] columnNames) - throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#prepareStatement(java.lang.String, int, int) - */ - - public PreparedStatement prepareStatement(String sql, int resultSetType, - int resultSetConcurrency) throws SQLException { - return new HivePreparedStatement(client, sql); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#prepareStatement(java.lang.String, int, int, int) - */ - - public PreparedStatement prepareStatement(String sql, int resultSetType, - int resultSetConcurrency, int resultSetHoldability) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#releaseSavepoint(java.sql.Savepoint) - */ - - public void releaseSavepoint(Savepoint savepoint) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#rollback() - */ - - public void rollback() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#rollback(java.sql.Savepoint) - */ - - public void rollback(Savepoint savepoint) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#setAutoCommit(boolean) - */ - - public void setAutoCommit(boolean autoCommit) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#setCatalog(java.lang.String) - */ - - public void setCatalog(String catalog) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#setClientInfo(java.util.Properties) - */ - - public void setClientInfo(Properties properties) - throws SQLClientInfoException { - // TODO Auto-generated method stub - throw new SQLClientInfoException("Method not supported", null); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#setClientInfo(java.lang.String, java.lang.String) - */ - - public void setClientInfo(String name, String value) - throws SQLClientInfoException { - // TODO Auto-generated method stub - throw new SQLClientInfoException("Method not supported", null); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#setHoldability(int) - */ - - public void setHoldability(int holdability) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#setReadOnly(boolean) - */ - - public void setReadOnly(boolean readOnly) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#setSavepoint() - */ - - public Savepoint setSavepoint() throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#setSavepoint(java.lang.String) - */ - - public Savepoint setSavepoint(String name) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - public void setSchema(String schema) throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#setTransactionIsolation(int) - */ - - public void setTransactionIsolation(int level) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Connection#setTypeMap(java.util.Map) - */ - - public void setTypeMap(Map> map) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - /* - * (non-Javadoc) - * - * @see java.sql.Wrapper#isWrapperFor(java.lang.Class) - */ - - public boolean isWrapperFor(Class iface) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } - - public T unwrap(Class iface) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); - } -} - Index: jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java =================================================================== --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java (revision 1637002) +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveQueryResultSet.java (working copy) @@ -1,223 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hive.metastore.api.FieldSchema; -import org.apache.hadoop.hive.metastore.api.Schema; -import org.apache.hadoop.hive.serde.serdeConstants; -import org.apache.hadoop.hive.serde2.SerDe; -import org.apache.hadoop.hive.serde2.SerDeUtils; -import org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils; -import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils.ObjectInspectorCopyOption; -import org.apache.hadoop.hive.serde2.objectinspector.StructField; -import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; -import org.apache.hadoop.hive.service.HiveInterface; -import org.apache.hadoop.hive.service.HiveServerException; -import org.apache.hadoop.io.BytesWritable; - -/** - * HiveQueryResultSet. - * - */ -public class HiveQueryResultSet extends HiveBaseResultSet { - - public static final Log LOG = LogFactory.getLog(HiveQueryResultSet.class); - - private HiveInterface client; - private SerDe serde; - - private int maxRows = 0; - private int rowsFetched = 0; - private int fetchSize = 50; - - private List fetchedRows; - private Iterator fetchedRowsItr; - - public HiveQueryResultSet(HiveInterface client, int maxRows) throws SQLException { - this.client = client; - this.maxRows = maxRows; - initSerde(); - row = Arrays.asList(new Object[columnNames.size()]); - } - - public HiveQueryResultSet(HiveInterface client) throws SQLException { - this(client, 0); - } - - /** - * Instantiate the serde used to deserialize the result rows. - */ - private void initSerde() throws SQLException { - try { - Schema fullSchema = client.getSchema(); - List schema = fullSchema.getFieldSchemas(); - columnNames = new ArrayList(); - columnTypes = new ArrayList(); - StringBuilder namesSb = new StringBuilder(); - StringBuilder typesSb = new StringBuilder(); - - if ((schema != null) && (!schema.isEmpty())) { - for (int pos = 0; pos < schema.size(); pos++) { - if (pos != 0) { - namesSb.append(","); - typesSb.append(","); - } - columnNames.add(schema.get(pos).getName()); - columnTypes.add(schema.get(pos).getType()); - namesSb.append(schema.get(pos).getName()); - typesSb.append(schema.get(pos).getType()); - } - } - String names = namesSb.toString(); - String types = typesSb.toString(); - - serde = new LazySimpleSerDe(); - Properties props = new Properties(); - if (names.length() > 0) { - LOG.debug("Column names: " + names); - props.setProperty(serdeConstants.LIST_COLUMNS, names); - } - if (types.length() > 0) { - LOG.debug("Column types: " + types); - props.setProperty(serdeConstants.LIST_COLUMN_TYPES, types); - } - SerDeUtils.initializeSerDe(serde, new Configuration(), props, null); - - } catch (Exception ex) { - ex.printStackTrace(); - throw new SQLException("Could not create ResultSet: " + ex.getMessage(), ex); - } - } - - @Override - public void close() throws SQLException { - client = null; - } - - /** - * Moves the cursor down one row from its current position. - * - * @see java.sql.ResultSet#next() - * @throws SQLException - * if a database access error occurs. - */ - public boolean next() throws SQLException { - if (maxRows > 0 && rowsFetched >= maxRows) { - return false; - } - - try { - if (fetchedRows == null || !fetchedRowsItr.hasNext()) { - fetchedRows = client.fetchN(fetchSize); - fetchedRowsItr = fetchedRows.iterator(); - } - - String rowStr = ""; - if (fetchedRowsItr.hasNext()) { - rowStr = fetchedRowsItr.next(); - } else { - return false; - } - - rowsFetched++; - if (LOG.isDebugEnabled()) { - LOG.debug("Fetched row string: " + rowStr); - } - - StructObjectInspector soi = (StructObjectInspector) serde.getObjectInspector(); - List fieldRefs = soi.getAllStructFieldRefs(); - Object data = serde.deserialize(new BytesWritable(rowStr.getBytes())); - - assert row.size() == fieldRefs.size() : row.size() + ", " + fieldRefs.size(); - for (int i = 0; i < fieldRefs.size(); i++) { - StructField fieldRef = fieldRefs.get(i); - ObjectInspector oi = fieldRef.getFieldObjectInspector(); - Object obj = soi.getStructFieldData(data, fieldRef); - row.set(i, convertLazyToJava(obj, oi)); - } - - if (LOG.isDebugEnabled()) { - LOG.debug("Deserialized row: " + row); - } - } catch (HiveServerException e) { - if (e.getErrorCode() == 0) { // error code == 0 means reached the EOF - return false; - } else { - throw new SQLException("Error retrieving next row", e); - } - } catch (Exception ex) { - ex.printStackTrace(); - throw new SQLException("Error retrieving next row", ex); - } - // NOTE: fetchOne dosn't throw new SQLException("Method not supported"). - return true; - } - - @Override - public void setFetchSize(int rows) throws SQLException { - fetchSize = rows; - } - - @Override - public int getFetchSize() throws SQLException { - return fetchSize; - } - - public T getObject(String columnLabel, Class type) throws SQLException { - //JDK 1.7 - throw new SQLException("Method not supported"); - } - - public T getObject(int columnIndex, Class type) throws SQLException { - //JDK 1.7 - throw new SQLException("Method not supported"); - } - - /** - * Convert a LazyObject to a standard Java object in compliance with JDBC 3.0 (see JDBC 3.0 - * Specification, Table B-3: Mapping from JDBC Types to Java Object Types). - * - * This method is kept consistent with {@link HiveResultSetMetaData#hiveTypeToSqlType}. - */ - private static Object convertLazyToJava(Object o, ObjectInspector oi) { - Object obj = ObjectInspectorUtils.copyToStandardObject(o, oi, ObjectInspectorCopyOption.JAVA); - - // for now, expose non-primitive as a string - // TODO: expose non-primitive as a structured object while maintaining JDBC compliance - if (obj != null && oi.getCategory() != ObjectInspector.Category.PRIMITIVE) { - obj = obj.toString(); - } - - return obj; - } - -} - Index: itests/hive-unit/src/test/java/org/apache/hadoop/hive/service/TestHiveServer.java =================================================================== --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/service/TestHiveServer.java (revision 1637002) +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/service/TestHiveServer.java (working copy) @@ -1,424 +0,0 @@ -/** - * 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.hadoop.hive.service; - -import java.util.List; -import java.util.Properties; - -import junit.framework.TestCase; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hive.common.ServerUtils; -import org.apache.hadoop.hive.conf.HiveConf; -import org.apache.hadoop.hive.metastore.api.FieldSchema; -import org.apache.hadoop.hive.metastore.api.Schema; -import org.apache.hadoop.hive.serde.serdeConstants; -import org.apache.hadoop.hive.serde2.dynamic_type.DynamicSerDe; -import org.apache.hadoop.io.BytesWritable; -import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.protocol.TProtocol; -import org.apache.thrift.transport.TSocket; -import org.apache.thrift.transport.TTransport; - -/** - * TestHiveServer. - * - */ -public class TestHiveServer extends TestCase { - - private HiveInterface client; - private static final String host = "localhost"; - private static final int port = 10000; - private final Path dataFilePath; - - private static String tableName = "testhivedrivertable"; - private final HiveConf conf; - private boolean standAloneServer = false; - private TTransport transport; - private final String invalidPath; - - public TestHiveServer(String name) { - super(name); - conf = new HiveConf(TestHiveServer.class); - String dataFileDir = conf.get("test.data.files").replace('\\', '/') - .replace("c:", ""); - invalidPath = dataFileDir+"/invalidpath/"; - dataFilePath = new Path(dataFileDir, "kv1.txt"); - // See data/conf/hive-site.xml - String paramStr = System.getProperty("test.service.standalone.server"); - if (paramStr != null && paramStr.equals("true")) { - standAloneServer = true; - } - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - if (standAloneServer) { - try { - transport = new TSocket(host, port); - TProtocol protocol = new TBinaryProtocol(transport); - client = new HiveClient(protocol); - transport.open(); - } catch (Throwable e) { - e.printStackTrace(); - } - } else { - client = new HiveServer.HiveServerHandler(); - } - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - if (standAloneServer) { - try { - client.clean(); - } catch (Exception e) { - e.printStackTrace(); - } - transport.close(); - } - } - - public void testExecute() throws Exception { - try { - client.execute("set hive.support.concurrency = false"); - client.execute("drop table " + tableName); - } catch (Exception ex) { - } - - try { - client.execute("create table " + tableName + " (num int)"); - client.execute("load data local inpath '" + dataFilePath.toString() - + "' into table " + tableName); - client.execute("select count(1) as cnt from " + tableName); - String row = client.fetchOne(); - assertEquals(row, "500"); - - Schema hiveSchema = client.getSchema(); - List listFields = hiveSchema.getFieldSchemas(); - assertEquals(listFields.size(), 1); - assertEquals(listFields.get(0).getName(), "cnt"); - assertEquals(listFields.get(0).getType(), "bigint"); - - Schema thriftSchema = client.getThriftSchema(); - List listThriftFields = thriftSchema.getFieldSchemas(); - assertEquals(listThriftFields.size(), 1); - assertEquals(listThriftFields.get(0).getName(), "cnt"); - assertEquals(listThriftFields.get(0).getType(), "i64"); - - client.execute("drop table " + tableName); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - public void notestExecute() throws Exception { - try { - client.execute("set hive.support.concurrency = false"); - client.execute("drop table " + tableName); - } catch (Exception ex) { - } - - client.execute("create table " + tableName + " (num int)"); - client.execute("load data local inpath '" + dataFilePath.toString() - + "' into table " + tableName); - client.execute("select count(1) from " + tableName); - String row = client.fetchOne(); - assertEquals(row, "500"); - client.execute("drop table " + tableName); - transport.close(); - } - - public void testNonHiveCommand() throws Exception { - try { - client.execute("set hive.support.concurrency = false"); - client.execute("drop table " + tableName); - } catch (Exception ex) { - } - - client.execute("create table " + tableName + " (num int)"); - client.execute("load data local inpath '" + dataFilePath.toString() - + "' into table " + tableName); - - // Command not part of HiveQL - verify no results - client.execute("SET hive.mapred.mode = nonstrict"); - - Schema schema = client.getSchema(); - assertEquals(schema.getFieldSchemasSize(), 0); - assertEquals(schema.getPropertiesSize(), 0); - - Schema thriftschema = client.getThriftSchema(); - assertEquals(thriftschema.getFieldSchemasSize(), 0); - assertEquals(thriftschema.getPropertiesSize(), 0); - - try { - String ret = client.fetchOne(); - assertTrue(false); - } catch (HiveServerException e) { - assertEquals(e.getErrorCode(), 0); - } - assertEquals(client.fetchN(10).size(), 0); - assertEquals(client.fetchAll().size(), 0); - - // Execute Hive query and fetch - client.execute("select * from " + tableName + " limit 10"); - client.fetchOne(); - - // Re-execute command not part of HiveQL - verify still no results - client.execute("SET hive.mapred.mode = nonstrict"); - - schema = client.getSchema(); - assertEquals(schema.getFieldSchemasSize(), 0); - assertEquals(schema.getPropertiesSize(), 0); - - thriftschema = client.getThriftSchema(); - assertEquals(thriftschema.getFieldSchemasSize(), 0); - assertEquals(thriftschema.getPropertiesSize(), 0); - - try { - String ret = client.fetchOne(); - assertTrue(false); - } catch (HiveServerException e) { - assertEquals(e.getErrorCode(), 0); - } - assertEquals(client.fetchN(10).size(), 0); - assertEquals(client.fetchAll().size(), 0); - - // Cleanup - client.execute("drop table " + tableName); - } - - /** - * Test metastore call. - */ - public void testMetastore() throws Exception { - try { - client.execute("set hive.support.concurrency = false"); - client.execute("drop table " + tableName); - } catch (Exception ex) { - } - - client.execute("create table " + tableName + " (num int)"); - List tabs = client.get_tables("default", tableName); - assertEquals(tabs.get(0), tableName); - client.execute("drop table " + tableName); - } - - /** - * Test cluster status retrieval. - */ - public void testGetClusterStatus() throws Exception { - HiveClusterStatus clusterStatus = client.getClusterStatus(); - assertNotNull(clusterStatus); - assertTrue(clusterStatus.getTaskTrackers() >= 0); - assertTrue(clusterStatus.getMapTasks() >= 0); - assertTrue(clusterStatus.getReduceTasks() >= 0); - assertTrue(clusterStatus.getMaxMapTasks() >= 0); - assertTrue(clusterStatus.getMaxReduceTasks() >= 0); - assertTrue(clusterStatus.getState() == JobTrackerState.INITIALIZING - || clusterStatus.getState() == JobTrackerState.RUNNING); - } - - /** - * - */ - public void testFetch() throws Exception { - // create and populate a table with 500 rows. - try { - client.execute("set hive.support.concurrency = false"); - client.execute("drop table " + tableName); - } catch (Exception ex) { - } - client.execute("create table " + tableName + " (key int, value string)"); - client.execute("load data local inpath '" + dataFilePath.toString() - + "' into table " + tableName); - - try { - // fetchAll test - client.execute("select key, value from " + tableName); - assertEquals(client.fetchAll().size(), 500); - assertEquals(client.fetchAll().size(), 0); - - // fetchOne test - client.execute("select key, value from " + tableName); - for (int i = 0; i < 500; i++) { - try { - String str = client.fetchOne(); - } catch (HiveServerException e) { - assertTrue(false); - } - } - try { - client.fetchOne(); - } catch (HiveServerException e) { - assertEquals(e.getErrorCode(), 0); - } - - // fetchN test - client.execute("select key, value from " + tableName); - assertEquals(client.fetchN(499).size(), 499); - assertEquals(client.fetchN(499).size(), 1); - assertEquals(client.fetchN(499).size(), 0); - } catch (Throwable e) { - e.printStackTrace(); - } - } - - public void testDynamicSerde() throws Exception { - try { - client.execute("set hive.support.concurrency = false"); - client.execute("drop table " + tableName); - } catch (Exception ex) { - } - - client.execute("create table " + tableName + " (key int, value string)"); - client.execute("load data local inpath '" + dataFilePath.toString() - + "' into table " + tableName); - // client.execute("select key, count(1) from " + tableName + - // " where key > 10 group by key"); - String sql = "select key, value from " + tableName + " where key > 10"; - client.execute(sql); - - // Instantiate DynamicSerDe - DynamicSerDe ds = new DynamicSerDe(); - Properties dsp = new Properties(); - dsp.setProperty(serdeConstants.SERIALIZATION_FORMAT, - org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol.class - .getName()); - dsp.setProperty( - org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_NAME, - "result"); - String serDDL = new String("struct result { "); - List schema = client.getThriftSchema().getFieldSchemas(); - for (int pos = 0; pos < schema.size(); pos++) { - if (pos != 0) { - serDDL = serDDL.concat(","); - } - serDDL = serDDL.concat(schema.get(pos).getType()); - serDDL = serDDL.concat(" "); - serDDL = serDDL.concat(schema.get(pos).getName()); - } - serDDL = serDDL.concat("}"); - - dsp.setProperty(serdeConstants.SERIALIZATION_DDL, serDDL); - dsp.setProperty(serdeConstants.SERIALIZATION_LIB, ds.getClass().toString()); - dsp.setProperty(serdeConstants.FIELD_DELIM, "9"); - ds.initialize(new Configuration(), dsp); - - String row = client.fetchOne(); - Object o = ds.deserialize(new BytesWritable(row.getBytes())); - - assertEquals(o.getClass().toString(), "class java.util.ArrayList"); - List lst = (List) o; - assertEquals(lst.get(0), 238); - - // TODO: serde doesn't like underscore -- struct result { string _c0} - sql = "select count(1) as c from " + tableName; - client.execute(sql); - row = client.fetchOne(); - - serDDL = new String("struct result { "); - schema = client.getThriftSchema().getFieldSchemas(); - for (int pos = 0; pos < schema.size(); pos++) { - if (pos != 0) { - serDDL = serDDL.concat(","); - } - serDDL = serDDL.concat(schema.get(pos).getType()); - serDDL = serDDL.concat(" "); - serDDL = serDDL.concat(schema.get(pos).getName()); - } - serDDL = serDDL.concat("}"); - - dsp.setProperty(serdeConstants.SERIALIZATION_DDL, serDDL); - // Need a new DynamicSerDe instance - re-initialization is not supported. - ds = new DynamicSerDe(); - ds.initialize(new Configuration(), dsp); - o = ds.deserialize(new BytesWritable(row.getBytes())); - } - - public void testAddJarShouldFailIfJarNotExist() throws Exception { - boolean queryExecutionFailed = false; - try { - client.execute("add jar " + invalidPath + "sample.jar"); - } catch (Exception e) { - queryExecutionFailed = true; - } - if (!queryExecutionFailed) { - fail("It should throw exception since jar does not exist"); - } - } - - public void testAddFileShouldFailIfFileNotExist() throws Exception { - boolean queryExecutionFailed = false; - try { - client.execute("add file " + invalidPath + "sample.txt"); - } catch (Exception e) { - queryExecutionFailed = true; - } - if (!queryExecutionFailed) { - fail("It should throw exception since file does not exist"); - } - } - - public void testAddArchiveShouldFailIfFileNotExist() throws Exception { - boolean queryExecutionFailed = false; - try { - client.execute("add archive " + invalidPath + "sample.zip"); - } catch (Exception e) { - queryExecutionFailed = true; - } - if (!queryExecutionFailed) { - fail("It should trow exception since archive does not exist"); - } - } - - public void testScratchDirShouldNotClearWhileStartup() throws Exception { - FileSystem fs = FileSystem.get(conf); - Path scratchDirPath = new Path(HiveConf.getVar(conf, - HiveConf.ConfVars.SCRATCHDIR)); - boolean fileExists = fs.exists(scratchDirPath); - if (!fileExists) { - fileExists = fs.mkdirs(scratchDirPath); - } - ServerUtils.cleanUpScratchDir(conf); - assertTrue("Scratch dir is not available after startup", fs.exists(scratchDirPath)); - } - - public void testScratchDirShouldClearWhileStartup() throws Exception { - FileSystem fs = FileSystem.get(conf); - Path scratchDirPath = new Path(HiveConf.getVar(conf, - HiveConf.ConfVars.SCRATCHDIR)); - boolean fileExists = fs.exists(scratchDirPath); - if (!fileExists) { - fileExists = fs.mkdirs(scratchDirPath); - } - try { - conf.setBoolVar(HiveConf.ConfVars.HIVE_START_CLEANUP_SCRATCHDIR, true); - ServerUtils.cleanUpScratchDir(conf); - } finally { - conf.setBoolVar(HiveConf.ConfVars.HIVE_START_CLEANUP_SCRATCHDIR, false); - } - assertFalse("Scratch dir is available after startup", fs.exists(scratchDirPath)); - } - -} Index: itests/hive-unit/src/test/java/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java =================================================================== --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java (revision 1637002) +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java (working copy) @@ -1,1196 +0,0 @@ -/** - * 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.hadoop.hive.jdbc; - -import static org.apache.hadoop.hive.conf.SystemVariables.SET_COLUMN_NAME; -import static org.apache.hadoop.hive.ql.exec.ExplainTask.EXPL_COLUMN_NAME; - -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.DriverManager; -import java.sql.DriverPropertyInfo; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Types; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import junit.framework.TestCase; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hive.conf.HiveConf; - -/** - * TestJdbcDriver. - * - */ -public class TestJdbcDriver extends TestCase { - private static final Log LOG = LogFactory.getLog(TestJdbcDriver.class); - private static final String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver"; - private static final String tableName = "testHiveJdbcDriver_Table"; - private static final String tableComment = "Simple table"; - private static final String viewName = "testHiveJdbcDriverView"; - private static final String viewComment = "Simple view"; - private static final String partitionedTableName = "testHiveJdbcDriverPartitionedTable"; - private static final String partitionedColumnName = "partcolabc"; - private static final String partitionedColumnValue = "20090619"; - private static final String partitionedTableComment = "Partitioned table"; - private static final String dataTypeTableName = "testdatatypetable"; - private static final String dataTypeTableComment = "Table with many column data types"; - private final HiveConf conf; - private final Path dataFilePath; - private final Path dataTypeDataFilePath; - private Connection con; - private boolean standAloneServer = false; - - public TestJdbcDriver(String name) { - super(name); - conf = new HiveConf(TestJdbcDriver.class); - String dataFileDir = conf.get("test.data.files").replace('\\', '/') - .replace("c:", ""); - dataFilePath = new Path(dataFileDir, "kv1.txt"); - dataTypeDataFilePath = new Path(dataFileDir, "datatypes.txt"); - standAloneServer = "true".equals(System - .getProperty("test.service.standalone.server")); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - Class.forName(driverName); - if (standAloneServer) { - // get connection - con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", - "", ""); - } else { - con = DriverManager.getConnection("jdbc:hive://", "", ""); - } - assertNotNull("Connection is null", con); - assertFalse("Connection should not be closed", con.isClosed()); - Statement stmt = con.createStatement(); - assertNotNull("Statement is null", stmt); - - stmt.executeQuery("set hive.support.concurrency = false"); - - // drop table. ignore error. - try { - stmt.executeQuery("drop table " + tableName); - } catch (Exception ex) { - fail(ex.toString()); - } - - // create table - ResultSet res = stmt.executeQuery("create table " + tableName - + " (under_col int comment 'the under column', value string) comment '" - + tableComment + "'"); - assertFalse(res.next()); - - // load data - res = stmt.executeQuery("load data local inpath '" - + dataFilePath.toString() + "' into table " + tableName); - assertFalse(res.next()); - - // also initialize a paritioned table to test against. - - // drop table. ignore error. - try { - stmt.executeQuery("drop table " + partitionedTableName); - } catch (Exception ex) { - fail(ex.toString()); - } - - res = stmt.executeQuery("create table " + partitionedTableName - + " (under_col int, value string) comment '"+partitionedTableComment - +"' partitioned by (" + partitionedColumnName + " STRING)"); - assertFalse(res.next()); - - // load data - res = stmt.executeQuery("load data local inpath '" - + dataFilePath.toString() + "' into table " + partitionedTableName - + " PARTITION (" + partitionedColumnName + "=" - + partitionedColumnValue + ")"); - assertFalse(res.next()); - - // drop table. ignore error. - try { - stmt.executeQuery("drop table " + dataTypeTableName); - } catch (Exception ex) { - fail(ex.toString()); - } - - res = stmt.executeQuery("create table " + dataTypeTableName - + " (c1 int, c2 boolean, c3 double, c4 string," - + " c5 array, c6 map, c7 map," - + " c8 struct," - + " c9 tinyint, c10 smallint, c11 float, c12 bigint," - + " c13 array>," - + " c14 map>," - + " c15 struct>," - + " c16 array,n:int>>," - + " c17 timestamp, " - + " c18 decimal(16,7)," - + " c19 binary," - + " c20 date) comment'" + dataTypeTableComment - +"' partitioned by (dt STRING)"); - assertFalse(res.next()); - - // load data - res = stmt.executeQuery("load data local inpath '" - + dataTypeDataFilePath.toString() + "' into table " + dataTypeTableName - + " PARTITION (dt='20090619')"); - assertFalse(res.next()); - - // drop view. ignore error. - try { - stmt.executeQuery("drop view " + viewName); - } catch (Exception ex) { - fail(ex.toString()); - } - - // create view - res = stmt.executeQuery("create view " + viewName + " comment '"+viewComment - +"' as select * from "+ tableName); - assertFalse(res.next()); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - - // drop table - Statement stmt = con.createStatement(); - assertNotNull("Statement is null", stmt); - ResultSet res = stmt.executeQuery("drop table " + tableName); - assertFalse(res.next()); - res = stmt.executeQuery("drop table " + partitionedTableName); - assertFalse(res.next()); - res = stmt.executeQuery("drop table " + dataTypeTableName); - assertFalse(res.next()); - - con.close(); - assertTrue("Connection should be closed", con.isClosed()); - - Exception expectedException = null; - try { - con.createStatement(); - } catch (Exception e) { - expectedException = e; - } - - assertNotNull( - "createStatement() on closed connection should throw exception", - expectedException); - } - - /** - * verify 'explain ...' resultset - * @throws SQLException - */ - public void testExplainStmt() throws SQLException { - Statement stmt = con.createStatement(); - - ResultSet res = stmt.executeQuery( - "explain select c1, c2, c3, c4, c5 as a, c6, c7, c8, c9, c10, c11, c12, " + - "c1*2, sentences(null, null, null) as b from " + dataTypeTableName + " limit 1"); - - ResultSetMetaData md = res.getMetaData(); - assertEquals(md.getColumnCount(), 1); // only one result column - assertEquals(md.getColumnLabel(1), EXPL_COLUMN_NAME); // verify the column name - //verify that there is data in the resultset - assertTrue("Nothing returned explain", res.next()); - } - - public void testPrepareStatement() { - - String sql = "from (select count(1) from " - + tableName - + " where 'not?param?not?param' <> 'not_param??not_param' and ?=? " - + " and 1=? and 2=? and 3.0=? and 4.0=? and 'test\\'string\"'=? and 5=? and ?=? " - + " and date '2012-01-01' = date ?" - + " ) t select '2011-03-25' ddate,'China',true bv, 10 num limit 10"; - - /////////////////////////////////////////////// - //////////////////// correct testcase - //////////////////// executed twice: once with the typed ps setters, once with the generic setObject - ////////////////////////////////////////////// - try { - PreparedStatement ps = createPreapredStatementUsingSetXXX(sql); - ResultSet res = ps.executeQuery(); - assertPreparedStatementResultAsExpected(res); - ps.close(); - - ps = createPreapredStatementUsingSetObject(sql); - res = ps.executeQuery(); - assertPreparedStatementResultAsExpected(res); - ps.close(); - - } catch (Exception e) { - e.printStackTrace(); - fail(e.toString()); - } - - /////////////////////////////////////////////// - //////////////////// other failure testcases - ////////////////////////////////////////////// - // set nothing for prepared sql - Exception expectedException = null; - try { - PreparedStatement ps = con.prepareStatement(sql); - ps.executeQuery(); - } catch (Exception e) { - expectedException = e; - } - assertNotNull( - "Execute the un-setted sql statement should throw exception", - expectedException); - - // set some of parameters for prepared sql, not all of them. - expectedException = null; - try { - PreparedStatement ps = con.prepareStatement(sql); - ps.setBoolean(1, true); - ps.setBoolean(2, true); - ps.executeQuery(); - } catch (Exception e) { - expectedException = e; - } - assertNotNull( - "Execute the invalid setted sql statement should throw exception", - expectedException); - - // set the wrong type parameters for prepared sql. - expectedException = null; - try { - PreparedStatement ps = con.prepareStatement(sql); - - // wrong type here - ps.setString(1, "wrong"); - - assertTrue(true); - ResultSet res = ps.executeQuery(); - if (!res.next()) { - throw new Exception("there must be a empty result set"); - } - } catch (Exception e) { - expectedException = e; - } - assertNotNull( - "Execute the invalid setted sql statement should throw exception", - expectedException); - - // setObject to the yet unknown type java.util.Date - expectedException = null; - try { - PreparedStatement ps = con.prepareStatement(sql); - ps.setObject(1, new Date()); - ps.executeQuery(); - } catch (Exception e) { - expectedException = e; - } - assertNotNull( - "Setting to an unknown type should throw an exception", - expectedException); - - } - - private PreparedStatement createPreapredStatementUsingSetObject(String sql) throws SQLException { - PreparedStatement ps = con.prepareStatement(sql); - - ps.setObject(1, true); //setBoolean - ps.setObject(2, true); //setBoolean - - ps.setObject(3, Short.valueOf("1")); //setShort - ps.setObject(4, 2); //setInt - ps.setObject(5, 3f); //setFloat - ps.setObject(6, Double.valueOf(4)); //setDouble - ps.setObject(7, "test'string\""); //setString - ps.setObject(8, 5L); //setLong - ps.setObject(9, (byte) 1); //setByte - ps.setObject(10, (byte) 1); //setByte - ps.setString(11, "2012-01-01"); //setString - - ps.setMaxRows(2); - return ps; - } - - private PreparedStatement createPreapredStatementUsingSetXXX(String sql) throws SQLException { - PreparedStatement ps = con.prepareStatement(sql); - - ps.setBoolean(1, true); //setBoolean - ps.setBoolean(2, true); //setBoolean - - ps.setShort(3, Short.valueOf("1")); //setShort - ps.setInt(4, 2); //setInt - ps.setFloat(5, 3f); //setFloat - ps.setDouble(6, Double.valueOf(4)); //setDouble - ps.setString(7, "test'string\""); //setString - ps.setLong(8, 5L); //setLong - ps.setByte(9, (byte) 1); //setByte - ps.setByte(10, (byte) 1); //setByte - ps.setString(11, "2012-01-01"); //setString - - ps.setMaxRows(2); - return ps; - } - - private void assertPreparedStatementResultAsExpected(ResultSet res ) throws SQLException { - assertNotNull(res); - - while (res.next()) { - assertEquals("2011-03-25", res.getString("ddate")); - assertEquals("10", res.getString("num")); - assertEquals((byte) 10, res.getByte("num")); - assertEquals("2011-03-25", res.getDate("ddate").toString()); - assertEquals(Double.valueOf(10).doubleValue(), res.getDouble("num"), 0.1); - assertEquals(10, res.getInt("num")); - assertEquals(Short.valueOf("10").shortValue(), res.getShort("num")); - assertEquals(10L, res.getLong("num")); - assertEquals(true, res.getBoolean("bv")); - Object o = res.getObject("ddate"); - assertNotNull(o); - o = res.getObject("num"); - assertNotNull(o); - } - res.close(); - assertTrue(true); - } - - public final void testSelectAll() throws Exception { - doTestSelectAll(tableName, -1, -1); // tests not setting maxRows (return all) - doTestSelectAll(tableName, 0, -1); // tests setting maxRows to 0 (return all) - } - - public final void testSelectAllPartioned() throws Exception { - doTestSelectAll(partitionedTableName, -1, -1); // tests not setting maxRows - // (return all) - doTestSelectAll(partitionedTableName, 0, -1); // tests setting maxRows to 0 - // (return all) - } - - public final void testSelectAllMaxRows() throws Exception { - doTestSelectAll(tableName, 100, -1); - } - - public final void testSelectAllFetchSize() throws Exception { - doTestSelectAll(tableName, 100, 20); - } - - public void testNullType() throws Exception { - Statement stmt = con.createStatement(); - try { - ResultSet res = stmt.executeQuery("select null from " + dataTypeTableName); - assertTrue(res.next()); - assertNull(res.getObject(1)); - } finally { - stmt.close(); - } - } - - public void testDataTypes() throws Exception { - Statement stmt = con.createStatement(); - - ResultSet res = stmt.executeQuery( - "select * from " + dataTypeTableName + " order by c1"); - ResultSetMetaData meta = res.getMetaData(); - - // row 1 - assertTrue(res.next()); - // skip the last (partitioning) column since it is always non-null - for (int i = 1; i < meta.getColumnCount(); i++) { - assertNull(res.getObject(i)); - } - - // row 2 - assertTrue(res.next()); - assertEquals(-1, res.getInt(1)); - assertEquals(false, res.getBoolean(2)); - assertEquals(-1.1d, res.getDouble(3)); - assertEquals("", res.getString(4)); - assertEquals("[]", res.getString(5)); - assertEquals("{}", res.getString(6)); - assertEquals("{}", res.getString(7)); - assertEquals("[null, null, null]", res.getString(8)); - assertEquals(-1, res.getByte(9)); - assertEquals(-1, res.getShort(10)); - assertEquals(-1.0f, res.getFloat(11)); - assertEquals(-1, res.getLong(12)); - assertEquals("[]", res.getString(13)); - assertEquals("{}", res.getString(14)); - assertEquals("[null, null]", res.getString(15)); - assertEquals("[]", res.getString(16)); - assertEquals(null, res.getString(17)); - assertEquals(null, res.getTimestamp(17)); - assertEquals(null, res.getBigDecimal(18)); - assertEquals(null, res.getString(20)); - assertEquals(null, res.getDate(20)); - - // row 3 - assertTrue(res.next()); - assertEquals(1, res.getInt(1)); - assertEquals(true, res.getBoolean(2)); - assertEquals(1.1d, res.getDouble(3)); - assertEquals("1", res.getString(4)); - assertEquals("[1, 2]", res.getString(5)); - assertEquals("{1=x, 2=y}", res.getString(6)); - assertEquals("{k=v}", res.getString(7)); - assertEquals("[a, 9, 2.2]", res.getString(8)); - assertEquals(1, res.getByte(9)); - assertEquals(1, res.getShort(10)); - assertEquals(1.0f, res.getFloat(11)); - assertEquals(1, res.getLong(12)); - assertEquals("[[a, b], [c, d]]", res.getString(13)); - assertEquals("{1={11=12, 13=14}, 2={21=22}}", res.getString(14)); - assertEquals("[1, [2, x]]", res.getString(15)); - assertEquals("[[{}, 1], [{c=d, a=b}, 2]]", res.getString(16)); - assertEquals("2012-04-22 09:00:00.123456789", res.getString(17)); - assertEquals("2012-04-22 09:00:00.123456789", res.getTimestamp(17).toString()); - assertEquals("123456789.0123456", res.getBigDecimal(18).toString()); - assertEquals("2013-01-01", res.getString(20)); - assertEquals("2013-01-01", res.getDate(20).toString()); - - // test getBoolean rules on non-boolean columns - assertEquals(true, res.getBoolean(1)); - assertEquals(true, res.getBoolean(4)); - - // no more rows - assertFalse(res.next()); - } - - private void doTestSelectAll(String tableName, int maxRows, int fetchSize) throws Exception { - boolean isPartitionTable = tableName.equals(partitionedTableName); - - Statement stmt = con.createStatement(); - if (maxRows >= 0) { - stmt.setMaxRows(maxRows); - } - if (fetchSize > 0) { - stmt.setFetchSize(fetchSize); - assertEquals(fetchSize, stmt.getFetchSize()); - } - - // JDBC says that 0 means return all, which is the default - int expectedMaxRows = maxRows < 1 ? 0 : maxRows; - - assertNotNull("Statement is null", stmt); - assertEquals("Statement max rows not as expected", expectedMaxRows, stmt - .getMaxRows()); - assertFalse("Statement should not be closed", stmt.isClosed()); - - ResultSet res; - - // run some queries - res = stmt.executeQuery("select * from " + tableName); - assertNotNull("ResultSet is null", res); - assertTrue("getResultSet() not returning expected ResultSet", res == stmt - .getResultSet()); - assertEquals("get update count not as expected", 0, stmt.getUpdateCount()); - int i = 0; - - ResultSetMetaData meta = res.getMetaData(); - int expectedColCount = isPartitionTable ? 3 : 2; - assertEquals( - "Unexpected column count", expectedColCount, meta.getColumnCount()); - - String colQualifier = ((tableName != null) && !tableName.isEmpty()) ? tableName.toLowerCase() + "." : ""; - boolean moreRow = res.next(); - while (moreRow) { - try { - i++; - assertEquals(res.getInt(1), res.getInt(colQualifier + "under_col")); - assertEquals(res.getString(1), res.getString(colQualifier + "under_col")); - assertEquals(res.getString(2), res.getString(colQualifier + "value")); - if (isPartitionTable) { - assertEquals(res.getString(3), partitionedColumnValue); - assertEquals(res.getString(3), res.getString(colQualifier + partitionedColumnName)); - } - assertFalse("Last result value was not null", res.wasNull()); - assertNull("No warnings should be found on ResultSet", res - .getWarnings()); - res.clearWarnings(); // verifying that method is supported - - // System.out.println(res.getString(1) + " " + res.getString(2)); - assertEquals( - "getInt and getString don't align for the same result value", - String.valueOf(res.getInt(1)), res.getString(1)); - assertEquals("Unexpected result found", "val_" + res.getString(1), res - .getString(2)); - moreRow = res.next(); - } catch (SQLException e) { - System.out.println(e.toString()); - e.printStackTrace(); - throw new Exception(e.toString()); - } - } - - // supposed to get 500 rows if maxRows isn't set - int expectedRowCount = maxRows > 0 ? maxRows : 500; - assertEquals("Incorrect number of rows returned", expectedRowCount, i); - - // should have no more rows - assertEquals(false, moreRow); - - assertNull("No warnings should be found on statement", stmt.getWarnings()); - stmt.clearWarnings(); // verifying that method is supported - - assertNull("No warnings should be found on connection", con.getWarnings()); - con.clearWarnings(); // verifying that method is supported - - stmt.close(); - assertTrue("Statement should be closed", stmt.isClosed()); - } - - public void testErrorMessages() throws SQLException { - String invalidSyntaxSQLState = "42000"; - - // These tests inherently cause exceptions to be written to the test output - // logs. This is undesirable, since you it might appear to someone looking - // at the test output logs as if something is failing when it isn't. Not - // sure - // how to get around that. - doTestErrorCase("SELECTT * FROM " + tableName, - "cannot recognize input near 'SELECTT' '*' 'FROM'", - invalidSyntaxSQLState, 40000); - doTestErrorCase("SELECT * FROM some_table_that_does_not_exist", - "Table not found", "42S02", 10001); - doTestErrorCase("drop table some_table_that_does_not_exist", - "Table not found", "42S02", 10001); - doTestErrorCase("SELECT invalid_column FROM " + tableName, - "Invalid table alias or column reference", invalidSyntaxSQLState, 10004); - doTestErrorCase("SELECT invalid_function(under_col) FROM " + tableName, - "Invalid function", invalidSyntaxSQLState, 10011); - - // TODO: execute errors like this currently don't return good error - // codes and messages. This should be fixed. - doTestErrorCase( - "create table " + tableName + " (key int, value string)", - "FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask", - "08S01", 1); - } - - private void doTestErrorCase(String sql, String expectedMessage, - String expectedSQLState, int expectedErrorCode) throws SQLException { - Statement stmt = con.createStatement(); - boolean exceptionFound = false; - try { - stmt.executeQuery(sql); - } catch (SQLException e) { - assertTrue("Adequate error messaging not found for '" + sql + "': " - + e.getMessage(), e.getMessage().contains(expectedMessage)); - assertEquals("Expected SQLState not found for '" + sql + "'", - expectedSQLState, e.getSQLState()); - assertEquals("Expected error code not found for '" + sql + "'", - expectedErrorCode, e.getErrorCode()); - exceptionFound = true; - } - - assertNotNull("Exception should have been thrown for query: " + sql, - exceptionFound); - } - - public void testShowTables() throws SQLException { - Statement stmt = con.createStatement(); - assertNotNull("Statement is null", stmt); - - ResultSet res = stmt.executeQuery("show tables"); - - boolean testTableExists = false; - while (res.next()) { - assertNotNull("table name is null in result set", res.getString(1)); - if (tableName.equalsIgnoreCase(res.getString(1))) { - testTableExists = true; - } - } - - assertTrue("table name " + tableName - + " not found in SHOW TABLES result set", testTableExists); - } - - public void testMetaDataGetTables() throws SQLException { - Map tests = new HashMap(); - tests.put("test%jdbc%", new Object[]{"testhivejdbcdriver_table" - , "testhivejdbcdriverpartitionedtable" - , "testhivejdbcdriverview"}); - tests.put("%jdbcdriver\\_table", new Object[]{"testhivejdbcdriver_table"}); - tests.put("testhivejdbcdriver\\_table", new Object[]{"testhivejdbcdriver_table"}); - tests.put("test_ivejdbcdri_er\\_table", new Object[]{"testhivejdbcdriver_table"}); - tests.put("test_ivejdbcdri_er_table", new Object[]{"testhivejdbcdriver_table"}); - tests.put("test_ivejdbcdri_er%table", new Object[]{ - "testhivejdbcdriver_table", "testhivejdbcdriverpartitionedtable" }); - tests.put("%jdbc%", new Object[]{ "testhivejdbcdriver_table" - , "testhivejdbcdriverpartitionedtable" - , "testhivejdbcdriverview"}); - tests.put("", new Object[]{}); - - for (String checkPattern: tests.keySet()) { - ResultSet rs = con.getMetaData().getTables("default", null, checkPattern, null); - int cnt = 0; - while (rs.next()) { - String resultTableName = rs.getString("TABLE_NAME"); - assertEquals("Get by index different from get by name.", rs.getString(3), resultTableName); - assertEquals("Excpected a different table.", tests.get(checkPattern)[cnt], resultTableName); - String resultTableComment = rs.getString("REMARKS"); - assertTrue("Missing comment on the table.", resultTableComment.length()>0); - String tableType = rs.getString("TABLE_TYPE"); - if (resultTableName.endsWith("view")) { - assertEquals("Expected a tabletype view but got something else.", "VIEW", tableType); - } - cnt++; - } - rs.close(); - assertEquals("Received an incorrect number of tables.", tests.get(checkPattern).length, cnt); - } - - // only ask for the views. - ResultSet rs = con.getMetaData().getTables("default", null, null - , new String[]{"VIEW"}); - int cnt=0; - while (rs.next()) { - cnt++; - } - rs.close(); - assertEquals("Incorrect number of views found.", 1, cnt); - } - - public void testMetaDataGetCatalogs() throws SQLException { - ResultSet rs = con.getMetaData().getCatalogs(); - int cnt = 0; - while (rs.next()) { - String catalogname = rs.getString("TABLE_CAT"); - assertEquals("Get by index different from get by name", rs.getString(1), catalogname); - switch(cnt) { - case 0: - assertEquals("default", catalogname); - break; - default: - fail("More then one catalog found."); - break; - } - cnt++; - } - rs.close(); - assertEquals("Incorrect catalog count", 1, cnt); - } - - public void testMetaDataGetSchemas() throws SQLException { - ResultSet rs = con.getMetaData().getSchemas(); - int cnt = 0; - while (rs.next()) { - cnt++; - } - rs.close(); - assertEquals("Incorrect schema count", 0, cnt); - } - - public void testMetaDataGetTableTypes() throws SQLException { - ResultSet rs = con.getMetaData().getTableTypes(); - Set tabletypes = new HashSet(); - tabletypes.add("TABLE"); - tabletypes.add("EXTERNAL TABLE"); - tabletypes.add("VIEW"); - - int cnt = 0; - while (rs.next()) { - String tabletype = rs.getString("TABLE_TYPE"); - assertEquals("Get by index different from get by name", rs.getString(1), tabletype); - tabletypes.remove(tabletype); - cnt++; - } - rs.close(); - assertEquals("Incorrect tabletype count.", 0, tabletypes.size()); - assertTrue("Found less tabletypes then we test for.", cnt >= tabletypes.size()); - } - - public void testMetaDataGetColumns() throws SQLException { - Map tests = new HashMap(); - tests.put(new String[]{"testhivejdbcdriver\\_table", null}, 2); - tests.put(new String[]{"testhivejdbc%", null}, 7); - tests.put(new String[]{"testhiveJDBC%", null}, 7); - tests.put(new String[]{"testhiveJDB\\C%", null}, 0); - tests.put(new String[]{"%jdbcdriver\\_table", null}, 2); - tests.put(new String[]{"%jdbcdriver\\_table%", "under\\_col"}, 1); - tests.put(new String[]{"%jdbcdriver\\_table%", "under\\_COL"}, 1); - tests.put(new String[]{"%jdbcdriver\\_table%", "under\\_co_"}, 1); - tests.put(new String[]{"%jdbcdriver\\_table%", "under_col"}, 1); - tests.put(new String[]{"%jdbcdriver\\_table%", "und%"}, 1); - tests.put(new String[]{"%jdbcdriver\\_table%", "%"}, 2); - tests.put(new String[]{"%jdbcdriver\\_table%", "_%"}, 2); - - for (String[] checkPattern: tests.keySet()) { - ResultSet rs = con.getMetaData().getColumns(null, null, checkPattern[0], - checkPattern[1]); - - // validate the metadata for the getColumns result set - ResultSetMetaData rsmd = rs.getMetaData(); - assertEquals("TABLE_CAT", rsmd.getColumnName(1)); - - int cnt = 0; - while (rs.next()) { - String columnname = rs.getString("COLUMN_NAME"); - int ordinalPos = rs.getInt("ORDINAL_POSITION"); - switch(cnt) { - case 0: - assertEquals("Wrong column name found", "under_col", columnname); - assertEquals("Wrong ordinal position found", ordinalPos, 1); - break; - case 1: - assertEquals("Wrong column name found", "value", columnname); - assertEquals("Wrong ordinal position found", ordinalPos, 2); - break; - default: - break; - } - cnt++; - } - rs.close(); - assertEquals("Found less columns then we test for.", tests.get(checkPattern).intValue(), cnt); - } - } - - /** - * Validate the Metadata for the result set of a metadata getColumns call. - */ - public void testMetaDataGetColumnsMetaData() throws SQLException { - ResultSet rs = con.getMetaData().getColumns(null, null - , "testhivejdbcdriver\\_table", null); - - ResultSetMetaData rsmd = rs.getMetaData(); - - assertEquals("TABLE_CAT", rsmd.getColumnName(1)); - assertEquals(Types.VARCHAR, rsmd.getColumnType(1)); - assertEquals(Integer.MAX_VALUE, rsmd.getColumnDisplaySize(1)); - - assertEquals("ORDINAL_POSITION", rsmd.getColumnName(17)); - assertEquals(Types.INTEGER, rsmd.getColumnType(17)); - assertEquals(11, rsmd.getColumnDisplaySize(17)); - } - - public void testConversionsBaseResultSet() throws SQLException { - ResultSet rs = new HiveMetaDataResultSet(Arrays.asList("key") - , Arrays.asList("long") - , Arrays.asList(1234, "1234", "abc")) { - private int cnt=1; - @Override - public boolean next() throws SQLException { - if (cnt", colRS.getString("TYPE_NAME").toLowerCase()); - assertEquals(meta.getPrecision(5), colRS.getInt("COLUMN_SIZE")); - assertEquals(meta.getScale(5), colRS.getInt("DECIMAL_DIGITS")); - - assertTrue(colRS.next()); - - assertEquals("c6", meta.getColumnName(6)); - assertEquals(Types.VARCHAR, meta.getColumnType(6)); - assertEquals("string", meta.getColumnTypeName(6)); - assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(6)); - assertEquals(Integer.MAX_VALUE, meta.getPrecision(6)); - assertEquals(0, meta.getScale(6)); - - assertEquals("c6", colRS.getString("COLUMN_NAME")); - assertEquals(Types.VARCHAR, colRS.getInt("DATA_TYPE")); - assertEquals("map", colRS.getString("TYPE_NAME").toLowerCase()); - assertEquals(meta.getPrecision(6), colRS.getInt("COLUMN_SIZE")); - assertEquals(meta.getScale(6), colRS.getInt("DECIMAL_DIGITS")); - - assertTrue(colRS.next()); - - assertEquals("c7", meta.getColumnName(7)); - assertEquals(Types.VARCHAR, meta.getColumnType(7)); - assertEquals("string", meta.getColumnTypeName(7)); - assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(7)); - assertEquals(Integer.MAX_VALUE, meta.getPrecision(7)); - assertEquals(0, meta.getScale(7)); - - assertEquals("c7", colRS.getString("COLUMN_NAME")); - assertEquals(Types.VARCHAR, colRS.getInt("DATA_TYPE")); - assertEquals("map", colRS.getString("TYPE_NAME").toLowerCase()); - assertEquals(meta.getPrecision(7), colRS.getInt("COLUMN_SIZE")); - assertEquals(meta.getScale(7), colRS.getInt("DECIMAL_DIGITS")); - - assertTrue(colRS.next()); - - assertEquals("c8", meta.getColumnName(8)); - assertEquals(Types.VARCHAR, meta.getColumnType(8)); - assertEquals("string", meta.getColumnTypeName(8)); - assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(8)); - assertEquals(Integer.MAX_VALUE, meta.getPrecision(8)); - assertEquals(0, meta.getScale(8)); - - assertEquals("c8", colRS.getString("COLUMN_NAME")); - assertEquals(Types.VARCHAR, colRS.getInt("DATA_TYPE")); - assertEquals("struct", colRS.getString("TYPE_NAME").toLowerCase()); - assertEquals(meta.getPrecision(8), colRS.getInt("COLUMN_SIZE")); - assertEquals(meta.getScale(8), colRS.getInt("DECIMAL_DIGITS")); - - assertTrue(colRS.next()); - - assertEquals("c9", meta.getColumnName(9)); - assertEquals(Types.TINYINT, meta.getColumnType(9)); - assertEquals("tinyint", meta.getColumnTypeName(9)); - assertEquals(4, meta.getColumnDisplaySize(9)); - assertEquals(3, meta.getPrecision(9)); - assertEquals(0, meta.getScale(9)); - - assertEquals("c9", colRS.getString("COLUMN_NAME")); - assertEquals(Types.TINYINT, colRS.getInt("DATA_TYPE")); - assertEquals("tinyint", colRS.getString("TYPE_NAME").toLowerCase()); - assertEquals(meta.getPrecision(9), colRS.getInt("COLUMN_SIZE")); - assertEquals(meta.getScale(9), colRS.getInt("DECIMAL_DIGITS")); - - assertTrue(colRS.next()); - - assertEquals("c10", meta.getColumnName(10)); - assertEquals(Types.SMALLINT, meta.getColumnType(10)); - assertEquals("smallint", meta.getColumnTypeName(10)); - assertEquals(6, meta.getColumnDisplaySize(10)); - assertEquals(5, meta.getPrecision(10)); - assertEquals(0, meta.getScale(10)); - - assertEquals("c10", colRS.getString("COLUMN_NAME")); - assertEquals(Types.SMALLINT, colRS.getInt("DATA_TYPE")); - assertEquals("smallint", colRS.getString("TYPE_NAME").toLowerCase()); - assertEquals(meta.getPrecision(10), colRS.getInt("COLUMN_SIZE")); - assertEquals(meta.getScale(10), colRS.getInt("DECIMAL_DIGITS")); - - assertTrue(colRS.next()); - - assertEquals("c11", meta.getColumnName(11)); - assertEquals(Types.FLOAT, meta.getColumnType(11)); - assertEquals("float", meta.getColumnTypeName(11)); - assertEquals(24, meta.getColumnDisplaySize(11)); - assertEquals(7, meta.getPrecision(11)); - assertEquals(7, meta.getScale(11)); - - assertEquals("c11", colRS.getString("COLUMN_NAME")); - assertEquals(Types.FLOAT, colRS.getInt("DATA_TYPE")); - assertEquals("float", colRS.getString("TYPE_NAME").toLowerCase()); - assertEquals(meta.getPrecision(11), colRS.getInt("COLUMN_SIZE")); - assertEquals(meta.getScale(11), colRS.getInt("DECIMAL_DIGITS")); - - assertTrue(colRS.next()); - - assertEquals("c12", meta.getColumnName(12)); - assertEquals(Types.BIGINT, meta.getColumnType(12)); - assertEquals("bigint", meta.getColumnTypeName(12)); - assertEquals(20, meta.getColumnDisplaySize(12)); - assertEquals(19, meta.getPrecision(12)); - assertEquals(0, meta.getScale(12)); - - assertEquals("c12", colRS.getString("COLUMN_NAME")); - assertEquals(Types.BIGINT, colRS.getInt("DATA_TYPE")); - assertEquals("bigint", colRS.getString("TYPE_NAME").toLowerCase()); - assertEquals(meta.getPrecision(12), colRS.getInt("COLUMN_SIZE")); - assertEquals(meta.getScale(12), colRS.getInt("DECIMAL_DIGITS")); - - assertEquals("_c12", meta.getColumnName(13)); - assertEquals(Types.INTEGER, meta.getColumnType(13)); - assertEquals("int", meta.getColumnTypeName(13)); - assertEquals(11, meta.getColumnDisplaySize(13)); - assertEquals(10, meta.getPrecision(13)); - assertEquals(0, meta.getScale(13)); - - assertEquals("b", meta.getColumnName(14)); - assertEquals(Types.VARCHAR, meta.getColumnType(14)); - assertEquals("string", meta.getColumnTypeName(14)); - assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(14)); - assertEquals(Integer.MAX_VALUE, meta.getPrecision(14)); - assertEquals(0, meta.getScale(14)); - - assertEquals("c17", meta.getColumnName(15)); - assertEquals(Types.TIMESTAMP, meta.getColumnType(15)); - assertEquals("timestamp", meta.getColumnTypeName(15)); - assertEquals(29, meta.getColumnDisplaySize(15)); - assertEquals(29, meta.getPrecision(15)); - assertEquals(9, meta.getScale(15)); - - assertEquals("c18", meta.getColumnName(16)); - assertEquals(Types.DECIMAL, meta.getColumnType(16)); - assertEquals("decimal", meta.getColumnTypeName(16)); - assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(16)); - assertEquals(Integer.MAX_VALUE, meta.getPrecision(16)); - assertEquals(Integer.MAX_VALUE, meta.getScale(16)); - - assertEquals("c20", meta.getColumnName(17)); - assertEquals(Types.DATE, meta.getColumnType(17)); - assertEquals("date", meta.getColumnTypeName(17)); - assertEquals(10, meta.getColumnDisplaySize(17)); - assertEquals(10, meta.getPrecision(17)); - assertEquals(0, meta.getScale(17)); - - for (int i = 1; i <= meta.getColumnCount(); i++) { - assertFalse(meta.isAutoIncrement(i)); - assertFalse(meta.isCurrency(i)); - assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(i)); - } - } - - // [url] [host] [port] [db] - private static final String[][] URL_PROPERTIES = new String[][] { - {"jdbc:hive://", "", "", "default"}, - {"jdbc:hive://localhost:10001/default", "localhost", "10001", "default"}, - {"jdbc:hive://localhost/notdefault", "localhost", "10000", "notdefault"}, - {"jdbc:hive://foo:1243", "foo", "1243", "default"}}; - - public void testDriverProperties() throws SQLException { - HiveDriver driver = new HiveDriver(); - - for (String[] testValues : URL_PROPERTIES) { - DriverPropertyInfo[] dpi = driver.getPropertyInfo(testValues[0], null); - assertEquals("unexpected DriverPropertyInfo array size", 3, dpi.length); - assertDpi(dpi[0], "HOST", testValues[1]); - assertDpi(dpi[1], "PORT", testValues[2]); - assertDpi(dpi[2], "DBNAME", testValues[3]); - } - - } - - public void testInvalidUrl() throws SQLException { - HiveDriver driver = new HiveDriver(); - - assertNull(driver.connect("jdbc:hive2://localhost:1000", null)); - } - - private static void assertDpi(DriverPropertyInfo dpi, String name, - String value) { - assertEquals("Invalid DriverPropertyInfo name", name, dpi.name); - assertEquals("Invalid DriverPropertyInfo value", value, dpi.value); - assertEquals("Invalid DriverPropertyInfo required", false, dpi.required); - } - - - /** - * validate schema generated by "set" command - * @throws SQLException - */ - public void testSetCommand() throws SQLException { - // execute set command - String sql = "set -v"; - Statement stmt = con.createStatement(); - ResultSet res = stmt.executeQuery(sql); - - // Validate resultset columns - ResultSetMetaData md = res.getMetaData() ; - assertEquals(1, md.getColumnCount()); - assertEquals(SET_COLUMN_NAME, md.getColumnLabel(1)); - - //check if there is data in the resultset - assertTrue("Nothing returned by set -v", res.next()); - - res.close(); - stmt.close(); - } - - public void testShowGrant() throws SQLException { - Statement stmt = con.createStatement(); - stmt.execute("grant select on table " + dataTypeTableName + " to user hive_test_user"); - stmt.execute("show grant user hive_test_user on table " + dataTypeTableName); - - ResultSet res = stmt.getResultSet(); - assertTrue(res.next()); - assertEquals("default", res.getString(1)); - assertEquals(dataTypeTableName, res.getString(2)); - assertEquals("", res.getString(3)); // partition - assertEquals("", res.getString(4)); // column - assertEquals("hive_test_user", res.getString(5)); - assertEquals("USER", res.getString(6)); - assertEquals("SELECT", res.getString(7)); - assertEquals(false, res.getBoolean(8)); // grant option - assertEquals(-1, res.getLong(9)); - assertNotNull(res.getString(10)); // grantor - assertFalse(res.next()); - res.close(); - } - - public void testShowRoleGrant() throws SQLException { - Statement stmt = con.createStatement(); - - // drop role. ignore error. - try { - stmt.execute("drop role role1"); - } catch (Exception ex) { - LOG.warn("Ignoring error during drop role: " + ex); - } - - stmt.execute("create role role1"); - stmt.execute("grant role role1 to user hive_test_user"); - stmt.execute("show role grant user hive_test_user"); - - ResultSet res = stmt.getResultSet(); - assertTrue(res.next()); - assertEquals("public", res.getString(1)); - assertTrue(res.next()); - assertEquals("role1", res.getString(1)); - res.close(); - } -} Index: service/src/test/org/apache/hadoop/hive/service/TestHiveServerSessions.java =================================================================== --- service/src/test/org/apache/hadoop/hive/service/TestHiveServerSessions.java (revision 1637002) +++ service/src/test/org/apache/hadoop/hive/service/TestHiveServerSessions.java (working copy) @@ -1,99 +0,0 @@ -/** - * 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.hadoop.hive.service; - -import junit.framework.TestCase; -import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.transport.TSocket; - -import java.io.IOException; -import java.net.ServerSocket; - -/** - * For testing HiveServer in server mode - * - */ -public class TestHiveServerSessions extends TestCase { - - private static final int clientNum = 2; - - private int port; - private Thread server; - - private TSocket[] transports = new TSocket[clientNum]; - private HiveClient[] clients = new HiveClient[clientNum]; - - public TestHiveServerSessions(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - port = findFreePort(); - server = new Thread(new Runnable() { - public void run() { - HiveServer.main(new String[]{"-p", String.valueOf(port)}); - } - }); - server.start(); - Thread.sleep(5000); - - for (int i = 0; i < transports.length ; i++) { - TSocket transport = new TSocket("localhost", port); - transport.open(); - transports[i] = transport; - clients[i] = new HiveClient(new TBinaryProtocol(transport)); - } - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - for (TSocket socket : transports) { - if (socket != null) { - try { - socket.close(); - } catch (Exception e) { - // ignroe - } - } - } - if (server != null) { - server.interrupt(); - } - } - - private int findFreePort() throws IOException { - ServerSocket socket= new ServerSocket(0); - int port = socket.getLocalPort(); - socket.close(); - return port; - } - - public void testSessionVars() throws Exception { - for (int i = 0; i < clients.length; i++) { - clients[i].execute("set hiveconf:var=value" + i); - } - - for (int i = 0; i < clients.length; i++) { - clients[i].execute("set hiveconf:var"); - assertEquals("hiveconf:var=value" + i, clients[i].fetchOne()); - } - } -} Index: service/src/java/org/apache/hadoop/hive/service/HiveServer.java =================================================================== --- service/src/java/org/apache/hadoop/hive/service/HiveServer.java (revision 1637002) +++ service/src/java/org/apache/hadoop/hive/service/HiveServer.java (working copy) @@ -1,711 +0,0 @@ -/** - * 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.hadoop.hive.service; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.hive.common.ServerUtils; -import org.apache.hadoop.hive.common.LogUtils; -import org.apache.hadoop.hive.common.LogUtils.LogInitializationException; -import org.apache.hadoop.hive.common.cli.CommonCliOptions; -import org.apache.hadoop.hive.conf.HiveConf; -import org.apache.hadoop.hive.metastore.HiveMetaStore; -import org.apache.hadoop.hive.metastore.api.MetaException; -import org.apache.hadoop.hive.metastore.api.Schema; -import org.apache.hadoop.hive.metastore.TServerSocketKeepAlive; -import org.apache.hadoop.hive.ql.CommandNeedRetryException; -import org.apache.hadoop.hive.ql.Driver; -import org.apache.hadoop.hive.ql.plan.api.QueryPlan; -import org.apache.hadoop.hive.ql.processors.CommandProcessor; -import org.apache.hadoop.hive.ql.processors.CommandProcessorFactory; -import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse; -import org.apache.hadoop.hive.ql.session.SessionState; -import org.apache.hadoop.hive.shims.ShimLoader; -import org.apache.hadoop.mapred.ClusterStatus; -import org.apache.thrift.TException; -import org.apache.thrift.TProcessor; -import org.apache.thrift.TProcessorFactory; -import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.server.TServer; -import org.apache.thrift.server.TThreadPoolServer; -import org.apache.thrift.transport.TServerSocket; -import org.apache.thrift.transport.TServerTransport; -import org.apache.thrift.transport.TTransport; -import org.apache.thrift.transport.TTransportFactory; -import com.facebook.fb303.fb_status; - -/** - * Thrift Hive Server Implementation. - */ -public class HiveServer extends ThriftHive { - private static final String VERSION = "1"; - - /** - * default port on which to start the Hive server - */ - private static final int DEFAULT_HIVE_SERVER_PORT = 10000; - - /** - * default minimum number of threads serving the Hive server - */ - private static final int DEFAULT_MIN_WORKER_THREADS = 100; - - /** - * default maximum number of threads serving the Hive server - */ - private static final int DEFAULT_MAX_WORKER_THREADS = Integer.MAX_VALUE; - - /** - * Handler which implements the Hive Interface This class can be used in lieu - * of the HiveClient class to get an embedded server. - */ - public static class HiveServerHandler extends HiveMetaStore.HMSHandler - implements HiveInterface { - /** - * Hive server uses org.apache.hadoop.hive.ql.Driver for run() and - * getResults() methods. - * It is the instance of the last Hive query. - */ - private Driver driver; - private CommandProcessorResponse response; - /** - * For processors other than Hive queries (Driver), they output to session.out (a temp file) - * first and the fetchOne/fetchN/fetchAll functions get the output from pipeIn. - */ - private BufferedReader pipeIn; - - /** - * Flag that indicates whether the last executed command was a Hive query. - */ - private boolean isHiveQuery; - - public static final Log LOG = LogFactory.getLog(HiveServer.class.getName()); - - /** - * Construct a new handler. - * - * @throws MetaException unable to create metastore - */ - public HiveServerHandler() throws MetaException { - this(new HiveConf(SessionState.class)); - } - - /** - * Construct a new handler with the specified hive configuration. - * - * @param conf caller specified hive configuration - * @throws MetaException unable to create metastore - */ - public HiveServerHandler(HiveConf conf) throws MetaException { - super(HiveServer.class.getName(), conf); - - isHiveQuery = false; - driver = null; - SessionState session = new SessionState(conf); - SessionState.start(session); - setupSessionIO(session); - } - - private void setupSessionIO(SessionState session) { - try { - LOG.info("Putting temp output to file " + session.getTmpOutputFile().toString()); - session.in = null; // hive server's session input stream is not used - // open a per-session file in auto-flush mode for writing temp results - session.out = new PrintStream(new FileOutputStream(session.getTmpOutputFile()), true, "UTF-8"); - // TODO: for hadoop jobs, progress is printed out to session.err, - // we should find a way to feed back job progress to client - session.err = new PrintStream(System.err, true, "UTF-8"); - } catch (IOException e) { - LOG.error("Error in creating temp output file ", e); - try { - session.in = null; - session.out = new PrintStream(System.out, true, "UTF-8"); - session.err = new PrintStream(System.err, true, "UTF-8"); - } catch (UnsupportedEncodingException ee) { - ee.printStackTrace(); - session.out = null; - session.err = null; - } - } - } - - /** - * Executes a query. - * - * @param cmd - * HiveQL query to execute - */ - public void execute(String cmd) throws HiveServerException, TException { - HiveServerHandler.LOG.info("Running the query: " + cmd); - SessionState session = SessionState.get(); - - String cmd_trimmed = cmd.trim(); - String[] tokens = cmd_trimmed.split("\\s"); - String cmd_1 = cmd_trimmed.substring(tokens[0].length()).trim(); - - int ret = 0; - String errorMessage = ""; - String SQLState = null; - - try { - // Close the existing driver object (CommandProcessor) before creating - // the new driver (CommandProcessor) object to clean-up the resources - if (driver != null) { - driver.close(); - driver = null; - } - CommandProcessor proc = CommandProcessorFactory.get(tokens[0]); - if (proc != null) { - if (proc instanceof Driver) { - isHiveQuery = true; - driver = (Driver) proc; - // In Hive server mode, we are not able to retry in the FetchTask - // case, when calling fetch quueries since execute() has returned. - // For now, we disable the test attempts. - driver.setTryCount(Integer.MAX_VALUE); - response = driver.run(cmd); - } else { - isHiveQuery = false; - driver = null; - // need to reset output for each non-Hive query - setupSessionIO(session); - response = proc.run(cmd_1); - } - - ret = response.getResponseCode(); - SQLState = response.getSQLState(); - errorMessage = response.getErrorMessage(); - } - } catch (Exception e) { - HiveServerException ex = new HiveServerException(); - ex.setMessage("Error running query: " + e.toString()); - ex.setErrorCode(ret == 0? -10000: ret); - throw ex; - } - - if (ret != 0) { - throw new HiveServerException("Query returned non-zero code: " + ret - + ", cause: " + errorMessage, ret, SQLState); - } - } - - /** - * Should be called by the client at the end of a session. - */ - public void clean() { - if (driver != null) { - driver.close(); - driver.destroy(); - } - - SessionState session = SessionState.get(); - if (session.getTmpOutputFile() != null) { - session.getTmpOutputFile().delete(); - } - pipeIn = null; - } - - /** - * Return the status information about the Map-Reduce cluster. - */ - public HiveClusterStatus getClusterStatus() throws HiveServerException, - TException { - HiveClusterStatus hcs; - try { - Driver drv = new Driver(); - drv.init(); - - ClusterStatus cs = drv.getClusterStatus(); - JobTrackerState state = JobTrackerState.valueOf(ShimLoader.getHadoopShims().getJobTrackerState(cs).name()); - - hcs = new HiveClusterStatus(cs.getTaskTrackers(), cs.getMapTasks(), cs - .getReduceTasks(), cs.getMaxMapTasks(), cs.getMaxReduceTasks(), - state); - } catch (Exception e) { - LOG.error(e.toString()); - e.printStackTrace(); - HiveServerException ex = new HiveServerException(); - ex.setMessage("Unable to get cluster status: " + e.toString()); - throw ex; - } - return hcs; - } - - /** - * Return the Hive schema of the query result. - */ - public Schema getSchema() throws HiveServerException, TException { - if (!isHiveQuery) { - Schema schema = response.getSchema(); - if (schema == null) { - // Return empty schema if the last command was not a Hive query - return new Schema(); - } - else { - return schema; - } - } - - assert driver != null: "getSchema() is called on a Hive query and driver is NULL."; - - try { - Schema schema = driver.getSchema(); - if (schema == null) { - schema = new Schema(); - } - LOG.info("Returning schema: " + schema); - return schema; - } catch (Exception e) { - LOG.error(e.toString()); - e.printStackTrace(); - HiveServerException ex = new HiveServerException(); - ex.setMessage("Unable to get schema: " + e.toString()); - throw ex; - } - } - - /** - * Return the Thrift schema of the query result. - */ - public Schema getThriftSchema() throws HiveServerException, TException { - if (!isHiveQuery) { - // Return empty schema if the last command was not a Hive query - return new Schema(); - } - - assert driver != null: "getThriftSchema() is called on a Hive query and driver is NULL."; - - try { - Schema schema = driver.getThriftSchema(); - if (schema == null) { - schema = new Schema(); - } - LOG.info("Returning schema: " + schema); - return schema; - } catch (Exception e) { - LOG.error(e.toString()); - e.printStackTrace(); - HiveServerException ex = new HiveServerException(); - ex.setMessage("Unable to get schema: " + e.toString()); - throw ex; - } - } - - - /** - * Fetches the next row in a query result set. - * - * @return the next row in a query result set. null if there is no more row - * to fetch. - */ - public String fetchOne() throws HiveServerException, TException { - if (!isHiveQuery) { - // Return no results if the last command was not a Hive query - List results = new ArrayList(1); - readResults(results, 1); - if (results.size() > 0) { - return results.get(0); - } else { // throw an EOF exception - throw new HiveServerException("OK", 0, ""); - } - } - - assert driver != null: "fetchOne() is called on a Hive query and driver is NULL."; - - ArrayList result = new ArrayList(); - driver.setMaxRows(1); - try { - if (driver.getResults(result)) { - return result.get(0); - } - // TODO: Cannot return null here because thrift cannot handle nulls - // TODO: Returning empty string for now. Need to figure out how to - // TODO: return null in some other way - throw new HiveServerException("OK", 0, ""); - // return ""; - } catch (CommandNeedRetryException e) { - HiveServerException ex = new HiveServerException(); - ex.setMessage(e.getMessage()); - throw ex; - } catch (IOException e) { - HiveServerException ex = new HiveServerException(); - ex.setMessage(e.getMessage()); - throw ex; - } - } - - private void cleanTmpFile() { - if (pipeIn != null) { - SessionState session = SessionState.get(); - File tmp = session.getTmpOutputFile(); - tmp.delete(); - pipeIn = null; - } - } - - /** - * Reads the temporary results for non-Hive (non-Driver) commands to the - * resulting List of strings. - * @param results list of strings containing the results - * @param nLines number of lines read at once. If it is <= 0, then read all lines. - */ - private void readResults(List results, int nLines) { - - if (pipeIn == null) { - SessionState session = SessionState.get(); - File tmp = session.getTmpOutputFile(); - try { - pipeIn = new BufferedReader(new FileReader(tmp)); - } catch (FileNotFoundException e) { - LOG.error("File " + tmp + " not found. ", e); - return; - } - } - - boolean readAll = false; - - for (int i = 0; i < nLines || nLines <= 0; ++i) { - try { - String line = pipeIn.readLine(); - if (line == null) { - // reached the end of the result file - readAll = true; - break; - } else { - results.add(line); - } - } catch (IOException e) { - LOG.error("Reading temp results encountered an exception: ", e); - readAll = true; - } - } - if (readAll) { - cleanTmpFile(); - } - } - - /** - * Fetches numRows rows. - * - * @param numRows - * Number of rows to fetch. - * @return A list of rows. The size of the list is numRows if there are at - * least numRows rows available to return. The size is smaller than - * numRows if there aren't enough rows. The list will be empty if - * there is no more row to fetch or numRows == 0. - * @throws HiveServerException - * Invalid value for numRows (numRows < 0) - */ - public List fetchN(int numRows) throws HiveServerException, - TException { - if (numRows < 0) { - HiveServerException ex = new HiveServerException(); - ex.setMessage("Invalid argument for number of rows: " + numRows); - throw ex; - } - - ArrayList result = new ArrayList(); - - if (!isHiveQuery) { - readResults(result, numRows); - return result; - } - - assert driver != null: "fetchN() is called on a Hive query and driver is NULL."; - - driver.setMaxRows(numRows); - try { - driver.getResults(result); - } catch (CommandNeedRetryException e) { - HiveServerException ex = new HiveServerException(); - ex.setMessage(e.getMessage()); - throw ex; - } catch (IOException e) { - HiveServerException ex = new HiveServerException(); - ex.setMessage(e.getMessage()); - throw ex; - } - return result; - } - - /** - * Fetches all the rows in a result set. - * - * @return All the rows in a result set of a query executed using execute - * method. - * - * TODO: Currently the server buffers all the rows before returning - * them to the client. Decide whether the buffering should be done - * in the client. - */ - public List fetchAll() throws HiveServerException, TException { - - ArrayList rows = new ArrayList(); - ArrayList result = new ArrayList(); - - if (!isHiveQuery) { - // Return all results if numRows <= 0 - readResults(result, 0); - return result; - } - - try { - while (driver.getResults(result)) { - rows.addAll(result); - result.clear(); - } - } catch (CommandNeedRetryException e) { - HiveServerException ex = new HiveServerException(); - ex.setMessage(e.getMessage()); - throw ex; - } catch (IOException e) { - HiveServerException ex = new HiveServerException(); - ex.setMessage(e.getMessage()); - throw ex; - } - return rows; - } - - /** - * Return the status of the server. - */ - @Override - public fb_status getStatus() { - return fb_status.ALIVE; - } - - /** - * Return the version of the server software. - */ - @Override - public String getVersion() { - return VERSION; - } - - @Override - public QueryPlan getQueryPlan() throws HiveServerException, TException { - QueryPlan qp = new QueryPlan(); - - if (!isHiveQuery) { - return qp; - } - - assert driver != null: "getQueryPlan() is called on a Hive query and driver is NULL."; - - // TODO for now only return one query at a time - // going forward, all queries associated with a single statement - // will be returned in a single QueryPlan - try { - qp.addToQueries(driver.getQueryPlan()); - } catch (Exception e) { - HiveServerException ex = new HiveServerException(); - ex.setMessage(e.toString()); - throw ex; - } - return qp; - } - - } - - /** - * ThriftHiveProcessorFactory. - * - */ - public static class ThriftHiveProcessorFactory extends TProcessorFactory { - private final HiveConf conf; - - public ThriftHiveProcessorFactory(TProcessor processor, HiveConf conf) { - super(processor); - this.conf = conf; - } - - @Override - @SuppressWarnings("unchecked") - public TProcessor getProcessor(TTransport trans) { - try { - Iface handler = new HiveServerHandler(new HiveConf(conf)); - return new ThriftHive.Processor(handler); - } catch (Exception e) { - HiveServerHandler.LOG.warn("Failed to get processor by exception " + e, e); - trans.close(); - throw new RuntimeException(e); - } - } - } - - /** - * HiveServer specific CLI - * - */ - static public class HiveServerCli extends CommonCliOptions { - private static final String OPTION_MAX_WORKER_THREADS = "maxWorkerThreads"; - private static final String OPTION_MIN_WORKER_THREADS = "minWorkerThreads"; - - public int port = DEFAULT_HIVE_SERVER_PORT; - public int minWorkerThreads = DEFAULT_MIN_WORKER_THREADS; - public int maxWorkerThreads = DEFAULT_MAX_WORKER_THREADS; - - @SuppressWarnings("static-access") - public HiveServerCli() { - super("hiveserver", true); - - // -p port - OPTIONS.addOption(OptionBuilder - .hasArg() - .withArgName("port") - .withDescription("Hive Server port number, default:" - + DEFAULT_HIVE_SERVER_PORT) - .create('p')); - - // min worker thread count - OPTIONS.addOption(OptionBuilder - .hasArg() - .withLongOpt(OPTION_MIN_WORKER_THREADS) - .withDescription("minimum number of worker threads, default:" - + DEFAULT_MIN_WORKER_THREADS) - .create()); - - // max worker thread count - OPTIONS.addOption(OptionBuilder - .hasArg() - .withLongOpt(OPTION_MAX_WORKER_THREADS) - .withDescription("maximum number of worker threads, default:" - + DEFAULT_MAX_WORKER_THREADS) - .create()); - } - - @Override - public void parse(String[] args) { - super.parse(args); - - // support the old syntax "hiveserver [port [threads]]" but complain - args = commandLine.getArgs(); - if (args.length >= 1) { - // complain about the deprecated syntax -- but still run - System.err.println( - "This usage has been deprecated, consider using the new command " - + "line syntax (run with -h to see usage information)"); - - port = Integer.parseInt(args[0]); - } - if (args.length >= 2) { - minWorkerThreads = Integer.parseInt(args[1]); - } - - // notice that command line options take precedence over the - // deprecated (old style) naked args... - if (commandLine.hasOption('p')) { - port = Integer.parseInt(commandLine.getOptionValue('p')); - } else { - // legacy handling - String hivePort = System.getenv("HIVE_PORT"); - if (hivePort != null) { - port = Integer.parseInt(hivePort); - } - } - if (commandLine.hasOption(OPTION_MIN_WORKER_THREADS)) { - minWorkerThreads = Integer.parseInt( - commandLine.getOptionValue(OPTION_MIN_WORKER_THREADS)); - } - if (commandLine.hasOption(OPTION_MAX_WORKER_THREADS)) { - maxWorkerThreads = Integer.parseInt( - commandLine.getOptionValue(OPTION_MAX_WORKER_THREADS)); - } - } - } - - public static void main(String[] args) { - try { - HiveServerCli cli = new HiveServerCli(); - - cli.parse(args); - - - // NOTE: It is critical to do this prior to initializing log4j, otherwise - // any log specific settings via hiveconf will be ignored - Properties hiveconf = cli.addHiveconfToSystemProperties(); - - // NOTE: It is critical to do this here so that log4j is reinitialized - // before any of the other core hive classes are loaded - try { - LogUtils.initHiveLog4j(); - } catch (LogInitializationException e) { - HiveServerHandler.LOG.warn(e.getMessage()); - } - - HiveConf conf = new HiveConf(HiveServerHandler.class); - ServerUtils.cleanUpScratchDir(conf); - - - boolean tcpKeepAlive = conf.getBoolVar(HiveConf.ConfVars.SERVER_TCP_KEEP_ALIVE); - int timeout = (int) HiveConf.getTimeVar( - conf, HiveConf.ConfVars.SERVER_READ_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); - - TServerTransport serverTransport = - tcpKeepAlive ? new TServerSocketKeepAlive(cli.port) : new TServerSocket(cli.port, timeout); - - // set all properties specified on the command line - for (Map.Entry item : hiveconf.entrySet()) { - conf.set((String) item.getKey(), (String) item.getValue()); - } - - ThriftHiveProcessorFactory hfactory = - new ThriftHiveProcessorFactory(null, conf); - - TThreadPoolServer.Args sargs = new TThreadPoolServer.Args(serverTransport) - .processorFactory(hfactory) - .transportFactory(new TTransportFactory()) - .protocolFactory(new TBinaryProtocol.Factory()) - .minWorkerThreads(cli.minWorkerThreads) - .maxWorkerThreads(cli.maxWorkerThreads); - - TServer server = new TThreadPoolServer(sargs); - - String msg = "Starting hive server on port " + cli.port - + " with " + cli.minWorkerThreads + " min worker threads and " - + cli.maxWorkerThreads + " max worker threads"; - HiveServerHandler.LOG.info(msg); - - HiveServerHandler.LOG.info("TCP keepalive = " + tcpKeepAlive); - - if (cli.isVerbose()) { - System.err.println(msg); - } - - server.serve(); - } catch (Exception x) { - x.printStackTrace(); - } - } -} Index: service/src/java/org/apache/hadoop/hive/service/HiveClient.java =================================================================== --- service/src/java/org/apache/hadoop/hive/service/HiveClient.java (revision 1637002) +++ service/src/java/org/apache/hadoop/hive/service/HiveClient.java (working copy) @@ -1,31 +0,0 @@ -/** - * 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.hadoop.hive.service; - -import org.apache.thrift.protocol.TProtocol; - -/** - * Thrift Hive Client Just an empty class that can be used to run queries on a - * stand alone hive server. - */ -public class HiveClient extends ThriftHive.Client implements HiveInterface { - public HiveClient(TProtocol prot) { - super(prot, prot); - } -} Index: service/src/java/org/apache/hadoop/hive/service/HiveInterface.java =================================================================== --- service/src/java/org/apache/hadoop/hive/service/HiveInterface.java (revision 1637002) +++ service/src/java/org/apache/hadoop/hive/service/HiveInterface.java (working copy) @@ -1,36 +0,0 @@ -/** - * 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.hadoop.hive.service; - -/** - * HiveInterface extends 2 interfaces, ThriftHive and ThriftHiveMetastore. - * - * ThriftHive.Iface is defined in: - * service/src/gen-javabean/org/apache/hadoop/hive/service/ThriftHive.java - * ThriftHiveMetastore.Iface is defined in: - * metastore/src/gen-javabean/org/apache - * /hadoop/hive/metastore/api/ThriftHiveMetastore.java - * - * These interfaces are generated by Thrift. The thrift files are in: - * ThriftHive: service/if/hive_service.thrift ThriftHiveMetastore: - * metastore/if/hive_metastore.thrift - */ -public interface HiveInterface extends ThriftHive.Iface, - org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.Iface { -} Index: cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java =================================================================== --- cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java (revision 1637002) +++ cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java (working copy) @@ -56,11 +56,7 @@ import org.apache.hadoop.hive.ql.CommandNeedRetryException; import org.apache.hadoop.hive.ql.Driver; import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse; -import org.apache.hadoop.hive.service.HiveClient; -import org.apache.hadoop.hive.service.HiveServerException; -import org.apache.thrift.TException; - // Cannot call class TestCliDriver since that's the name of the generated // code for the script-based testing public class TestCliDriverMethods extends TestCase { @@ -230,66 +226,6 @@ } - /** - * test remote execCommand - */ - public void testRemoteCall() throws Exception { - MyCliSessionState ss = new MyCliSessionState(new HiveConf(), - org.apache.hadoop.hive.cli.TestCliDriverMethods.MyCliSessionState.ClientResult.RETURN_OK); - ss.err = System.err; - ByteArrayOutputStream data = new ByteArrayOutputStream(); - ss.out = new PrintStream(data); - MyCliSessionState.start(ss); - - CliDriver cliDriver = new CliDriver(); - cliDriver.processCmd("remote command"); - assertTrue(data.toString().contains("test result")); - - } - - /** - * test remote Exception - */ - public void testServerException() throws Exception { - MyCliSessionState ss = new MyCliSessionState( - new HiveConf(), - org.apache.hadoop.hive.cli.TestCliDriverMethods.MyCliSessionState.ClientResult.RETURN_SERVER_EXCEPTION); - ByteArrayOutputStream data = new ByteArrayOutputStream(); - ss.err = new PrintStream(data); - ss.out = System.out; - MyCliSessionState.start(ss); - - CliDriver cliDriver = new CliDriver(); - cliDriver.processCmd("remote command"); - assertTrue(data.toString().contains("[Hive Error]: test HiveServerException")); - data.reset(); - - - } - - /** - * test remote Exception - */ - public void testServerTException() throws Exception { - MyCliSessionState ss = new MyCliSessionState( - new HiveConf(), - org.apache.hadoop.hive.cli.TestCliDriverMethods.MyCliSessionState.ClientResult.RETURN_T_EXCEPTION); - ByteArrayOutputStream data = new ByteArrayOutputStream(); - ss.err = new PrintStream(data); - ss.out = System.out; - MyCliSessionState.start(ss); - - CliDriver cliDriver = new CliDriver(); - cliDriver.processCmd("remote command"); - assertTrue(data.toString().contains("[Thrift Error]: test TException")); - assertTrue(data.toString().contains( - "[Thrift Error]: Hive server is not cleaned due to thrift exception: test TException")); - - } - - /** - * test remote Exception - */ public void testProcessSelectDatabase() throws Exception { CliSessionState sessinState = new CliSessionState(new HiveConf()); CliSessionState.start(sessinState); @@ -494,63 +430,4 @@ return status; } } - - private static class MyCliSessionState extends CliSessionState { - - public enum ClientResult { - RETURN_OK, RETURN_SERVER_EXCEPTION, RETURN_T_EXCEPTION - }; - - private final ClientResult result; - - public MyCliSessionState(HiveConf conf, ClientResult result) { - super(conf); - this.result = result; - } - - @Override - public boolean isRemoteMode() { - return true; - } - - @Override - public HiveClient getClient() { - - HiveClient result = mock(HiveClient.class); - if (ClientResult.RETURN_OK.equals(this.result)) { - List fetchResult = new ArrayList(1); - fetchResult.add("test result"); - try { - when(result.fetchN(anyInt())).thenReturn(fetchResult); - } catch (HiveServerException e) { - } catch (Exception e) { - } - } else if (ClientResult.RETURN_SERVER_EXCEPTION.equals(this.result)) { - HiveServerException exception = new HiveServerException("test HiveServerException", 10, - "sql state"); - try { - when(result.fetchN(anyInt())).thenThrow(exception); - - when(result.fetchN(anyInt())).thenThrow(exception); - } catch (TException e) { - ; - } - return result; - } else if (ClientResult.RETURN_T_EXCEPTION.equals(this.result)) { - TException exception = new TException("test TException"); - try { - // org.mockito.Mockito. - doThrow(exception).when(result).clean(); - when(result.fetchN(anyInt())).thenThrow(exception); - } catch (TException e) { - e.printStackTrace(); - } - return result; - } - return result; - } - - } - - } Index: cli/src/test/org/apache/hadoop/hive/cli/TestOptionsProcessor.java =================================================================== --- cli/src/test/org/apache/hadoop/hive/cli/TestOptionsProcessor.java (revision 1637002) +++ cli/src/test/org/apache/hadoop/hive/cli/TestOptionsProcessor.java (working copy) @@ -41,8 +41,7 @@ System.clearProperty("hivevar"); assertNull(System.getProperty("_A")); String[] args = { "-hiveconf", "_A=B", "-define", "C=D", "-hivevar", "X=Y", - "-S", "true", "-database", "testDb", "-e", "execString", "-v", "true", - "-h", "yahoo.host", "-p", "3000"}; + "-S", "true", "-database", "testDb", "-e", "execString", "-v", "true"}; // stage 1 assertTrue(processor.process_stage1(args)); @@ -55,8 +54,6 @@ processor.process_stage2(sessionState); assertEquals("testDb", sessionState.database); assertEquals("execString", sessionState.execString); - assertEquals("yahoo.host", sessionState.host); - assertEquals(3000, sessionState.port); assertEquals(0, sessionState.initFiles.size()); assertTrue(sessionState.getIsVerbose()); sessionState.setConf(null); Index: cli/src/test/org/apache/hadoop/hive/cli/TestCliSessionState.java =================================================================== --- cli/src/test/org/apache/hadoop/hive/cli/TestCliSessionState.java (revision 1637002) +++ cli/src/test/org/apache/hadoop/hive/cli/TestCliSessionState.java (working copy) @@ -18,21 +18,10 @@ package org.apache.hadoop.hive.cli; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; - import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.MetaStoreUtils; import org.apache.hadoop.hive.ql.session.SessionState; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; /** @@ -40,47 +29,7 @@ */ public class TestCliSessionState { - private static TCPServer server; - private static String command = null; - - @BeforeClass - public static void start() throws Exception { - // start fake server - server = new TCPServer(); - Thread thread = new Thread(server); - thread.start(); - // wait for start server; - while (server.getPort() == 0) { - Thread.sleep(20); - } - } - - @AfterClass - public static void stop() throws IOException { - server.stop(); - } - /** - * test CliSessionState for remote - */ - @Test - public void testConnect() throws Exception { - CliSessionState sessionState = new CliSessionState(new HiveConf()); - sessionState.port = server.getPort(); - sessionState.setHost(InetAddress.getLocalHost().getHostName()); - // check connect - sessionState.connect(); - assertTrue(sessionState.isRemoteMode()); - assertEquals(server.getPort(), sessionState.getPort()); - assertEquals(InetAddress.getLocalHost().getHostName(), sessionState.getHost()); - assertNotNull(sessionState.getClient()); - sessionState.close(); - // close should send command clean - assertEquals(command, "clean"); - - } - - /** * test default db name */ @Test @@ -89,44 +38,4 @@ assertEquals(MetaStoreUtils.DEFAULT_DATABASE_NAME, SessionState.get().getCurrentDatabase()); } - - /** - * fake hive server - */ - private static class TCPServer implements Runnable { - private int port = 0; - private boolean stop = false; - private ServerSocket welcomeSocket; - - public void run() { - try { - - welcomeSocket = new ServerSocket(0); - port = welcomeSocket.getLocalPort(); - while (!stop) { - byte[] buffer = new byte[512]; - Socket connectionSocket = welcomeSocket.accept(); - InputStream input = connectionSocket.getInputStream(); - OutputStream output = connectionSocket.getOutputStream(); - int read = input.read(buffer); - // command without service bytes - command = new String(buffer, 8, read - 13); - // send derived - output.write(buffer, 0, read); - } - } catch (IOException e) { - ; - } - - } - - public int getPort() { - return port; - } - - public void stop() throws IOException { - stop = true; - welcomeSocket.close(); - } - } } Index: cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java =================================================================== --- cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java (revision 1637002) +++ cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java (working copy) @@ -68,10 +68,7 @@ import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse; import org.apache.hadoop.hive.ql.session.SessionState; import org.apache.hadoop.hive.ql.session.SessionState.LogHelper; -import org.apache.hadoop.hive.service.HiveClient; -import org.apache.hadoop.hive.service.HiveServerException; import org.apache.hadoop.io.IOUtils; -import org.apache.thrift.TException; import sun.misc.Signal; import sun.misc.SignalHandler; @@ -150,51 +147,8 @@ stringifyException(e)); ret = 1; } - } else if (ss.isRemoteMode()) { // remote mode -- connecting to remote hive server - HiveClient client = ss.getClient(); - PrintStream out = ss.out; - PrintStream err = ss.err; - + } else { // local mode try { - client.execute(cmd_trimmed); - List results; - do { - results = client.fetchN(LINES_TO_FETCH); - for (String line : results) { - out.println(line); - } - } while (results.size() == LINES_TO_FETCH); - } catch (HiveServerException e) { - ret = e.getErrorCode(); - if (ret != 0) { // OK if ret == 0 -- reached the EOF - String errMsg = e.getMessage(); - if (errMsg == null) { - errMsg = e.toString(); - } - ret = e.getErrorCode(); - err.println("[Hive Error]: " + errMsg); - } - } catch (TException e) { - String errMsg = e.getMessage(); - if (errMsg == null) { - errMsg = e.toString(); - } - ret = -10002; - err.println("[Thrift Error]: " + errMsg); - } finally { - try { - client.clean(); - } catch (TException e) { - String errMsg = e.getMessage(); - if (errMsg == null) { - errMsg = e.toString(); - } - err.println("[Thrift Error]: Hive server is not cleaned due to thrift exception: " - + errMsg); - } - } - } else { // local mode - try { CommandProcessor proc = CommandProcessorFactory.get(tokens, (HiveConf) conf); ret = processLocalCmd(cmd, proc, ss); } catch (SQLException e) { @@ -695,31 +649,6 @@ private int executeDriver(CliSessionState ss, HiveConf conf, OptionsProcessor oproc) throws Exception { - // connect to Hive Server - if (ss.getHost() != null) { - ss.connect(); - if (ss.isRemoteMode()) { - prompt = "[" + ss.host + ':' + ss.port + "] " + prompt; - char[] spaces = new char[prompt.length()]; - Arrays.fill(spaces, ' '); - prompt2 = new String(spaces); - } - } - - // CLI remote mode is a thin client: only load auxJars in local mode - if (!ss.isRemoteMode()) { - // hadoop-20 and above - we need to augment classpath using hiveconf - // components - // see also: code in ExecDriver.java - ClassLoader loader = conf.getClassLoader(); - String auxJars = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEAUXJARS); - if (StringUtils.isNotBlank(auxJars)) { - loader = Utilities.addToClassPath(loader, StringUtils.split(auxJars, ",")); - } - conf.setClassLoader(loader); - Thread.currentThread().setContextClassLoader(loader); - } - CliDriver cli = new CliDriver(); cli.setHiveVariables(oproc.getHiveVariables()); Index: cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java =================================================================== --- cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java (revision 1637002) +++ cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java (working copy) @@ -83,20 +83,6 @@ .withDescription("Use value for given property") .create()); - // -h hostname/ippaddress - options.addOption(OptionBuilder - .hasArg() - .withArgName("hostname") - .withDescription("connecting to Hive Server on remote host") - .create('h')); - - // -p port - options.addOption(OptionBuilder - .hasArg() - .withArgName("port") - .withDescription("connecting to Hive Server on port number") - .create('p')); - // Substitution option -d, --define options.addOption(OptionBuilder .withValueSeparator() @@ -169,10 +155,6 @@ ss.setIsVerbose(commandLine.hasOption('v')); - ss.host = (String) commandLine.getOptionValue('h'); - - ss.port = Integer.parseInt((String) commandLine.getOptionValue('p', "10000")); - String[] initFiles = commandLine.getOptionValues('i'); if (null != initFiles) { ss.initFiles = Arrays.asList(initFiles); Index: cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java =================================================================== --- cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java (revision 1637002) +++ cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java (working copy) @@ -25,13 +25,6 @@ import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.ql.session.SessionState; -import org.apache.hadoop.hive.service.HiveClient; -import org.apache.thrift.TException; -import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.protocol.TProtocol; -import org.apache.thrift.transport.TSocket; -import org.apache.thrift.transport.TTransport; -import org.apache.thrift.transport.TTransportException; /** * SessionState for hive cli. @@ -63,66 +56,16 @@ */ public List initFiles = new ArrayList(); - /** - * host name and port number of remote Hive server - */ - protected String host; - protected int port; - - private boolean remoteMode; - - private TTransport transport; - private HiveClient client; - public CliSessionState(HiveConf conf) { super(conf); - remoteMode = false; } - /** - * Connect to Hive Server - */ - public void connect() throws TTransportException { - transport = new TSocket(host, port); - TProtocol protocol = new TBinaryProtocol(transport); - client = new HiveClient(protocol); - transport.open(); - remoteMode = true; - } - - public void setHost(String host) { - this.host = host; - } - - public String getHost() { - return host; - } - - public int getPort() { - return port; - } - @Override public void close() { try { super.close(); - if (remoteMode) { - client.clean(); - transport.close(); - } } catch (IOException ioe) { ioe.printStackTrace(); - } catch (TException e) { - e.printStackTrace(); - } + } } - - public boolean isRemoteMode() { - return remoteMode; - } - - public HiveClient getClient() { - return client; - } - }