Search in sources :

Example 1 with EntityName

use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName 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 2 with EntityName

use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName in project tis by qlangtech.

the class TestSqlTaskNode method testParseWithSingleDumpNode.

public void testParseWithSingleDumpNode() {
    EntityName exportName = EntityName.parse("employees.employee");
    // , NodeType nodetype, IDumpNodeMapContext dumpNodesContext
    IDumpNodeMapContext dumpNodesContext = EasyMock.createMock("dumpNodesContext", IDumpNodeMapContext.class);
    EasyMock.expect(dumpNodesContext.nullableMatch(exportName.getTabName())).andReturn(exportName);
    SqlTaskNode taskNode = new SqlTaskNode(exportName, NodeType.DUMP, dumpNodesContext);
    taskNode.setContent("SELECT e.a,e.b,e.c FROM employee e");
    EasyMock.replay(dumpNodesContext);
    TableTupleCreator tupleCreator = taskNode.parse(true);
    assertNotNull("tupleCreator can not be null", tupleCreator);
    EasyMock.verify(dumpNodesContext);
}
Also used : TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName)

Example 3 with EntityName

use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName in project tis by qlangtech.

the class FlatTableRelation method buildInvokeQueryHeaderByTailerInfo.

/**
 * 执行调用通过子查询父表逻辑
 *
 * @return
 */
public FuncFormat buildInvokeQueryHeaderByTailerInfo() {
    FuncFormat r = new FuncFormat();
    final String paramsList = this.getHeaderKeys().stream().map((m) -> {
        TisGroupBy.TisColumn col = new TisGroupBy.TisColumn(m.getHeadLinkKey());
        r.appendLine("val " + col.getJavaVarName() + " = row.getColumn(\"" + m.getTailerLinkKey() + "\")");
        return col.getJavaVarName();
    }).collect(Collectors.joining(","));
    EntityName headerEntity = this.getHeaderEntity();
    r.startLine("val " + (this.isHeaderMulti() ? headerEntity.entities() + ": List[RowMap] " : headerEntity.getJavaEntityName() + ": RowMap ") + " = this." + this.buildQueryHeaderByTailerInfoMethodName() + "(" + paramsList + ") ");
    return r;
}
Also used : FuncFormat(com.qlangtech.tis.sql.parser.visitor.FuncFormat) DependencyNode(com.qlangtech.tis.sql.parser.meta.DependencyNode) StringUtils(org.apache.commons.lang.StringUtils) EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName) Set(java.util.Set) TisGroupBy(com.qlangtech.tis.sql.parser.TisGroupBy) TabCardinality(com.qlangtech.tis.sql.parser.er.TabCardinality) Collectors(java.util.stream.Collectors) List(java.util.List) TableRelation(com.qlangtech.tis.sql.parser.er.TableRelation) CollectionUtils(org.apache.commons.collections.CollectionUtils) Optional(java.util.Optional) PrimaryTableMeta(com.qlangtech.tis.sql.parser.er.PrimaryTableMeta) LinkKeys(com.qlangtech.tis.sql.parser.er.LinkKeys) FuncFormat(com.qlangtech.tis.sql.parser.visitor.FuncFormat) EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName) TisGroupBy(com.qlangtech.tis.sql.parser.TisGroupBy)

Example 4 with EntityName

use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName in project tis by qlangtech.

the class FlatTableRelation method buildInvokeQueryHeaderByTailerInfoResultProcess.

/**
 * 创建查询结处理
 *
 * @param primary
 * @param preTableRelation 上一个表关联关系
 * @return
 */
public FuncFormat buildInvokeQueryHeaderByTailerInfoResultProcess(PrimaryTableMeta primary, FlatTableRelation preTableRelation) {
    FuncFormat f = new FuncFormat();
    EntityName headerEntity = this.getHeaderEntity();
    f.appendLine("val " + headerEntity.getJavaEntityName() + "Meta : AliasList = tabColumnMetaMap.get(\"" + headerEntity.getTabName() + "\");");
    // TableRelation.FinalLinkKey finalLinkKey = getFinalLinkKey(primary.getDBPrimayKeyName().getName(), preTableRelation);
    // final String pkColGetter = headerEntity.createColGetterLiteria(finalLinkKey.linkKeyName);
    // headerEntity.getJavaEntityName() + "Meta.getColMeta(\"" + finalLinkKey.linkKeyName + "\")";
    final String createCompositePKLiteria = primary.createCompositePK(headerEntity.getJavaEntityName() + "Meta", this.isHeaderMulti() ? "r" : headerEntity.getJavaEntityName(), true, preTableRelation);
    if (this.isHeaderMulti()) {
        // 遍历结果集
        f.buildRowMapTraverseLiteria(headerEntity, (mm) -> {
            mm.startLine("pushPojo2Queue(" + createCompositePKLiteria + ", row)").append("/*gencode3*/");
        // mm.startLine("pushPojo2Queue(new CompositePK("
        // + headerEntity.createColValLiteria(finalLinkKey.linkKeyName, "r") + ", r), row)");
        });
    } else {
        f.methodBody("if(" + headerEntity.getJavaEntityName() + " != null)", (mm) -> {
            mm.startLine("return " + createCompositePKLiteria).append("/*gencode4*/");
        // mm.startLine("return new CompositePK(" + headerEntity.createColValLiteria("dddddd")
        // + "," + headerEntity.getJavaEntityName() + ")").append("/*codegen4*/");
        });
    }
    f.startLine(" null");
    return f;
}
Also used : FuncFormat(com.qlangtech.tis.sql.parser.visitor.FuncFormat) EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName)

