Skip to main content

documents

This notebook contains examples of how to work with YSON documents on YTsaurus.

Notebooks demonstrates how to:

  1. Create a document.
  2. Write content to a document.
  3. Partially update a document.
  4. Partially read a document.

Documents can be used to store small amount of data, for example:

  1. Common configuration for operation's runner.
  2. Debug metadata about ML training run.
  3. Settings for YT-based service (like CHYT).

The document behaves as a whole in terms of Cypress-specific features:

  • locks
  • owners
  • revisions
  • creation_time, modification_time and expiration_time
  • attributes
  • and other features

Limits

  • RPS should be < 1
  • Single document should be about some KB.
  • The total volume of all user documents must not exceed <10MB.
from yt import wrapper as yt
import uuid

Create a base directory for examples

username = yt.get_user_name()
if yt.exists(f"//sys/users/{username}/@user_info/home_path"):
home = yt.get(f"//sys/users/{username}/@user_info/home_path")
working_dir = f"{home}/{uuid.uuid4().hex}"
else:
working_dir = f"//tmp/examples/{uuid.uuid4().hex}"
yt.create("map_node", working_dir)
print(working_dir)

Example

Let's create an empty document and wright some data.

document_path = f"{working_dir}/document"
yt.create("document", document_path)
yt.set(document_path, {"data": {"ytsaurus": ["master", "proxies", "scheduler", "exec nodes", "data nodes"]}})
yt.get(document_path)

The document can be partially readed and updated.

yt.get(f"{document_path}/data/ytsaurus")
yt.set(f"{document_path}/object_class", "Safe")
yt.get(document_path)

The document can also be completely rewritten.

yt.set(document_path, "[DATA EXPUNGED]")
yt.get(document_path)