Search in sources :

Example 1 with ITabPartition

use of com.qlangtech.tis.fullbuild.indexbuild.ITabPartition in project plugins by qlangtech.

the class TestHiveFlatTableBuilder method testTotalpaySummary.

public void testTotalpaySummary() throws Exception {
    HiveFlatTableBuilder flatTableBuilder = (HiveFlatTableBuilder) flatTableBuilderStore.getPlugin();
    // ISqlTask nodeMeta, boolean isFinalNode
    // , ITemplateContext tplContext, ITaskContext taskContext, IFs2Table fs2Table, IJoinTaskStatus joinTaskStatus
    IFs2Table fs2Table = new MockFs2Table();
    IJoinTaskStatus joinTaskStatus = EasyMock.createMock("joinTaskStatus", IJoinTaskStatus.class);
    joinTaskStatus.setComplete(true);
    joinTaskStatus.createJobStatus(EasyMock.anyInt());
    JobLog jobLog = new JobLog();
    EasyMock.expect(joinTaskStatus.getJoblog(EasyMock.anyInt())).andReturn(jobLog).anyTimes();
    joinTaskStatus.setStart();
    IJoinTaskContext joinTaskContext = EasyMock.createMock("joinTaskContext", IJoinTaskContext.class);
    Map<IDumpTable, ITabPartition> dateParams = Maps.newHashMap();
    EasyMock.expect(joinTaskContext.getAttribute(ExecChainContextUtils.PARTITION_DATA_PARAMS)).andReturn(dateParams).anyTimes();
    Map<String, Boolean> taskWorkStatus = Maps.newHashMap();
    EasyMock.expect(joinTaskContext.getAttribute(AdapterTask.KEY_TASK_WORK_STATUS)).andReturn(taskWorkStatus);
    ERRules erRules = EasyMock.createMock("erRules", ERRules.class);
    EasyMock.expect(joinTaskContext.getAttribute("er_rules")).andReturn(erRules);
    EasyMock.replay(joinTaskStatus, joinTaskContext, erRules);
    MockTemplateContext tplContext = new MockTemplateContext(joinTaskContext);
    flatTableBuilder.startTask((context) -> {
        try (InputStream input = TestHiveFlatTableBuilder.class.getResourceAsStream("groupby_totalpay.sql")) {
            // try (InputStream input = TestHiveFlatTableBuilder.class.getResourceAsStream("totalpay_summary.sql")) {
            ISqlTask sqlTask = new DefaultSqlTask(IOUtils.toString(input, TisUTF8.get()));
            // ISqlTask nodeMeta, boolean isFinalNode
            // , ITemplateContext tplContext, ITaskContext taskContext, //
            // IJoinTaskStatus joinTaskStatus
            DataflowTask joinTask = flatTableBuilder.createTask(sqlTask, true, tplContext, context, joinTaskStatus);
            joinTask.run();
        }
    });
}
Also used : ISqlTask(com.qlangtech.tis.sql.parser.ISqlTask) InputStream(java.io.InputStream) ITabPartition(com.qlangtech.tis.fullbuild.indexbuild.ITabPartition) IDumpTable(com.qlangtech.tis.fullbuild.indexbuild.IDumpTable) IFs2Table(com.qlangtech.tis.fs.IFs2Table) IJoinTaskStatus(com.qlangtech.tis.fullbuild.phasestatus.IJoinTaskStatus) JobLog(com.qlangtech.tis.fullbuild.phasestatus.JobLog) DataflowTask(com.qlangtech.tis.fullbuild.taskflow.DataflowTask) IJoinTaskContext(com.qlangtech.tis.order.center.IJoinTaskContext) ERRules(com.qlangtech.tis.sql.parser.er.ERRules)

Example 2 with ITabPartition

use of com.qlangtech.tis.fullbuild.indexbuild.ITabPartition in project tis by qlangtech.

the class SqlRewriter method visitAliasedRelation.

