You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2022/08/04 12:41:38 UTC

[GitHub] [hive] deniskuzZ commented on a diff in pull request #3499: HIVE-26446: HiveProtoLoggingHook fails to populate TablesWritten fiel…

deniskuzZ commented on code in PR #3499:
URL: https://github.com/apache/hive/pull/3499#discussion_r937732530


##########
ql/src/test/org/apache/hadoop/hive/ql/hooks/TestHiveProtoLoggingHook.java:
##########
@@ -322,4 +338,63 @@ private void assertOtherInfo(HiveHookEventProto event, OtherInfoType key, String
       Assert.assertEquals(value, val);
     }
   }
+
+  private void testTablesWritten(WriteEntity we, boolean isPartitioned) throws Exception {
+    String query = isPartitioned ?
+            "insert into test_partition partition(dt = '20220102', lable = 'test1') values('20220103', 'banana');" :
+            "insert into default.testTable1 values('ab')";
+    HashSet<WriteEntity> tableWritten = new HashSet<>();
+    tableWritten.add(we);
+    QueryState state = new QueryState.Builder().withHiveConf(conf).build();
+    @SuppressWarnings("serial")
+    QueryPlan queryPlan = new QueryPlan(HiveOperation.QUERY) {
+    };
+    queryPlan.setQueryId("test_queryId");
+    queryPlan.setQueryStartTime(1234L);
+    queryPlan.setQueryString(query);
+    queryPlan.setRootTasks(new ArrayList<>());
+    queryPlan.setInputs(new HashSet<>());
+    queryPlan.setOutputs(tableWritten);
+    PerfLogger perf = PerfLogger.getPerfLogger(conf, true);
+    HookContext ctx = new HookContext(queryPlan, state, null, "test_user", "192.168.10.11",
+            "hive_addr", "test_op_id", "test_session_id", "test_thread_id", true, perf, null);
+
+    ctx.setHookType(HookType.PRE_EXEC_HOOK);
+    EventLogger evtLogger = new EventLogger(conf, SystemClock.getInstance());
+    evtLogger.handle(ctx);
+    evtLogger.shutdown();
+
+    HiveHookEventProto event = loadEvent(conf, tmpFolder);
+
+    Assert.assertEquals(EventType.QUERY_SUBMITTED.name(), event.getEventType());
+    Assert.assertEquals(we.getTable().getFullyQualifiedName(), event.getTablesWritten(0));
+  }
+
+  private Table newTable(boolean isPartitioned) {

Review Comment:
   would it be better to use builder:
   ````
   TableBuilder builder =
           new TableBuilder().setDbName(DB_NAME).setTableName(tableName).addCol("test_id", "int", "test col id")
               .addCol("test_value", "string", "test col value").setPartCols(partCols)
               .setType(tableType).setLocation(location).setTemporary(true);
       if (tableParams != null) {
         builder.setTableParams(tableParams);
       }
       builder.build(conf);
   ````



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org