Skip to content

Commit

Permalink
HIVE-21976: Offset should be null instead of zero in Calcite HiveSort…
Browse files Browse the repository at this point in the history
…Limit (Jesus Camacho Rodriguez, reviewed by Vineet Garg)

Close apache/hive#716
  • Loading branch information
jcamachor authored and Sungwoo Park committed Aug 16, 2023
1 parent e10a5e3 commit 985bc6d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4039,11 +4039,12 @@ private RelNode genLimitLogicalPlan(QB qb, RelNode srcRel) throws SemanticExcept
QBParseInfo qbp = getQBParseInfo(qb);
SimpleEntry<Integer,Integer> entry =
qbp.getDestToLimit().get(qbp.getClauseNames().iterator().next());
Integer offset = (entry == null) ? 0 : entry.getKey();
Integer offset = (entry == null) ? null : entry.getKey();
Integer fetch = (entry == null) ? null : entry.getValue();

if (fetch != null) {
RexNode offsetRN = cluster.getRexBuilder().makeExactLiteral(BigDecimal.valueOf(offset));
RexNode offsetRN = (offset == null || offset == 0) ?
null : cluster.getRexBuilder().makeExactLiteral(BigDecimal.valueOf(offset));
RexNode fetchRN = cluster.getRexBuilder().makeExactLiteral(BigDecimal.valueOf(fetch));
RelTraitSet traitSet = cluster.traitSetOf(HiveRelNode.CONVENTION);
RelCollation canonizedCollation = traitSet.canonize(RelCollations.EMPTY);
Expand Down
5 changes: 5 additions & 0 deletions ql/src/test/queries/clientpositive/external_jdbc_table4.q
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ SELECT db1_ext_auth1.ikey, b.ikey * 2 FROM db1_ext_auth1 JOIN (SELECT * FROM db1

SELECT db1_ext_auth1.ikey, b.ikey * 2 FROM db1_ext_auth1 JOIN (SELECT * FROM db1_ext_auth1) b;

EXPLAIN
SELECT db1_ext_auth1.ikey FROM db1_ext_auth1 LIMIT 10;

SELECT db1_ext_auth1.ikey FROM db1_ext_auth1 LIMIT 10;

DROP TABLE db1_ext_auth1;
DROP TABLE db2_ext_auth2;
DROP TABLE db1_ext_auth2;
Expand Down
45 changes: 45 additions & 0 deletions ql/src/test/results/clientpositive/llap/external_jdbc_table4.q.out
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,51 @@ POSTHOOK: Input: default@db1_ext_auth1
44 200
44 40
44 88
PREHOOK: query: EXPLAIN
SELECT db1_ext_auth1.ikey FROM db1_ext_auth1 LIMIT 10
PREHOOK: type: QUERY
PREHOOK: Input: default@db1_ext_auth1
#### A masked pattern was here ####
POSTHOOK: query: EXPLAIN
SELECT db1_ext_auth1.ikey FROM db1_ext_auth1 LIMIT 10
POSTHOOK: type: QUERY
POSTHOOK: Input: default@db1_ext_auth1
#### A masked pattern was here ####
STAGE DEPENDENCIES:
Stage-0 is a root stage

STAGE PLANS:
Stage: Stage-0
Fetch Operator
limit: -1
Processor Tree:
TableScan
alias: db1_ext_auth1
properties:
hive.sql.query SELECT "ikey"
FROM (SELECT "IKEY" AS "ikey"
FROM "EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1"
FETCH NEXT 10 ROWS ONLY) AS "t0"
hive.sql.query.fieldNames ikey
hive.sql.query.fieldTypes int
hive.sql.query.split false
Select Operator
expressions: ikey (type: int)
outputColumnNames: _col0
ListSink

PREHOOK: query: SELECT db1_ext_auth1.ikey FROM db1_ext_auth1 LIMIT 10
PREHOOK: type: QUERY
PREHOOK: Input: default@db1_ext_auth1
#### A masked pattern was here ####
POSTHOOK: query: SELECT db1_ext_auth1.ikey FROM db1_ext_auth1 LIMIT 10
POSTHOOK: type: QUERY
POSTHOOK: Input: default@db1_ext_auth1
#### A masked pattern was here ####
-20
100
20
44
PREHOOK: query: DROP TABLE db1_ext_auth1
PREHOOK: type: DROPTABLE
PREHOOK: Input: default@db1_ext_auth1
Expand Down

0 comments on commit 985bc6d

Please sign in to comment.