Search in sources :

Example 1 with HiveInsertFromSelectParser

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;
}
Also used : HiveInsertFromSelectParser(com.qlangtech.tis.hive.HiveInsertFromSelectParser)

Example 2 with HiveInsertFromSelectParser

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);
    }
}
Also used : EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName) IPath(com.qlangtech.tis.fs.IPath) ITISFileSystem(com.qlangtech.tis.fs.ITISFileSystem) Connection(java.sql.Connection) ParseException(org.apache.hadoop.hive.ql.parse.ParseException) HiveInsertFromSelectParser(com.qlangtech.tis.hive.HiveInsertFromSelectParser)

Example 3 with HiveInsertFromSelectParser

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();
}
Also used : HiveColumn(com.qlangtech.tis.hive.HiveColumn) HiveInsertFromSelectParser(com.qlangtech.tis.hive.HiveInsertFromSelectParser)

Example 4 with HiveInsertFromSelectParser

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()));
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) Logger(org.slf4j.Logger) MREngine(com.qlangtech.tis.plugin.datax.MREngine) HiveColumn(com.qlangtech.tis.hive.HiveColumn) IJoinTaskContext(com.qlangtech.tis.order.center.IJoinTaskContext) HiveParser(org.apache.hadoop.hive.ql.parse.HiveParser) LoggerFactory(org.slf4j.LoggerFactory) HiveInsertFromSelectParser(com.qlangtech.tis.hive.HiveInsertFromSelectParser) Collectors(java.util.stream.Collectors) Tree(org.antlr.runtime.tree.Tree) IParamContext(com.qlangtech.tis.order.center.IParamContext) ERRules(com.qlangtech.tis.sql.parser.er.ERRules) IFs2Table(com.qlangtech.tis.fs.IFs2Table) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta) JoinTaskStatus(com.qlangtech.tis.fullbuild.phasestatus.impl.JoinPhaseStatus.JoinTaskStatus) ITISFileSystem(com.qlangtech.tis.fs.ITISFileSystem) IJoinTaskContext(com.qlangtech.tis.order.center.IJoinTaskContext) HiveInsertFromSelectParser(com.qlangtech.tis.hive.HiveInsertFromSelectParser)

Aggregations

HiveInsertFromSelectParser (com.qlangtech.tis.hive.HiveInsertFromSelectParser)4 ITISFileSystem (com.qlangtech.tis.fs.ITISFileSystem)2 HiveColumn (com.qlangtech.tis.hive.HiveColumn)2 IFs2Table (com.qlangtech.tis.fs.IFs2Table)1 IPath (com.qlangtech.tis.fs.IPath)1 JoinTaskStatus (com.qlangtech.tis.fullbuild.phasestatus.impl.JoinPhaseStatus.JoinTaskStatus)1 IJoinTaskContext (com.qlangtech.tis.order.center.IJoinTaskContext)1 IParamContext (com.qlangtech.tis.order.center.IParamContext)1 MREngine (com.qlangtech.tis.plugin.datax.MREngine)1 SqlTaskNodeMeta (com.qlangtech.tis.sql.parser.SqlTaskNodeMeta)1 ERRules (com.qlangtech.tis.sql.parser.er.ERRules)1 EntityName (com.qlangtech.tis.sql.parser.tuple.creator.EntityName)1 Connection (java.sql.Connection)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Tree (org.antlr.runtime.tree.Tree)1 StringUtils (org.apache.commons.lang.StringUtils)1 HiveParser (org.apache.hadoop.hive.ql.parse.HiveParser)1 ParseException (org.apache.hadoop.hive.ql.parse.ParseException)1 Logger (org.slf4j.Logger)1