[
https://issues.apache.org/jira/browse/FLINK-14886?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Leonard Xu updated FLINK-14886:
-------------------------------
Comment: was deleted
(was: use legacy planner, return correct result.
{code:java}
// org.apache.flink.table.runtime.batch.sql.JavaSqlITCase
@Test
public void testScalarQuery() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = BatchTableEnvironment.create(env, config());
DataSet<Tuple2<String, Double>> ds =
CollectionDataSets.getSmall2TupleDataSet(env);
tableEnv.registerDataSet("t", ds, "a, b");
String sqlQuery =
"select t1.a, t1.b, \n" +
" (select avg(t2.b) \n" +
" from t t2\n" +
" where t2.a = t1.a)\n" +
"from t t1 order by t1.a, t1.b\n";
Table result = tableEnv.sqlQuery(sqlQuery);
System.out.println(tableEnv.explain(result));
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "boy,100.0,100.0\n" + "null,50.0,null\n";
compareResultAsText(results, expected);
}
{code}
use Blink planner, return wrong result(test failed):
{code:java}
// org.apache.flink.table.planner.runtime.batch.sql.MiscITCase
@Test
def testScalarQueryJoin(): Unit = {
checkQuery(
Seq[(String, Double)](("boy", 100d), (null, 50d)),
"select t1.f0, t1.f1,(select avg(t2.f1) \n from Table1 t2\n where t2.f0
= t1.f0)\nfrom Table1 t1",
Seq(("boy", 100, 100), ("boy", 100, null))
)
} {code}
{code:java}
// org.apache.flink.test.operators.util.CollectionDataSets
public static DataSet<Tuple2<String, Double>>
getSmall2TupleDataSet(ExecutionEnvironment env) {
List<Tuple2<String, Double>> data = new ArrayList<>();
data.add(new Tuple2<>("boy", 100d));
data.add(new Tuple2<>(null, 50d));
Collections.shuffle(data);
return env.fromCollection(data);
}
{code})
> Wrong result in scalar query using blink planner
> ------------------------------------------------
>
> Key: FLINK-14886
> URL: https://issues.apache.org/jira/browse/FLINK-14886
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / Planner
> Affects Versions: 1.9.1
> Reporter: Leonard Xu
> Priority: Blocker
> Fix For: 1.10.0, 1.9.2
>
>
>
> In TPC-DS query6.sql, I found the query result is incorrect, I analyze the
> root cause and simplify the issue as following:
> {code:java}
> create table t(
> a varchar(100),
> b float
> );
> insert into t(a,b) values('boy', 100);
> insert into t(a,b) values(null, 50);
> select t1.a, t1.b, (select avg(t2.b)
> from t t2
> where t2.a = t1.a)
> from t t1;
> {code}
> the result when use blink planner is:
> {code:java}
> | a | b | EXP |
> |-----|-----|-----|
> | boy| 100| 100|
> | null| 50| 100|
> {code}
> but correct result should be :
> {code:java}
> | a | b | EXP |
> |-----|-----|-----|
> | boy| 100| 100|
> | null| 50| null|
> {code}
> Both flink legacy planner and other DB system can produce the correct
> result.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)