Skip to content

Commit

Permalink
fix correlate with limit
Browse files Browse the repository at this point in the history
  • Loading branch information
zinking committed Dec 12, 2015
1 parent de38802 commit 7a4c4e4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
Expand Up @@ -777,9 +777,11 @@ private static Expression implementNullSemantics(
// v0 != null && v1 != null && f(v0, v1)
for (Ord<RexNode> operand : Ord.zip(call.getOperands())) {
if (translator.isNullable(operand.e)) {
list.add(
translator.translate(
operand.e, NullAs.IS_NOT_NULL));
Expression te = translator.translate(operand.e, NullAs.IS_NOT_NULL);
Class tec = (Class) te.getType();
if (!tec.isPrimitive()) {
list.add(te);
}
translator = translator.setNullable(operand.e, false);
}
}
Expand Down
Expand Up @@ -1638,11 +1638,13 @@ public void set(int source, int target) {
if ((target < 0) && mappingType.isMandatorySource()) {
throw new IllegalArgumentException("Target is required");
}
if ((target >= targetCount) && (targetCount >= 0)) {
if ((target >= targetCount) && (targetCount >= 0) && mappingType.isMandatorySource()) {
throw new IllegalArgumentException(
"Target must be less than target count, " + targetCount);
}
targets[source] = target;
if ((target > 0) && target < targetCount) {
targets[source] = target;
}
}

public void setAll(Mapping mapping) {
Expand Down
58 changes: 26 additions & 32 deletions core/src/test/resources/sql/scalar.oq
Expand Up @@ -124,52 +124,46 @@ select deptno, (select sum(empno) from "scott".emp where 1 = 0 group by ()) as x
!ok

# [CALCITE-709] Errors with LIMIT inside scalar sub-query
!if (false) {
select deptno, (select sum(empno) from "scott".emp where deptno = dept.deptno limit 1) as x from "scott".dept;
+--------+----------------------+
| DEPTNO | X |
+--------+----------------------+
| 10 | 23555 |
| 20 | 38501 |
| 30 | 46116 |
| 40 | null |
+--------+----------------------+
select deptno, (select sum(cast(empno as int)) from "scott".emp where deptno = dept.deptno limit 1) as x from "scott".dept;
+--------+-------+
| DEPTNO | X |
+--------+-------+
| 10 | 23555 |
| 20 | 38501 |
| 30 | 46116 |
| 40 | |
+--------+-------+
(4 rows)

!ok
!}

# [CALCITE-709] Errors with LIMIT inside scalar sub-query
!if (false) {
select deptno, (select sum(empno) from "scott".emp where deptno = dept.deptno limit 0) as x from "scott".dept;
+--------+----------------------+
| DEPTNO | X |
+--------+----------------------+
| 10 | 23555 |
| 20 | 38501 |
| 30 | 46116 |
| 40 | null |
+--------+----------------------+
select deptno, (select sum(cast(empno as int)) from "scott".emp where deptno = dept.deptno limit 0) as x from "scott".dept;
+--------+---+
| DEPTNO | X |
+--------+---+
| 10 | |
| 20 | |
| 30 | |
| 40 | |
+--------+---+
(4 rows)

!ok
!}

# [CALCITE-709] Errors with LIMIT inside scalar sub-query
!if (false) {
select deptno, (select deptno from "scott".emp where deptno = dept.deptno limit 1) as x from "scott".dept;
+--------+------+
| DEPTNO | X |
+--------+------+
| 10 | 10 |
| 20 | 20 |
| 30 | 30 |
| 40 | null |
+--------+------+
+--------+----+
| DEPTNO | X |
+--------+----+
| 10 | 10 |
| 20 | 20 |
| 30 | 30 |
| 40 | |
+--------+----+
(4 rows)

!ok
!}

select deptno, (select deptno from "scott".emp where deptno = dept.deptno limit 0) as x from "scott".dept;
+--------+---+
Expand Down

0 comments on commit 7a4c4e4

Please sign in to comment.