[ 
https://issues.apache.org/jira/browse/HIVE-26095?focusedWorklogId=751457&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-751457
 ]

ASF GitHub Bot logged work on HIVE-26095:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 01/Apr/22 08:58
            Start Date: 01/Apr/22 08:58
    Worklog Time Spent: 10m 
      Work Description: kasakrisz commented on a change in pull request #3156:
URL: https://github.com/apache/hive/pull/3156#discussion_r840236630



##########
File path: 
service/src/test/org/apache/hive/service/cli/operation/TestQueryLifeTimeHooksWithSQLOperation.java
##########
@@ -110,6 +118,45 @@ public void afterExecution(QueryLifeTimeHookContext ctx, 
boolean hasError) {
       assertNull(ctx.getHookContext().getException());
       assertNotNull(ctx.getHookContext().getQueryInfo());
       assertNotNull(ctx.getHookContext().getQueryInfo().getQueryDisplay());
+      assertQueryId(ctx.getQueryId());
     }
   }
+
+  /**
+   * Asserts that the specified query id exists and has the expected prefix 
and size.
+   *
+   * <p>
+   * A query id looks like below:
+   * <pre>
+   *   username_20220330093338_dab90f30-5e79-463d-8359-0d2fff57effa
+   * </pre>
+   * and we can accurately predict how the prefix should look like. T
+   * </p>
+   *
+   * @param actualQueryId the query id to verify
+   */
+  private static void assertQueryId(String actualQueryId) {
+    assertNotNull(actualQueryId);
+    String expectedIdPrefix = makeQueryIdStablePrefix();
+    String actualIdPrefix = actualQueryId.substring(0, 
expectedIdPrefix.length());
+    assertEquals(expectedIdPrefix, actualIdPrefix);
+    assertEquals(expectedIdPrefix.length() + 41, actualQueryId.length());
+  }
+
+  /**
+   * Makes a query id prefix that is stable for an hour. The prefix changes 
every hour but this is enough to guarantee

Review comment:
       IIUC  `TestQueryLifeTimeHooksWithSQLOperation` tests whether data is 
passed to  `QueryLifeTimeHookWithParseHooks`. I think the test is more isolated 
and focus only to the data broadcasting functionality if the data is generated 
by the test. It can be achieved by setting the queryId explicitly in the 
beginning of the test to some constant and check it in the assertion part the 
exact same constant. I believe it can be set by `hive.query.id` config setting.
   
   Or you can also ask the actual queryId via the `hive.query.id` config 
setting somewhere in the beginning of the test and use that value in the assert 
part instead of generating a new one.
   
   Or as a last option if none of above works a regex can be used to check the 
format.
   
   If you also want to test the queryId format is correct an UT for 
`QueryPlan.makeQueryId` would do that but I think a regex is still needed for 
that or at least for checking the date time part.




-- 
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]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 751457)
    Time Spent: 1.5h  (was: 1h 20m)

> Add queryid in QueryLifeTimeHookContext
> ---------------------------------------
>
>                 Key: HIVE-26095
>                 URL: https://issues.apache.org/jira/browse/HIVE-26095
>             Project: Hive
>          Issue Type: New Feature
>          Components: Hooks
>            Reporter: Stamatis Zampetakis
>            Assignee: Stamatis Zampetakis
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 4.0.0-alpha-2
>
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> A 
> [QueryLifeTimeHook|https://github.com/apache/hive/blob/6c0b86ef0cfc67c5acb3468408e1d46fa6ef8024/ql/src/java/org/apache/hadoop/hive/ql/hooks/QueryLifeTimeHook.java]
>  is executed various times in the life-cycle of a query but it is not always 
> possible to obtain the id of the query. The query id is inside the 
> {{HookContext}} but the latter is not always available notably during 
> compilation.
> The query id is useful for many purposes as it is the only way to uniquely 
> identify the query/command that is currently running. It is also the only way 
> to match together events appearing in before and after methods.
> The goal of this jira is to add the query id in 
> [QueryLifeTimeHookContext|https://github.com/apache/hive/blob/6c0b86ef0cfc67c5acb3468408e1d46fa6ef8024/ql/src/java/org/apache/hadoop/hive/ql/hooks/QueryLifeTimeHookContext.java]
>  and make it available during all life-cycle events.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to