Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ public String getPlan() {
public QueryCost estimate(AbstractQueryContext qctx) throws LensException {
MethodMetricsContext validateGauge = MethodMetricsFactory.createMethodGauge(qctx.getDriverConf(this), true,
VALIDATE_GAUGE);
String rewrittenQuery = rewriteQuery(qctx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why changes are done in estimate, when you are fixing bug in prepareQuery.

Copy link
Author

@RajashekharChoukimath RajashekharChoukimath Aug 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the azure-world, we are not going to have Lens interacting with the actual underlying drivers. https://docs.google.com/document/d/1K5Q3ZQZAEGkf472DZ_zuLbHZ9ycx86YAEhqbxO0o-aA/edit#

The cleaner way for me is to remove driverconnection which Lens is making for the explain part in prepareInternal Method
https://github.com/apache/lens/blob/master/lens-driver-jdbc/src/main/java/org/apache/lens/driver/jdbc/JDBCDriver.java#L728

qctx.setSelectedDriverQuery(rewrittenQuery);
validate(qctx);
validateGauge.markSuccess();
return calculateQueryCost(qctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class PreparedQueryContext extends AbstractQueryContext implements Delaye
/**
* The millis in week.
*/
private static long millisInWeek = 7 * 24 * 60 * 60 * 1000;
private static long millisInTenMinutes = 10 * 60 * 1000;

/**
* Instantiates a new prepared query context.
Expand Down Expand Up @@ -129,7 +129,7 @@ public long getDelay(TimeUnit units) {
if (this.prepareStartTime != null) {
Date now = new Date();
long elapsedMills = now.getTime() - this.prepareStartTime.getTime();
delayMillis = millisInWeek - elapsedMills;
delayMillis = millisInTenMinutes - elapsedMills;
return units.convert(delayMillis, TimeUnit.MILLISECONDS);
} else {
return Integer.MAX_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
import org.apache.lens.api.query.QueryStatus;
import org.apache.lens.server.api.error.LensException;
import org.apache.lens.server.api.query.FinishedLensQuery;
import org.apache.lens.server.api.query.PreparedLensQuery;
import org.apache.lens.server.api.query.PreparedQueryContext;
import org.apache.lens.server.api.query.QueryContext;
import org.apache.lens.server.session.LensSessionImpl;
import org.apache.lens.server.util.UtilityMethods;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.dbutils.*;
import org.apache.commons.dbutils.handlers.BeanHandler;
Expand Down Expand Up @@ -868,4 +868,18 @@ public void insertPreparedQuery(PreparedQueryContext preparedQueryContext) throw
DbUtils.closeQuietly(conn);
}
}

public PreparedLensQuery getPreparedQuery(String handle) {
ResultSetHandler<PreparedLensQuery> rsh = new BeanHandler<>(PreparedLensQuery.class,
new BasicRowProcessor(new FinishedLensQueryBeanProcessor()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is FinishedLensQueryBeanProcessor created for Prepared query ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it.

String sql = "select * from prepared_queries where handle=?";
QueryRunner runner = new QueryRunner(ds);
try {
PreparedLensQuery preparedLensQuery = runner.query(sql, rsh, handle);
return preparedLensQuery;
} catch (SQLException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is exception eaten up?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it.

log.error("SQL exception while executing query.", e);
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you returning null?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2461,7 +2461,13 @@ private PreparedQueryContext getPreparedQueryContext(LensSessionHandle sessionHa
acquire(sessionHandle);
PreparedQueryContext ctx = preparedQueries.get(prepareHandle);
if (ctx == null) {
throw new NotFoundException("Prepared query not found " + prepareHandle);
PreparedLensQuery preparedLensQuery = lensServerDao.getPreparedQuery(prepareHandle.getQueryHandleString());
if (preparedLensQuery == null) {
throw new NotFoundException("Prepared query not found " + prepareHandle);
}
ctx = new PreparedQueryContext(preparedLensQuery.getUserquery(), preparedLensQuery.getSubmitter(), conf,
drivers.values());
ctx.setSelectedDriverQuery(preparedLensQuery.getDriverquery());
}
return ctx;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ public void testPreparedQueryDAO() throws Exception {
PreparedQueryContext preparedQueryContext = new PreparedQueryContext("query", "user1", driverConf,
createDriver(driverConf));
preparedQueryContext.setPrepareEndTime(new Date());
service.lensServerDao.insertPreparedQuery(preparedQueryContext);
service.lensServerDao.insertPreparedQuery(preparedQueryContext);
PreparedLensQuery preparedLensQuery = service.lensServerDao.getPreparedQuery(preparedQueryContext.getQueryHandleString());
Assert.assertEquals(preparedLensQuery.getHandle(), preparedQueryContext.getQueryHandleString());
Assert.assertEquals(preparedLensQuery.getSubmitter(), "user1");
} catch (Exception e) {
Assert.fail("it shouldn't be coming in this catch block");
}
Expand Down