我试图使用配置单元语句示例将数据从java类中的其他表插入到配置单元表中,源表和目标表都存在于同一个配置单元数据库中。
所有源表都包含数据。
以下类执行上述查询:
@Component
public class HiveExecutor implements IExecutor{
static final Logger logger = Logger.getLogger(HiveExecutor.class);
@Autowired
ConnectionFactory connectionFactory;
@Override
public ResultSetHolder executeSql(String sql) throws IOException {
logger.info(" Inside hive executor for SQL : " + sql);
ResultSetHolder rsHolder = new ResultSetHolder();
IConnector connector = connectionFactory.getConnector("hive");
ConnectionHolder conHolder = connector.getConnection();
Object obj = conHolder.getConObject();
if(obj instanceof Statement) {
Statement stmt = (Statement) obj;
ResultSet rs=null;
try {
if(sql.toUpperCase().contains("INSERT")) {
int result = stmt.executeUpdate(sql);
if(result != 0)
logger.info("Successfull insertion operation. Number of rows changed: "+result);
else
logger.info("Unsuccessfull insertion operation.");
}
else
rs = stmt.executeQuery(sql);
rsHolder.setResultSet(rs);
rsHolder.setType(ResultType.resultset);
} catch (SQLException e) {
e.printStackTrace();
}
}
return rsHolder;
}
@Override
public Boolean registerTempTable(DataFrame df, String tableName) {
// TODO Auto-generated method stub
return null;
}
}
执行select查询时,它确实会带来数据,但它失败/对于insert查询返回0。
当从hivecli执行相同的插入查询时,它会按预期工作,将数据插入到目标表中。
1条答案
按热度按时间9w11ddsr1#
尝试在连接字符串中指定队列名称:
连接字符串=“jdbc:hive2://host:port/db;主体=主体=Hive/hiveserver2host@your-realm.com?mapreduce.job.queuename=prod";