luocooong commented on a change in pull request #2422:
URL: https://github.com/apache/drill/pull/2422#discussion_r790134460



##########
File path: 
contrib/storage-phoenix/src/main/java/org/apache/drill/exec/store/phoenix/PhoenixBatchReader.java
##########
@@ -71,58 +74,64 @@ public PhoenixBatchReader(PhoenixSubScan subScan) {
 
   @Override
   public boolean open(SchemaNegotiator negotiator) {
-    try {
+    UserGroupInformation ugi = ImpersonationUtil.getProcessUserUGI();
+    return ugi.doAs((PrivilegedAction<Boolean>) () -> {
       errorContext = negotiator.parentErrorContext();
-      conn = subScan.getPlugin().getDataSource().getConnection();
-      pstmt = conn.prepareStatement(subScan.getSql());
-      results = pstmt.executeQuery();
-      meta = pstmt.getMetaData();
-    } catch (SQLException e) {
-      throw UserException
-              .dataReadError(e)
-              .message("Failed to execute the phoenix sql query. " + 
e.getMessage())
-              .addContext(errorContext)
-              .build(logger);
-    }
-    try {
-      negotiator.tableSchema(defineMetadata(), true);
-      reader = new PhoenixReader(negotiator.build(), columns, results);
-      bindColumns(reader.getStorage());
-    } catch (SQLException e) {
-      throw UserException
-              .dataReadError(e)
-              .message("Failed to get type of columns from metadata. " + 
e.getMessage())
-              .addContext(errorContext)
-              .build(logger);
-    }
-    watch = Stopwatch.createStarted();
-    return true;
+      try {
+        pstmt =
+          
subScan.getPlugin().getDataSource(negotiator.userName()).getConnection().prepareStatement(subScan.getSql());
+        results = pstmt.executeQuery();
+        meta = pstmt.getMetaData();
+      } catch (SQLException e) {
+        throw UserException
+          .dataReadError(e)
+          .message("Failed to execute the phoenix sql query. " + 
e.getMessage())
+          .addContext(negotiator.parentErrorContext())
+          .build(logger);
+      }
+      try {
+        negotiator.tableSchema(defineMetadata(), true);
+        reader = new PhoenixReader(negotiator.build(), columns, results);
+        bindColumns(reader.getStorage());
+      } catch (SQLException e) {
+        throw UserException
+          .dataReadError(e)
+          .message("Failed to get type of columns from metadata. " + 
e.getMessage())
+          .addContext(errorContext)
+          .build(logger);
+      }
+      watch = Stopwatch.createStarted();
+      return true;
+    });
   }
 
   @Override
   public boolean next() {
+    UserGroupInformation ugi = ImpersonationUtil.getProcessUserUGI();
     try {
-      while(!reader.getStorage().isFull()) {
-        if (!reader.processRow()) { // return true if one row is processed.
-          watch.stop();
-          logger.debug("Phoenix fetch total record numbers : {}", 
reader.getRowCount());
-          return false; // the EOF is reached.
+      return ugi.doAs((PrivilegedExceptionAction<Boolean>) () -> {

Review comment:
       I fully agree that we will not use the impersonation feature until it is 
enabled, thank you.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to