def test_basic_functionality(self): # pandas UDF add_one = udf(lambda i: i + 1, result_type=DataTypes.BIGINT(), func_type="pandas") # general Python UDF subtract_one = udf(SubtractOne(), DataTypes.BIGINT(), DataTypes.BIGINT()) table_sink = source_sink_utils.TestAppendSink(['a', 'b', 'c', 'd'], [ DataTypes.BIGINT(), DataTypes.BIGINT(), DataTypes.BIGINT(), DataTypes.BIGINT() ]) self.t_env.register_table_sink("Results", table_sink) t = self.t_env.from_elements([(1, 2, 3), (2, 5, 6), (3, 1, 9)], ['a', 'b', 'c']) t.where(add_one(t.b) <= 3) \ .select(t.a, t.b + 1, add(t.a + 1, subtract_one(t.c)) + 2, add(add_one(t.a), 1)) \ .execute_insert("Results") \ .wait() actual = source_sink_utils.results() self.assert_equals(actual, ["+I[1, 3, 6, 3]", "+I[3, 2, 14, 5]"])
def test_basic_functionality(self): # pandas UDF self.t_env.create_temporary_system_function( "add_one", udf(lambda i: i + 1, result_type=DataTypes.BIGINT(), udf_type="pandas")) self.t_env.create_temporary_system_function("add", add) # general Python UDF self.t_env.create_temporary_system_function( "subtract_one", udf(SubtractOne(), DataTypes.BIGINT(), DataTypes.BIGINT())) table_sink = source_sink_utils.TestAppendSink(['a', 'b', 'c', 'd'], [ DataTypes.BIGINT(), DataTypes.BIGINT(), DataTypes.BIGINT(), DataTypes.BIGINT() ]) self.t_env.register_table_sink("Results", table_sink) t = self.t_env.from_elements([(1, 2, 3), (2, 5, 6), (3, 1, 9)], ['a', 'b', 'c']) exec_insert_table( t.where("add_one(b) <= 3").select( "a, b + 1, add(a + 1, subtract_one(c)) + 2, " "add(add_one(a), 1L)"), "Results") actual = source_sink_utils.results() self.assert_equals(actual, ["1,3,6,3", "3,2,14,5"])
def test_basic_functionality(self): add_one = udf(lambda i: i + 1, result_type=DataTypes.BIGINT(), func_type="pandas") # general Python UDF subtract_one = udf(SubtractOne(), result_type=DataTypes.BIGINT()) t = self.t_env.from_elements([(1, 2, 3), (2, 5, 6), (3, 1, 9)], ['a', 'b', 'c']) t = t.where(add_one(t.b) <= 3) \ .select(t.a, t.b + 1, add(t.a + 1, subtract_one(t.c)) + 2, add(add_one(t.a), 1)) result = self.collect(t) self.assert_equals(result, ["+I[1, 3, 6, 3]", "+I[3, 2, 14, 5]"])
def test_basic_functionality(self): self.t_env.register_function( "add_one", udf(lambda i: i + 1, DataTypes.BIGINT(), DataTypes.BIGINT(), udf_type="pandas")) self.t_env.register_function("add", add) # general Python UDF self.t_env.register_function( "subtract_one", udf(SubtractOne(), DataTypes.BIGINT(), DataTypes.BIGINT())) t = self.t_env.from_elements([(1, 2, 3), (2, 5, 6), (3, 1, 9)], ['a', 'b', 'c']) t = t.where("add_one(b) <= 3") \ .select("a, b + 1, add(a + 1, subtract_one(c)) + 2, add(add_one(a), 1L)") result = self.collect(t) self.assert_equals(result, ["1,3,6,3", "3,2,14,5"])
def test_basic_functionality(self): # pandas UDF add_one = udf(lambda i: i + 1, result_type=DataTypes.BIGINT(), func_type="pandas") # general Python UDF subtract_one = udf(SubtractOne(), DataTypes.BIGINT(), DataTypes.BIGINT()) sink_table_ddl = """ CREATE TABLE Results(a BIGINT, b BIGINT, c BIGINT, d BIGINT) WITH ('connector'='test-sink') """ self.t_env.execute_sql(sink_table_ddl) t = self.t_env.from_elements([(1, 2, 3), (2, 5, 6), (3, 1, 9)], ['a', 'b', 'c']) t.where(add_one(t.b) <= 3) \ .select(t.a, t.b + 1, add(t.a + 1, subtract_one(t.c)) + 2, add(add_one(t.a), 1)) \ .execute_insert("Results") \ .wait() actual = source_sink_utils.results() self.assert_equals(actual, ["+I[1, 3, 6, 3]", "+I[3, 2, 14, 5]"])