@Override
protected Void visitAliasedRelation(AliasedRelation node, Integer indent) {
    if (node.getRelation() instanceof Table) {
        Table tab = (Table) node.getRelation();
        Map.Entry<IDumpTable, ITabPartition> dumpTable = parseDumpTable(tab.getName());
        waitProcessAliasTabsSet.add(new AliasTable(node.getAlias().getValue(), dumpTable.getKey(), dumpTable.getValue()));
        processTable(dumpTable);
        builder.append(' ').append(formatExpression(node.getAlias(), parameters));
        SqlFormatter.appendAliasColumns(builder, node.getColumnNames());
        return null;
    } else if (node.getRelation() instanceof TableSubquery) {
        SqlRewriter w = new SqlRewriter(new SqlStringBuilder(), this.tabPartition, this.erRules, this.parameters, false, joinContext);
        w.process(node.getRelation(), 0);
        Optional<AliasTable> subTable = w.getWaitProcessAliasTabsSet().stream().findFirst();
        if (!subTable.isPresent()) {
            throw new IllegalStateException("subtable:" + node.getAlias().getValue() + " can not find subtable");
        }
        // 为了重写select部分的pt,pmod部分,需要把该别名记录下来
        waitProcessAliasTabsSet.add(new AliasTable(node.getAlias().getValue(), subTable.get()));
        return super.visitAliasedRelation(node, indent);
    } else {
        throw new UnsupportedOperationException();
    }
// process(node.getRelation(), indent);
// builder.append(' ').append(formatExpression(node.getAlias(), parameters));
// SqlFormatter.appendAliasColumns(builder, node.getColumnNames());
// return null;//
// return super.visitAliasedRelation(node, indent);
}
Also used : IDumpTable(com.qlangtech.tis.fullbuild.indexbuild.IDumpTable) Optional(java.util.Optional) ITabPartition(com.qlangtech.tis.fullbuild.indexbuild.ITabPartition) IDumpTable(com.qlangtech.tis.fullbuild.indexbuild.IDumpTable) Map(java.util.Map)

Example 3 with ITabPartition

use of com.qlangtech.tis.fullbuild.indexbuild.ITabPartition in project tis by qlangtech.

the class TestSqlTaskNodeMeta method testGetRewriteSql.

public void testGetRewriteSql() throws Exception {
    SqlTaskNodeMeta taskNodeMeta = new SqlTaskNodeMeta();
    SqlDataFlowTopology topology = SqlTaskNodeMeta.getSqlDataFlowTopology(TestSupplyGoodsParse.topologyName);
    assertNotNull(topology);
    SqlTaskNodeMeta finalNode = topology.getFinalNode();
    assertNotNull(finalNode);
    taskNodeMeta.setSql(finalNode.getSql());
    Map<IDumpTable, ITabPartition> dumpPartition = Maps.newHashMap();
    String pt = "20200703113848";
    dumpPartition.put(EntityName.parse("scmdb.warehouse_goods"), () -> pt);
    dumpPartition.put(EntityName.parse("tis.stock_info_collapse"), () -> pt);
    dumpPartition.put(EntityName.parse("scmdb.supplier_goods"), () -> pt);
    dumpPartition.put(EntityName.parse("tis.warehouse_collapse"), () -> pt);
    dumpPartition.put(EntityName.parse("tis.supplier_collapse"), () -> pt);
    dumpPartition.put(EntityName.parse("scmdb.goods"), () -> pt);
    dumpPartition.put(EntityName.parse("scmdb.stock_info"), () -> pt);
    dumpPartition.put(EntityName.parse("scmdb.category"), () -> pt);
    dumpPartition.put(EntityName.parse("scmdb.goods_sync_shop"), () -> pt);
    ITemplateContext tplContext = EasyMock.createMock("templateContext", ITemplateContext.class);
    IJoinTaskContext joinTaskContext = EasyMock.createMock("joinTaskContext", IJoinTaskContext.class);
    EasyMock.expect(tplContext.getExecContext()).andReturn(joinTaskContext);
    EasyMock.expect(joinTaskContext.getExecutePhaseRange()).andReturn(ExecutePhaseRange.fullRange()).times(2);
    EasyMock.expect(joinTaskContext.getIndexShardCount()).andReturn(1).times(1);
    Optional<ERRules> erRule = ERRules.getErRule(TestSupplyGoodsParse.topologyName);
    assertTrue(erRule.isPresent());
    EasyMock.replay(tplContext, joinTaskContext);
    ISqlTask.RewriteSql rewriteSql = taskNodeMeta.getRewriteSql("supply_goods", new TabPartitions(dumpPartition), erRule.get(), tplContext, true);
    assertNotNull(rewriteSql);
    assertEquals(TestSqlRewriter.getScriptContent("supply_goods_rewrite_result.txt"), rewriteSql.sqlContent);
    System.out.println(rewriteSql.sqlContent);
    EasyMock.verify(tplContext, joinTaskContext);
}
Also used : ITabPartition(com.qlangtech.tis.fullbuild.indexbuild.ITabPartition) IDumpTable(com.qlangtech.tis.fullbuild.indexbuild.IDumpTable) SqlDataFlowTopology(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta.SqlDataFlowTopology) IJoinTaskContext(com.qlangtech.tis.order.center.IJoinTaskContext) ITemplateContext(com.qlangtech.tis.fullbuild.taskflow.ITemplateContext) ERRules(com.qlangtech.tis.sql.parser.er.ERRules)

Example 4 with ITabPartition

