This is an automated email from the ASF dual-hosted git repository.

kgyrtkirk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 6efbfd6  HIVE-23404: Schedules in the past should be accepted (Zoltan 
Haindrich reviewed by Jesus Camacho Rodriguez)
6efbfd6 is described below

commit 6efbfd63e1b890cd99af30945c08f55ad0c3ed65
Author: Zoltan Haindrich <[email protected]>
AuthorDate: Tue Jun 2 21:13:08 2020 +0200

    HIVE-23404: Schedules in the past should be accepted (Zoltan Haindrich 
reviewed by Jesus Camacho Rodriguez)
---
 common/src/java/org/apache/hadoop/hive/conf/Constants.java       | 6 ++++++
 .../hadoop/hive/ql/scheduled/ScheduledQueryExecutionService.java | 4 ++++
 .../apache/hadoop/hive/ql/schq/TestScheduledQueryService.java    | 3 ++-
 ql/src/test/queries/clientpositive/schq_past.q                   | 9 +++++++++
 ql/src/test/results/clientpositive/llap/schq_past.q.out          | 8 ++++++++
 .../main/java/org/apache/hadoop/hive/metastore/ObjectStore.java  | 6 ------
 .../src/main/sql/derby/hive-schema-4.0.0.derby.sql               | 2 +-
 .../src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql          | 2 +-
 8 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/common/src/java/org/apache/hadoop/hive/conf/Constants.java 
b/common/src/java/org/apache/hadoop/hive/conf/Constants.java
index 7b2c234..a79be8d 100644
--- a/common/src/java/org/apache/hadoop/hive/conf/Constants.java
+++ b/common/src/java/org/apache/hadoop/hive/conf/Constants.java
@@ -77,4 +77,10 @@ public class Constants {
 
   /**  A named lock is acquired prior to executing the query; enabling to run 
queries in parallel which might interfere with eachother. */
   public static final String HIVE_QUERY_EXCLUSIVE_LOCK = 
"hive.query.exclusive.lock";
+
+  public static final String SCHEDULED_QUERY_NAMESPACE = 
"scheduled.query.namespace";
+  public static final String SCHEDULED_QUERY_SCHEDULENAME = 
"scheduled.query.schedulename";
+  public static final String SCHEDULED_QUERY_EXECUTIONID = 
"scheduled.query.executionid";
+  public static final String SCHEDULED_QUERY_USER = "scheduled.query.user";
+
 }
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/scheduled/ScheduledQueryExecutionService.java
 
