Skip to content

Commit

Permalink
Update to latest version of datacontract-cli, add in sqlalchemy as ne…
Browse files Browse the repository at this point in the history
…w export type, add in ODCS v3 to validate
  • Loading branch information
pflooky committed Sep 12, 2024
1 parent ba9a5e6 commit 6603622
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Current formats supported:
- SodaCL
- SQL
- SQL Query
- SQLAlchemy
- Terraform

## Validate
Expand Down
2 changes: 1 addition & 1 deletion datacontract-cli
Submodule datacontract-cli updated 86 files
+24 −2 .github/workflows/ci.yaml
+17 −1 CHANGELOG.md
+47 −2 README.md
+19 −3 datacontract/cli.py
+5 −10 datacontract/data_contract.py
+2 −0 datacontract/engines/fastjsonschema/s3/s3_read_files.py
+1 −7 datacontract/engines/soda/check_soda_execute.py
+81 −23 datacontract/engines/soda/connections/kafka.py
+12 −2 datacontract/export/avro_converter.py
+3 −2 datacontract/export/dbml_converter.py
+1 −0 datacontract/export/exporter.py
+6 −0 datacontract/export/exporter_factory.py
+4 −0 datacontract/export/spark_converter.py
+64 −29 datacontract/export/sql_type_converter.py
+169 −0 datacontract/export/sqlalchemy_converter.py
+1 −0 datacontract/imports/avro_importer.py
+1 −1 datacontract/imports/bigquery_importer.py
+112 −0 datacontract/imports/dbml_importer.py
+66 −90 datacontract/imports/dbt_importer.py
+1 −0 datacontract/imports/importer.py
+5 −0 datacontract/imports/importer_factory.py
+28 −9 datacontract/imports/spark_importer.py
+33 −5 datacontract/integration/datamesh_manager.py
+1 −1 datacontract/integration/opentelemetry.py
+6 −2 datacontract/model/data_contract_specification.py
+0 −32 datacontract/publish/publish.py
+23 −17 pyproject.toml
+19 −0 tests/fixtures/avro/export/datacontract_enum.avsc
+19 −0 tests/fixtures/avro/export/datacontract_enum.yaml
+22 −0 tests/fixtures/avro/export/datacontract_test_required.avsc
+19 −0 tests/fixtures/avro/export/datacontract_test_required.yaml
+71 −0 tests/fixtures/dbml/import/datacontract.yaml
+29 −0 tests/fixtures/dbml/import/datacontract_schema_filtered.yaml
+48 −0 tests/fixtures/dbml/import/datacontract_table_filtered.yaml
+26 −0 tests/fixtures/dbml/import/dbml.txt
+ tests/fixtures/parquet/data/array.parquet
+ tests/fixtures/parquet/data/bigint.parquet
+ tests/fixtures/parquet/data/blob.parquet
+ tests/fixtures/parquet/data/boolean.parquet
+ tests/fixtures/parquet/data/combined.parquet
+ tests/fixtures/parquet/data/date.parquet
+ tests/fixtures/parquet/data/decimal.parquet
+ tests/fixtures/parquet/data/double.parquet
+ tests/fixtures/parquet/data/float.parquet
+ tests/fixtures/parquet/data/integer.parquet
+ tests/fixtures/parquet/data/line_items.parquet
+ tests/fixtures/parquet/data/list.parquet
+ tests/fixtures/parquet/data/map.parquet
+ tests/fixtures/parquet/data/orders.parquet
+ tests/fixtures/parquet/data/string.parquet
+ tests/fixtures/parquet/data/struct.parquet
+ tests/fixtures/parquet/data/time.parquet
+ tests/fixtures/parquet/data/timestamp.parquet
+60 −8 tests/fixtures/parquet/datacontract.yaml
+19 −0 tests/fixtures/parquet/datacontract_array.yaml
+15 −0 tests/fixtures/parquet/datacontract_bigint.yaml
+17 −0 tests/fixtures/parquet/datacontract_binary.yaml
+15 −0 tests/fixtures/parquet/datacontract_boolean.yaml
+15 −0 tests/fixtures/parquet/datacontract_date.yaml
+2 −5 tests/fixtures/parquet/datacontract_decimal.yaml
+15 −0 tests/fixtures/parquet/datacontract_double.yaml
+15 −0 tests/fixtures/parquet/datacontract_float.yaml
+15 −0 tests/fixtures/parquet/datacontract_integer.yaml
+19 −0 tests/fixtures/parquet/datacontract_map.yaml
+15 −0 tests/fixtures/parquet/datacontract_string.yaml
+21 −0 tests/fixtures/parquet/datacontract_struct.yaml
+3 −17 tests/fixtures/parquet/datacontract_timestamp.yaml
+68 −54 tests/fixtures/parquet/helper/create_parquet_files.py
+22 −0 tests/fixtures/spark/export/datacontract.yaml
+21 −0 tests/fixtures/spec/datacontract_aliases.yaml
+30 −0 tests/fixtures/spec/datacontract_fields_field.yaml
+22 −0 tests/test_export_avro.py
+2 −0 tests/test_export_complex_data_contract.py
+4 −1 tests/test_export_dbml.py
+37 −0 tests/test_export_spark.py
+91 −0 tests/test_export_sqlalchemy.py
+2 −0 tests/test_import_avro.py
+68 −0 tests/test_import_dbml.py
+3 −3 tests/test_import_dbt.py
+82 −1 tests/test_import_spark.py
+1 −1 tests/test_integration_opentelemetry.py
+17 −0 tests/test_spec_fields_field.py
+15 −0 tests/test_spec_ref.py
+5 −6 tests/test_test_kafka.py
+98 −11 tests/test_test_parquet.py
+3 −2 tests/test_test_sqlserver.py
26 changes: 26 additions & 0 deletions example/dbml/dbml.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Project "Orders Latest" {
Note: '''Successful customer orders in the webshop.
All orders since 2020-01-01.
Orders with their line items are in their current state (no history included).
'''
}

