zabetak commented on a change in pull request #2979:
URL: https://github.com/apache/hive/pull/2979#discussion_r795840746



##########
File path: ql/src/test/queries/clientpositive/order_null2.q
##########
@@ -0,0 +1,70 @@
+create table test1
+(
+  a string,
+  b timestamp,
+  c timestamp
+);
+
+INSERT INTO TABLE test1 VALUES
+('John Doe', '1990-05-10 00:00:00.0', '2022-01-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-12-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-11-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-10-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-09-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2022-01-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-12-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-11-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-10-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', null);

Review comment:
       I suppose the example can be simplified a bit by: 
   
   1. picking more user-friendly names/types; 
   2. using fewer rows; 
   
   ```
   create table person (name string, country string, age int);
   insert into person values 
   ('John Doe', 'France', 20),
   ('Alex Dum', 'France', 24),
   ('Victor Hug', 'France', null);
   ```

##########
File path: ql/src/test/queries/clientpositive/order_null2.q
##########
@@ -0,0 +1,70 @@
+create table test1
+(
+  a string,
+  b timestamp,
+  c timestamp
+);
+
+INSERT INTO TABLE test1 VALUES
+('John Doe', '1990-05-10 00:00:00.0', '2022-01-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-12-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-11-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-10-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-09-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2022-01-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-12-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-11-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-10-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', null);
+
+-- hive.default.nulls.last is true by default, it sets NULLS_FIRST for DESC
+EXPLAIN AST
+SELECT a, b, c, row_number() OVER (PARTITION BY a, b ORDER BY b DESC, c DESC)
+FROM test1;
+
+EXPLAIN
+SELECT a, b, c, row_number() OVER (PARTITION BY a, b ORDER BY b DESC, c DESC)
+FROM test1;
+
+SELECT a, b, c, row_number() OVER (PARTITION BY a, b ORDER BY b DESC, c DESC)
+FROM test1;
+
+-- we set hive.default.nulls.last=false, it sets NULLS_LAST for DESC
+set hive.default.nulls.last=false;
+
+EXPLAIN AST
+SELECT a, b, c, row_number() OVER (PARTITION BY a, b ORDER BY b DESC, c DESC)
+FROM test1;
+
+EXPLAIN
+SELECT a, b, c, row_number() OVER (PARTITION BY a, b ORDER BY b DESC, c DESC)
+FROM test1;
+
+SELECT a, b, c, row_number() OVER (PARTITION BY a, b ORDER BY b DESC, c DESC)
+FROM test1;
+
+-- we set hive.default.nulls.last=false but we have explicit NULLS_LAST, we 
expect NULLS_LAST
+set hive.default.nulls.last=false;

Review comment:
       Do we need to reset the property if it is already done above?

##########
File path: ql/src/test/queries/clientpositive/order_null2.q
##########
@@ -0,0 +1,70 @@
+create table test1
+(
+  a string,
+  b timestamp,
+  c timestamp
+);
+
+INSERT INTO TABLE test1 VALUES
+('John Doe', '1990-05-10 00:00:00.0', '2022-01-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-12-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-11-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-10-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-09-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2022-01-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-12-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-11-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-10-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', null);
+
+-- hive.default.nulls.last is true by default, it sets NULLS_FIRST for DESC
+EXPLAIN AST
+SELECT a, b, c, row_number() OVER (PARTITION BY a, b ORDER BY b DESC, c DESC)
+FROM test1;
+
+EXPLAIN
+SELECT a, b, c, row_number() OVER (PARTITION BY a, b ORDER BY b DESC, c DESC)
+FROM test1;
+
+SELECT a, b, c, row_number() OVER (PARTITION BY a, b ORDER BY b DESC, c DESC)
+FROM test1;

Review comment:
       Do we need the explain statements? Aren't the results enough to 
guarantee that the behavior is the expected one?
   If we need the explains do we need multiple?

##########
File path: ql/src/test/queries/clientpositive/order_null2.q
##########
@@ -0,0 +1,70 @@
+create table test1
+(
+  a string,
+  b timestamp,
+  c timestamp
+);
+
+INSERT INTO TABLE test1 VALUES
+('John Doe', '1990-05-10 00:00:00.0', '2022-01-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-12-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-11-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-10-10 00:00:00.0'),
+('John Doe', '1990-05-10 00:00:00.0', '2021-09-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2022-01-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-12-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-11-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', '2021-10-10 00:00:00.0'),
+('John Doe', '1987-05-10 00:00:00.0', null);
+
+-- hive.default.nulls.last is true by default, it sets NULLS_FIRST for DESC

Review comment:
       Better set the property explicitly and not rely on defaults. We mostly 
want to test the behavior of the property not the defaults which I guess are 
covered by other places.

##########
File path: parser/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
##########
@@ -863,7 +863,7 @@ import org.apache.hadoop.hive.conf.HiveConf;
   }
   protected boolean nullsLast() {
     if(hiveConf == null){
-      return false;
+      return HiveConf.ConfVars.HIVE_DEFAULT_NULLS_LAST.defaultBoolVal;

Review comment:
       Good idea, on keeping this change as separate commit but let's also give 
it a unique JIRA id since I don't see any change landing in Hive without a JIRA 
reference. 




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to