use of com.qlangtech.tis.hive.HiveInsertFromSelectParser in project plugins by qlangtech.
the class JoinHiveTask method getSQLParserResult.
private HiveInsertFromSelectParser getSQLParserResult(String sql) throws ParseException {
final HiveInsertFromSelectParser insertParser = new HiveInsertFromSelectParser();
insertParser.start(sql);
return insertParser;
}
use of com.qlangtech.tis.hive.HiveInsertFromSelectParser in project plugins by qlangtech.
the class JoinHiveTask method processJoinTask.
/**
* 处理join表,是否需要自动创建表或者删除重新创建表
*
* @param sql
*/
private void processJoinTask(String sql) {
try {
final HiveInsertFromSelectParser insertParser = getSQLParserResult(sql);
final Connection conn = this.getTaskContext().getObj();
// final DumpTable dumpTable =
// DumpTable.createTable(insertParser.getTargetTableName());
final EntityName dumpTable = EntityName.parse(this.getName());
final String path = FSHistoryFileUtils.getJoinTableStorePath(fileSystem.getRootDir(), dumpTable).replaceAll("\\.", Path.SEPARATOR);
if (fileSystem == null) {
throw new IllegalStateException("fileSys can not be null");
}
ITISFileSystem fs = fileSystem;
IPath parent = fs.getPath(path);
initializeHiveTable(this.fileSystem, parent, mrEngine, HdfsFormat.DEFAULT_FORMAT, insertParser.getCols(), insertParser.getColsExcludePartitionCols(), conn, dumpTable, ITableDumpConstant.MAX_PARTITION_SAVE);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.qlangtech.tis.hive.HiveInsertFromSelectParser in project plugins by qlangtech.
the class UnionHiveTask method getParsersString.
private String getParsersString() {
StringBuilder sb = new StringBuilder();
int parserSize = parserList.size();
int parserCnt = 0;
for (HiveInsertFromSelectParser parser : parserList) {
Map<String, HiveColumn> columnMap = parser.getColsMap();
sb.append("SELECT ");
int columnSize = columnSet.size();
int columnCnt = 0;
for (String column : columnSet) {
if (columnMap.containsKey(column)) {
HiveColumn hiveColumn = columnMap.get(column);
if (hiveColumn.hasAliasName()) {
sb.append(hiveColumn.getRawName()).append(" AS ").append(column);
} else if (hiveColumn.hasDefaultValue()) {
sb.append(hiveColumn.getDefalutValue()).append(" AS ").append(column);
} else {
sb.append(hiveColumn.getName());
}
} else {
sb.append("'' AS ").append(column);
}
if (++columnCnt < columnSize) {
sb.append(", ");
}
}
sb.append(" FROM `").append(parser.getSourceTableName()).append("`");
if (parser.getWhere() != null) {
sb.append(" where ").append(getConditionString(parser.getWhere().getChild(0)));
}
if (++parserCnt < parserSize) {
sb.append("\nUNION ALL\n");
}
}
return sb.toString();
}
use of com.qlangtech.tis.hive.HiveInsertFromSelectParser in project plugins by qlangtech.
the class UnionHiveTask method parseSubTab.
private void parseSubTab() {
IJoinTaskContext chainContext = getContext().getExecContext();
for (String subTaskSql : getSubTaskSqls()) {
HiveInsertFromSelectParser parser = new HiveInsertFromSelectParser();
// try {
// StringWriter writer = new StringWriter();
// velocityEngine.evaluate(velocityContext, writer, "sql", subTaskSql);
// subTaskSql = writer.toString();
// IOUtils.close(writer);
parser.start(subTaskSql);
parserList.add(parser);
parser.getCols().stream().filter(column -> !partitionColumns.contains(column.getName())).forEach(column -> columnSet.add(column.getName()));
// } catch (IOException | ParseException e) {
// throw new IllegalStateException("parse sub table " + e.getMessage(), e);
// }
}
columnSet.addAll(partitionColumns);
// FIXME: in order to pass the compile phase ,make setContent comment
// setContent(getUnionSql());
chainContext.setAttribute(IParamContext.KEY_BUILD_TARGET_TABLE_NAME, this.getTableName());
chainContext.setAttribute("colsExcludePartitionColsList", columnSet.stream().filter(column -> !partitionColumns.contains(column)).collect(Collectors.toList()));
}
Aggregations