Repository: lens
Updated Branches:
  refs/heads/master 12774400d -> 7947acda7


LENS-1304 : Log Driver query in lens finished_queries


Project: http://git-wip-us.apache.org/repos/asf/lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/7947acda
Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/7947acda
Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/7947acda

Branch: refs/heads/master
Commit: 7947acda7be47764f69ab32a08289bb8c9e7c9a1
Parents: 1277440
Author: Raghavendra Singh <raghavendra.si...@inmobi.com>
Authored: Sat Sep 17 10:52:28 2016 +0530
Committer: Amareshwari Sriramadasu <amareshw...@apache.org>
Committed: Sat Sep 17 10:52:28 2016 +0530

----------------------------------------------------------------------
 .../server/api/query/FinishedLensQuery.java     | 11 +++++++++
 .../apache/lens/server/query/LensServerDAO.java | 11 +++++----
 .../apache/lens/server/query/TestLensDAO.java   | 26 +++++++++++++++++---
 3 files changed, 39 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lens/blob/7947acda/lens-server-api/src/main/java/org/apache/lens/server/api/query/FinishedLensQuery.java
----------------------------------------------------------------------
diff --git 
a/lens-server-api/src/main/java/org/apache/lens/server/api/query/FinishedLensQuery.java
 
b/lens-server-api/src/main/java/org/apache/lens/server/api/query/FinishedLensQuery.java
index 1d56757..edd4284 100644
--- 
a/lens-server-api/src/main/java/org/apache/lens/server/api/query/FinishedLensQuery.java
+++ 
b/lens-server-api/src/main/java/org/apache/lens/server/api/query/FinishedLensQuery.java
@@ -175,6 +175,13 @@ public class FinishedLensQuery {
   private String priority;
 
   /**
+   * The selected driver's query.
+   */
+  @Getter
+  @Setter
+  private String driverQuery;
+
+  /**
    * Instantiates a new finished lens query.
    */
   public FinishedLensQuery() {
@@ -204,6 +211,7 @@ public class FinishedLensQuery {
     this.selectedDriver = ctx.getSelectedDriver();
     if (null != ctx.getSelectedDriver()) {
       this.driverName = ctx.getSelectedDriver().getFullyQualifiedName();
+      this.driverQuery = ctx.getSelectedDriverQuery();
     }
     //Priority can be null in case no driver is fit to execute a query and 
launch fails.
     if (null != ctx.getPriority()) {
@@ -230,6 +238,9 @@ public class FinishedLensQuery {
     qctx.getDriverStatus().setDriverFinishTime(getDriverEndTime());
     qctx.setResultSetPath(getResult());
     qctx.setQueryName(getQueryName());
+    if (null != driverQuery){
+      qctx.setSelectedDriverQuery(driverQuery);
+    }
     if (getPriority() != null) {
       qctx.setPriority(Priority.valueOf(getPriority()));
     }

http://git-wip-us.apache.org/repos/asf/lens/blob/7947acda/lens-server/src/main/java/org/apache/lens/server/query/LensServerDAO.java
----------------------------------------------------------------------
diff --git 
a/lens-server/src/main/java/org/apache/lens/server/query/LensServerDAO.java 
b/lens-server/src/main/java/org/apache/lens/server/query/LensServerDAO.java
index 47159b5..2ec938e 100644
--- a/lens-server/src/main/java/org/apache/lens/server/query/LensServerDAO.java
+++ b/lens-server/src/main/java/org/apache/lens/server/query/LensServerDAO.java
@@ -83,11 +83,11 @@ public class LensServerDAO {
    */
   public void createFinishedQueriesTable() throws Exception {
     String sql = "CREATE TABLE if not exists finished_queries (handle 
varchar(255) not null unique,"
-      + "userquery varchar(10000) not null," + "submitter varchar(255) not 
null," + "priority varchar(255), "
+      + "userquery varchar(20000) not null," + "submitter varchar(255) not 
null," + "priority varchar(255), "
       + "starttime bigint, " + "endtime bigint," + "result varchar(255)," + 
"status varchar(255), "
       + "metadata varchar(100000), " + "rows int, " + "filesize bigint, " + 
"errormessage varchar(10000), "
       + "driverstarttime bigint, " + "driverendtime bigint, " + "drivername 
varchar(10000), "
-      + "queryname varchar(255), " + "submissiontime bigint" + ")";
+      + "queryname varchar(255), " + "submissiontime bigint, " + "driverquery 
varchar(1000000)" + ")";
     try {
       QueryRunner runner = new QueryRunner(ds);
       runner.update(sql);
@@ -110,15 +110,16 @@ public class LensServerDAO {
       Connection conn = null;
       String sql = "insert into finished_queries (handle, userquery, 
submitter, priority, "
         + "starttime,endtime,result,status,metadata,rows,filesize,"
-        + "errormessage,driverstarttime,driverendtime, drivername, queryname, 
submissiontime)"
-        + " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+        + "errormessage,driverstarttime,driverendtime, drivername, queryname, 
submissiontime, driverquery)"
+        + " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
       try {
         conn = getConnection();
         QueryRunner runner = new QueryRunner();
         runner.update(conn, sql, query.getHandle(), query.getUserQuery(), 
query.getSubmitter(), query.getPriority(),
             query.getStartTime(), query.getEndTime(), query.getResult(), 
query.getStatus(), query.getMetadata(),
             query.getRows(), query.getFileSize(), query.getErrorMessage(), 
query.getDriverStartTime(),
-            query.getDriverEndTime(), query.getDriverName(), 
query.getQueryName(), query.getSubmissionTime());
+            query.getDriverEndTime(), query.getDriverName(), 
query.getQueryName(), query.getSubmissionTime(),
+            query.getDriverQuery());
         conn.commit();
       } finally {
         DbUtils.closeQuietly(conn);

http://git-wip-us.apache.org/repos/asf/lens/blob/7947acda/lens-server/src/test/java/org/apache/lens/server/query/TestLensDAO.java
----------------------------------------------------------------------
diff --git 
a/lens-server/src/test/java/org/apache/lens/server/query/TestLensDAO.java 
b/lens-server/src/test/java/org/apache/lens/server/query/TestLensDAO.java
index 74d9a1f..2a820ec 100644
--- a/lens-server/src/test/java/org/apache/lens/server/query/TestLensDAO.java
+++ b/lens-server/src/test/java/org/apache/lens/server/query/TestLensDAO.java
@@ -33,7 +33,9 @@ import org.apache.lens.api.query.QueryHandle;
 import org.apache.lens.api.query.QueryStatus;
 import org.apache.lens.driver.jdbc.JDBCResultSet;
 import org.apache.lens.server.LensServices;
+import org.apache.lens.server.api.driver.LensDriver;
 import org.apache.lens.server.api.driver.MockDriver;
+import org.apache.lens.server.api.query.DriverSelectorQueryContext;
 import org.apache.lens.server.api.query.FinishedLensQuery;
 import org.apache.lens.server.api.query.QueryContext;
 import org.apache.lens.server.api.query.QueryExecutionService;
@@ -62,13 +64,25 @@ public class TestLensDAO {
   @Test
   public void testLensServerDAO() throws Exception {
     QueryExecutionServiceImpl service = 
LensServices.get().getService(QueryExecutionService.NAME);
+    String driverQuery = "SELECT aliasName1.Id FROM driverTable1 aliasName1";
+    String userQuery = "SELECT ID FROM testTable";
 
     // Test insert query
-    QueryContext queryContext = service.createContext("SELECT ID FROM 
testTable", "foo@localhost", new LensConf(),
-      new Configuration(), 0);
+    QueryContext queryContext = service.createContext(userQuery, 
"foo@localhost", new LensConf(),
+            new Configuration(), 0);
     long submissionTime = queryContext.getSubmissionTime();
     queryContext.setQueryName("daoTestQuery1");
-    queryContext.getDriverContext().setSelectedDriver(new MockDriver());
+
+    LensDriver mockDriver = new MockDriver();
+    DriverSelectorQueryContext mockDriverContext = new 
DriverSelectorQueryContext(userQuery,
+            new Configuration(), Lists.newArrayList(mockDriver), false);
+
+    queryContext.setDriverContext(mockDriverContext);
+    queryContext.getDriverContext().setSelectedDriver(mockDriver);
+    // Add a query for the selected driver
+    queryContext.getDriverContext().setDriverQuery(mockDriver, driverQuery);
+    
Assert.assertEquals(queryContext.getDriverContext().getSelectedDriverQuery(), 
driverQuery);
+
     FinishedLensQuery finishedLensQuery = new FinishedLensQuery(queryContext);
     finishedLensQuery.setStatus(QueryStatus.Status.SUCCESSFUL.name());
     finishedLensQuery.setPriority(Priority.NORMAL.toString());
@@ -118,12 +132,16 @@ public class TestLensDAO {
       JDBCResultSet.JDBCResultSetMetadata.class);
     // Assert
     Assert.assertNotNull(actualRsMeta, "Should be able to read back metadata 
for jdbc queries");
-    // Validate metadat
+    // Validate metadata
     Assert.assertEquals(actualRsMeta.getColumns().size(), 1);
     
Assert.assertEquals(actualRsMeta.getColumns().get(0).getName().toLowerCase(), 
"handle");
 
     Assert.assertEquals(actual.getHandle(), finishedHandle);
     Assert.assertEquals(Priority.valueOf(actual.getPriority()), 
Priority.NORMAL);
+    Assert.assertEquals(actual.getDriverQuery(), driverQuery);
+    // when driver list contains the selected driver, selected driver should 
get set correctly in context
+    QueryContext retrievedQueryContext = actual.toQueryContext(new 
Configuration(), Lists.newArrayList(mockDriver));
+    Assert.assertEquals(retrievedQueryContext.getSelectedDriverQuery(), 
driverQuery);
 
     // Test find finished queries
     LensSessionHandle session = service.openSession("foo@localhost", "bar", 
new HashMap<String, String>());

Reply via email to