本文整理汇总了Java中org.apache.flink.table.api.java.BatchTableEnvironment.fromDataSet方法的典型用法代码示例。如果您正苦于以下问题:Java BatchTableEnvironment.fromDataSet方法的具体用法?Java BatchTableEnvironment.fromDataSet怎么用?Java BatchTableEnvironment.fromDataSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.table.api.java.BatchTableEnvironment
的用法示例。
在下文中一共展示了BatchTableEnvironment.fromDataSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUserDefinedScalarFunction
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testUserDefinedScalarFunction() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
tableEnv.registerFunction("hashCode", new OldHashCode());
tableEnv.registerFunction("hashCode", new HashCode());
DataSource<String> input = env.fromElements("a", "b", "c");
Table table = tableEnv.fromDataSet(input, "text");
Table result = table.select("text.hashCode()");
DataSet<Integer> ds = tableEnv.toDataSet(result, Integer.class);
List<Integer> results = ds.collect();
String expected = "97\n98\n99";
compareResultAsText(results, expected);
}
示例2: testSimpleSelectRenameAll
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testSimpleSelectRenameAll() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
Table in = tableEnv.fromDataSet(ds);
Table result = in
.select("f0 as a, f1 as b, f2 as c")
.select("a, b");
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String 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";
compareResultAsText(results, expected);
}
示例3: testAsFromTupleByName
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testAsFromTupleByName() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
Table table = tableEnv.fromDataSet(CollectionDataSets.get3TupleDataSet(env), "f2");
DataSet<Row> ds = tableEnv.toDataSet(table, Row.class);
List<Row> results = ds.collect();
String expected = "Hi\n" + "Hello\n" + "Hello world\n" +
"Hello world, how are you?\n" + "I am fine.\n" + "Luke Skywalker\n" +
"Comment#1\n" + "Comment#2\n" + "Comment#3\n" + "Comment#4\n" +
"Comment#5\n" + "Comment#6\n" + "Comment#7\n" +
"Comment#8\n" + "Comment#9\n" + "Comment#10\n" +
"Comment#11\n" + "Comment#12\n" + "Comment#13\n" +
"Comment#14\n" + "Comment#15\n";
compareResultAsText(results, expected);
}
示例4: testGroupNoAggregation
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testGroupNoAggregation() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> input = CollectionDataSets.get3TupleDataSet(env);
Table table = tableEnv.fromDataSet(input, "a, b, c");
Table result = table
.groupBy("b").select("a.sum as d, b").groupBy("b, d").select("b");
DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
String expected = "1\n" + "2\n" + "3\n" + "4\n" + "5\n" + "6\n";
List<Row> results = ds.collect();
compareResultAsText(results, expected);
}
示例5: testSimpleSelectWithNaming
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testSimpleSelectWithNaming() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
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);
List<Row> results = resultSet.collect();
String 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";
compareResultAsText(results, expected);
}
示例6: testDistinct
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testDistinct() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> input = CollectionDataSets.get3TupleDataSet(env);
Table table = tableEnv.fromDataSet(input, "a, b, c");
Table distinct = table.select("b").distinct();
DataSet<Row> ds = tableEnv.toDataSet(distinct, Row.class);
List<Row> results = ds.collect();
String expected = "1\n" + "2\n" + "3\n"+ "4\n"+ "5\n"+ "6\n";
compareResultAsText(results, expected);
}
示例7: testDisjunctivePreds
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testDisjunctivePreds() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> input = CollectionDataSets.get3TupleDataSet(env);
Table table = tableEnv.fromDataSet(input, "a, b, c");
Table result = table
.filter("a < 2 || a > 20");
DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
List<Row> results = ds.collect();
String expected = "1,1,Hi\n" + "21,6,Comment#15\n";
compareResultAsText(results, expected);
}
示例8: testGroupedAggregate
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testGroupedAggregate() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> input = CollectionDataSets.get3TupleDataSet(env);
Table table = tableEnv.fromDataSet(input, "a, b, c");
Table result = table
.groupBy("b").select("b, a.sum");
DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
List<Row> results = ds.collect();
String expected = "1,1\n" + "2,5\n" + "3,15\n" + "4,34\n" + "5,65\n" + "6,111\n";
compareResultAsText(results, expected);
}
示例9: testDistinctAfterAggregate
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testDistinctAfterAggregate() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple5<Integer, Long, Integer, String, Long>> input = CollectionDataSets.get5TupleDataSet(env);
Table table = tableEnv.fromDataSet(input, "a, b, c, d, e");
Table distinct = table.groupBy("a, e").select("e").distinct();
DataSet<Row> ds = tableEnv.toDataSet(distinct, Row.class);
List<Row> results = ds.collect();
String expected = "1\n" + "2\n" + "3\n";
compareResultAsText(results, expected);
}
示例10: testJoinWithExtended
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testJoinWithExtended() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
DataSet<Tuple2<Integer, String>> input1 = env.fromElements(new Tuple2<>(1,"d"));
DataSet<Tuple2<Integer, String>> input2 = env.fromElements(new Tuple2<>(1,"d"));
Table table1 = tableEnv.fromDataSet(input1, "a, b");
Table table2 = tableEnv.fromDataSet(input2, "c, d");
Table table = table1
.join(table2)
.where("b = d")
.select("a, c");
String result = tableEnv.explain(table, true).replaceAll("\\r\\n", "\n");
try (Scanner scanner = new Scanner(new File(testFilePath +
"../../src/test/scala/resources/testJoin1.out"))){
String source = scanner.useDelimiter("\\A").next().replaceAll("\\r\\n", "\n");
assertEquals(source, result);
}
}
示例11: testJoinWithNonMatchingKeyTypes
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test(expected = ValidationException.class)
public void testJoinWithNonMatchingKeyTypes() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
Table in1 = tableEnv.fromDataSet(ds1, "a, b, c");
Table in2 = tableEnv.fromDataSet(ds2, "d, e, f, g, h");
Table result = in1.join(in2)
// Must fail. Types of join fields are not compatible (Integer and String)
.where("a === g").select("c, g");
tableEnv.toDataSet(result, Row.class).collect();
}
示例12: testUnionWithExtended
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testUnionWithExtended() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
DataSet<Tuple2<Integer, String>> input1 = env.fromElements(new Tuple2<>(1,"d"));
DataSet<Tuple2<Integer, String>> input2 = env.fromElements(new Tuple2<>(1,"d"));
Table table1 = tableEnv.fromDataSet(input1, "count, word");
Table table2 = tableEnv.fromDataSet(input2, "count, word");
Table table = table1.unionAll(table2);
String result = tableEnv.explain(table, true).replaceAll("\\r\\n", "\n");
try (Scanner scanner = new Scanner(new File(testFilePath +
"../../src/test/scala/resources/testUnion1.out"))){
String source = scanner.useDelimiter("\\A").next().replaceAll("\\r\\n", "\n");
assertEquals(source, result);
}
}
示例13: testSelectFromTable
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testSelectFromTable() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
Table in = tableEnv.fromDataSet(ds, "a,b,c");
tableEnv.registerTable("T", in);
String sqlQuery = "SELECT a, c FROM T";
Table result = tableEnv.sql(sqlQuery);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "1,Hi\n" + "2,Hello\n" + "3,Hello world\n" +
"4,Hello world, how are you?\n" + "5,I am fine.\n" + "6,Luke Skywalker\n" +
"7,Comment#1\n" + "8,Comment#2\n" + "9,Comment#3\n" + "10,Comment#4\n" +
"11,Comment#5\n" + "12,Comment#6\n" + "13,Comment#7\n" +
"14,Comment#8\n" + "15,Comment#9\n" + "16,Comment#10\n" +
"17,Comment#11\n" + "18,Comment#12\n" + "19,Comment#13\n" +
"20,Comment#14\n" + "21,Comment#15\n";
compareResultAsText(results, expected);
}
示例14: testJoin
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testJoin() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
Table in1 = tableEnv.fromDataSet(ds1, "a, b, c");
Table in2 = tableEnv.fromDataSet(ds2, "d, e, f, g, h");
Table result = in1.join(in2).where("b === e").select("c, g");
DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
List<Row> results = ds.collect();
String expected = "Hi,Hallo\n" + "Hello,Hallo Welt\n" + "Hello world,Hallo Welt\n";
compareResultAsText(results, expected);
}
示例15: testGenericRowWithAlias
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test(expected = TableException.class)
public void testGenericRowWithAlias() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
// use null value the enforce GenericType
DataSet<Row> dataSet = env.fromElements(Row.of((Integer) null));
assertTrue(dataSet.getType() instanceof GenericTypeInfo);
assertTrue(dataSet.getType().getTypeClass().equals(Row.class));
// Must fail. Cannot import DataSet<Row> with GenericTypeInfo.
tableEnv.fromDataSet(dataSet, "nullField");
}