Ejemplo n.º 1
0
 def check_cython_coder(self, python_field_coders, cython_field_coders,
                        data):
     from apache_beam.coders.coder_impl import create_InputStream, create_OutputStream
     from pyflink.fn_execution.beam.beam_stream import BeamInputStream, BeamOutputStream
     py_flatten_row_coder = coder_impl.FlattenRowCoderImpl(
         python_field_coders)
     internal = py_flatten_row_coder.encode(data)
     beam_input_stream = create_InputStream(internal)
     input_stream = BeamInputStream(beam_input_stream,
                                    beam_input_stream.size())
     beam_output_stream = create_OutputStream()
     cy_flatten_row_coder = fast_coder_impl.FlattenRowCoderImpl(
         cython_field_coders)
     value = cy_flatten_row_coder.decode(input_stream)
     output_stream = BeamOutputStream(beam_output_stream)
     cy_flatten_row_coder.encode(value, output_stream)
     output_stream.flush()
     generator_result = py_flatten_row_coder.decode_from_stream(
         create_InputStream(beam_output_stream.get()), False)
     result = []
     for item in generator_result:
         result.append(item)
     try:
         self.assertEqual(result, data)
     except AssertionError:
         self.assertEqual(len(result), len(data))
         self.assertEqual(len(result[0]), len(data[0]))
         for i in range(len(data[0])):
             if isinstance(data[0][i], float):
                 from pyflink.table.tests.test_udf import float_equal
                 assert float_equal(data[0][i], result[0][i], 1e-6)
             else:
                 self.assertEqual(data[0][i], result[0][i])
Ejemplo n.º 2
0
 def check_cython_coder(self, python_field_coders, cython_field_coders,
                        data):
     from apache_beam.coders.coder_impl import create_InputStream, create_OutputStream
     from pyflink.fn_execution.fast_coder_impl import InputStreamAndFunctionWrapper
     py_flatten_row_coder = coder_impl.FlattenRowCoderImpl(
         python_field_coders)
     internal = py_flatten_row_coder.encode(data)
     input_stream = create_InputStream(internal)
     output_stream = create_OutputStream()
     cy_flatten_row_coder = fast_coder_impl.FlattenRowCoderImpl(
         cython_field_coders)
     value = cy_flatten_row_coder.decode_from_stream(input_stream, False)
     wrapper_func_input_element = InputStreamAndFunctionWrapper(
         lambda v: [v[i] for i in range(len(v))], value)
     cy_flatten_row_coder.encode_to_stream(wrapper_func_input_element,
                                           output_stream, False)
     generator_result = py_flatten_row_coder.decode_from_stream(
         create_InputStream(output_stream.get()), False)
     result = []
     for item in generator_result:
         result.append(item)
     try:
         self.assertEqual(result, data)
     except AssertionError:
         self.assertEqual(len(result), len(data))
         self.assertEqual(len(result[0]), len(data[0]))
         for i in range(len(data[0])):
             if isinstance(data[0][i], float):
                 from pyflink.table.tests.test_udf import float_equal
                 assert float_equal(data[0][i], result[0][i], 1e-6)
             else:
                 self.assertEqual(data[0][i], result[0][i])
Ejemplo n.º 3
0
 def get_impl(self):
     return coder_impl.FlattenRowCoderImpl(
         [c.get_impl() for c in self._field_coders])