Ejemplo n.º 1
0
  @Test(expected = ExpressionException.class)
  public void testNonWorkingSubstring2() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    TableEnvironment tableEnv = new TableEnvironment();

    DataSet<Tuple2<String, String>> ds =
        env.fromElements(new Tuple2<>("ABCD", "a"), new Tuple2<>("ABCD", "b"));

    Table in = tableEnv.fromDataSet(ds, "a, b");

    Table result = in.select("a.substring(b, 15)");

    DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
    List<Row> results = resultSet.collect();
    String expected = "";
    compareResultAsText(results, expected);
  }
Ejemplo n.º 2
0
  @Test
  public void testSubstringWithMaxEnd() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    TableEnvironment tableEnv = new TableEnvironment();

    DataSet<Tuple2<String, Integer>> ds =
        env.fromElements(new Tuple2<>("ABCD", 2), new Tuple2<>("ABCD", 1));

    Table in = tableEnv.fromDataSet(ds, "a, b");

    Table result = in.select("a.substring(b)");

    DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
    List<Row> results = resultSet.collect();
    String expected = "CD\nBCD";
    compareResultAsText(results, expected);
  }
Ejemplo n.º 3
0
  @Test
  public void testSimpleSelectAllWithAs() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    TableEnvironment tableEnv = new TableEnvironment();

    DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);

    Table in = tableEnv.fromDataSet(ds, "a,b,c");

    Table result = in.select("a, b, c");

    DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
    resultSet.writeAsText(resultPath, FileSystem.WriteMode.OVERWRITE);

    env.execute();

    expected =
        "1,1,Hi\n"
            + "2,2,Hello\n"
            + "3,2,Hello world\n"
            + "4,3,Hello world, "
            + "how are you?\n"
            + "5,3,I am fine.\n"
            + "6,3,Luke Skywalker\n"
            + "7,4,"
            + "Comment#1\n"
            + "8,4,Comment#2\n"
            + "9,4,Comment#3\n"
            + "10,4,Comment#4\n"
            + "11,5,"
            + "Comment#5\n"
            + "12,5,Comment#6\n"
            + "13,5,Comment#7\n"
            + "14,5,Comment#8\n"
            + "15,5,"
            + "Comment#9\n"
            + "16,6,Comment#10\n"
            + "17,6,Comment#11\n"
            + "18,6,Comment#12\n"
            + "19,"
            + "6,Comment#13\n"
            + "20,6,Comment#14\n"
            + "21,6,Comment#15\n";
  }
Ejemplo n.º 4
0
  @Test
  public void testSimpleSelectWithNaming() throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    TableEnvironment tableEnv = new TableEnvironment();

    DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);

    Table in = tableEnv.fromDataSet(ds);

    Table result = in.select("f0 as a, f1 as b").select("a, b");

    DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
    resultSet.writeAsText(resultPath, FileSystem.WriteMode.OVERWRITE);

    env.execute();

    expected =
        "1,1\n" + "2,2\n" + "3,2\n" + "4,3\n" + "5,3\n" + "6,3\n" + "7,4\n" + "8,4\n" + "9,4\n"
            + "10,4\n" + "11,5\n" + "12,5\n" + "13,5\n" + "14,5\n" + "15,5\n" + "16,6\n" + "17,6\n"
            + "18,6\n" + "19,6\n" + "20,6\n" + "21,6\n";
  }