-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathtest3360.java
More file actions
70 lines (55 loc) · 2.69 KB
/
Copy pathtest3360.java
File metadata and controls
70 lines (55 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package dataflow;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import common.gspCommon;
import gudusoft.gsqlparser.EDbVendor;
import gudusoft.gsqlparser.dlineage.DataFlowAnalyzer;
import gudusoft.gsqlparser.dlineage.dataflow.model.Option;
import gudusoft.gsqlparser.dlineage.dataflow.model.json.Dataflow;
import gudusoft.gsqlparser.dlineage.dataflow.model.json.Relationship;
import gudusoft.gsqlparser.dlineage.dataflow.model.xml.dataflow;
import gudusoft.gsqlparser.dlineage.metadata.Schema;
import gudusoft.gsqlparser.dlineage.metadata.TreeNode;
import junit.framework.TestCase;
public class test3360 extends TestCase{
public void testSqlServerResultSet() throws IOException {
// Given a SQL file with a result set output .
EDbVendor vendor = EDbVendor.dbvmssql;
DataFlowAnalyzer analyzer = analyseSqlFiles(gspCommon.BASE_SQL_DIR_PRIVATE +"dlineage/mssql/3655.sql", vendor);
// When we generate the data flow using the variable and cursor options
analyzer.generateDataFlow();
dataflow df = analyzer.getDataFlow();
Dataflow dataFlow = DataFlowAnalyzer.getSqlflowJSONModel(vendor, df, false);
// Then we receive relationships with processIds
List<Relationship> selectRels = Arrays.stream(dataFlow.getRelationships())
.filter(r -> r.getEffectType().equals("select"))
.collect(Collectors.toList());
assertTrue(!selectRels.isEmpty());
selectRels.stream().forEach(t->assertTrue(t.getProcedureId()!=null));
Schema schema = dataFlow.getDbobjs().getServers().get(0).getDatabases().get(0).getSchemas().get(1);
List<String> procedureIds = schema.getProcedures().stream()
.map(TreeNode::getId)
.collect(Collectors.toList());
selectRels.stream().forEach(t->assertTrue(procedureIds.contains(t.getProcedureId())));
}
private DataFlowAnalyzer analyseSqlFiles(String path, EDbVendor vendor) throws IOException {
File sqlFiles = new File(path);
Option option = new Option();
// Transform will be enabled only if SQL Derivation is enabled
option.setTransform(false);
option.setShowConstantTable(false);
option.setVendor(vendor);
option.setSimpleOutput(true);
// Enabling Text format avoids saveXML and parsing the dataflow as a text output only
option.setTextFormat(true);
// Shows lineage for procedures that are top level selects with no specific target output
option.setSimpleShowTopSelectResultSet(true);
option.setSimpleShowVariable(true);
option.setSimpleShowCursor(true);
option.setTraceProcedure(true);
return new DataFlowAnalyzer(sqlFiles, option);
}
}