Java Code Examples for org.apache.calcite.util.Util#toLinux()

The following examples show how to use org.apache.calcite.util.Util#toLinux() . 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: SqlQueryParser.java    From quark with Apache License 2.0 5 votes vote down vote up
private Function<RelNode, Void> printer() {
  return new Function<RelNode, Void>() {
    public Void apply(RelNode relNode) {
      String s = Util.toLinux(RelOptUtil.toString(relNode));
      LOG.info(s);
      return null;
    }
  };
}
 
Example 2
Source File: OsAdapterTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
private String foo(String... args) throws SQLException {
  final ByteArrayInputStream inStream = new ByteArrayInputStream(new byte[0]);
  final InputStreamReader in =
      new InputStreamReader(inStream, StandardCharsets.UTF_8);
  final StringWriter outSw = new StringWriter();
  final PrintWriter out = new PrintWriter(outSw);
  final StringWriter errSw = new StringWriter();
  final PrintWriter err = new PrintWriter(errSw);
  new SqlShell(in, out, err, args).run();
  return Util.toLinux(outSw.toString());
}
 
Example 3
Source File: PlannerTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-569">[CALCITE-569]
 * ArrayIndexOutOfBoundsException when deducing collation</a>. */
@Test void testOrderByNonSelectColumn() throws Exception {
  final SchemaPlus schema = Frameworks.createRootSchema(true)
      .add("tpch", new ReflectiveSchema(new TpchSchema()));

  String query = "select t.psPartkey from\n"
      + "(select ps.psPartkey from `tpch`.`partsupp` ps\n"
      + "order by ps.psPartkey, ps.psSupplyCost) t\n"
      + "order by t.psPartkey";

  List<RelTraitDef> traitDefs = new ArrayList<>();
  traitDefs.add(ConventionTraitDef.INSTANCE);
  traitDefs.add(RelCollationTraitDef.INSTANCE);
  final SqlParser.Config parserConfig =
      SqlParser.configBuilder().setLex(Lex.MYSQL).build();
  FrameworkConfig config = Frameworks.newConfigBuilder()
      .parserConfig(parserConfig)
      .defaultSchema(schema)
      .traitDefs(traitDefs)
      .programs(Programs.ofRules(Programs.RULE_SET))
      .build();
  String plan;
  try (Planner p = Frameworks.getPlanner(config)) {
    SqlNode n = p.parse(query);
    n = p.validate(n);
    RelNode r = p.rel(n).project();
    plan = RelOptUtil.toString(r);
    plan = Util.toLinux(plan);
  }
  assertThat(plan,
      equalTo("LogicalSort(sort0=[$0], dir0=[ASC])\n"
      + "  LogicalProject(psPartkey=[$0])\n"
      + "    LogicalTableScan(table=[[tpch, partsupp]])\n"));
}
 
Example 4
Source File: CalciteAssert.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static Consumer<ResultSet> checkResultContains(
    final String expected, final int count) {
  return s -> {
    try {
      final String actual = Util.toLinux(toString(s));
      assertEquals(count, countMatches(actual, expected),
          () -> actual + " should have " + count + " occurrence of " + expected);
    } catch (SQLException e) {
      throw TestUtil.rethrow(e);
    }
  };
}
 
Example 5
Source File: CalciteAssert.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static Consumer<ResultSet> checkMaskedResultContains(
    final String expected) {
  return s -> {
    try {
      final String actual = Util.toLinux(toString(s));
      final String maskedActual = Matchers.trimNodeIds(actual);
      assertThat(maskedActual, containsString(expected));
    } catch (SQLException e) {
      throw TestUtil.rethrow(e);
    }
  };
}
 
Example 6
Source File: SortRemoveRuleTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
private String toString(RelNode rel) {
  return Util.toLinux(
      RelOptUtil.dumpPlan("", rel, SqlExplainFormat.TEXT,
          SqlExplainLevel.DIGEST_ATTRIBUTES));
}
 
Example 7
Source File: PlannerTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
private String toString(RelNode rel) {
  return Util.toLinux(
      RelOptUtil.dumpPlan("", rel, SqlExplainFormat.TEXT,
          SqlExplainLevel.EXPPLAN_ATTRIBUTES));
}
 
Example 8
Source File: PigRelBuilderTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Converts a relational expression to a sting with linux line-endings. */
private String str(RelNode r) {
  return Util.toLinux(RelOptUtil.toString(r));
}