use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class ServerLoadDataInfileHandler method parseOneLine.
private void parseOneLine(List<SQLExpr> columns, String table, String[] line, boolean toFile, String lineEnd) {
if (loadData.getEnclose() != null && loadData.getEnclose().charAt(0) > 0x0020) {
for (int i = 0; i < line.length; i++) {
line[i] = line[i].trim();
}
}
RouteResultset rrs = tryDirectRoute(sql, line);
if (rrs == null || rrs.getNodes() == null || rrs.getNodes().length == 0) {
String insertSql = makeSimpleInsert(columns, line, table);
rrs = serverConnection.routeSQL(insertSql, ServerParse.INSERT);
}
if (rrs == null || rrs.getNodes() == null || rrs.getNodes().length == 0) {
// do nothing
} else {
for (RouteResultsetNode routeResultsetNode : rrs.getNodes()) {
String name = routeResultsetNode.getName();
LoadData data = routeResultMap.get(name);
if (data == null) {
data = new LoadData();
data.setCharset(loadData.getCharset());
data.setEnclose(loadData.getEnclose());
data.setFieldTerminatedBy(loadData.getFieldTerminatedBy());
data.setLineTerminatedBy(loadData.getLineTerminatedBy());
data.setEscape(loadData.getEscape());
routeResultMap.put(name, data);
}
String jLine = joinField(line, data);
if (data.getData() == null) {
data.setData(Lists.newArrayList(jLine));
} else {
data.getData().add(jLine);
}
if (toFile && data.getData().size() > 10000) {
// avoid OOM
saveDataToFile(data, name);
}
}
}
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class SQLJob method run.
public void run() {
try {
if (ds == null) {
RouteResultsetNode node = new RouteResultsetNode(dataNodeOrDatabase, ServerParse.SELECT, sql);
// create new connection
PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(node.getName());
dn.getConnection(dn.getDatabase(), true, true, node, this, node);
} else {
ds.getConnection(dataNodeOrDatabase, true, this, null);
}
} catch (Exception e) {
LOGGER.info("can't get connection for sql ,error:" + e);
doFinished(true);
}
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class BaseHandlerBuilder method noShardBuild.
/**
* no shard-ing node,just send to the first node
*/
protected final void noShardBuild() {
this.needCommon = false;
GlobalVisitor visitor = new GlobalVisitor(node, true);
visitor.visit();
String sql = visitor.getSql().toString();
RouteResultsetNode[] rrss = getTableSources(node.getNoshardNode(), sql);
hBuilder.checkRRSs(rrss);
MultiNodeMergeHandler mh = new MultiNodeMergeHandler(getSequenceId(), rrss, session.getSource().isAutocommit() && !session.getSource().isTxStart(), session, null);
addHandler(mh);
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class TableNodeHandlerBuilder method nestLoopBuild.
@Override
protected void nestLoopBuild() {
try {
List<Item> filters = node.getNestLoopFilters();
PushDownVisitor pdVisitor = new PushDownVisitor(node, true);
if (filters == null || filters.isEmpty())
throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "unexpected exception!");
List<RouteResultsetNode> rrssList = new ArrayList<>();
MergeBuilder mergeBuilder = new MergeBuilder(session, node, needCommon, pdVisitor);
if (tableConfig == null || tableConfig.getTableType() == TableTypeEnum.TYPE_GLOBAL_TABLE) {
for (Item filter : filters) {
node.setWhereFilter(filter);
RouteResultsetNode[] rrssArray = mergeBuilder.construct().getNodes();
rrssList.addAll(Arrays.asList(rrssArray));
}
if (filters.size() == 1) {
this.needCommon = false;
}
} else {
boolean tryGlobal = filters.size() == 1;
for (Item filter : filters) {
node.setWhereFilter(filter);
pdVisitor.visit();
RouteResultsetNode[] rrssArray = mergeBuilder.construct().getNodes();
rrssList.addAll(Arrays.asList(rrssArray));
}
if (tryGlobal) {
this.needCommon = mergeBuilder.getNeedCommonFlag();
}
}
RouteResultsetNode[] rrssArray = new RouteResultsetNode[rrssList.size()];
rrssArray = rrssList.toArray(rrssArray);
buildMergeHandler(node, rrssArray);
} catch (Exception e) {
throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "", e);
}
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class TableNodeHandlerBuilder method buildOwn.
@Override
public void buildOwn() {
try {
PushDownVisitor pdVisitor = new PushDownVisitor(node, true);
MergeBuilder mergeBuilder = new MergeBuilder(session, node, needCommon, pdVisitor);
String sql = null;
if (node.getAst() != null && node.getParent() == null) {
// it's root
pdVisitor.visit();
sql = pdVisitor.getSql().toString();
}
RouteResultsetNode[] rrssArray;
// maybe some node is view
if (sql == null) {
rrssArray = mergeBuilder.construct().getNodes();
} else {
rrssArray = mergeBuilder.constructByStatement(sql, node.getAst()).getNodes();
}
this.needCommon = mergeBuilder.getNeedCommonFlag();
buildMergeHandler(node, rrssArray);
} catch (Exception e) {
throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "table node buildOwn exception!", e);
}
}
Aggregations