当前位置: 首页>>代码示例>>Java>>正文


Java BatchTableEnvironment类代码示例

本文整理汇总了Java中org.apache.flink.table.api.java.BatchTableEnvironment的典型用法代码示例。如果您正苦于以下问题:Java BatchTableEnvironment类的具体用法?Java BatchTableEnvironment怎么用?Java BatchTableEnvironment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BatchTableEnvironment类属于org.apache.flink.table.api.java包,在下文中一共展示了BatchTableEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAggregationWithTwoCount

import org.apache.flink.table.api.java.BatchTableEnvironment; //导入依赖的package包/类
@Test
public void testAggregationWithTwoCount() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());

	DataSource<Tuple2<Float, String>> input =
		env.fromElements(
			new Tuple2<>(1f, "Hello"),
			new Tuple2<>(2f, "Ciao"));

	Table table =
		tableEnv.fromDataSet(input);

	Table result =
		table.select("f0.count, f1.count");

	DataSet<Row> ds = tableEnv.toDataSet(result, Row.class);
	List<Row> results = ds.collect();
	String expected = "2,2";
	compareResultAsText(results, expected);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:22,代码来源:AggregationsITCase.java

示例2: 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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:41,代码来源:HBaseConnectorITCase.java

示例3: main

import org.apache.flink.table.api.java.BatchTableEnvironment; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

		// set up execution environment
		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
		BatchTableEnvironment tEnv = TableEnvironment.getTableEnvironment(env);

		DataSet<WC> input = env.fromElements(
			new WC("Hello", 1),
			new WC("Ciao", 1),
			new WC("Hello", 1));

		// register the DataSet as table "WordCount"
		tEnv.registerDataSet("WordCount", input, "word, frequency");

		// run a SQL query on the Table and retrieve the result as a new Table
		Table table = tEnv.sql(
			"SELECT word, SUM(frequency) as frequency FROM WordCount GROUP BY word");

		DataSet<WC> result = tEnv.toDataSet(table, WC.class);

		result.print();
	}
 
开发者ID:axbaretto,项目名称:flink,代码行数:23,代码来源:WordCountSQL.java

示例4: 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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:TableEnvironmentITCase.java

示例5: testRegisterWithFields

import org.apache.flink.table.api.java.BatchTableEnvironment; //导入依赖的package包/类
@Test
public void testRegisterWithFields() 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, "a, b, c");
	Table t = tableEnv.scan(tableName);

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

	DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
	List<Row> results = resultSet.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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:24,代码来源:TableEnvironmentITCase.java

示例6: testTableRegister

import org.apache.flink.table.api.java.BatchTableEnvironment; //导入依赖的package包/类
@Test
public void testTableRegister() 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);
	Table t = tableEnv.fromDataSet(ds);
	tableEnv.registerTable(tableName, t);
	Table result = tableEnv.scan(tableName).select("f0, f1").filter("f0 > 7");

	DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
	List<Row> results = resultSet.collect();
	String expected = "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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:19,代码来源:TableEnvironmentITCase.java

示例7: 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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:TableEnvironmentITCase.java

示例8: 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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:26,代码来源:TableEnvironmentITCase.java

示例9: testAsFromTupleToPojo

import org.apache.flink.table.api.java.BatchTableEnvironment; //导入依赖的package包/类
@Ignore
@Test
public void testAsFromTupleToPojo() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());

	List<Tuple4<String, Integer, Double, String>> data = new ArrayList<>();
	data.add(new Tuple4<>("Rofl", 1, 1.0, "Hi"));
	data.add(new Tuple4<>("lol", 2, 1.0, "Hi"));
	data.add(new Tuple4<>("Test me", 4, 3.33, "Hello world"));

	Table table = tableEnv
		.fromDataSet(env.fromCollection(data), "q, w, e, r")
		.select("q as a, w as b, e as c, r as d");

	DataSet<SmallPojo2> ds = tableEnv.toDataSet(table, SmallPojo2.class);
	List<SmallPojo2> results = ds.collect();
	String expected = "Rofl,1,1.0,Hi\n" + "lol,2,1.0,Hi\n" + "Test me,4,3.33,Hello world\n";
	compareResultAsText(results, expected);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:TableEnvironmentITCase.java

