I convert the Java to a standalone class with a “main” method and run it in a debugger. In my experience, bugs in Janino are extremely rare so I just assume it works.
> On Feb 21, 2026, at 8:38 AM, Yang Zhou <[email protected]> wrote: > > > > 我漏掉中文,英文不太好, 避免机翻出现误差,我把中文也带上 > 大家好, 我正在阅读 Calicte 示例/csv 模块中的 CsvFilterableTable.java 代码。我编写了测试代码来验证 SQL 语句 > `SELECT * FROM orders WHERE id > 2` 的处理情况。 它的执行计划如下: > ```bash > EnumerableInterpreter BindableTableScan(table=[[orders]], > filters=[[>(CAST($0):INTEGER NOT NULL, 2)]]) > ``` > > > 因为在 CsvEnumerator#moveNext() 读取数据时没有过滤掉 id > 2 的条件,后来我了解到 > `CsvFilterableTable#addFilter()` 并不会移除不符合条件的过滤器,所以这些过滤器仍然会被 > TableScanNode#createFilterable() 处理。由于我之前没有使用过 Janino,所以在阅读以下代码时遇到了问题: > ``java > final Scalar condition = compiler.compile(ImmutableList.of(filter2), > inputRowType); > final Context context = compiler.createContext(); > enumerable = enumerable.where(row -> { context.values = row.getValues(); > Boolean b = (Boolean) condition.execute(context); return b != null && b; }); > > ``` > > > 我在 IDEA 中添加了 Janino 调试配置,如下所示: > ```bash > -Dorg.codehaus.janino.source_debugging.enable=true > -Dorg.codehaus.janino.source_debugging.dir=/opt/code/java/calcite-all/1.37/example/csv/generated/janino-debug > ``` > 我看到了 Janino 生成的代码文件,但生成的代码只包含方法。当我手动创建类文件,将方法粘贴到其中并进行调试时,我发现行号错位了。 > ```java > public org.apache.calcite.interpreter.Scalar apply(final > org.apache.calcite.DataContext root) { > return new org.apache.calcite.interpreter.Scalar(){ > public void execute(org.apache.calcite.interpreter.Context context, > Object[] outputValues) { > final Object[] current = context.values; > final String input_value = current[0] == null ? null : > current[0].toString(); > outputValues[0] = (input_value == null ? 0 : > org.apache.calcite.runtime.SqlFunctions.toInt(input_value)) > 2; > } > > public Object execute(org.apache.calcite.interpreter.Context context) { > final Object[] values = new Object[1]; > this.execute(context, values); > return values[0]; > } > > }; > } > > > public Object apply(Object root) { > return this.apply((org.apache.calcite.DataContext) root); > } > ``` > 我不知道如何调试上面生成的函数代码。 感谢您的回复。 > > > > > At 2026-02-22 00:29:09, "Yang Zhou" <[email protected]> wrote: >> Hi friends, >> >> I'm reading the CsvFilterableTable.java code in the Calicte example/csv >> module. I wrote test code to verify the processing of the SQL `SELECT * FROM >> orders WHERE id > 2`. >> >> Its execution plan is as follows: >> >> ``bash >> EnumerableInterpreter >> BindableTableScan(table=[[orders]], filters=[[>(CAST($0):INTEGER NOT NULL, >> 2)]]) >> ``` >> >> Because id > 2 was not filtered while reading by CsvEnumerator#moveNext(), I >> later learned that `CsvFilterableTable#addFilter()` does not remove filters >> that do not meet the criteria, so the filters are still processed by >> TableScanNode#createFilterable(). Since I haven't used Janino before, I >> encountered a problem while reading the following code: >> >> ``java >> final Scalar condition = >> compiler.compile(ImmutableList.of(filter2), inputRowType); >> final Context context = compiler.createContext(); >> enumerable = enumerable.where(row -> { >> context.values = row.getValues(); >> Boolean b = (Boolean) condition.execute(context); >> return b != null && b; >> }); >> ``` >> >> I added the janino debug configuration in IDEA as follows: >> >> ```bash >> -Dorg.codehaus.janino.source_debugging.enable=true >> -Dorg.codehaus.janino.source_debugging.dir=/opt/code/java/calcite-all/1.37/example/csv/generated/janino-debug >> ``` >> >> I did see the code files generated by janino, but the generated code only >> contained methods. When I manually created class files, pasted the methods >> into them, and debugged, I found that the line numbers were misaligned. >> >> ```java >> public org.apache.calcite.interpreter.Scalar apply(final >> org.apache.calcite.DataContext root) { >> return new org.apache.calcite.interpreter.Scalar(){ >> public void execute(org.apache.calcite.interpreter.Context context, Object[] >> outputValues) { >> final Object[] current = context.values; >> final String input_value = current[0] == null ? null : current[0].toString(); >> outputValues[0] = (input_value == null ? 0 : >> org.apache.calcite.runtime.SqlFunctions.toInt(input_value)) > 2; >> } >> >> public Object execute(org.apache.calcite.interpreter.Context context) { >> final Object[] values = new Object[1]; >> this.execute(context, values); >> return values[0]; >> } }; >> >> } >> public Object apply(Object root) { >> >> return this.apply((org.apache.calcite.DataContext) root); >> >> } >> ``` >> >> I don't know how to debug the function code generated above. >> >> Thanks for your other replies.
