test_arch_api.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import uuid
  17. import numpy as np
  18. from fate_arch import session
  19. sess = session.Session()
  20. sess.init_computing()
  21. data = []
  22. for i in range(10):
  23. features = np.random.random(10)
  24. features = ",".join([str(x) for x in features])
  25. data.append((i, features))
  26. c_table = sess.computing.parallelize(data, include_key=True, partition=4)
  27. for k, v in c_table.collect():
  28. print(v)
  29. print()
  30. table_meta = sess.persistent(computing_table=c_table, namespace="experiment", name=str(uuid.uuid1()))
  31. storage_session = sess.storage()
  32. s_table = storage_session.get_table(namespace=table_meta.get_namespace(), name=table_meta.get_name())
  33. for k, v in s_table.collect():
  34. print(v)
  35. print()
  36. t2 = sess.computing.load(
  37. table_meta.get_address(),
  38. partitions=table_meta.get_partitions(),
  39. schema=table_meta.get_schema())
  40. for k, v in t2.collect():
  41. print(v)
  42. sess.destroy_all_sessions()