forked from datacontract/datacontract-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf69a7e
commit cee03e5
Showing
7 changed files
with
214 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
# https://duckdb.org/docs/data/csv/overview.html | ||
# ['SQLNULL', 'BOOLEAN', 'BIGINT', 'DOUBLE', 'TIME', 'DATE', 'TIMESTAMP', 'VARCHAR'] | ||
def convert_to_duckdb_csv_type(field) -> None | str: | ||
type = field.type | ||
if type is None: | ||
return "VARCHAR" | ||
if type.lower() in ["string", "varchar", "text"]: | ||
return "VARCHAR" | ||
if type.lower() in ["timestamp", "timestamp_tz"]: | ||
return "TIMESTAMP" | ||
if type.lower() in ["timestamp_ntz"]: | ||
return "TIMESTAMP" | ||
if type.lower() in ["date"]: | ||
return "DATE" | ||
if type.lower() in ["time"]: | ||
return "TIME" | ||
if type.lower() in ["number", "decimal", "numeric"]: | ||
# precision and scale not supported by data contract | ||
return "VARCHAR" | ||
if type.lower() in ["float", "double"]: | ||
return "DOUBLE" | ||
if type.lower() in ["integer", "int", "long", "bigint"]: | ||
return "BIGINT" | ||
if type.lower() in ["boolean"]: | ||
return "BOOLEAN" | ||
if type.lower() in ["object", "record", "struct"]: | ||
# not supported in CSV | ||
return "VARCHAR" | ||
if type.lower() in ["bytes"]: | ||
# not supported in CSV | ||
return "VARCHAR" | ||
if type.lower() in ["array"]: | ||
return "VARCHAR" | ||
if type.lower() in ["null"]: | ||
return "SQLNULL" | ||
return "VARCHAR" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
dataContractSpecification: 0.9.2 | ||
id: "123" | ||
info: | ||
title: "Test" | ||
version: 1.0.0 | ||
owner: my-domain-team | ||
models: | ||
sample_model: | ||
description: Sample Model | ||
type: table | ||
fields: | ||
id: | ||
type: text | ||
required: true | ||
primary: true | ||
unique: true | ||
title: ID | ||
description: A unique identifier | ||
minLength: 4 | ||
maxLength: 5 | ||
pattern: ^\d+ | ||
enum: | ||
- "1234" | ||
- "22345" | ||
model_date: | ||
type: text | ||
required: true | ||
unique: false | ||
title: Model Date | ||
description: Model date | ||
field_c: | ||
type: integer | ||
exclusiveMaximum: 22346 | ||
|
||
examples: | ||
- type: csv | ||
description: Sample Model Example | ||
model: sample_model | ||
data: |- | ||
id,model_date,field_c | ||
"1234","2023-09-09",2 | ||
"22345","2023-09-09",22345 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import logging | ||
|
||
from typer.testing import CliRunner | ||
|
||
from datacontract.data_contract import DataContract | ||
|
||
runner = CliRunner() | ||
|
||
logging.basicConfig(level=logging.DEBUG, force=True) | ||
|
||
|
||
def test_formats(): | ||
data_contract = DataContract(data_contract_file="fixtures/examples/datacontract_formats_valid.yaml", examples=True) | ||
run = data_contract.test() | ||
print(run) | ||
print(run.result) | ||
assert run.result == "passed" |