use of com.actiontech.dble.net.mysql.RequestFilePacket in project dble by actiontech.
the class ServerLoadDataInfileHandler method start.
@Override
public void start(String strSql) {
clear();
this.sql = strSql;
if (this.checkPartition(strSql)) {
serverConnection.writeErrMessage(ErrorCode.ER_UNSUPPORTED_PS, " unsupported load data with Partition");
clear();
return;
}
SQLStatementParser parser = new MySqlStatementParser(strSql);
statement = (MySqlLoadDataInFileStatement) parser.parseStatement();
fileName = parseFileName(strSql);
if (fileName == null) {
serverConnection.writeErrMessage(ErrorCode.ER_FILE_NOT_FOUND, " file name is null !");
clear();
return;
}
schema = DbleServer.getInstance().getConfig().getSchemas().get(serverConnection.getSchema());
tableId2DataNodeCache = (LayerCachePool) DbleServer.getInstance().getCacheService().getCachePool("TableID2DataNodeCache");
tableName = statement.getTableName().getSimpleName();
if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
tableName = tableName.toLowerCase();
}
tableConfig = schema.getTables().get(tableName);
tempPath = SystemConfig.getHomePath() + File.separator + "temp" + File.separator + serverConnection.getId() + File.separator;
tempFile = tempPath + "clientTemp.txt";
tempByteBuffer = new ByteArrayOutputStream();
List<SQLExpr> columns = statement.getColumns();
if (tableConfig != null) {
String pColumn = getPartitionColumn();
if (pColumn != null && columns != null && columns.size() > 0) {
for (int i = 0, columnsSize = columns.size(); i < columnsSize; i++) {
String column = StringUtil.removeBackQuote(columns.get(i).toString());
if (pColumn.equalsIgnoreCase(column)) {
partitionColumnIndex = i;
break;
}
}
}
}
parseLoadDataPram();
if (statement.isLocal()) {
isStartLoadData = true;
// request file from client
ByteBuffer buffer = serverConnection.allocate();
RequestFilePacket filePacket = new RequestFilePacket();
filePacket.setFileName(fileName.getBytes());
filePacket.setPacketId(1);
filePacket.write(buffer, serverConnection, true);
} else {
if (!new File(fileName).exists()) {
serverConnection.writeErrMessage(ErrorCode.ER_FILE_NOT_FOUND, fileName + " is not found!");
clear();
} else {
parseFileByLine(fileName, loadData.getCharset(), loadData.getLineTerminatedBy());
RouteResultset rrs = buildResultSet(routeResultMap);
if (rrs != null) {
flushDataToFile();
isStartLoadData = false;
serverConnection.getSession2().execute(rrs);
}
}
}
}
Aggregations