use of com.qlangtech.tis.sql.parser.NodeProcessResult in project tis by qlangtech.
the class StreamTransformVisitor method visitQuerySpecification.
// @Override
// protected NodeProcessResult<?> visitSelectItem(SelectItem node,
// StackableAstVisitorContext<Integer> context) {
//
// System.out.println(node);
//
// return null;
// // return super.visitSelectItem(node, context);
// }
@SuppressWarnings("all")
protected NodeProcessResult<?> visitQuerySpecification(QuerySpecification body, StackableAstVisitorContext<Integer> context) {
// return visitQueryBody(node, context);
// Select select = ;
// this.visitSelect(, context);
//
NodeProcessResult<ColRef> selectresult = (NodeProcessResult<ColRef>) this.process(body.getSelect(), context);
if (selectresult == null || selectresult.getResult() == null || selectresult.getResult().getColRefMap().size() < 1) {
throw new IllegalStateException("selectresult can not be null");
}
this.colsRef = selectresult.getResult();
if (body.getLimit().isPresent()) {
System.out.println("Limit = " + body.getLimit().get());
}
// final List<Expression> groupIds = Lists.newArrayList();
Optional<GroupBy> gby = body.getGroupBy();
GroupBy group = null;
if (gby.isPresent()) {
group = gby.get();
this.visitGroupBy(group, context);
}
Optional<Relation> from = body.getFrom();
// /////////////////////////////////////////////////////////////////////////
// System.out.println("======================================================");
// List<SelectItem>
// SingleColumn single = null;
Relation rel = null;
// Table table = null;
if (from.isPresent()) {
rel = from.get();
// rewriter.newline().append("FROM ");
// processRelation(rel, rewriter);
processFromRemoveAlias(colsRef, rel, context);
// this.processRelation(rel, context);
} else {
throw new IllegalStateException("have not set from \n" + body);
}
// colsRef.colRefMap.entrySet().stream()
// .forEach((r) -> System.out.println("[" + r.getKey() + "]," +
// r.getValue().toString()));
Optional<Expression> w = body.getWhere();
Expression where = null;
if (w.isPresent()) {
where = w.get();
process(where, context);
// rewriter.newline().append("WHERE ");
// rewriter.append(table);
// processExpression(where, rewriter);
} else {
// if (table != null) {
// rewriter.newline().append("WHERE ");
// }
}
return null;
}
use of com.qlangtech.tis.sql.parser.NodeProcessResult in project tis by qlangtech.
the class StreamTransformVisitor method visitSelect.
@Override
protected NodeProcessResult<?> visitSelect(Select node, StackableAstVisitorContext<Integer> context) {
context.processSelect = true;
try {
SingleColumn single = null;
Expression express = null;
DereferenceExpression dref = null;
ColName colName = null;
ColRef colRef = new ColRef();
// Map<ColName /* colName */, IDataTupleCreator> colRefMap = Maps.newHashMap();
// Map<String/* ref */, IDataTupleCreator> baseRefMap = Maps.newHashMap();
NodeProcessResult<ColRef> result = new NodeProcessResult<ColRef>(colRef);
IDataTupleCreator tupleCreator = null;
for (SelectItem item : node.getSelectItems()) {
if (item instanceof SingleColumn) {
single = (SingleColumn) item;
express = single.getExpression();
if (express instanceof DereferenceExpression) {
dref = ((DereferenceExpression) express);
if (dref.getBase() instanceof Identifier) {
if (single.getAlias().isPresent()) {
colName = new ColName(dref.getField().getValue(), single.getAlias().get().getValue());
} else {
colName = new ColName(dref.getField().getValue());
}
tupleCreator = createTableTupleCreator(dref, colRef);
colRef.getColRefMap().put(colName, tupleCreator);
} else {
// this.process(dref.getBase(), context);
faild(dref.getBase());
}
} else {
if (single.getAlias().isPresent()) {
String name = single.getAlias().get().getValue();
colName = new ColName(name);
if (express instanceof SearchedCaseExpression) {
colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
continue;
} else if (express instanceof CoalesceExpression) {
// COALESCE(a2.has_fetch, 0)
colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
continue;
} else if (express instanceof FunctionCall) {
// "concat_ws"(',', "collect_set"("split"(i.batch_msg, '[\\w\\W]*\\|')[1]))
colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
continue;
} else if (express instanceof SubscriptExpression) {
// "split"(i.batch_msg, '[\\w\\W]*\\|')[1]
colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
continue;
} else if (express instanceof Identifier) {
processIdentifier((Identifier) express, colRef);
continue;
} else if (express instanceof StringLiteral) {
/**
* select 中存在以下使用常量作为列字段
* SELECT
* '' as num_unit_id,
* '' as num_unit_name
* FROM goods
*/
colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
continue;
} else if (express instanceof IfExpression) {
/**
* IF((COALESCE("instr"(sl.logo_url, 'http'), 0) > 0), sl.logo_url, "concat"('http://', sl.logo_url))
*/
colRef.getColRefMap().put(colName, new FunctionDataTupleCreator(express, colRef));
continue;
}
faild(express);
} else if (express instanceof Identifier) {
// 没有设置表应用,select里面的表应该只有一个
// 这种情况下from中只有一个原表
processIdentifier((Identifier) express, colRef);
continue;
}
faild(express);
// process(express, context);
// IDataTupleCreator tupleCreator = new IDataTupleCreator() {
//
// @Override
// public Object getVal(String name) {
// return null;
// }
// };
//
// ValueOperator.createGatherValueOperator(new
// ColName(single.getAlias().get().getValue()),
// express, params);
}
// single.getAlias();
} else {
throw new IllegalStateException("item type:" + item.getClass() + "" + item);
}
// visitSelectItem(item, context);
}
// System.out.println(MoreObjects.toStringHelper(colRefMap).add);
return result;
// return new NodeProcessResult<Map<ColName /* colName */, String /* base */
// >>(colRefMap);
} finally {
context.processSelect = false;
}
// return super.visitSelect(node, context);
}
use of com.qlangtech.tis.sql.parser.NodeProcessResult in project tis by qlangtech.
the class TableReferenceVisitor method visitJoin.
@Override
protected NodeProcessResult<?> visitJoin(Join node, StackableAstVisitorContext<Integer> context) {
final Type type = node.getType();
Relation left = node.getLeft();
processLeftOrRightRelation(context, left, null, null);
Relation right = node.getRight();
Optional<JoinOn> joinOn = node.getCriteria().filter(criteria -> criteria instanceof JoinOn).map(criteria -> (JoinOn) criteria);
processLeftOrRightRelation(context, right, joinOn, type);
return null;
}
Aggregations