You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "zhuwenzhuang (via GitHub)" <gi...@apache.org> on 2023/08/30 13:12:04 UTC

[GitHub] [calcite] zhuwenzhuang opened a new pull request, #3404: [CALCITE-5968] Provide an interface class for RexExecutable to decouple janino runtime binding

zhuwenzhuang opened a new pull request, #3404:
URL: https://github.com/apache/calcite/pull/3404

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] LakeShen commented on a diff in pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "LakeShen (via GitHub)" <gi...@apache.org>.
LakeShen commented on code in PR #3404:
URL: https://github.com/apache/calcite/pull/3404#discussion_r1318408293


##########
core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java:
##########
@@ -378,4 +383,140 @@ public void run() {
   interface Action {
     void check(RexBuilder rexBuilder, RexExecutorImpl executor);
   }
+
+  /**
+   * ArrayList-based DataContext to check Rex execution.
+   */
+  public static class TestDataContext extends SingleValueDataContext {
+    private TestDataContext(Object[] values) {
+      super("inputRecord", values);
+    }
+  }
+
+  /**
+   * Context that holds a value for a particular context name.
+   */
+  static class SingleValueDataContext implements DataContext {
+    private final String name;
+    private final Object value;
+
+    SingleValueDataContext(String name, Object value) {
+      this.name = name;
+      this.value = value;
+    }
+
+    public SchemaPlus getRootSchema() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public JavaTypeFactory getTypeFactory() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public QueryProvider getQueryProvider() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public Object get(String name) {
+      if (this.name.equals(name)) {
+        return value;
+      } else {
+        throw new RuntimeException("Wrong DataContext access");
+      }
+    }
+  }
+
+  /**
+   * User defined executable.
+   */
+  static class UserExecutable implements RexExecutable {
+    final RexBuilder rexBuilder;
+    final List<RexNode> exps;
+    DataContext dataContext;
+    UserExecutable(final RexBuilder rexBuilder, final List<RexNode> exps) {
+      assert exps != null && exps.size() == 1;
+      this.rexBuilder = rexBuilder;
+      this.exps = exps;
+    }
+    @Override public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
+        List<RexNode> reducedValues) {
+      Object[] values;
+      try {
+        values = execute();
+        assert values.length == constExps.size();
+        final List<Object> valueList = Arrays.asList(values);
+        for (Pair<RexNode, Object> value : Pair.zip(constExps, valueList)) {
+          reducedValues.add(
+              rexBuilder.makeLiteral(value.right, value.left.getType(), true));
+        }
+      } catch (RuntimeException e) {
+        // One or more of the expressions failed.
+        // Don't reduce any of the expressions.
+        reducedValues.addAll(constExps);
+      }
+    }
+    @Override public void setDataContext(DataContext dataContext) {
+      this.dataContext = dataContext;
+    }
+    @Override public Object[] execute() {
+      final RexNode exp = exps.get(0);
+      assert exp instanceof RexCall;
+      RexCall call = (RexCall) exp;
+      // NOTE: this isn't a correct substring function implementation, only for testing
+      if (!call.op.getName().equals("SUBSTRING")) {
+        throw new RuntimeException("not supported");
+      }
+      assert call.getOperands().get(0) instanceof RexInputRef;
+      assert call.getOperands().get(1) instanceof RexLiteral;
+      String str = (String) ((Object[]) dataContext.get("inputRecord"))[0];
+      Integer startIndex = ((RexLiteral) call.getOperands().get(1)).getValueAs(Integer.class);
+      Object[] values = new Object[1];
+      values[0] = str.substring(startIndex - 1);
+      return values;
+    }
+  }
+  /**
+   * User defined executor.
+   */
+  static class UserExecutor implements RexExecutor {
+    @Override public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
+        List<RexNode> reducedValues) {
+      this.getExecutable(rexBuilder, constExps, null).reduce(rexBuilder, constExps, reducedValues);
+    }
+    @Override public RexExecutable getExecutable(RexBuilder rexBuilder, List<RexNode> exps,
+        RelDataType rowType) {
+      return new UserExecutable(rexBuilder, exps);
+    }
+  }
+  @Test public void userExecutorTest() throws Exception {
+    check((rexBuilder, executor) -> {
+      Object[] values = new Object[1];
+      final DataContext testContext = new TestDataContext(values);
+      final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory();
+      final RelDataType varchar =
+          typeFactory.createSqlType(SqlTypeName.VARCHAR);
+      final RelDataType integer =
+          typeFactory.createSqlType(SqlTypeName.INTEGER);
+      // Calcite is internally creating the input ref via a RexRangeRef
+      // which eventually leads to a RexInputRef. So we are good.
+      final RexInputRef input = rexBuilder.makeInputRef(varchar, 0);
+      final RexNode lengthArg = rexBuilder.makeLiteral(3, integer, true);
+      final RexNode substr =
+          rexBuilder.makeCall(SqlStdOperatorTable.SUBSTRING, input,
+              lengthArg);
+      ImmutableList<RexNode> constExps = ImmutableList.of(substr);
+      final RelDataType rowType = typeFactory.builder()
+          .add("someStr", varchar)
+          .build();
+      RexExecutor useExecutor = new UserExecutor();
+      final RexExecutable exec =

Review Comment:
   Hi @zhuwenzhuang ,could you add more test cases to cover your logic? I see only SUBSTRING case is added here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] sonarcloud[bot] commented on pull request #3404: [CALCITE-5968] Provide an interface class for RexExecutable to decouple janino runtime binding

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-1699169038

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3404)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [3 Code Smells](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL)
   
   [![82.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '82.6%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list) [82.6% Coverage](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding [calcite]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-2564992410

   This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] chunweilei commented on a diff in pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "chunweilei (via GitHub)" <gi...@apache.org>.
chunweilei commented on code in PR #3404:
URL: https://github.com/apache/calcite/pull/3404#discussion_r1328415065


##########
core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java:
##########
@@ -378,4 +383,140 @@ public void run() {
   interface Action {
     void check(RexBuilder rexBuilder, RexExecutorImpl executor);
   }
+
+  /**
+   * ArrayList-based DataContext to check Rex execution.
+   */
+  public static class TestDataContext extends SingleValueDataContext {
+    private TestDataContext(Object[] values) {
+      super("inputRecord", values);
+    }
+  }
+
+  /**
+   * Context that holds a value for a particular context name.
+   */
+  static class SingleValueDataContext implements DataContext {
+    private final String name;
+    private final Object value;
+
+    SingleValueDataContext(String name, Object value) {
+      this.name = name;
+      this.value = value;
+    }
+
+    public SchemaPlus getRootSchema() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public JavaTypeFactory getTypeFactory() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public QueryProvider getQueryProvider() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public Object get(String name) {
+      if (this.name.equals(name)) {
+        return value;
+      } else {
+        throw new RuntimeException("Wrong DataContext access");
+      }
+    }
+  }
+
+  /**
+   * User defined executable.
+   */
+  static class UserExecutable implements RexExecutable {
+    final RexBuilder rexBuilder;
+    final List<RexNode> exps;
+    DataContext dataContext;
+    UserExecutable(final RexBuilder rexBuilder, final List<RexNode> exps) {
+      assert exps != null && exps.size() == 1;
+      this.rexBuilder = rexBuilder;
+      this.exps = exps;
+    }
+    @Override public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
+        List<RexNode> reducedValues) {
+      Object[] values;
+      try {
+        values = execute();
+        assert values.length == constExps.size();
+        final List<Object> valueList = Arrays.asList(values);
+        for (Pair<RexNode, Object> value : Pair.zip(constExps, valueList)) {
+          reducedValues.add(
+              rexBuilder.makeLiteral(value.right, value.left.getType(), true));
+        }
+      } catch (RuntimeException e) {
+        // One or more of the expressions failed.
+        // Don't reduce any of the expressions.
+        reducedValues.addAll(constExps);
+      }

Review Comment:
   I think we should call reducedValues.clear before reducedValues.addAll according to your comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] sonarcloud[bot] commented on pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-1723254669

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3404)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [3 Code Smells](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL)
   
   [![83.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '83.0%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list) [83.0% Coverage](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding [calcite]

Posted by "zhuwenzhuang (via GitHub)" <gi...@apache.org>.
zhuwenzhuang commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-1754674152

   Can someone please help review this PR? Thank you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] chunweilei commented on a diff in pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "chunweilei (via GitHub)" <gi...@apache.org>.
chunweilei commented on code in PR #3404:
URL: https://github.com/apache/calcite/pull/3404#discussion_r1328411668


##########
core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java:
##########
@@ -378,4 +383,140 @@ public void run() {
   interface Action {
     void check(RexBuilder rexBuilder, RexExecutorImpl executor);
   }
+
+  /**
+   * ArrayList-based DataContext to check Rex execution.
+   */
+  public static class TestDataContext extends SingleValueDataContext {
+    private TestDataContext(Object[] values) {
+      super("inputRecord", values);
+    }
+  }
+
+  /**
+   * Context that holds a value for a particular context name.
+   */
+  static class SingleValueDataContext implements DataContext {
+    private final String name;
+    private final Object value;
+
+    SingleValueDataContext(String name, Object value) {
+      this.name = name;
+      this.value = value;
+    }
+
+    public SchemaPlus getRootSchema() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public JavaTypeFactory getTypeFactory() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public QueryProvider getQueryProvider() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public Object get(String name) {
+      if (this.name.equals(name)) {
+        return value;
+      } else {
+        throw new RuntimeException("Wrong DataContext access");
+      }
+    }
+  }
+
+  /**
+   * User defined executable.
+   */
+  static class UserExecutable implements RexExecutable {
+    final RexBuilder rexBuilder;
+    final List<RexNode> exps;
+    DataContext dataContext;
+    UserExecutable(final RexBuilder rexBuilder, final List<RexNode> exps) {

Review Comment:
    DataContext dataContext -> final  DataContext dataContext ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] sonarcloud[bot] commented on pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-1709544266

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3404)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [3 Code Smells](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL)
   
   [![83.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '83.0%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list) [83.0% Coverage](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] sonarcloud[bot] commented on pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-1702386795

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3404)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [3 Code Smells](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL)
   
   [![83.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '83.0%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list) [83.0% Coverage](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] zhuwenzhuang commented on a diff in pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "zhuwenzhuang (via GitHub)" <gi...@apache.org>.
zhuwenzhuang commented on code in PR #3404:
URL: https://github.com/apache/calcite/pull/3404#discussion_r1328591724


##########
core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java:
##########
@@ -378,4 +383,140 @@ public void run() {
   interface Action {
     void check(RexBuilder rexBuilder, RexExecutorImpl executor);
   }
+
+  /**
+   * ArrayList-based DataContext to check Rex execution.
+   */
+  public static class TestDataContext extends SingleValueDataContext {
+    private TestDataContext(Object[] values) {
+      super("inputRecord", values);
+    }
+  }
+
+  /**
+   * Context that holds a value for a particular context name.
+   */
+  static class SingleValueDataContext implements DataContext {
+    private final String name;
+    private final Object value;
+
+    SingleValueDataContext(String name, Object value) {
+      this.name = name;
+      this.value = value;
+    }
+
+    public SchemaPlus getRootSchema() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public JavaTypeFactory getTypeFactory() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public QueryProvider getQueryProvider() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public Object get(String name) {
+      if (this.name.equals(name)) {
+        return value;
+      } else {
+        throw new RuntimeException("Wrong DataContext access");
+      }
+    }
+  }
+
+  /**
+   * User defined executable.
+   */
+  static class UserExecutable implements RexExecutable {
+    final RexBuilder rexBuilder;
+    final List<RexNode> exps;
+    DataContext dataContext;
+    UserExecutable(final RexBuilder rexBuilder, final List<RexNode> exps) {

Review Comment:
   setDataContext will change the dataContext



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] chunweilei commented on a diff in pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "chunweilei (via GitHub)" <gi...@apache.org>.
chunweilei commented on code in PR #3404:
URL: https://github.com/apache/calcite/pull/3404#discussion_r1328413055


##########
core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java:
##########
@@ -378,4 +383,140 @@ public void run() {
   interface Action {
     void check(RexBuilder rexBuilder, RexExecutorImpl executor);
   }
+
+  /**
+   * ArrayList-based DataContext to check Rex execution.
+   */
+  public static class TestDataContext extends SingleValueDataContext {
+    private TestDataContext(Object[] values) {
+      super("inputRecord", values);
+    }
+  }
+
+  /**
+   * Context that holds a value for a particular context name.
+   */
+  static class SingleValueDataContext implements DataContext {
+    private final String name;
+    private final Object value;
+
+    SingleValueDataContext(String name, Object value) {
+      this.name = name;
+      this.value = value;
+    }
+
+    public SchemaPlus getRootSchema() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public JavaTypeFactory getTypeFactory() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public QueryProvider getQueryProvider() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public Object get(String name) {
+      if (this.name.equals(name)) {
+        return value;
+      } else {
+        throw new RuntimeException("Wrong DataContext access");
+      }
+    }
+  }
+
+  /**
+   * User defined executable.
+   */
+  static class UserExecutable implements RexExecutable {
+    final RexBuilder rexBuilder;
+    final List<RexNode> exps;

Review Comment:
   UserExecutable -> UserRedefinedRexExecutableImpl? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] sonarcloud[bot] commented on pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-1723284653

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3404)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [3 Code Smells](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL)
   
   [![83.3%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '83.3%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list) [83.3% Coverage](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding [calcite]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-2739046779

   This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding [calcite]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-3894770438

   This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] zhuwenzhuang commented on a diff in pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "zhuwenzhuang (via GitHub)" <gi...@apache.org>.
zhuwenzhuang commented on code in PR #3404:
URL: https://github.com/apache/calcite/pull/3404#discussion_r1322281984


##########
core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java:
##########
@@ -378,4 +383,140 @@ public void run() {
   interface Action {
     void check(RexBuilder rexBuilder, RexExecutorImpl executor);
   }
+
+  /**
+   * ArrayList-based DataContext to check Rex execution.
+   */
+  public static class TestDataContext extends SingleValueDataContext {
+    private TestDataContext(Object[] values) {
+      super("inputRecord", values);
+    }
+  }
+
+  /**
+   * Context that holds a value for a particular context name.
+   */
+  static class SingleValueDataContext implements DataContext {
+    private final String name;
+    private final Object value;
+
+    SingleValueDataContext(String name, Object value) {
+      this.name = name;
+      this.value = value;
+    }
+
+    public SchemaPlus getRootSchema() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public JavaTypeFactory getTypeFactory() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public QueryProvider getQueryProvider() {
+      throw new RuntimeException("Unsupported");
+    }
+
+    public Object get(String name) {
+      if (this.name.equals(name)) {
+        return value;
+      } else {
+        throw new RuntimeException("Wrong DataContext access");
+      }
+    }
+  }
+
+  /**
+   * User defined executable.
+   */
+  static class UserExecutable implements RexExecutable {
+    final RexBuilder rexBuilder;
+    final List<RexNode> exps;
+    DataContext dataContext;
+    UserExecutable(final RexBuilder rexBuilder, final List<RexNode> exps) {
+      assert exps != null && exps.size() == 1;
+      this.rexBuilder = rexBuilder;
+      this.exps = exps;
+    }
+    @Override public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
+        List<RexNode> reducedValues) {
+      Object[] values;
+      try {
+        values = execute();
+        assert values.length == constExps.size();
+        final List<Object> valueList = Arrays.asList(values);
+        for (Pair<RexNode, Object> value : Pair.zip(constExps, valueList)) {
+          reducedValues.add(
+              rexBuilder.makeLiteral(value.right, value.left.getType(), true));
+        }
+      } catch (RuntimeException e) {
+        // One or more of the expressions failed.
+        // Don't reduce any of the expressions.
+        reducedValues.addAll(constExps);
+      }
+    }
+    @Override public void setDataContext(DataContext dataContext) {
+      this.dataContext = dataContext;
+    }
+    @Override public Object[] execute() {
+      final RexNode exp = exps.get(0);
+      assert exp instanceof RexCall;
+      RexCall call = (RexCall) exp;
+      // NOTE: this isn't a correct substring function implementation, only for testing
+      if (!call.op.getName().equals("SUBSTRING")) {
+        throw new RuntimeException("not supported");
+      }
+      assert call.getOperands().get(0) instanceof RexInputRef;
+      assert call.getOperands().get(1) instanceof RexLiteral;
+      String str = (String) ((Object[]) dataContext.get("inputRecord"))[0];
+      Integer startIndex = ((RexLiteral) call.getOperands().get(1)).getValueAs(Integer.class);
+      Object[] values = new Object[1];
+      values[0] = str.substring(startIndex - 1);
+      return values;
+    }
+  }
+  /**
+   * User defined executor.
+   */
+  static class UserExecutor implements RexExecutor {
+    @Override public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
+        List<RexNode> reducedValues) {
+      this.getExecutable(rexBuilder, constExps, null).reduce(rexBuilder, constExps, reducedValues);
+    }
+    @Override public RexExecutable getExecutable(RexBuilder rexBuilder, List<RexNode> exps,
+        RelDataType rowType) {
+      return new UserExecutable(rexBuilder, exps);
+    }
+  }
+  @Test public void userExecutorTest() throws Exception {
+    check((rexBuilder, executor) -> {
+      Object[] values = new Object[1];
+      final DataContext testContext = new TestDataContext(values);
+      final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory();
+      final RelDataType varchar =
+          typeFactory.createSqlType(SqlTypeName.VARCHAR);
+      final RelDataType integer =
+          typeFactory.createSqlType(SqlTypeName.INTEGER);
+      // Calcite is internally creating the input ref via a RexRangeRef
+      // which eventually leads to a RexInputRef. So we are good.
+      final RexInputRef input = rexBuilder.makeInputRef(varchar, 0);
+      final RexNode lengthArg = rexBuilder.makeLiteral(3, integer, true);
+      final RexNode substr =
+          rexBuilder.makeCall(SqlStdOperatorTable.SUBSTRING, input,
+              lengthArg);
+      ImmutableList<RexNode> constExps = ImmutableList.of(substr);
+      final RelDataType rowType = typeFactory.builder()
+          .add("someStr", varchar)
+          .build();
+      RexExecutor useExecutor = new UserExecutor();
+      final RexExecutable exec =

Review Comment:
   Hi @LakeShen. 
   The userExecutorTest covered a user-defined RexExecutable/RexExecutor scenario. So, maybe adding more mock functions will not increase the code coverage.
   Please let me know which part of code requires additional coverage with test cases. Thank you.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] sonarcloud[bot] commented on pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-1723286430

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3404)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [3 Code Smells](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL)
   
   [![83.3%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '83.3%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list) [83.3% Coverage](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] chunweilei commented on a diff in pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "chunweilei (via GitHub)" <gi...@apache.org>.
chunweilei commented on code in PR #3404:
URL: https://github.com/apache/calcite/pull/3404#discussion_r1328410380


##########
core/src/main/java/org/apache/calcite/rex/RexExecutable.java:
##########
@@ -17,100 +17,38 @@
 package org.apache.calcite.rex;
 
 import org.apache.calcite.DataContext;
-import org.apache.calcite.linq4j.function.Function1;
-import org.apache.calcite.runtime.Hook;
-import org.apache.calcite.runtime.Utilities;
-import org.apache.calcite.util.Pair;
 
 import org.checkerframework.checker.nullness.qual.Nullable;
-import org.codehaus.commons.compiler.CompileException;
-import org.codehaus.janino.ClassBodyEvaluator;
-import org.codehaus.janino.Scanner;
 
-import java.io.IOException;
-import java.io.Serializable;
-import java.io.StringReader;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Arrays;
 import java.util.List;
 
-import static java.util.Objects.requireNonNull;
-
 /**
- * Result of compiling code generated from a {@link RexNode} expression.
+ * Executable interface for a {@link RexNode} expression.
  */
-public class RexExecutable {
-  private static final String GENERATED_CLASS_NAME = "Reducer";
-
-  private final Function1<DataContext, @Nullable Object @Nullable []> compiledFunction;
-  private final String code;
-  private @Nullable DataContext dataContext;
-
-  public RexExecutable(String code, Object reason) {
-    this.code = code;
-    this.compiledFunction = compile(code, reason);
-  }
-
-  private static Function1<DataContext, @Nullable Object @Nullable []> compile(String code,
-      Object reason) {
-    try {
-      final ClassBodyEvaluator cbe = new ClassBodyEvaluator();
-      cbe.setClassName(GENERATED_CLASS_NAME);
-      cbe.setExtendedClass(Utilities.class);
-      cbe.setImplementedInterfaces(new Class[] {Function1.class, Serializable.class});
-      cbe.setParentClassLoader(RexExecutable.class.getClassLoader());
-      cbe.cook(new Scanner(null, new StringReader(code)));
-      Class c = cbe.getClazz();
-      //noinspection unchecked
-      final Constructor<Function1<DataContext, @Nullable Object @Nullable []>> constructor =
-          c.getConstructor();
-      return constructor.newInstance();
-    } catch (CompileException | IOException | InstantiationException
-        | IllegalAccessException | InvocationTargetException
-        | NoSuchMethodException e) {
-      throw new RuntimeException("While compiling " + reason, e);
-    }
-  }
-
-  public void setDataContext(DataContext dataContext) {
-    this.dataContext = dataContext;
-  }
-
-  public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
-      List<RexNode> reducedValues) {
-    @Nullable Object[] values;
-    try {
-      values = execute();
-      if (values == null) {
-        reducedValues.addAll(constExps);
-        values = new Object[constExps.size()];
-      } else {
-        assert values.length == constExps.size();
-        final List<@Nullable Object> valueList = Arrays.asList(values);
-        for (Pair<RexNode, @Nullable Object> value : Pair.zip(constExps, valueList)) {
-          reducedValues.add(
-              rexBuilder.makeLiteral(value.right, value.left.getType(), true));
-        }
-      }
-    } catch (RuntimeException e) {
-      // One or more of the expressions failed.
-      // Don't reduce any of the expressions.
-      reducedValues.addAll(constExps);
-      values = new Object[constExps.size()];
-    }
-    Hook.EXPRESSION_REDUCER.run(Pair.of(code, values));
-  }
-
-  public Function1<DataContext, @Nullable Object @Nullable []> getFunction() {
-    return compiledFunction;
-  }
-
-  public @Nullable Object @Nullable [] execute() {
-    return compiledFunction.apply(requireNonNull(dataContext, "dataContext"));
-  }
+public interface RexExecutable {
+
+  /** Reduces expressions, and writes their results into {@code reducedValues}.
+   *
+   * <p>If an expression cannot be reduced, writes the original expression.
+   * For example, {@code CAST('abc' AS INTEGER)} gives an error when executed, so the executor
+   * ignores the error and writes the original expression.
+   *
+   * @param rexBuilder Rex builder

Review Comment:
   Some functions are deleted, which may cause compatibility issues in the downstream project.  But I think it is accepted if the change is positive.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [calcite] sonarcloud[bot] commented on pull request #3404: [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-1702365799

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=3404)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=3404&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL) [3 Code Smells](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=3404&resolved=false&types=CODE_SMELL)
   
   [![83.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '83.0%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list) [83.0% Coverage](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=3404&metric=new_duplicated_lines_density&view=list)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CALCITE-5968] Provide an interface for RexExecutable to decouple janino runtime binding [calcite]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3404:
URL: https://github.com/apache/calcite/pull/3404#issuecomment-3447985115

   This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org