use of org.apache.inlong.manager.common.pojo.query.ColumnInfoBean in project incubator-inlong by apache.
the class HiveServerDao method queryStructure.
/**
* Query Hive column structure
*/
public List<ColumnInfoBean> queryStructure(String querySql, String jdbcUrl, String user, String password) throws Exception {
try (Connection conn = this.getHiveConnection(jdbcUrl, user, password)) {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(querySql);
List<ColumnInfoBean> columnInfoBeans = new ArrayList<>();
try {
while (rs.next()) {
ColumnInfoBean columnInfoBean = new ColumnInfoBean();
columnInfoBean.setColumnName(rs.getString(1));
columnInfoBean.setColumnType(rs.getString(2));
columnInfoBean.setColumnDesc(rs.getString(3));
columnInfoBeans.add(columnInfoBean);
}
} catch (Exception e) {
LOG.error("query table structure error", e);
}
return columnInfoBeans;
}
}
use of org.apache.inlong.manager.common.pojo.query.ColumnInfoBean in project incubator-inlong by apache.
the class DefaultHiveTableOperator method createTable.
private void createTable(String groupId, SinkForSortDTO config) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("begin create hive table for inlong group={}, config={}", groupId, config);
}
// Get all info from config
HiveSinkDTO hiveInfo = HiveSinkDTO.getFromJson(config.getExtParams());
HiveTableQueryBean tableBean = getTableQueryBean(config, hiveInfo);
try {
// create database if not exists
dataSourceService.createDb(tableBean);
// check if the table exists
List<ColumnInfoBean> columns = dataSourceService.queryColumns(tableBean);
if (columns.size() == 0) {
// no such table, create one
dataSourceService.createTable(tableBean);
} else {
// set columns, skip the first columns already exist in hive
List<HiveColumnQueryBean> columnsSkipHistory = tableBean.getColumns().stream().skip(columns.size()).collect(toList());
if (columnsSkipHistory.size() != 0) {
tableBean.setColumns(columnsSkipHistory);
dataSourceService.createColumn(tableBean);
}
}
sinkService.updateStatus(config.getId(), EntityStatus.SINK_CONFIG_SUCCESSFUL.getCode(), "create hive table success");
} catch (Throwable e) {
LOGGER.error("create hive table error, ", e);
sinkService.updateStatus(config.getId(), EntityStatus.SINK_CONFIG_FAILED.getCode(), e.getMessage());
throw new WorkflowException("create hive table failed, reason: " + e.getMessage());
}
LOGGER.info("success create hive table for data group [" + groupId + "]");
}
Aggregations