JDBC enhancement PR#1624 - address Madhavan' review comments.

This commit is contained in:
yabinmeng 2023-10-16 09:08:31 -05:00
parent 179a51c20b
commit 8fb7446a24
5 changed files with 20 additions and 17 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -17,13 +17,10 @@
package io.nosqlbench.adapter.jdbc.opdispensers;
import io.nosqlbench.adapter.jdbc.JDBCSpace;
import io.nosqlbench.adapter.jdbc.optypes.JDBCDMLOp;
import io.nosqlbench.adapter.jdbc.optypes.JDBCOp;
import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
import io.nosqlbench.adapters.api.templating.ParsedOp;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public abstract class JDBCBaseOpDispenser extends BaseOpDispenser<JDBCOp, JDBCSpace> {
protected static final String ERROR_STATEMENT_CREATION =

View File

@ -44,6 +44,7 @@ public abstract class JDBCDMLOp extends JDBCOp {
String pStmtSqlStr,
List<Object> pStmtValList) {
super(jdbcSpace);
assert(StringUtils.isNotBlank(pStmtSqlStr));
this.isReadStmt = isReadStmt;
this.pStmtSqlStr = pStmtSqlStr;
@ -77,24 +78,29 @@ public abstract class JDBCDMLOp extends JDBCOp {
for (int i=0; i<valList.size(); i++) {
int fieldIdx = i + 1;
String inputFieldVal = ((String)valList.get(i)).trim();
Object fieldValObj = valList.get(i);
assert (fieldValObj != null);
try {
Object fieldValObj = inputFieldVal;
// Special processing for Vector
if (fieldValObj instanceof String) {
String strObj = (String)fieldValObj;
if (StringUtils.isNotBlank(strObj)) {
strObj = strObj.trim();
// If the 'fieldVal' is a string like "[<float_num_1>, <float_num_2>, ... <float_num_n>]" format,
// convert it to the Vector object
if ( inputFieldVal.startsWith("[") && inputFieldVal.endsWith("]") ) {
if (strObj.startsWith("[") && strObj.endsWith("]")) {
JDBCPgVector vector = new JDBCPgVector();
vector.setValue(inputFieldVal);
vector.setValue(strObj);
fieldValObj = vector;
}
}
}
stmt.setObject(fieldIdx, fieldValObj);
}
catch (JDBCPgVectorException | SQLException e) {
throw new RuntimeException(
"Failed to parse the prepared statement value for field[" + fieldIdx + "] " + inputFieldVal);
"Failed to parse the prepared statement value for field[" + fieldIdx + "] " + fieldValObj);
}
}