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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; package io.nosqlbench.adapter.jdbc.opdispensers;
import io.nosqlbench.adapter.jdbc.JDBCSpace; import io.nosqlbench.adapter.jdbc.JDBCSpace;
import io.nosqlbench.adapter.jdbc.optypes.JDBCDMLOp;
import io.nosqlbench.adapter.jdbc.optypes.JDBCOp; import io.nosqlbench.adapter.jdbc.optypes.JDBCOp;
import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser; import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter; import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
import io.nosqlbench.adapters.api.templating.ParsedOp; 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> { public abstract class JDBCBaseOpDispenser extends BaseOpDispenser<JDBCOp, JDBCSpace> {
protected static final String ERROR_STATEMENT_CREATION = protected static final String ERROR_STATEMENT_CREATION =

View File

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