如何在 RelBuilder 中使用 SqlStdOperatorTable.IN?
How to use SqlStdOperatorTable.IN with RelBuilder?
我正在尝试使用 RelBuilder 构建类似于
看到了一些东西 here,但它没有太大帮助,对我没有用(
RelBuilder builder = RelBuilder.create(calciteConfig);
RelRunner relRunner = calciteConnection.unwrap(RelRunner.class);
builder.scan("dremio", "test1");
RexBuilder rexBuilder = new RexBuilder(new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT));
RexNode rexNode = rexBuilder.makeCall(
SqlStdOperatorTable.IN,
builder.field("device_type"),
rexBuilder.makeLiteral("TABLET"),
rexBuilder.makeLiteral("MOBILE"));
RelNode test1 = builder
.filter(rexNode)
.limit(10, 100)
.build();
您必须使用 RelBuilder#in
或 RexBuilder#makeIn
API。这是测试用例:
@Test void testIn() {
final RelBuilder builder = RelBuilder.create(config().build());
builder.scan("EMP");
final RexNode literal1 = builder.literal("foo");
final RexNode literal2 = builder.literal("bar");
RexNode inRex = builder.in(builder.field("ENAME"), ImmutableList.of(literal1, literal2));
RelNode root = builder.filter(inRex)
.build();
final String expected = "" +
"LogicalFilter(condition=[SEARCH(, Sarg['bar', 'foo']:CHAR(3))])\n" +
" LogicalTableScan(table=[[scott, EMP]])\n";
}
如果您想了解更多上下文,为什么 RexCall()
的构造函数中存在检查
即assert operator.kind != SqlKind.IN
请参考这个CALCITE-4173
我正在尝试使用 RelBuilder 构建类似于
看到了一些东西 here,但它没有太大帮助,对我没有用(
RelBuilder builder = RelBuilder.create(calciteConfig);
RelRunner relRunner = calciteConnection.unwrap(RelRunner.class);
builder.scan("dremio", "test1");
RexBuilder rexBuilder = new RexBuilder(new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT));
RexNode rexNode = rexBuilder.makeCall(
SqlStdOperatorTable.IN,
builder.field("device_type"),
rexBuilder.makeLiteral("TABLET"),
rexBuilder.makeLiteral("MOBILE"));
RelNode test1 = builder
.filter(rexNode)
.limit(10, 100)
.build();
您必须使用 RelBuilder#in
或 RexBuilder#makeIn
API。这是测试用例:
@Test void testIn() {
final RelBuilder builder = RelBuilder.create(config().build());
builder.scan("EMP");
final RexNode literal1 = builder.literal("foo");
final RexNode literal2 = builder.literal("bar");
RexNode inRex = builder.in(builder.field("ENAME"), ImmutableList.of(literal1, literal2));
RelNode root = builder.filter(inRex)
.build();
final String expected = "" +
"LogicalFilter(condition=[SEARCH(, Sarg['bar', 'foo']:CHAR(3))])\n" +
" LogicalTableScan(table=[[scott, EMP]])\n";
}
如果您想了解更多上下文,为什么 RexCall()
的构造函数中存在检查
即assert operator.kind != SqlKind.IN
请参考这个CALCITE-4173