Skip to main content

Manage data contracts via SDKs

Limited availability

Data contracts can currently only be managed for tables, views, and materialized views.

Create new contract

To create a contract for an existing asset in Atlan:

Create a data contract
Table asset = Table.updater("default/snowflake/1717514525/RAW/WIDEWORLD/SALE_TXN", "SALE_TXN")
.build();
String spec = client
.contracts.generateInitialSpec(asset); // (1)
DataContractSpec dcs = DataContractSpec.fromString(spec) // (2)
.toBuilder()
.description("Changed description.")
.extraProperty("something", "extra")
.build();
DataContract contract = DataContract.creator(spec, asset) // (3)
.build();
AssetMutationResponse response = contract.save(client); // (4)
  1. Start by initializing a data contract. You can use the .contracts.generateInitialSpec() on any Atlan client to generate the initial YAML data contract specification for a given asset.

  2. (Optional) You can translate the YAML string representation into a specification object that you can then programmatically extend, without needing to do direct string manipulations.

    Loses all comments

Be aware that doing this conversion will remove any comments in the YAML. ::: 3. You need to provide the contract specification (YAML), as a string, and the asset the contract will govern to the DataContract.creator() method.

Converting an object into the string form

If you programmatically modified the specification as an object, you can convert it back to its YAML string form simply by calling .toString() on the object. You are always asked to provide the YAML string form here to make sure that if you want to keep any comments, you have the option to do so (since the object form removes any comments).

  1. Finally, you can call the save() method to create the new data contract in Atlan. Because this operation will persist the asset in Atlan, you must provide it an AtlanClient through which to connect to the tenant.

Retrieve contract

By asset:

To retrieve the latest contract and certified contract of a given asset using its qualified name:

Retrieve latest and certified data contract of a asset
Table table = Table.get(client, "default/snowflake/1717514525/RAW/WIDEWORLD/SALE_TXN", true); // (1)
DataContract latest = table.getDataContractLatest(); // (2)
DataContract certified = table.getDataContractLatestCertified(); // (3)
  1. First, retrieve the asset by its qualifiedName. Because this operation will retrieve the asset from Atlan, you must provide it an AtlanClient through which to connect to the tenant.
  2. Retrieve the latest data contract by using .getDataContractLatest().
  3. Retrieve the certified data contract by using the .getDataContractLatestCertified().

By qualified name:

To retrieve a contract by its version (V1, V2, etc) using its qualified name:

Retrieve a data contract by its version
DataContract contract = DataContract.get( // (1)!
client, "default/snowflake/1717514525/RAW/WIDEWORLD/SALE_TXN/Table/contract/V1"
);
  1. The qualifiedName of the data contract must be in the format: <assetQualifiedName>/<assetType>/contract/V<versionNumber>. For this example:
    • assetQualifiedName: qualifiedName of a Snowflake table.
    • assetType: type of this asset in Atlan, i.e: Table.
    • versionNumber: specific version of the data contract to retrieve, e.g: 1, 2, and so on.

Update contract

In the following example, we're updating the contact certificateStatus field to VERIFIED (shown as PUBLISHED in the UI):

Update a data contract
DataContractSpec updatedContractDetails = DataContractSpec.fromString(spec) // (1)
.toBuilder()
.status(DataContractStatus.VERIFIED) // (2)
.build();
DataContract contract = DataContract.updater( // (3)
"default/snowflake/1717514525/RAW/WIDEWORLD/SALE_TXN/contract",
"Data contract for SALE_TXN"
)
.dataContractSpec(updatedContractDetails.toString()) // (4)
.build();
AssetMutationResponse response = contract.save(client); // (5)
  1. Begin by constructing the updated data contract specification. This example assumes you already have the string YAML form in a variable named spec, which you have retrieved from the data contract using one of the retrieval methods above.

  2. After converting the specification into a builder (using .toBuilder()) you can chain any updates you want against it, such as changing its status.

  3. Use the updater() method to update a data contract.

    • qualifiedName of the data contract, ie: <assetQualifiedName>/contract (where assetQualifiedName is, in this example, the qualifiedName of a Snowflake table).
    • name of the data contract. (NOTE: SDKs and CLI always generate it in the format: "Data contract for dataset (asset.name)").
  4. You can then add any other updates or attributes. In this example, we're updating the contract spec itself (must be string).

  5. To update the data contract in Atlan, call the save() method with the object you've built. Because this operation will persist the asset in Atlan, you must provide it an AtlanClient through which to connect to the tenant.

Delete contract

Soft-delete (archive)

To soft-delete, or archive, a contract:

Coming soon

Hard-delete (purge)

To permanently delete (purge) a contract:

Coming soon
Was this page helpful?