Search in sources :

Example 11 with ERRules.$

use of com.qlangtech.tis.sql.parser.er.ERRules.$ in project tis by qlangtech.

the class OfflineDatasourceAction method doGetErRule.

/**
 * 取得ER关系规则
 *
 * @param context
 * @throws Exception
 */
public void doGetErRule(Context context) throws Exception {
    String topology = this.getString("topology");
    // 强制同步,时间长了,toplolog上会新加一些数据表,导致ER规则和现有topology不同步,需要同步一下
    boolean forceSync = this.getBoolean("sync");
    if (StringUtils.isEmpty(topology)) {
        throw new IllegalArgumentException("param 'topology' can not be null");
    }
    ERRules erRule = null;
    if (!ERRules.ruleExist(topology)) {
        // 还没有创建ER规则
        erRule = new ERRules();
        for (DependencyNode node : getDumpNodesFromTopology(topology)) {
            erRule.addDumpNode(node);
        }
    } else {
        erRule = ERRules.getErRule(topology).get();
        final List<DependencyNode> oldErRules = erRule.getDumpNodes();
        if (forceSync) {
            List<DependencyNode> dumpNodes = getDumpNodesFromTopology(topology);
            /**
             * *************************************
             * 需要添加的节点
             * ***************************************
             */
            List<DependencyNode> shallBeAdd = dumpNodes.stream().filter((n) -> !oldErRules.stream().filter((old) -> StringUtils.equals(n.getTabid(), old.getTabid())).findAny().isPresent()).collect(Collectors.toList());
            /**
             * *************************************
             * 需要删除的节点
             * ***************************************
             */
            Iterator<DependencyNode> it = oldErRules.iterator();
            while (it.hasNext()) {
                DependencyNode old = it.next();
                if (!dumpNodes.stream().filter((n) -> StringUtils.equals(n.getTabid(), old.getTabid())).findAny().isPresent()) {
                    it.remove();
                }
            }
            oldErRules.addAll(shallBeAdd);
        }
    }
    this.setBizResult(context, erRule);
}
Also used : WorkFlow(com.qlangtech.tis.workflow.pojo.WorkFlow) StringUtils(org.apache.commons.lang.StringUtils) ERRules.$(com.qlangtech.tis.sql.parser.er.ERRules.$) SqlTaskNode(com.qlangtech.tis.sql.parser.SqlTaskNode) JoinRule(com.qlangtech.tis.git.GitUtils.JoinRule) TIS(com.qlangtech.tis.TIS) WorkFlowCriteria(com.qlangtech.tis.workflow.pojo.WorkFlowCriteria) Autowired(org.springframework.beans.factory.annotation.Autowired) Option(com.qlangtech.tis.manage.common.Option) DbScope(com.qlangtech.tis.offline.DbScope) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) IFieldErrorHandler(com.qlangtech.tis.runtime.module.misc.IFieldErrorHandler) JSONObject(org.json.JSONObject) Matcher(java.util.regex.Matcher) DescriptorExtensionList(com.qlangtech.tis.extension.DescriptorExtensionList) PermissionConstant(com.qlangtech.tis.manage.PermissionConstant) FullbuildPhase(com.qlangtech.tis.assemble.FullbuildPhase) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) PostParam(com.qlangtech.tis.manage.common.HttpUtils.PostParam) Validator(com.qlangtech.tis.plugin.annotation.Validator) GitRepositoryCommitPojo(com.qlangtech.tis.offline.pojo.GitRepositoryCommitPojo) DelegateControl4JsonPostMsgHandler(com.qlangtech.tis.runtime.module.misc.impl.DelegateControl4JsonPostMsgHandler) HeteroList(com.qlangtech.tis.util.HeteroList) Descriptor(com.qlangtech.tis.extension.Descriptor) TabCardinality(com.qlangtech.tis.sql.parser.er.TabCardinality) Collectors(java.util.stream.Collectors) name.fraser.neil.plaintext.diff_match_patch(name.fraser.neil.plaintext.diff_match_patch) IFullBuildContext(com.qlangtech.tis.fullbuild.IFullBuildContext) IOUtils(org.apache.commons.io.IOUtils) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IWorkFlowDAO(com.qlangtech.tis.workflow.dao.IWorkFlowDAO) IControlMsgHandler(com.qlangtech.tis.runtime.module.misc.IControlMsgHandler) TableRelation(com.qlangtech.tis.sql.parser.er.TableRelation) DataxAction(com.qlangtech.tis.coredefine.module.action.DataxAction) SqlDataFlowTopology(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta.SqlDataFlowTopology) DBConfigSuit(com.qlangtech.tis.db.parser.DBConfigSuit) Pattern(java.util.regex.Pattern) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties) Types(java.sql.Types) Pager(com.koubei.web.tag.pager.Pager) java.util(java.util) Func(com.qlangtech.tis.manage.spring.aop.Func) UploadPluginMeta(com.qlangtech.tis.util.UploadPluginMeta) Context(com.alibaba.citrus.turbine.Context) TISDb(com.qlangtech.tis.offline.pojo.TISDb) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil) Lists(com.google.common.collect.Lists) PropertyType(com.qlangtech.tis.extension.impl.PropertyType) DatasourceTable(com.qlangtech.tis.workflow.pojo.DatasourceTable) CollectionUtils(org.apache.commons.collections.CollectionUtils) GitUtils(com.qlangtech.tis.git.GitUtils) OfflineManager(com.qlangtech.tis.offline.module.manager.impl.OfflineManager) FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) com.qlangtech.tis.sql.parser.meta(com.qlangtech.tis.sql.parser.meta) WorkflowPojo(com.qlangtech.tis.offline.pojo.WorkflowPojo) IWorkflowDAOFacade(com.qlangtech.tis.workflow.dao.IWorkflowDAOFacade) MapUtils(org.apache.commons.collections.MapUtils) IdentityName(com.qlangtech.tis.plugin.IdentityName) JSONTokener(org.json.JSONTokener) com.qlangtech.tis.plugin.ds(com.qlangtech.tis.plugin.ds) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) File(java.io.File) TisSqlFormatException(com.qlangtech.tis.sql.parser.exception.TisSqlFormatException) JSON(com.alibaba.fastjson.JSON) ERRules(com.qlangtech.tis.sql.parser.er.ERRules) BasicModule(com.qlangtech.tis.runtime.module.action.BasicModule) AppDomainInfo(com.qlangtech.tis.manage.common.AppDomainInfo) CoreAction(com.qlangtech.tis.coredefine.module.action.CoreAction) Assert(com.qlangtech.tis.common.utils.Assert) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta) IUser(com.qlangtech.tis.manage.common.IUser) PrimaryTableMeta(com.qlangtech.tis.sql.parser.er.PrimaryTableMeta) JSONArray(org.json.JSONArray) PluginDescMeta(com.qlangtech.tis.coredefine.module.action.PluginDescMeta) ERRules(com.qlangtech.tis.sql.parser.er.ERRules)

