I have built my custom schema with calcite help. Now I would like to expose it through servlet and connect to it with Avatica. I am using servlet because my container is JIRA. Here is some relevant code from servlet
public class JDBCServlet extends HttpServlet {
private final Service service;
private final ProtobufHandler pbHandler;
private final ProtobufTranslation protobufTranslation;
private final MetricsSystem metrics;
final ThreadLocal<UnsynchronizedBuffer> threadLocalBuffer;
public JDBCServlet(LocalDBProvider provider) {
this.service = provider.service();
this.metrics = provider.metrics();
this.protobufTranslation = new ProtobufTranslationImpl();
this.pbHandler = new ProtobufHandler(service, protobufTranslation, metrics);
this.threadLocalBuffer = new ThreadLocal<UnsynchronizedBuffer>() {
@Override
public UnsynchronizedBuffer initialValue() {
return new UnsynchronizedBuffer();
}
};
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("DO GET DO GET");
doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("DO POST DO POST");
response.setContentType("application/octet-stream;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
final byte[] requestBytes;
// Avoid a new buffer creation for every HTTP request
final UnsynchronizedBuffer buffer = threadLocalBuffer.get();
try (ServletInputStream inputStream = request.getInputStream()) {
requestBytes = AvaticaUtils.readFullyToBytes(inputStream, buffer);
} finally {
buffer.reset();
}
Handler.HandlerResponse<byte[]> handlerResponse;
try {
handlerResponse = pbHandler.apply(requestBytes);
} catch (Exception e) {
handlerResponse = pbHandler.convertToErrorResponse(e);
}
response.setStatus(handlerResponse.getStatusCode());
response.getOutputStream().write(handlerResponse.getResponse());
response.getOutputStream().close();
}
}
Code is based on AvaticaProtobufHandler withouth Jetty related stuff.
Service is built using LocalService and CalciteConnection with my custom schema:
new LocalService(DRIVER.createMeta((AvaticaConnection) bootstrap.getConnection()));
When connecting with squirrel (with avatica jars:) with url: jdbc:avatica:remote:url=http://127.0.0.1:2990/jira/plugins/servlet/smartqljdbctest;serialization=PROTOBUF
a couple of HTTP POST request is handshaked with the driver but the whole things fails on Meta.toProto() method:
} else {
// Can a "row" be a primitive? A struct? Only an Array?
throw new RuntimeException("Only arrays are supported");
}
I assume that I've bootstrapped the servlet wrong, but don't know why?