data_utils.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. import os
  2. import uuid
  3. from fate_arch.common import file_utils
  4. from fate_arch.storage import StorageEngine
  5. def default_output_info(task_id, task_version, output_type):
  6. return f"output_{output_type}_{task_id}_{task_version}", uuid.uuid1().hex
  7. def default_input_fs_path(name, namespace, prefix=None, storage_engine=StorageEngine.HDFS):
  8. if storage_engine == StorageEngine.HDFS:
  9. return default_hdfs_path(data_type="input", name=name, namespace=namespace, prefix=prefix)
  10. elif storage_engine == StorageEngine.LOCALFS:
  11. return default_localfs_path(data_type="input", name=name, namespace=namespace)
  12. def default_output_fs_path(name, namespace, prefix=None, storage_engine=StorageEngine.HDFS):
  13. if storage_engine == StorageEngine.HDFS:
  14. return default_hdfs_path(data_type="output", name=name, namespace=namespace, prefix=prefix)
  15. elif storage_engine == StorageEngine.LOCALFS:
  16. return default_localfs_path(data_type="output", name=name, namespace=namespace)
  17. def default_localfs_path(name, namespace, data_type):
  18. return os.path.join(file_utils.get_project_base_directory(), 'localfs', data_type, namespace, name)
  19. def default_hdfs_path(data_type, name, namespace, prefix=None):
  20. p = f"/fate/{data_type}_data/{namespace}/{name}"
  21. if prefix:
  22. p = f"{prefix}/{p}"
  23. return p