use of com.qlangtech.tis.sql.parser.visitor.StreamTransformVisitor in project tis by qlangtech.
the class SqlTaskNode method reflectTableCols.
// 依赖的数据库表,可能有相同的表明,但是来自两个数据库的情况
// private static final Map<String /* tableName */, List<TableTupleCreator>> dumpNodes;
// static {
// try {
//
// List<TableTupleCreator> tables = null;
// Map<String /* tableName */, List<TableTupleCreator>> builder = Maps.newHashMap();
//
// File f = new File(
// "D:\\j2ee_solution\\eclipse-java-oxygen-mars-develop\\workspace\\tis-mars\\tis-sql-parser\\src\\main\\resources\\dump_tabs\\dump_tabs.txt");
// LineIterator lineIt = FileUtils.lineIterator(f, "utf8");
// String line = null;
// TableTupleCreator tupleCreator = null;
//
// EntityName entityName = null;
// while (lineIt.hasNext()) {
// line = lineIt.nextLine();
//
// entityName = EntityName.parse(line);
//
// tupleCreator = new TableTupleCreator(line, NodeType.DUMP);
//
// tables = builder.get(entityName.getTabName());
// if (tables == null) {
// tables = Lists.newArrayList();
// builder.put(entityName.getTabName(), tables);
// }
//
// tupleCreator.setRealEntityName(entityName);
// tables.add(tupleCreator);
//
// }
// dumpNodes = Collections.unmodifiableMap(builder);// builder.build();
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
//
// }
public static List<ColumnMetaData> reflectTableCols(String sql) {
if (StringUtils.isEmpty(sql)) {
throw new IllegalArgumentException("param sql can not be null");
}
List<ColumnMetaData> result = Lists.newArrayList();
Query query = parseQuery(sql);
StreamTransformVisitor v = new StreamTransformVisitor(null);
query.accept(v, new StackableAstVisitorContext<>(1));
ColRef colsRef = v.getColsRef();
int index = 0;
for (Map.Entry<ColName, IDataTupleCreator> /* colName */
entry : colsRef.getColRefMap().entrySet()) {
// int index, String key, int type, boolean pk
result.add(new ColumnMetaData(index++, StringUtils.lowerCase(entry.getKey().getName()), new DataType(-1), /**
* 暂时无法取到类型,先用-1占一下位置
*/
false));
}
return result;
}
use of com.qlangtech.tis.sql.parser.visitor.StreamTransformVisitor in project tis by qlangtech.
the class SqlTaskNode method parse.
public TableTupleCreator parse(boolean parseAllRefTab) {
if (tupleCterator != null) {
return this.tupleCterator;
}
this.tupleCterator = new TableTupleCreator(this.exportName.getTabName(), nodetype);
tupleCterator.setRealEntityName(this.exportName);
try {
Query query = parseQuery(this.getContent());
StreamTransformVisitor v = new StreamTransformVisitor(this.dumpNodesContext);
query.accept(v, new StackableAstVisitorContext<>(1));
ColRef colsRefs = v.getColsRef();
tupleCterator.setColsRefs(colsRefs);
// TaskNode 識別
if (parseAllRefTab) {
for (Map.Entry<String, IDataTupleCreator> /**
* ref
*/
entry : colsRefs.getBaseRefEntities()) {
entry.getValue().accept(taskNodeRecognizedVisitor);
}
}
return tupleCterator;
} catch (Exception e) {
throw new RuntimeException("exportName:" + this.exportName, e);
}
}
Aggregations