b/ql/src/java/org/apache/hadoop/hive/ql/scheduled/ScheduledQueryExecutionService.java
index ca12093..3cbaa60 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/scheduled/ScheduledQueryExecutionService.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/scheduled/ScheduledQueryExecutionService.java
@@ -223,6 +223,10 @@ public class ScheduledQueryExecutionService implements 
Closeable {
         HiveConf conf = new HiveConf(context.conf);
         conf.set(Constants.HIVE_QUERY_EXCLUSIVE_LOCK, 
lockNameFor(q.getScheduleKey()));
         conf.setVar(HiveConf.ConfVars.HIVE_AUTHENTICATOR_MANAGER, 
SessionStateUserAuthenticator.class.getName());
+        conf.set(Constants.SCHEDULED_QUERY_NAMESPACE, 
q.getScheduleKey().getClusterNamespace());
+        conf.set(Constants.SCHEDULED_QUERY_SCHEDULENAME, 
q.getScheduleKey().getScheduleName());
+        conf.set(Constants.SCHEDULED_QUERY_USER, q.getUser());
+        conf.set(Constants.SCHEDULED_QUERY_EXECUTIONID, 
Long.toString(q.getExecutionId()));
         conf.unset(HiveConf.ConfVars.HIVESESSIONID.varname);
         state = new SessionState(conf, q.getUser());
         state.setIsHiveServerQuery(true);
diff --git 
a/ql/src/test/org/apache/hadoop/hive/ql/schq/TestScheduledQueryService.java 
b/ql/src/test/org/apache/hadoop/hive/ql/schq/TestScheduledQueryService.java
index dd8da34..ebf37d1 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/schq/TestScheduledQueryService.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/schq/TestScheduledQueryService.java
@@ -90,7 +90,7 @@ public class TestScheduledQueryService {
   private int getNumRowsReturned(IDriver driver, String query) throws 
Exception {
     driver.run(query);
     FetchTask ft = driver.getFetchTask();
-    List res = new ArrayList();
+    List<?> res = new ArrayList<>();
     if (ft == null) {
       return 0;
     }
@@ -117,6 +117,7 @@ public class TestScheduledQueryService {
       r.setExecutionId(id++);
       r.setQuery(stmt);
       r.setScheduleKey(new ScheduledQueryKey("sch1", getClusterNamespace()));
+      r.setUser("nobody");
       if (id == 1) {
         return r;
       } else {
diff --git a/ql/src/test/queries/clientpositive/schq_past.q 
b/ql/src/test/queries/clientpositive/schq_past.q
new file mode 100644
index 0000000..735ba03
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/schq_past.q
@@ -0,0 +1,9 @@
+--! qt:authorizer
+--! qt:scheduledqueryservice
+
+set user.name=hive_admin_user;
+set role admin;
+
+-- defining a schedule in the past should be allowed
+create scheduled query ingest cron '0 0 0 1 * ? 2000' defined as select 1;
+
diff --git a/ql/src/test/results/clientpositive/llap/schq_past.q.out 
b/ql/src/test/results/clientpositive/llap/schq_past.q.out
new file mode 100644
index 0000000..1667743
--- /dev/null
+++ b/ql/src/test/results/clientpositive/llap/schq_past.q.out
@@ -0,0 +1,8 @@
+PREHOOK: query: set role admin
+PREHOOK: type: SHOW_ROLES
+POSTHOOK: query: set role admin
+POSTHOOK: type: SHOW_ROLES
+PREHOOK: query: create scheduled query ingest cron '0 0 0 1 * ? 2000' defined 
as select 1
+PREHOOK: type: CREATE SCHEDULED QUERY
+POSTHOOK: query: create scheduled query ingest cron '0 0 0 1 * ? 2000' defined 
as select 1
+POSTHOOK: type: CREATE SCHEDULED QUERY
diff --git 
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
 
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
index 3922282..8fd4982 100644
--- 
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
+++ 
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
@@ -13174,9 +13174,6 @@ public class ObjectStore implements RawStore, 
Configurable {
       }
       openTransaction();
       Integer nextExecutionTime = computeNextExecutionTime(schq.getSchedule());
-      if (nextExecutionTime == null) {
-        throw new InvalidInputException("Invalid schedule: " + 
schq.getSchedule());
-      }
       schq.setNextExecution(nextExecutionTime);
       pm.makePersistent(schq);
       commited = commitTransaction();
@@ -13222,9 +13219,6 @@ public class ObjectStore implements RawStore, 
Configurable {
       persisted.doUpdate(schq);
       if (!scheduledQuery.isSetNextExecution()) {
         Integer nextExecutionTime = 
computeNextExecutionTime(schq.getSchedule());
-        if (nextExecutionTime == null) {
-          throw new InvalidInputException("Invalid schedule: " + 
schq.getSchedule());
-        }
         persisted.setNextExecution(nextExecutionTime);
       } else {
         persisted.setNextExecution(schq.getNextExecution());
diff --git 
a/standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql
 
b/standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql
index 727abce..d548c90 100644
--- 
a/standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql
+++ 
b/standalone-metastore/metastore-server/src/main/sql/derby/hive-schema-4.0.0.derby.sql
@@ -747,7 +747,7 @@ CREATE TABLE "APP"."SCHEDULED_QUERIES" (
   "USER" varchar(128) not null,
   "SCHEDULE" varchar(256) not null,
   "QUERY" varchar(4000) not null,
-  "NEXT_EXECUTION" integer not null,
+  "NEXT_EXECUTION" integer,
   "ACTIVE_EXECUTION_ID" bigint
 );
 
diff --git 
a/standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql
 
b/standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql
index 421524b..db6cebc 100644
--- 
a/standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql
+++ 
b/standalone-metastore/metastore-server/src/main/sql/derby/upgrade-3.2.0-to-4.0.0.derby.sql
@@ -26,7 +26,7 @@ CREATE TABLE "APP"."SCHEDULED_QUERIES" (
   "USER" varchar(128) not null,
   "SCHEDULE" varchar(256) not null,
   "QUERY" varchar(4000) not null,
-  "NEXT_EXECUTION" integer not null
+  "NEXT_EXECUTION" integer
 );
 
 CREATE INDEX NEXTEXECUTIONINDEX ON APP.SCHEDULED_QUERIES 
(ENABLED,CLUSTER_NAMESPACE,NEXT_EXECUTION);

Reply via email to