Java Code Examples for org.apache.calcite.linq4j.tree.Expressions#declare()

The following examples show how to use org.apache.calcite.linq4j.tree.Expressions#declare() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveEnumerableRelImplementor.java    From marble with Apache License 2.0 6 votes vote down vote up
@Override protected Collection<Statement> buildInitialStatements() {
  List<Statement> initialStatements = new ArrayList<>();
  Type typeOfHiveUdfInstanceHolder = new Type() {
    @Override public String getTypeName() {
      return "HiveUDFInstanceHolder";
    }

    @Override public String toString() {
      return "HiveUDFInstanceHolder";
    }
  };
  DeclarationStatement hiveUdfInstanceHolder =
      Expressions.declare(Modifier.FINAL,
          Expressions.parameter(typeOfHiveUdfInstanceHolder,
              "hiveUDFInstanceHolder"),
          Expressions.new_(typeOfHiveUdfInstanceHolder));
  initialStatements.add(hiveUdfInstanceHolder);
  return initialStatements;
}
 
Example 2
Source File: InlinerTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testNoInlineMultipleUsage() {
  ParameterExpression p1 = Expressions.parameter(int.class, "p1");
  ParameterExpression p2 = Expressions.parameter(int.class, "p2");
  DeclarationStatement decl = Expressions.declare(16, "x",
      Expressions.subtract(p1, p2));
  b.add(decl);
  b.add(
      Expressions.return_(null,
          Expressions.add(decl.parameter, decl.parameter)));
  assertEquals(
      "{\n"
          + "  final int x = p1 - p2;\n"
          + "  return x + x;\n"
          + "}\n",
      b.toBlock().toString());
}
 
Example 3
Source File: InlinerTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testInlineSingleUsage() {
  DeclarationStatement decl = Expressions.declare(16, "x",
      Expressions.add(ONE, TWO));
  b.add(decl);
  b.add(Expressions.return_(null, decl.parameter));
  assertEquals("{\n  return 1 + 2;\n}\n", b.toBlock().toString());
}
 
Example 4
Source File: InlinerTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testInlineConstant() {
  DeclarationStatement decl = Expressions.declare(16, "x", ONE);
  b.add(decl);
  b.add(
      Expressions.return_(null,
          Expressions.add(decl.parameter, decl.parameter)));
  assertEquals("{\n  return 1 + 1;\n}\n", b.toBlock().toString());
}
 
Example 5
Source File: InlinerTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testInlineParameter() {
  ParameterExpression pe = Expressions.parameter(int.class, "p");
  DeclarationStatement decl = Expressions.declare(16, "x", pe);
  b.add(decl);
  b.add(
      Expressions.return_(null,
          Expressions.add(decl.parameter, decl.parameter)));
  assertEquals("{\n  return p + p;\n}\n", b.toBlock().toString());
}