Search in sources :

Example 1 with TableTupleCreator

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

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

the class TestOrderCustomersSqlParse method assertA1Tuple.

private void assertA1Tuple(IDataTupleCreator tupleCreator) {
    Assert.assertNotNull(tupleCreator);
    Assert.assertTrue(tupleCreator instanceof TableTupleCreator);
    TableTupleCreator a1Tuple = (TableTupleCreator) tupleCreator;
    Assert.assertEquals("a1", a1Tuple.getMediaTabRef());
    // EntitiyRef entityRef = a1Tuple.getEntityRef();
    // Assert.assertNotNull(entityRef);
    Assert.assertEquals("tis.innertab_a1", a1Tuple.getEntityName().toString());
    // Assert.assertNotNull(entityRef.getTaskNode());
    // SqlTaskNode a1Task = entityRef.getTaskNode();
    // Assert.assertNotNull(a1Task);
    Assert.assertEquals(1, a1Tuple.getColsRefs().getBaseRefSize());
    Optional<Map.Entry<String, IDataTupleCreator>> /* ref */
    e = a1Tuple.getColsRefs().getBaseRefEntities().stream().findFirst();
    Assert.assertTrue(e.isPresent());
    Map.Entry<String, IDataTupleCreator> /* ref */
    i_ref = e.get();
    Assert.assertEquals("i", i_ref.getKey());
    Assert.assertNotNull(i_ref.getValue());
    Assert.assertTrue(i_ref.getValue() instanceof TableTupleCreator);
    TableTupleCreator iTuple = (TableTupleCreator) i_ref.getValue();
    Assert.assertEquals("i", iTuple.getMediaTabRef());
    Assert.assertEquals("order.instancedetail", iTuple.getEntityName().toString());
    Assert.assertEquals(NodeType.DUMP, iTuple.getNodetype());
    ;
}
Also used : IDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.IDataTupleCreator) TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) Map(java.util.Map)

Example 3 with TableTupleCreator

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

the class TestOrderCustomersSqlParse method testParse.

public void testParse() throws Exception {
    final String order_customers = "order_customers";
    TableTupleCreator task = parseSqlTaskNode(order_customers);
    ColRef colRef = task.getColsRefs();
    Assert.assertNotNull(colRef);
    ColRef.ListMap /* colName */
    colRefMap = colRef.getColRefMap();
    // {name:has_fetch=FunctionDataTuple,
    // name:customer_ids=ref:a1,entity:innertab_a1,
    // name:order_id=ref:a1,entity:innertab_a1}
    IDataTupleCreator tupleCreator = null;
    Assert.assertEquals(3, colRefMap.size());
    ColName hasFetch = new ColName("has_fetch");
    tupleCreator = colRefMap.get(hasFetch);
    Assert.assertTrue(tupleCreator instanceof FunctionDataTupleCreator);
    FunctionDataTupleCreator funcDataTuple = (FunctionDataTupleCreator) tupleCreator;
    Assert.assertEquals(1, funcDataTuple.getParams().size());
    Optional<ColName> funcParam = funcDataTuple.getParams().keySet().stream().findFirst();
    Assert.assertTrue(funcParam.isPresent());
    ColName hasFetchParam = funcParam.get();
    Assert.assertEquals("has_fetch", hasFetchParam.getAliasName());
    Assert.assertEquals("has_fetch", hasFetchParam.getName());
    Optional<IDataTupleCreator> hasFetchRef = funcDataTuple.getParams().values().stream().findFirst();
    Assert.assertTrue(hasFetchRef.isPresent());
    IDataTupleCreator asTableTuple = hasFetchRef.get();
    Assert.assertTrue(asTableTuple instanceof TableTupleCreator);
    TableTupleCreator a2Tuple = (TableTupleCreator) asTableTuple;
    // EntitiyRef entityRef = a2Tuple.getEntityRef();
    // Assert.assertNotNull(entityRef);
    Assert.assertEquals("tis.innertab_a2", a2Tuple.getEntityName().toString());
    // task = entityRef.getTaskNode();
    // Assert.assertNotNull(task);
    ColName hasFetchOfinnertab_a2 = new ColName("has_fetch");
    tupleCreator = task.getColsRefs().getColRefMap().get(hasFetchOfinnertab_a2);
    Assert.assertTrue(tupleCreator instanceof FunctionDataTupleCreator);
    funcDataTuple = (FunctionDataTupleCreator) tupleCreator;
    Assert.assertEquals(1, funcDataTuple.getParams().size());
    ColName customerIds = new ColName("customer_ids");
    tupleCreator = colRefMap.get(customerIds);
    assertA1Tuple(tupleCreator);
    ColName orderid = new ColName("order_id");
    tupleCreator = colRefMap.get(orderid);
    assertA1Tuple(tupleCreator);
    Assert.assertEquals(2, colRef.getBaseRefKeys().size());
    Assert.assertTrue(colRef.getTupleCreator("a1") != null);
    Assert.assertTrue(colRef.getTupleCreator("a2") != null);
    Assert.assertTrue(colRef.getTupleCreator("a1") instanceof TableTupleCreator);
    Assert.assertTrue(colRef.getTupleCreator("a2") instanceof TableTupleCreator);
}
Also used : ColRef(com.qlangtech.tis.sql.parser.tuple.creator.impl.ColRef) IDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.IDataTupleCreator) TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) FunctionDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator)

Example 4 with TableTupleCreator

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