Example 5 with EntityName

use of com.qlangtech.tis.sql.parser.tuple.creator.EntityName in project tis by qlangtech.

the class FlatTableRelation method buildQueryHeaderByTailerInfo.

/**
 * 通过子表查询主表(head),生成查询方法
 *
 * @param extraHeaderColKeys 额外的col
 * @return
 */
public FuncFormat buildQueryHeaderByTailerInfo(final Set<String> extraHeaderColKeys) {
    // final String paramsList = this.getJoinerKeys().stream().map((jk) -> {
    // TisGroupBy.TisColumn col = new TisGroupBy.TisColumn(jk.getChildKey());
    // return col.getJavaVarName() + " : String";
    // }).collect(Collectors.joining(","));
    // EntityName headerEntity = relation.getHeader().parseEntityName();
    final EntityName tailerEntity = this.getTailerEntity();
    final EntityName headEntity = this.getHeaderEntity();
    final String methodToken = "private def " + this.buildQueryHeaderByTailerInfoMethodName() + "(" + this.getJoinerKeysQueryMethodParamsLiteria() + ") : " + (this.isHeaderMulti() ? "List[RowMap]" : "RowMap") + " =";
    FuncFormat r = new FuncFormat();
    r.methodBody(methodToken, (m) -> {
        // 定义结果集对象
        m.startLine(headEntity.buildDefineRowMapListLiteria());
        // 创建查询对象
        m.startLine(headEntity.buildDefineCriteriaEqualLiteria());
        // << 设置查询条件
        // this.getJoinerKeys().stream().forEach((mm) -> {
        // TisGroupBy.TisColumn col = new TisGroupBy.TisColumn(mm.getChildKey());
        // m.appendLine(col.buildDefineParam());
        // });
        m.returnLine();
        m.startLine(headEntity.buildCreateCriteriaLiteria());
        this.getHeaderKeys().stream().forEach((mm) -> {
            TisGroupBy.TisColumn col = new TisGroupBy.TisColumn(mm.getHeadLinkKey());
            m.append(col.buildPropCriteriaEqualLiteria());
        });
        // 设置查询条件>>
        // 设置select的列
        Set<String> selCols = this.getHeaderKeys().stream().map((link) -> link.getHeadLinkKey()).collect(Collectors.toSet());
        selCols.addAll(extraHeaderColKeys);
        m.startLine(headEntity.buildAddSelectorColsLiteria(selCols));
        // 执行dao查询
        m.startLine(headEntity.buildExecuteQueryDAOLiteria());
        if (this.isHeaderMulti()) {
            m.startLine("return " + headEntity.entities());
        } else {
            m.methodBody("for ( ( r:RowMap) <- " + headEntity.entities() + ".asScala)", (rt) -> {
                rt.startLine("return r");
            });
            m.startLine("null");
        }
    });
    return r;
}
Also used : FuncFormat(com.qlangtech.tis.sql.parser.visitor.FuncFormat) DependencyNode(com.qlangtech.tis.sql.parser.meta.DependencyNode) StringUtils(org.apache.commons.lang.StringUtils) EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName) Set(java.util.Set) TisGroupBy(com.qlangtech.tis.sql.parser.TisGroupBy) TabCardinality(com.qlangtech.tis.sql.parser.er.TabCardinality) Collectors(java.util.stream.Collectors) List(java.util.List) TableRelation(com.qlangtech.tis.sql.parser.er.TableRelation) CollectionUtils(org.apache.commons.collections.CollectionUtils) Optional(java.util.Optional) PrimaryTableMeta(com.qlangtech.tis.sql.parser.er.PrimaryTableMeta) LinkKeys(com.qlangtech.tis.sql.parser.er.LinkKeys) FuncFormat(com.qlangtech.tis.sql.parser.visitor.FuncFormat) EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName) TisGroupBy(com.qlangtech.tis.sql.parser.TisGroupBy)

Aggregations

EntityName (com.qlangtech.tis.sql.parser.tuple.creator.EntityName)17 DependencyNode (com.qlangtech.tis.sql.parser.meta.DependencyNode)6 Collectors (java.util.stream.Collectors)5 StringUtils (org.apache.commons.lang.StringUtils)5 Connection (java.sql.Connection)4 ITISFileSystem (com.qlangtech.tis.fs.ITISFileSystem)3 TisGroupBy (com.qlangtech.tis.sql.parser.TisGroupBy)3 FuncFormat (com.qlangtech.tis.sql.parser.visitor.FuncFormat)3 Lists (com.google.common.collect.Lists)2 IDumpTable (com.qlangtech.tis.fullbuild.indexbuild.IDumpTable)2 LinkKeys (com.qlangtech.tis.sql.parser.er.LinkKeys)2 PrimaryTableMeta (com.qlangtech.tis.sql.parser.er.PrimaryTableMeta)2 TabCardinality (com.qlangtech.tis.sql.parser.er.TabCardinality)2 TableRelation (com.qlangtech.tis.sql.parser.er.TableRelation)2 FlatTableRelation (com.qlangtech.tis.sql.parser.stream.generate.FlatTableRelation)2 java.util (java.util)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Pattern (java.util.regex.Pattern)2