matrixone icon indicating copy to clipboard operation
matrixone copied to clipboard

[Bug]: truncated type DECIMAL64 value when preparedStmt insert value to decimal type by setDouble

Open aressu1985 opened this issue 3 years ago • 0 comments

Is there an existing issue for the same bug?

  • [X] I have checked the existing issues.

Environment

- Version or commit-id (e.g. v0.1.0 or 8b23a93):0.6.0
- Hardware parameters:
- OS type:
- Others:

Actual Behavior

2022/10/12 11:52:14.862956 +0800 ERROR frontend/mysql_cmd_executor.go:2477 truncated type DECIMAL64 value ? for column c_discount, 1 2022/10/12 11:52:14.863008 +0800 ERROR frontend/util.go:454 Connection id: 1006 Status: fail Statement: insert into customer (c_w_id, c_d_id, c_id, c_discount, c_credit, c_last, c_first, c_credit_lim, c_balance, c_ytd_payment, c_payment_cnt, c_delivery_cnt, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_since, c_middle, c_data) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) Error: truncated type DECIMAL64 value ? for column c_discount, 1 github.com/matrixorigin/matrixone/pkg/frontend.logStatementStringStatus /Users/sudong/Program/MatrixOrigin/matrixone/pkg/frontend/util.go:454 github.com/matrixorigin/matrixone/pkg/frontend.logStatementStatus /Users/sudong/Program/MatrixOrigin/matrixone/pkg/frontend/util.go:446 github.com/matrixorigin/matrixone/pkg/frontend.(*MysqlCmdExecutor).doComQuery /Users/sudong/Program/MatrixOrigin/matrixone/pkg/frontend/mysql_cmd_executor.go:2486 github.com/matrixorigin/matrixone/pkg/frontend.(*MysqlCmdExecutor).ExecRequest /Users/sudong/Program/MatrixOrigin/matrixone/pkg/frontend/mysql_cmd_executor.go:2609 github.com/matrixorigin/matrixone/pkg/frontend.(*Routine).Loop /Users/sudong/Program/MatrixOrigin/matrixone/pkg/frontend/routine.go:125

DDL: CREATE TABLE customer ( c_w_id int NOT NULL, c_d_id int NOT NULL, c_id int NOT NULL, c_discount decimal(4, 4) , c_credit char(2) NOT NULL, c_last varchar(16) NOT NULL, c_first varchar(16) NOT NULL, c_credit_lim decimal(12, 2) NOT NULL, c_balance decimal(12, 2) NOT NULL, c_ytd_payment float NOT NULL, c_payment_cnt int NOT NULL, c_delivery_cnt int NOT NULL, c_street_1 varchar(20) NOT NULL, c_street_2 varchar(20) NOT NULL, c_city varchar(20) NOT NULL, c_state char(2) NOT NULL, c_zip char(9) NOT NULL, c_phone char(16) NOT NULL, c_since timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, c_middle char(2) NOT NULL, c_data varchar(500) NOT NULL, PRIMARY KEY (c_w_id, c_d_id, c_id) );

CODE: protected void loadCustomerHistory(Connection conn, int w_id, int districtsPerWarehouse, int customersPerDistrict) {

    int k = 0;

    //try (PreparedStatement histPrepStmt = getInsertStatement(conn, TPCCConstants.TABLENAME_HISTORY)) {
    try{
        PreparedStatement histPrepStmt = conn.prepareStatement(
            "INSERT INTO `history` (" +
                "  h_c_id, h_c_d_id, h_c_w_id, h_d_id, h_w_id, " +
                "  h_date, h_amount, h_data) " +
                "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
        );
        for (int d = 1; d <= districtsPerWarehouse; d++) {
            for (int c = 1; c <= customersPerDistrict; c++) {
                Timestamp sysdate = new Timestamp(System.currentTimeMillis());

                History history = new History();
                history.h_c_id = c;
                history.h_c_d_id = d;
                history.h_c_w_id = w_id;
                history.h_d_id = d;
                history.h_w_id = w_id;
                history.h_date = sysdate;
                history.h_amount = 10;
                history.h_data = TPCCUtil.randomStr(TPCCUtil.randomNumber(10, 24, benchmark.rng()));


                int idx = 1;
                histPrepStmt.setInt(idx++, history.h_c_id);
                histPrepStmt.setInt(idx++, history.h_c_d_id);
                histPrepStmt.setInt(idx++, history.h_c_w_id);
                histPrepStmt.setInt(idx++, history.h_d_id);
                histPrepStmt.setInt(idx++, history.h_w_id);
                histPrepStmt.setTimestamp(idx++, history.h_date);
                histPrepStmt.setDouble(idx++, history.h_amount);
                histPrepStmt.setString(idx, history.h_data);
                histPrepStmt.addBatch();

                k++;

                if (k != 0 && (k % workConf.getBatchSize()) == 0) {
                    histPrepStmt.executeBatch();
                    histPrepStmt.clearBatch();
                }
            }
        }

        histPrepStmt.executeBatch();
        histPrepStmt.clearBatch();

    } catch (SQLException se) {
        LOG.error(se.getMessage());
    }

}

Expected Behavior

No response

Steps to Reproduce

No response

Additional information

No response

aressu1985 avatar Oct 12 '22 03:10 aressu1985