conversion_from_dataframe.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ################################################################################
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. ################################################################################
  18. import logging
  19. import sys
  20. import pandas as pd
  21. import numpy as np
  22. from pyflink.table import (DataTypes, TableEnvironment, EnvironmentSettings)
  23. def conversion_from_dataframe():
  24. t_env = TableEnvironment.create(EnvironmentSettings.in_streaming_mode())
  25. t_env.get_config().set("parallelism.default", "1")
  26. # define the source with watermark definition
  27. pdf = pd.DataFrame(np.random.rand(1000, 2))
  28. table = t_env.from_pandas(
  29. pdf,
  30. schema=DataTypes.ROW([DataTypes.FIELD("a", DataTypes.DOUBLE()),
  31. DataTypes.FIELD("b", DataTypes.DOUBLE())]))
  32. print(table.to_pandas())
  33. if __name__ == '__main__':
  34. logging.basicConfig(stream=sys.stdout, level=logging.INFO, format="%(message)s")
  35. conversion_from_dataframe()