Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PreparedStatement.setNull for jdbc #17

Open
poroszd opened this issue Jun 9, 2017 · 5 comments
Open

Support PreparedStatement.setNull for jdbc #17

poroszd opened this issue Jun 9, 2017 · 5 comments

Comments

@poroszd
Copy link

poroszd commented Jun 9, 2017

I'm using the jdbc interface to move data from Spark to MapD, but it does not work for null values, as MapDPreparedStatement.setNull() is not implemented.

Am I missing something, or it would be really this simple?

   @Override
   public void setNull(int parameterIndex, int sqlType) throws SQLException { //logger.debug("Entered");
-    throw new UnsupportedOperationException("Not supported yet," + " line:" + new Throwable().getStackTrace()[0].
-            getLineNumber() + " class:" + new Throwable().getStackTrace()[0].getClassName() + " method:" + new Throwable().
-            getStackTrace()[0].getMethodName());
+    parmRep[parameterIndex - 1] = "NULL";
+    repCount++;
   }
@asuhan
Copy link

asuhan commented Jun 9, 2017

@dwayneberry should we make the suggested change?

@poroszd
Copy link
Author

poroszd commented Jun 9, 2017

FWIW, I compiled it myself (I had to update the thrift.version to 0.10.0, e.g. org.apache.thrift.TSerializable wasn't even present in 0.9.3) and moved the data successfully.

@poroszd
Copy link
Author

poroszd commented Jun 12, 2017

Well, I was indeed missing something. This does not work for batch inserts (e.g. it will insert 'NULL' as string value for text columns).
This is because the prepared statement keeps track of only the string representation of the parameters (parmRep), and the addBatch() method tries to infer whether the parameter was null using this string representation. I think you either have to handle null specially in getQuery(), or keep track of the type of the parameters.

@billmaimone
Copy link

@RalphLoen Any comment on this? You've been playing with Spark.

@dwayneberry
Copy link
Contributor

dwayneberry commented Jun 20, 2017

@poroszd Currently this code does not differentiate between empty string and NULL. It treats empty string as NULL.

To get your fix to work

 @Override
   public void setNull(int parameterIndex, int sqlType) throws SQLException { //logger.debug("Entered");
-    throw new UnsupportedOperationException("Not supported yet," + " line:" + new Throwable().getStackTrace()[0].
-            getLineNumber() + " class:" + new Throwable().getStackTrace()[0].getClassName() + " method:" + new Throwable().
-            getStackTrace()[0].getMethodName());
+    parmRep[parameterIndex - 1] = "";
+    repCount++;
   }

Should do it.

But really the longer term solution, if you want to be able to support an empty length string (edge case this fix will not support), we will need to add an additional flag

@randyzwitch randyzwitch transferred this issue from heavyai/heavydb Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants