[
https://issues.apache.org/jira/browse/CALCITE-5895?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17752205#comment-17752205
]
Julian Hyde commented on CALCITE-5895:
--------------------------------------
I agree this is a bug, and we should fix it. The parser correctly changes 'emp
TABLESAMPLE(100)' to 'emp'. But it should not convert 'emp TABLESAMPLE(0)' to
'emp', as it currently does.
I think implementation 2 would be better and easier. You would not need to
write a planner rule, and it seems clear to me where the logic should go:
* Move the {{if (fRate > 0.0f && fRate < 1.0f)}} logic from {{Parser.jj}} to
{{{}SqlToRelConverter.convertFrom{}}}.
* In {{{}SqlToRelConverter{}}}, you should use {{RelBuilder.empty()}} to
create an empty relation of the right type.
* For extra credit, move the {{if (rate.compareTo(BigDecimal.ZERO) < 0 ||
rate.compareTo(ONE_HUNDRED) > 0)}} logic from {{Parser.jj}} to
{{{}SqlValidatorImpl.validateQuery{}}}. The parser shouldn't be doing very much
validation. (And add a negative test to {{{}SqlValidatorTest{}}}.)
I really wish that we had an implementation of {{TABLESAMPLE}} in enumerable
mode. Then we could add a {{tablesample.iq}} test that actually executed
queries.
> The result of table sample rate 0 is incorrect result and should return the
> empty result
> -----------------------------------------------------------------------------------------
>
> Key: CALCITE-5895
> URL: https://issues.apache.org/jira/browse/CALCITE-5895
> Project: Calcite
> Issue Type: Bug
> Reporter: LakeShen
> Assignee: LakeShen
> Priority: Major
> Fix For: 1.36.0
>
> Attachments: image-2023-08-05-22-45-02-513.png
>
>
> For The sql:
> {code:java}
> select * from emp tablesample bernoulli(0) where empno > 5
> {code}
> The plan is :
> {code:java}
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
> SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
> LogicalFilter(condition=[>($0, 5)])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> {code}
> I think the correct result of above SQL is empty.
> But its result is the following SQL result:
> {code:java}
> select * from emp where empno > 5
> {code}
> It's an incorrect result
--
This message was sent by Atlassian Jira
(v8.20.10#820010)