/** * Gets the all prepared queries. * * @param userName the user name * @param queryName the query name * @param fromDate the from date * @param toDate the to date * @return the all prepared queries */ public List<QueryPrepareHandle> getAllPreparedQueries(String userName, String queryName, String fromDate, String toDate) { Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget(client); return target.queryParam("sessionid", connection.getSessionHandle()) .queryParam("user", userName).queryParam("queryName", queryName).queryParam("fromDate", fromDate) .queryParam("toDate", toDate).request().get(new GenericType<List<QueryPrepareHandle>>() {}); }
public void close() { try { connection.close(); } catch (Exception exc) { log.error("Error closing connection", exc); } }
/** * Gets the prepared queries web target. * * @param client the client * @return the prepared queries web target */ private WebTarget getPreparedQueriesWebTarget(Client client) { return client.target(connection.getLensConnectionParams().getBaseConnectionUrl()) .path(connection.getLensConnectionParams().getQueryResourcePath()).path("preparedqueries"); }
public WebTarget getLogWebTarget() { Client client = buildClient(); return getLogWebTarget(client); }
private WebTarget getMetastoreWebTarget() { return getMetastoreWebTarget(buildClient()); }
private WebTarget getSessionWebTarget() { return getSessionWebTarget(buildClient()); }
public XFlattenedColumns getQueryableFields(String tableName, boolean flattened) { WebTarget target = getMetastoreWebTarget(); JAXBElement<XFlattenedColumns> fields = target.path("flattened").path(tableName) .queryParam("sessionid", this.connection.getSessionHandle()) .queryParam("add_chains", flattened) .request(MediaType.APPLICATION_XML).get(new GenericType<JAXBElement<XFlattenedColumns>>() { }); return fields.getValue(); }
/** * Explain query. * * @param sql the sql * @param conf config to be used for the query * @return the query plan * @throws LensAPIException */ public LensAPIResult<QueryPlan> explainQuery(String sql, LensConf conf) throws LensAPIException { if (!connection.isOpen()) { throw new IllegalStateException("Lens Connection has to be established before querying"); } Client client = connection.buildClient(); FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), connection .getSessionHandle(), MediaType.APPLICATION_XML_TYPE)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), sql)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "explain")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf, MediaType.APPLICATION_XML_TYPE)); WebTarget target = getQueryWebTarget(client); Response response = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE)); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(new GenericType<LensAPIResult<QueryPlan>>() {}); } throw new LensAPIException(response.readEntity(LensAPIResult.class)); }
private void connectToLensServer() { log.debug("Connecting to lens server {}", new LensConnectionParams(conf)); connection = new LensConnection(new LensConnectionParams(conf)); connection.open(password); log.debug("Successfully connected to server {}", connection); pathValidator = new PathValidator(connection.getLensConnectionParams().getSessionConf()); Preconditions.checkNotNull(pathValidator, "Error in initializing Path Validator."); }
/** * Prepare query. * * @param sql the sql * @param queryName the query name * @return the query prepare handle * @throws LensAPIException */ public LensAPIResult<QueryPrepareHandle> prepareQuery(String sql, String queryName, LensConf conf) throws LensAPIException { if (!connection.isOpen()) { throw new IllegalStateException("Lens Connection has to be established before querying"); } Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget(client); Response response = target.request().post(Entity.entity(prepareForm(sql, "PREPARE", queryName, conf), MediaType.MULTIPART_FORM_DATA_TYPE)); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(new GenericType<LensAPIResult<QueryPrepareHandle>>() {}); } throw new LensAPIException(response.readEntity(LensAPIResult.class)); }
protected WebTarget getMLWebTarget() { Client client = connection.buildClient(); LensConnectionParams connParams = connection.getLensConnectionParams(); String baseURI = connParams.getBaseConnectionUrl(); String mlURI = connParams.getConf().get(LENS_ML_RESOURCE_PATH, DEFAULT_ML_RESOURCE_PATH); return client.target(baseURI).path(mlURI); }
/** * Instantiates a new lens jdbc connection. * * @param uri the uri * @param info the info */ public LensJdbcConnection(String uri, Properties info) { LensConnectionParams params = JDBCUtils.parseUrl(uri); connection = new LensConnection(params); // TODO: should we prompt here? connection.open(""); }
private WebTarget getMetastoreWebTarget() { return getMetastoreWebTarget(connection.buildClient()); }
/** * Instantiates a new lens ml jersey client. * * @param connection the connection */ public LensMLJerseyClient(LensConnection connection, String password) { this.connection = connection; connection.open(password); this.sessionHandle = null; }
public APIResult addFileResource(String path) { return this.connection.addResourceToConnection("file", path); }
/** * Builds the. * * @return the lens connection */ public LensConnection build() { LensConnectionParams params = new LensConnectionParams(); if (baseUrl != null && !baseUrl.isEmpty()) { params.setBaseUrl(baseUrl); } if (database != null && !database.isEmpty()) { params.setDbName(database); } if (user != null && !user.isEmpty()) { params.getSessionVars().put("user.name", user); } if (password != null && !password.isEmpty()) { params.getSessionVars().put("user.pass", password); } return new LensConnection(params); }
public XDimensionTable getDimensionTable(String table) { WebTarget target = getMetastoreWebTarget(); JAXBElement<XDimensionTable> result = target.path("dimtables").path(table) .queryParam("sessionid", this.connection.getSessionHandle()) .request(MediaType.APPLICATION_XML) .get(new GenericType<JAXBElement<XDimensionTable>>() { }); return result.getValue(); }
/** * Execute query. * * @param phandle the phandle * @param queryName the query name * @param conf config to be used for the query * @return the query handle */ private QueryHandle submitQuery(QueryPrepareHandle phandle, String queryName, LensConf conf) { if (!connection.isOpen()) { throw new IllegalStateException("Lens Connection has to be " + "established before querying"); } Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget((client)).path(phandle.toString()); FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), connection .getSessionHandle(), MediaType.APPLICATION_XML_TYPE)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute")); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("queryName").build(), queryName == null ? "" : queryName)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf, MediaType.APPLICATION_XML_TYPE)); QueryHandle handle = target.request() .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), QueryHandle.class); this.query = new ProxyLensQuery(this, handle); return handle; }
private void connectToLensServer() { log.debug("Connecting to lens server {}", new LensConnectionParams(conf)); connection = new LensConnection(new LensConnectionParams(conf)); connection.open(password); log.debug("Successfully connected to server {}", connection); pathValidator = new PathValidator(connection.getLensConnectionParams().getSessionConf()); Preconditions.checkNotNull(pathValidator, "Error in initializing Path Validator."); }
/** * Explain and prepare. * * @param sql the sql * @param queryName the query name * @param conf config to be used for the query * @return the query plan * @throws LensAPIException */ public LensAPIResult<QueryPlan> explainAndPrepare(String sql, String queryName, LensConf conf) throws LensAPIException { if (!connection.isOpen()) { throw new IllegalStateException("Lens Connection has to be established before querying"); } Client client = connection.buildClient(); WebTarget target = getPreparedQueriesWebTarget(client); Response response = target.request().post( Entity.entity(prepareForm(sql, "EXPLAIN_AND_PREPARE", queryName, conf), MediaType.MULTIPART_FORM_DATA_TYPE), Response.class); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.readEntity(new GenericType<LensAPIResult<QueryPlan>>() {}); } throw new LensAPIException(response.readEntity(LensAPIResult.class)); }