本文整理汇总了Java中org.apache.flink.table.api.java.BatchTableEnvironment.toDataSet方法的典型用法代码示例。如果您正苦于以下问题:Java BatchTableEnvironment.toDataSet方法的具体用法?Java BatchTableEnvironment.toDataSet怎么用?Java BatchTableEnvironment.toDataSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.table.api.java.BatchTableEnvironment
的用法示例。
在下文中一共展示了BatchTableEnvironment.toDataSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTableSourceFullScan
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testTableSourceFullScan() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(4);
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, new TableConfig());
HBaseTableSource hbaseTable = new HBaseTableSource(getConf(), TEST_TABLE);
hbaseTable.addColumn(FAMILY1, F1COL1, Integer.class);
hbaseTable.addColumn(FAMILY2, F2COL1, String.class);
hbaseTable.addColumn(FAMILY2, F2COL2, Long.class);
hbaseTable.addColumn(FAMILY3, F3COL1, Double.class);
hbaseTable.addColumn(FAMILY3, F3COL2, Boolean.class);
hbaseTable.addColumn(FAMILY3, F3COL3, String.class);
tableEnv.registerTableSource("hTable", hbaseTable);
Table result = tableEnv.sqlQuery(
"SELECT " +
" h.family1.col1, " +
" h.family2.col1, " +
" h.family2.col2, " +
" h.family3.col1, " +
" h.family3.col2, " +
" h.family3.col3 " +
"FROM hTable AS h"
);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected =
"10,Hello-1,100,1.01,false,Welt-1\n" +
"20,Hello-2,200,2.02,true,Welt-2\n" +
"30,Hello-3,300,3.03,false,Welt-3\n" +
"40,null,400,4.04,true,Welt-4\n" +
"50,Hello-5,500,5.05,false,Welt-5\n" +
"60,Hello-6,600,6.06,true,Welt-6\n" +
"70,Hello-7,700,7.07,false,Welt-7\n" +
"80,null,800,8.08,true,Welt-8\n";
TestBaseUtils.compareResultAsText(results, expected);
}
示例2: testValues
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testValues() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
String sqlQuery = "VALUES (1, 'Test', TRUE, DATE '1944-02-24', 12.4444444444444445)," +
"(2, 'Hello', TRUE, DATE '1944-02-24', 12.666666665)," +
"(3, 'World', FALSE, DATE '1944-12-24', 12.54444445)";
Table result = tableEnv.sql(sqlQuery);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "3,World,false,1944-12-24,12.5444444500000000\n" +
"2,Hello,true,1944-02-24,12.6666666650000000\n" +
// Calcite converts to decimals and strings with equal length
"1,Test ,true,1944-02-24,12.4444444444444445\n";
compareResultAsText(results, expected);
}
示例3: testFilterFromDataSet
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testFilterFromDataSet() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
tableEnv.registerDataSet("DataSetTable", ds, "x, y, z");
String sqlQuery = "SELECT x FROM DataSetTable WHERE z LIKE '%Hello%'";
Table result = tableEnv.sql(sqlQuery);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "2\n" + "3\n" + "4";
compareResultAsText(results, expected);
}
示例4: testValues
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testValues() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
String sqlQuery = "VALUES (1, 'Test', TRUE, DATE '1944-02-24', 12.4444444444444445)," +
"(2, 'Hello', TRUE, DATE '1944-02-24', 12.666666665)," +
"(3, 'World', FALSE, DATE '1944-12-24', 12.54444445)";
Table result = tableEnv.sqlQuery(sqlQuery);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "3,World,false,1944-12-24,12.5444444500000000\n" +
"2,Hello,true,1944-02-24,12.6666666650000000\n" +
// Calcite converts to decimals and strings with equal length
"1,Test ,true,1944-02-24,12.4444444444444445\n";
compareResultAsText(results, expected);
}
示例5: testFilterFromDataSet
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testFilterFromDataSet() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
tableEnv.registerDataSet("DataSetTable", ds, "x, y, z");
String sqlQuery = "SELECT x FROM DataSetTable WHERE z LIKE '%Hello%'";
Table result = tableEnv.sqlQuery(sqlQuery);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "2\n" + "3\n" + "4";
compareResultAsText(results, expected);
}
示例6: testAsFromPojoProjected
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testAsFromPojoProjected() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
List<SmallPojo> data = new ArrayList<>();
data.add(new SmallPojo("Peter", 28, 4000.00, "Sales", new Integer[] {42}));
data.add(new SmallPojo("Anna", 56, 10000.00, "Engineering", new Integer[] {}));
data.add(new SmallPojo("Lucy", 42, 6000.00, "HR", new Integer[] {1, 2, 3}));
Table table = tableEnv
.fromDataSet(env.fromCollection(data), "name AS d")
.select("d");
DataSet<Row> ds = tableEnv.toDataSet(table, Row.class);
List<Row> results = ds.collect();
String expected =
"Peter\n" +
"Anna\n" +
"Lucy\n";
compareResultAsText(results, expected);
}
示例7: testSimpleRegister
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testSimpleRegister() throws Exception {
final String tableName = "MyTable";
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
tableEnv.registerDataSet(tableName, ds);
Table t = tableEnv.scan(tableName);
Table result = t.select("f0, f1");
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);
}
示例8: testNotEquals
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testNotEquals() 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 <> 0 ) ");
DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
List<Row> results = ds.collect();
String expected = "2,2,Hello\n" + "4,3,Hello world, how are you?\n" + "6,3,Luke Skywalker\n" + "8,4," +
"Comment#2\n" + "10,4,Comment#4\n" + "12,5,Comment#6\n" + "14,5,Comment#8\n" + "16,6," +
"Comment#10\n" + "18,6,Comment#12\n" + "20,6,Comment#14\n";
compareResultAsText(results, expected);
}
示例9: testAsFromTuple
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testAsFromTuple() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
Table table = tableEnv
.fromDataSet(CollectionDataSets.get3TupleDataSet(env), "a, b, c")
.select("a, b, c");
DataSet<Row> ds = tableEnv.toDataSet(table, Row.class);
List<Row> results = ds.collect();
String 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";
compareResultAsText(results, expected);
}
示例10: testAsFromAndToTuple
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testAsFromAndToTuple() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
Table table = tableEnv
.fromDataSet(CollectionDataSets.get3TupleDataSet(env), "a, b, c")
.select("a, b, c");
TypeInformation<?> ti = new TupleTypeInfo<Tuple3<Integer, Long, String>>(
BasicTypeInfo.INT_TYPE_INFO,
BasicTypeInfo.LONG_TYPE_INFO,
BasicTypeInfo.STRING_TYPE_INFO);
DataSet<?> ds = tableEnv.toDataSet(table, ti);
List<?> results = ds.collect();
String 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";
compareResultAsText(results, expected);
}
示例11: testAllPassingFilter
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testAllPassingFilter() 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("true");
DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
List<Row> results = ds.collect();
String 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";
compareResultAsText(results, expected);
}
示例12: 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);
}
示例13: 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);
}
示例14: testTableSourceProjection
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testTableSourceProjection() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(4);
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, new TableConfig());
HBaseTableSource hbaseTable = new HBaseTableSource(getConf(), TEST_TABLE);
hbaseTable.addColumn(FAMILY1, F1COL1, Integer.class);
hbaseTable.addColumn(FAMILY2, F2COL1, String.class);
hbaseTable.addColumn(FAMILY2, F2COL2, Long.class);
hbaseTable.addColumn(FAMILY3, F3COL1, Double.class);
hbaseTable.addColumn(FAMILY3, F3COL2, Boolean.class);
hbaseTable.addColumn(FAMILY3, F3COL3, String.class);
tableEnv.registerTableSource("hTable", hbaseTable);
Table result = tableEnv.sqlQuery(
"SELECT " +
" h.family1.col1, " +
" h.family3.col1, " +
" h.family3.col2, " +
" h.family3.col3 " +
"FROM hTable AS h"
);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected =
"10,1.01,false,Welt-1\n" +
"20,2.02,true,Welt-2\n" +
"30,3.03,false,Welt-3\n" +
"40,4.04,true,Welt-4\n" +
"50,5.05,false,Welt-5\n" +
"60,6.06,true,Welt-6\n" +
"70,7.07,false,Welt-7\n" +
"80,8.08,true,Welt-8\n";
TestBaseUtils.compareResultAsText(results, expected);
}
示例15: testTableSourceFieldOrder
import org.apache.flink.table.api.java.BatchTableEnvironment; //导入方法依赖的package包/类
@Test
public void testTableSourceFieldOrder() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(4);
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, new TableConfig());
HBaseTableSource hbaseTable = new HBaseTableSource(getConf(), TEST_TABLE);
// shuffle order of column registration
hbaseTable.addColumn(FAMILY2, F2COL1, String.class);
hbaseTable.addColumn(FAMILY3, F3COL1, Double.class);
hbaseTable.addColumn(FAMILY1, F1COL1, Integer.class);
hbaseTable.addColumn(FAMILY2, F2COL2, Long.class);
hbaseTable.addColumn(FAMILY3, F3COL2, Boolean.class);
hbaseTable.addColumn(FAMILY3, F3COL3, String.class);
tableEnv.registerTableSource("hTable", hbaseTable);
Table result = tableEnv.sqlQuery(
"SELECT * FROM hTable AS h"
);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected =
"Hello-1,100,1.01,false,Welt-1,10\n" +
"Hello-2,200,2.02,true,Welt-2,20\n" +
"Hello-3,300,3.03,false,Welt-3,30\n" +
"null,400,4.04,true,Welt-4,40\n" +
"Hello-5,500,5.05,false,Welt-5,50\n" +
"Hello-6,600,6.06,true,Welt-6,60\n" +
"Hello-7,700,7.07,false,Welt-7,70\n" +
"null,800,8.08,true,Welt-8,80\n";
TestBaseUtils.compareResultAsText(results, expected);
}