示例10: testAsFromTupleByPosition

import org.apache.flink.table.api.java.BatchTableEnvironment; //导入依赖的package包/类
@Test
public void testAsFromTupleByPosition() 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);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:JavaTableEnvironmentITCase.java

示例11: testAsFromAndToPrivateFieldPojo

import org.apache.flink.table.api.java.BatchTableEnvironment; //导入依赖的package包/类
@Test
public void testAsFromAndToPrivateFieldPojo() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());

	List<PrivateSmallPojo> data = new ArrayList<>();
	data.add(new PrivateSmallPojo("Peter", 28, 4000.00, "Sales"));
	data.add(new PrivateSmallPojo("Anna", 56, 10000.00, "Engineering"));
	data.add(new PrivateSmallPojo("Lucy", 42, 6000.00, "HR"));

	Table table = tableEnv
		.fromDataSet(env.fromCollection(data),
			"department AS a, " +
			"age AS b, " +
			"salary AS c, " +
			"name AS d")
		.select("a, b, c, d");

	DataSet<PrivateSmallPojo2> ds = tableEnv.toDataSet(table, PrivateSmallPojo2.class);
	List<PrivateSmallPojo2> results = ds.collect();
	String expected =
		"Sales,28,4000.0,Peter\n" +
		"Engineering,56,10000.0,Anna\n" +
		"HR,42,6000.0,Lucy\n";
	compareResultAsText(results, expected);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:27,代码来源:TableEnvironmentITCase.java

示例12: testFilterWithoutExtended

import org.apache.flink.table.api.java.BatchTableEnvironment; //导入依赖的package包/类
@Test
public void testFilterWithoutExtended() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);

	DataSet<Tuple2<Integer, String>> input = env.fromElements(new Tuple2<>(1,"d"));
	Table table = tableEnv
		.fromDataSet(input, "a, b")
		.filter("a % 2 = 0");

	String result = tableEnv.explain(table).replaceAll("\\r\\n", "\n");
	try (Scanner scanner = new Scanner(new File(testFilePath +
		"../../src/test/scala/resources/testFilter0.out"))){
		String source = scanner.useDelimiter("\\A").next().replaceAll("\\r\\n", "\n");
		assertEquals(source, result);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:ExplainTest.java

示例13: testFilterWithExtended

import org.apache.flink.table.api.java.BatchTableEnvironment; //导入依赖的package包/类
@Test
public void testFilterWithExtended() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);

	DataSet<Tuple2<Integer, String>> input = env.fromElements(new Tuple2<>(1,"d"));
	Table table = tableEnv
		.fromDataSet(input, "a, b")
		.filter("a % 2 = 0");

	String result = tableEnv.explain(table, true).replaceAll("\\r\\n", "\n");
	try (Scanner scanner = new Scanner(new File(testFilePath +
		"../../src/test/scala/resources/testFilter1.out"))){
		String source = scanner.useDelimiter("\\A").next().replaceAll("\\r\\n", "\n");
		assertEquals(source, result);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:ExplainTest.java

示例14: testJoinWithoutExtended

import org.apache.flink.table.api.java.BatchTableEnvironment; //导入依赖的package包/类
@Test
public void testJoinWithoutExtended() 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).replaceAll("\\r\\n", "\n");
	try (Scanner scanner = new Scanner(new File(testFilePath +
		"../../src/test/scala/resources/testJoin0.out"))){
		String source = scanner.useDelimiter("\\A").next().replaceAll("\\r\\n", "\n");
		assertEquals(source, result);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:22,代码来源:ExplainTest.java

示例15: main

import org.apache.flink.table.api.java.BatchTableEnvironment; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();
	BatchTableEnvironment tEnv = TableEnvironment.getTableEnvironment(env);

	DataSet<WC> input = env.fromElements(
			new WC("Hello", 1),
			new WC("Ciao", 1),
			new WC("Hello", 1));

	Table table = tEnv.fromDataSet(input);

	Table filtered = table
			.groupBy("word")
			.select("word, frequency.sum as frequency")
			.filter("frequency = 2");

	DataSet<WC> result = tEnv.toDataSet(filtered, WC.class);

	result.print();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:WordCountTable.java


注:本文中的org.apache.flink.table.api.java.BatchTableEnvironment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。