Search in sources :

Example 1 with RequestFilePacket

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);
            }
        }
    }
}
Also used : RequestFilePacket(com.actiontech.dble.net.mysql.RequestFilePacket) SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) ByteBuffer(java.nio.ByteBuffer) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) RouteResultset(com.actiontech.dble.route.RouteResultset)

Aggregations

RequestFilePacket (com.actiontech.dble.net.mysql.RequestFilePacket)1 RouteResultset (com.actiontech.dble.route.RouteResultset)1 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)1 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)1 ByteBuffer (java.nio.ByteBuffer)1