Hive Method Not Supported

2019-05-26 06:53发布

I am trying to run a SQl query using Hive as an underlying data store, the query invokes Big Decimal function and throws the following error :

Method not supported at

org.apache.hadoop.hive.jdbc.HivePreparedStatement.setBigDecimal(HivePreparedStatement.java:317) 

That is simply because Hive does not support as follows :

public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
    // TODO Auto-generated method stub
    throw new SQLException("Method not supported");
  }

Please suggest what can be other workarounds or fixes available to counter such an issue

标签: java sql hive
2条回答
劳资没心,怎么记你
2楼-- · 2019-05-26 06:58

The original Hive JDBC driver only supported few of the JDBC interfaces, see HIVE-48: Support JDBC connections for interoperability between Hive and RDBMS. So the commit left auto-generated "not supported" code for interfaces like CallableStatement or PreparedStatement.

With HIVE-2158: add the HivePreparedStatement implementation based on current HIVE supported data-type some of the methods were fleshed out, see the commit. But types like Blob, AsciiStream, binary stream and ... bigDecimal were not added. When HIVE-2158 was resolved (2011-06-15) the support for DECIMAL in Hive was not in, it came with HIVE-2693: Add DECIMAL data type, on 2013-01-17. When support for DECIMAL was added, looks like the JDBC driver interface was not updated.

So basically the JDBC driver needs to be updated with the new types supported. You should file a JIRA for this. Workaround: don't use DECIMAL, or don't use PrepareStatement.

查看更多
Anthone
3楼-- · 2019-05-26 07:22

I had similar issue with ".setObject" method, but after update to version 1.2.1 it was resolved. ".setBigDecimal" currently it is not implemented. Here is the implementation of the class. However in .setObject method currently has line like this which in fact solve the case.

if(value instanceof BigDecimal){
    st.setString(valueIndex, value.toString());
}

This worked for me, but you can lose precision without any warning!

In general it seems that metamodel supports decimal poorly. If you get all the columns with statemant like this

Column[] columnNames = table.getColumns();

and one of the columns is decimal you'll notice that there is no information about the precision.

查看更多
登录 后发表回答