I'm joining datasets from different sources (using the newly implemented
qualified scan), however the following INNER join query returns many more
rows than I would expect (it returns all combinations of rows as an OUTER
join would):

builder.scan("source1", "article_facts")
    .filter(builder.call(SqlStdOperatorTable.EQUALS, builder.field(1, 0,
"property_id"), builder.literal(5)))
    .project(builder.field(1, 0, "article_id"))
  .scan("source2", "articles")
    .project(builder.field(1, 0, "id"))
  .join(JoinRelType.INNER, builder.call(SqlStdOperatorTable.EQUALS,
      builder.field(2, 0, "article_id"),
      builder.field(2, 1, "id")))
  .build()

The plan output appears correct:

LogicalJoin(condition=[=($0, $0)], joinType=[inner])
    LogicalProject(article_id=[$0])
      LogicalFilter(condition=[=($1, 5)])
        LogicalTableScan(table=[[source1, article_facts]])
    LogicalProject(id=[$0])
      LogicalTableScan(table=[[source2, articles]])

I have tried reproducing this as a test case in RelBuilderTest, but if I
call executeQuery on a statement containing a join I get:

Internal error: Error while applying rule EnumerableJoinRule, args
[rel#40:LogicalJoin.NONE.[](left=rel#38:Subset#1.NONE.[0],right=rel#39:Subset#2.NONE.[0],condition==($7,
$0),joinType=inner)]

I presume this is due to some limitation of the test environment, so right
now I'm unsure how to get this to work.

One more thing I noticed is that the filter predicate (== 5) is not pushed
down to the database (Postgres in this case). Instead calcite used `select
* from article_facts` and applied the filter afterwards. Is that expected
behaviour for the RelBuilder?

Thanks!

Chris

Reply via email to