use of com.qlangtech.tis.fullbuild.indexbuild.ITabPartition in project tis by qlangtech.

the class TestIndexSwapTaskflowLauncher method createRangeChainContext.

// 
public static DefaultChainContext createRangeChainContext(String collectionName, FullbuildPhase start, FullbuildPhase end, String... pts) throws Exception {
    TestParamContext params = new TestParamContext();
    params.set(IFullBuildContext.KEY_APP_SHARD_COUNT, String.valueOf(shardCount));
    params.set(IFullBuildContext.KEY_APP_NAME, collectionName);
    params.set(IFullBuildContext.KEY_WORKFLOW_NAME, "totalpay");
    params.set(IFullBuildContext.KEY_WORKFLOW_ID, WF_ID);
    params.set(IExecChainContext.COMPONENT_START, start.getName());
    params.set(IExecChainContext.COMPONENT_END, end.getName());
    final DefaultChainContext chainContext = new DefaultChainContext(params);
    ExecutePhaseRange range = chainContext.getExecutePhaseRange();
    Assert.assertEquals(start, range.getStart());
    Assert.assertEquals(end, range.getEnd());
    Map<IDumpTable, ITabPartition> dateParams = Maps.newHashMap();
    chainContext.setAttribute(ExecChainContextUtils.PARTITION_DATA_PARAMS, new TabPartitions(dateParams));
    chainContext.setAttribute(IExecChainContext.KEY_TASK_ID, TASK_ID);
    // final PluginStore<IndexBuilderTriggerFactory> buildTriggerFactory = TIS.getPluginStore(IndexBuilderTriggerFactory.class);
    // assertNotNull(buildTriggerFactory.getPlugin());
    // if (pts.length > 0) {
    // chainContext.setPs(pts[0]);
    // } else {
    // SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
    // String pt = format.format(new Date());
    // chainContext.setPs(pt);
    // }
    chainContext.setMdcParamContext(() -> {
    });
    return chainContext;
}
Also used : ExecutePhaseRange(com.qlangtech.tis.exec.ExecutePhaseRange) DefaultChainContext(com.qlangtech.tis.exec.impl.DefaultChainContext) ITabPartition(com.qlangtech.tis.fullbuild.indexbuild.ITabPartition) IDumpTable(com.qlangtech.tis.fullbuild.indexbuild.IDumpTable) TabPartitions(com.qlangtech.tis.sql.parser.TabPartitions) TestParamContext(com.qlangtech.tis.fullbuild.taskflow.TestParamContext)

Example 5 with ITabPartition

use of com.qlangtech.tis.fullbuild.indexbuild.ITabPartition in project tis by qlangtech.

the class ExecChainContextUtils method getDependencyTablesMINPartition.

public static ITabPartition getDependencyTablesMINPartition(IJoinTaskContext context) {
    TabPartitions dateParams = getDependencyTablesPartitions(context);
    // dateParams.values().stream().min(Comparator.comparing((r) -> Long.parseLong(r.getPt())));
    Optional<ITabPartition> min = dateParams.getMinTablePartition();
    if (!min.isPresent()) {
        return () -> context.getPartitionTimestamp();
    }
    return min.get();
}
Also used : ITabPartition(com.qlangtech.tis.fullbuild.indexbuild.ITabPartition) TabPartitions(com.qlangtech.tis.sql.parser.TabPartitions)

Aggregations

ITabPartition (com.qlangtech.tis.fullbuild.indexbuild.ITabPartition)6 IDumpTable (com.qlangtech.tis.fullbuild.indexbuild.IDumpTable)5 IJoinTaskContext (com.qlangtech.tis.order.center.IJoinTaskContext)3 ERRules (com.qlangtech.tis.sql.parser.er.ERRules)3 ExecutePhaseRange (com.qlangtech.tis.exec.ExecutePhaseRange)2 ITemplateContext (com.qlangtech.tis.fullbuild.taskflow.ITemplateContext)2 TabPartitions (com.qlangtech.tis.sql.parser.TabPartitions)2 JSON (com.alibaba.fastjson.JSON)1 JSONObject (com.alibaba.fastjson.JSONObject)1 JSONField (com.alibaba.fastjson.annotation.JSONField)1 ParsingOptions (com.facebook.presto.sql.parser.ParsingOptions)1 SqlParser (com.facebook.presto.sql.parser.SqlParser)1 Expression (com.facebook.presto.sql.tree.Expression)1 Statement (com.facebook.presto.sql.tree.Statement)1 Joiner (com.google.common.base.Joiner)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 TIS (com.qlangtech.tis.TIS)1 DefaultChainContext (com.qlangtech.tis.exec.impl.DefaultChainContext)1 IFs2Table (com.qlangtech.tis.fs.IFs2Table)1