Implementation:Datahub project Datahub SchemaTron CLI
| Knowledge Sources | |
|---|---|
| Domains | Schema_Conversion, CLI_Tooling |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Description
SchemaTron is a Java CLI application that converts Avro schema files into DataHub SchemaMetadata aspects and emits them via configurable sinks. Built with picocli for command-line argument parsing, it supports two emission modes: REST (via RestEmitter) and file (via FileEmitter).
The application processes either a single Avro schema file or an entire directory of .avsc files. For each file, it:
- Reads and parses the Avro schema using Apache Avro's
Schema.Parser. - Converts the schema to a DataHub
SchemaMetadataviaAvroSchemaConverter. - Constructs a
DatasetUrnfrom the platform and fully qualified schema name. - Wraps the result in a
MetadataChangeProposalWrapperwithUPSERTchange type. - Emits to the configured sink (REST API or JSON file).
Usage
Invoked as a standalone Java CLI tool for batch conversion of Avro schemas to DataHub metadata. Part of the SchemaTron toolchain alongside the Python avro_schema_to_mce.py script.
Code Reference
Source Location
metadata-integration/java/datahub-schematron/cli/src/main/java/io/datahubproject/schematron/cli/SchemaTron.java
Signature
@Slf4j
@Command(
name = "schema-translator",
description = "Converts schemas to DataHub format and emits them",
mixinStandardHelpOptions = true)
public class SchemaTron implements Callable<Integer> {
@Option(names = {"-i", "--input"}, description = "Input schema file or directory")
private String input;
@Option(names = {"-s", "--server"}, description = "DataHub server URL",
defaultValue = "http://localhost:8080")
private String server;
@Option(names = {"-t", "--token"}, description = "DataHub access token",
defaultValue = "")
private String token;
@Option(names = {"-p", "--platform"}, description = "Data platform name",
defaultValue = "avro")
private String platform;
@Option(names = {"--sink"}, description = "DataHub sink name",
defaultValue = "rest")
private String sink;
@Option(names = {"--output-file"}, description = "Output file for the emitted metadata",
defaultValue = "metadata.json")
private String outputFile;
@Override
public Integer call() throws Exception
public static void main(String[] args)
}
Import
import io.datahubproject.schematron.cli.SchemaTron;
I/O Contract
Inputs
| Option | Type | Default | Description |
|---|---|---|---|
-i / --input |
String |
(required) | Path to an Avro schema file or directory of .avsc files
|
-s / --server |
String |
http://localhost:8080 |
DataHub GMS server URL |
-t / --token |
String |
"" |
DataHub access token for authentication |
-p / --platform |
String |
"avro" |
Data platform name for the dataset URN |
--sink |
String |
"rest" |
Emission sink: "rest" or "file"
|
--output-file |
String |
"metadata.json" |
Output file path (only used with file sink) |
Outputs
| Output | Description |
|---|---|
| REST emission | MetadataChangeProposal events sent to the DataHub GMS REST API
|
| File emission | JSON file containing serialized metadata change proposals |
| Exit code | 0 on success
|
Usage Examples
# Convert a single schema and emit via REST
java -jar schematron.jar -i schema.avsc -p kafka -s http://datahub:8080
# Convert a directory of schemas to a file
java -jar schematron.jar -i schemas/ --sink file --output-file metadata.json
# With authentication token
java -jar schematron.jar -i schema.avsc -s http://datahub:8080 -t mytoken
Related Pages
- Datahub_project_Datahub_Avro_Schema_To_Mce -- Python counterpart for Avro schema conversion
- Datahub_project_Datahub_MetadataChangeProposalWrapper_Java -- The wrapper type used for emitting MCPs
- Datahub_project_Datahub_SchemaTronDataHubType -- Type model used by the schema converter
- Datahub_project_Datahub_FieldPath_Schematron -- Field path model used during schema conversion