Table test.orders {
"order_id" "text" [pk,unique,not null,Note: "An internal ID that identifies an order in the online shop."]
"order_timestamp" "timestamp" [not null,Note: "The business timestamp in UTC when the order was successfully registered in the source system and the payment was successful."]
"order_total" "record" [not null,Note: "Total amount the smallest monetary unit (e.g., cents)."]
"customer_id" "text" [null,Note: "Unique identifier for the customer."]
"customer_email_address" "text" [not null,Note: "The email address, as entered by the customer. The email address was not verified."]
"processed_timestamp" "timestamp" [not null,Note: "The timestamp when the record was processed by the data platform."]
Note: "One record per order. Includes cancelled and deleted orders."
}


Table orders.line_items {
"lines_item_id" "text" [pk,unique,not null,Note: "Primary key of the lines_item_id table"]
"order_id" "text" [null,Note: "An internal ID that identifies an order in the online shop."]
"sku" "text" [null,Note: "The purchased article number"]
Note: "A single article that is part of an order."
}

Ref: orders.line_items.order_id > test.orders.order_id
9 changes: 8 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
<select name="data-contract-type" id="data-contract-type">
<option value="dataContractSpecification">Data Contract Specification</option>
<option value="dataProductSpecification">Data Product Specification</option>
<option value="odcs" selected>Open Data Contract Standard (ODCS)</option>
<option value="odcs" selected>Open Data Contract Standard v2 (ODCS)</option>
<option value="odcs-v3" selected>Open Data Contract Standard v3 (ODCS)</option>
</select>
<div id="github-links" class="github-links-container">
<div id="odcs-github-link" class="github-link">
Expand All @@ -72,6 +73,12 @@
data-size="large" data-show-count="true" data-hello="world" aria-description="odcs"
aria-label="Star bitol-io/open-data-contract-standard on GitHub">Star</a>
</div>
<div id="odcs-v3-github-link" class="github-link">
<a class="github-button" href="https://github.com/bitol-io/open-data-contract-standard"
data-color-scheme="no-preference: light; light: light; dark: dark;" data-icon="octicon-star"
data-size="large" data-show-count="true" data-hello="world" aria-description="odcs"
aria-label="Star bitol-io/open-data-contract-standard on GitHub">Star</a>
</div>
<div id="dataContractSpecification-github-link" class="github-link">
<a class="github-button" href="https://github.com/datacontract/datacontract-specification"
data-color-scheme="no-preference: light; light: light; dark: dark;" data-icon="octicon-star"
Expand Down
3 changes: 3 additions & 0 deletions pyscript.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ packages = [
"example/avro/orders.avsc" = "./example/avro/orders.avsc"
"example/bigquery/complete_table_schema.json" = "./example/bigquery/complete_table_schema.json"
"example/dbt/manifest_jaffle_duckdb.json" = "./example/dbt/manifest_jaffle_duckdb.json"
"example/dbml/dbml.txt" = "./example/dbml/dbml.txt"
"example/jsonschema/orders_union-types.json" = "./example/jsonschema/orders_union-types.json"
"example/sql/customer.sql" = "./example/sql/customer.sql"
"example/unity/unity_table_schema.json" = "./example/unity/unity_table_schema.json"
Expand Down Expand Up @@ -46,11 +47,13 @@ files = [
"export/spark_converter.py",
"export/sql_converter.py",
"export/sql_type_converter.py",
"export/sqlalchemy_converter.py",
"export/terraform_converter.py",
"imports/importer.py",
"imports/importer_factory.py",
"imports/avro_importer.py",
"imports/bigquery_importer.py",
"imports/dbml_importer.py",
"imports/dbt_importer.py",
"imports/jsonschema_importer.py",
"imports/odcs_importer.py",
Expand Down
7 changes: 7 additions & 0 deletions src/js/config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@

export const defaultJsonSchemaName = "odcs"
export const defaultValidateJsonSchemaName = "odcs-v3"

export const odcsDetails = {
schemaUrl: "https://raw.githubusercontent.com/bitol-io/open-data-contract-standard/main/schema/odcs-json-schema-latest.json",
exampleUrl: "https://raw.githubusercontent.com/bitol-io/open-data-contract-standard/main/docs/examples/all/full-example.odcs.yaml",
githubUrl: "https://github.com/bitol-io/open-data-contract-standard"
}

export const odcsV3Details = {
schemaUrl: "https://raw.githubusercontent.com/bitol-io/open-data-contract-standard/dev_v3/schema/odcs-json-schema-v3.0.0.json",
exampleUrl: "https://raw.githubusercontent.com/bitol-io/open-data-contract-standard/dev_v3/docs/examples/all/full-example.odcs.yaml",
githubUrl: "https://github.com/bitol-io/open-data-contract-standard"
}

export const dataContractSpecificationDetails = {
schemaUrl: "https://raw.githubusercontent.com/datacontract/datacontract-specification/main/datacontract.schema.json",
exampleUrl: "https://raw.githubusercontent.com/datacontract/datacontract-specification/main/examples/covid-cases/datacontract.yaml",
Expand Down
12 changes: 7 additions & 5 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import {setJsonSchema, setupEditorSession} from "./util.js";
import {
dataContractSpecificationDetails,
dataProductSpecificationDetails,
defaultJsonSchemaName,
odcsDetails
defaultValidateJsonSchemaName,
odcsDetails,
odcsV3Details
} from "./config.js";

const jsonSchemaMap = new Map()
jsonSchemaMap.set("odcs", odcsDetails)
jsonSchemaMap.set("odcs-v3", odcsV3Details)
jsonSchemaMap.set("dataContractSpecification", dataContractSpecificationDetails)
jsonSchemaMap.set("dataProductSpecification", dataProductSpecificationDetails)

Expand All @@ -20,10 +22,10 @@ async function initAceEditor() {
ace.require("ace/ext/language_tools")
setupEditorSession(editor, "ace/mode/yaml")

githubLinks.dataset.prevValue = defaultJsonSchemaName
const githubLink = document.getElementById(`${defaultJsonSchemaName}-github-link`)
githubLinks.dataset.prevValue = defaultValidateJsonSchemaName
const githubLink = document.getElementById(`${defaultValidateJsonSchemaName}-github-link`)
githubLink.style.display = "block"
await setJsonSchema(jsonSchemaMap, exampleMap, editor, provider, defaultJsonSchemaName)
await setJsonSchema(jsonSchemaMap, exampleMap, editor, provider, defaultValidateJsonSchemaName)
}

function initSelectSchemaListener() {
Expand Down
4 changes: 2 additions & 2 deletions src/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from src.python.model import OdcsDetails, DataContractSpecDetails, AvroDetails, AvroIdlDetails, BigQueryDetails, \
DbmlDetails, DbtDetails, DbtSourcesDetails, DbtStagingSqlDetails, GoDetails, GreatExpectationsDetails, HtmlDetails, \
JsonSchemaDetails, ProtobufDetails, PydanticModelDetails, RdfDetails, SodaClDetails, SparkDetails, SqlDetails, \
SqlQueryDetails, TerraformDetails, DataContractSpec
SqlQueryDetails, SqlAlchemyDetails, TerraformDetails, DataContractSpec

convert_output_type = pydom["#convert-output-type"][0]
ace = window.ace
Expand All @@ -23,7 +23,7 @@
AvroDetails(), AvroIdlDetails(), BigQueryDetails(), DbmlDetails(), DbtDetails(), DbtSourcesDetails(),
DbtStagingSqlDetails(), GoDetails(), GreatExpectationsDetails(), HtmlDetails(), JsonSchemaDetails(),
OdcsDetails(), ProtobufDetails(), PydanticModelDetails(), RdfDetails(), SodaClDetails(), SparkDetails(),
SqlDetails(), SqlQueryDetails(), TerraformDetails()
SqlDetails(), SqlQueryDetails(), SqlAlchemyDetails(), TerraformDetails()
]

data_contract_examples = {}
Expand Down
7 changes: 7 additions & 0 deletions src/python/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class DataContractSpecDetails(DataSourceDetails):
class DbmlDetails(DataSourceDetails):
name = "dbml"
display_name = "DBML"
example_file = "example/dbml/dbml.txt"


class DbtDetails(DataSourceDetails):
Expand Down Expand Up @@ -181,6 +182,12 @@ class SqlQueryDetails(DataSourceDetails):
additional_opts = {"editor_mode": "sql"}


class SqlAlchemyDetails(DataSourceDetails):
name = "sqlalchemy"
display_name = "SQLAlchemy"
additional_opts = {"editor_mode": "sql"}


class TerraformDetails(DataSourceDetails):
name = "terraform"
display_name = "Terraform"
Expand Down

0 comments on commit 6603622

Please sign in to comment.