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);
}
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());
;
}
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);
}
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);
}
});
}
});
}
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);
}
Aggregations