the class TableReferenceVisitor method setFuncGroupByTuple.

private void setFuncGroupByTuple(IDataTupleCreator tupleCreator, final String tabRefName) {
    Stream<FunctionDataTupleCreator> funcs = this.colRef.getColRefMap().values().stream().filter((r) -> r instanceof FunctionDataTupleCreator).map((r) -> (FunctionDataTupleCreator) r);
    funcs.forEach((f) -> {
        Optional<TisGroupBy> g = f.getGroupBy();
        if (g.isPresent()) {
            g.get().getGroups().forEach((group) -> {
                TableTupleCreator tabTuple = null;
                if (!group.isTupleSetted() && StringUtils.equals(group.getTabRef(), tabRefName)) {
                    if (!(tupleCreator instanceof TableTupleCreator)) {
                        throw new IllegalStateException("tupleCreator type shall be TableTupleCterator");
                    }
                    tabTuple = (TableTupleCreator) tupleCreator;
                    if (!tabRefName.equals(tabTuple.getMediaTabRef())) {
                        throw new IllegalStateException("tabRefName:" + tabRefName + ",tabTuple.getMediaTabRef:" + tabTuple.getMediaTabRef() + " shall be equal");
                    }
                    group.setTabTuple(tabTuple);
                }
            });
        }
    });
}
Also used : IDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.IDataTupleCreator) FunctionDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator) ColRef(com.qlangtech.tis.sql.parser.tuple.creator.impl.ColRef) StringUtils(org.apache.commons.lang.StringUtils) com.facebook.presto.sql.tree(com.facebook.presto.sql.tree) TisGroupBy(com.qlangtech.tis.sql.parser.TisGroupBy) TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) TabCriteriaEntityRecognizeVisitor(com.qlangtech.tis.sql.parser.tuple.creator.impl.TabCriteriaEntityRecognizeVisitor) Stream(java.util.stream.Stream) IDumpNodeMapContext(com.qlangtech.tis.sql.parser.IDumpNodeMapContext) StackableAstVisitorContext(com.facebook.presto.sql.tree.TISStackableAstVisitor.StackableAstVisitorContext) Optional(java.util.Optional) Type(com.facebook.presto.sql.tree.Join.Type) NodeProcessResult(com.qlangtech.tis.sql.parser.NodeProcessResult) Joiner(com.google.common.base.Joiner) NodeUtils(com.qlangtech.tis.sql.parser.utils.NodeUtils) TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) FunctionDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator) TisGroupBy(com.qlangtech.tis.sql.parser.TisGroupBy)

Example 5 with TableTupleCreator

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

the class TestSupplyGoodsParse method testTopologyParse.

public void testTopologyParse() throws Exception {
    // this.parseSqlTaskNode()
    List<SqlTaskNode> processNodes = this.parseTopologySqlTaskNodes(topologyName);
    assertTrue(processNodes.size() > 0);
    assertEquals(4, processNodes.size());
    SqlTaskNodeMeta.SqlDataFlowTopology topology = SqlTaskNodeMeta.getSqlDataFlowTopology(topologyName);
    TableTupleCreator tableTupleCreator = topology.parseFinalSqlTaskNode();
    ColRef.ListMap cols = tableTupleCreator.getColsRefs().getColRefMap();
    assertTrue(cols.size() > 0);
    assertEquals("parse from suppyGoods cols size", 58, cols.size());
    assertNotNull("tableTupleCreator", tableTupleCreator);
}
Also used : SqlTaskNode(com.qlangtech.tis.sql.parser.SqlTaskNode) ColRef(com.qlangtech.tis.sql.parser.tuple.creator.impl.ColRef) TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta)

Aggregations

TableTupleCreator (com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator)9 IDataTupleCreator (com.qlangtech.tis.sql.parser.tuple.creator.IDataTupleCreator)5 ColRef (com.qlangtech.tis.sql.parser.tuple.creator.impl.ColRef)5 FunctionDataTupleCreator (com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator)3 Map (java.util.Map)3 Joiner (com.google.common.base.Joiner)2 SqlTaskNodeMeta (com.qlangtech.tis.sql.parser.SqlTaskNodeMeta)2 IEntityNameGetter (com.qlangtech.tis.sql.parser.tuple.creator.IEntityNameGetter)2 TaskNodeTraversesCreatorVisitor (com.qlangtech.tis.sql.parser.tuple.creator.impl.TaskNodeTraversesCreatorVisitor)2 com.facebook.presto.sql.tree (com.facebook.presto.sql.tree)1 Type (com.facebook.presto.sql.tree.Join.Type)1 Query (com.facebook.presto.sql.tree.Query)1 StackableAstVisitorContext (com.facebook.presto.sql.tree.TISStackableAstVisitor.StackableAstVisitorContext)1 IDumpNodeMapContext (com.qlangtech.tis.sql.parser.IDumpNodeMapContext)1 NodeProcessResult (com.qlangtech.tis.sql.parser.NodeProcessResult)1 SqlTaskNode (com.qlangtech.tis.sql.parser.SqlTaskNode)1 TisGroupBy (com.qlangtech.tis.sql.parser.TisGroupBy)1 TisGroup (com.qlangtech.tis.sql.parser.TisGroupBy.TisGroup)1 TestERRules (com.qlangtech.tis.sql.parser.er.TestERRules)1 EntityName (com.qlangtech.tis.sql.parser.tuple.creator.EntityName)1