Example 12 with ERRules.$

use of com.qlangtech.tis.sql.parser.er.ERRules.$ in project tis by qlangtech.

the class TestCoreAction method createMockErRules.

public ERRules createMockErRules(TableMeta totalpayMeta) {
    ERRules erRules = mock("erRules", ERRules.class);
    if (totalpayMeta != null) {
        TabExtraMeta extraMeta = new TabExtraMeta();
        extraMeta.setSharedKey(totalpayMeta.getSharedKey());
        PrimaryTableMeta tabMeta = new PrimaryTableMeta(totalpayMeta.getTabName(), extraMeta);
        EasyMock.expect(erRules.getPrimaryTabs()).andReturn(Lists.newArrayList(tabMeta)).anyTimes();
    } else {
        EasyMock.expect(erRules.getPrimaryTabs()).andReturn(Collections.emptyList()).anyTimes();
    }
    MockERRulesGetter.erRules = erRules;
    return erRules;
}
Also used : PrimaryTableMeta(com.qlangtech.tis.sql.parser.er.PrimaryTableMeta) TabExtraMeta(com.qlangtech.tis.sql.parser.meta.TabExtraMeta) ERRules(com.qlangtech.tis.sql.parser.er.ERRules)

Aggregations

ERRules (com.qlangtech.tis.sql.parser.er.ERRules)12 SqlDataFlowTopology (com.qlangtech.tis.sql.parser.SqlTaskNodeMeta.SqlDataFlowTopology)4 PrimaryTableMeta (com.qlangtech.tis.sql.parser.er.PrimaryTableMeta)4 TableRelation (com.qlangtech.tis.sql.parser.er.TableRelation)3 IDumpTable (com.qlangtech.tis.fullbuild.indexbuild.IDumpTable)2 ITabPartition (com.qlangtech.tis.fullbuild.indexbuild.ITabPartition)2 Func (com.qlangtech.tis.manage.spring.aop.Func)2 IJoinTaskContext (com.qlangtech.tis.order.center.IJoinTaskContext)2 TestJoinTaskContext (com.qlangtech.tis.order.center.TestJoinTaskContext)2 SqlTaskNodeMeta (com.qlangtech.tis.sql.parser.SqlTaskNodeMeta)2 TabExtraMeta (com.qlangtech.tis.sql.parser.meta.TabExtraMeta)2 WorkFlow (com.qlangtech.tis.workflow.pojo.WorkFlow)2 WorkFlowCriteria (com.qlangtech.tis.workflow.pojo.WorkFlowCriteria)2 Context (com.alibaba.citrus.turbine.Context)1 JSON (com.alibaba.fastjson.JSON)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Pager (com.koubei.web.tag.pager.Pager)1 TIS (com.qlangtech.tis.TIS)1 FullbuildPhase (com.qlangtech.tis.assemble.FullbuildPhase)1