-
Notifications
You must be signed in to change notification settings - Fork 4
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
4dc2ec3
commit 5dc2b54
Showing
6 changed files
with
271 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[ | ||
{ | ||
"fields": [ | ||
{ | ||
"fieldName": "col1", | ||
"fieldPath": "col1", | ||
"nativeType": "INT", | ||
"nullable": true | ||
}, | ||
{ | ||
"fieldName": "col2", | ||
"fieldPath": "col2", | ||
"nativeType": "ARRAY<STRUCT>", | ||
"nullable": false, | ||
"subfields": [ | ||
{ | ||
"fieldName": "col2_1", | ||
"fieldPath": "col2.col2_1", | ||
"nativeType": "ARRAY<TEXT>", | ||
"nullable": false | ||
}, | ||
{ | ||
"fieldName": "col2_1", | ||
"fieldPath": "col2.col2_1", | ||
"nativeType": "BOOL", | ||
"nullable": true | ||
}, | ||
{ | ||
"fieldName": "col2_3", | ||
"fieldPath": "col2.col2_3", | ||
"nativeType": "RECORD", | ||
"nullable": true | ||
} | ||
] | ||
} | ||
], | ||
"schemaType": "SQL", | ||
"sqlSchema": { | ||
"materialization": "EXTERNAL" | ||
} | ||
} | ||
] |
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,43 @@ | ||
[ | ||
{ | ||
"fields": [ | ||
{ | ||
"fieldName": "col1", | ||
"fieldPath": "col1", | ||
"nativeType": "INT", | ||
"nullable": true | ||
}, | ||
{ | ||
"fieldName": "col2", | ||
"fieldPath": "col2", | ||
"nativeType": "ARRAY<STRUCT>", | ||
"nullable": false, | ||
"subfields": [ | ||
{ | ||
"fieldName": "col2_1", | ||
"fieldPath": "col2.col2_1", | ||
"nativeType": "ARRAY<TEXT>", | ||
"nullable": false | ||
}, | ||
{ | ||
"fieldName": "col2_1", | ||
"fieldPath": "col2.col2_1", | ||
"nativeType": "BOOL", | ||
"nullable": true | ||
}, | ||
{ | ||
"fieldName": "col2_3", | ||
"fieldPath": "col2.col2_3", | ||
"nativeType": "RECORD", | ||
"nullable": true | ||
} | ||
] | ||
} | ||
], | ||
"schemaType": "SQL", | ||
"sqlSchema": { | ||
"materialization": "MATERIALIZED_VIEW", | ||
"tableSchema": "CREATE VIEW AS SELECT * FROM my-project.dataset.upstream" | ||
} | ||
} | ||
] |
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,43 @@ | ||
[ | ||
{ | ||
"fields": [ | ||
{ | ||
"fieldName": "col1", | ||
"fieldPath": "col1", | ||
"nativeType": "INT", | ||
"nullable": true | ||
}, | ||
{ | ||
"fieldName": "col2", | ||
"fieldPath": "col2", | ||
"nativeType": "ARRAY<STRUCT>", | ||
"nullable": false, | ||
"subfields": [ | ||
{ | ||
"fieldName": "col2_1", | ||
"fieldPath": "col2.col2_1", | ||
"nativeType": "ARRAY<TEXT>", | ||
"nullable": false | ||
}, | ||
{ | ||
"fieldName": "col2_1", | ||
"fieldPath": "col2.col2_1", | ||
"nativeType": "BOOL", | ||
"nullable": true | ||
}, | ||
{ | ||
"fieldName": "col2_3", | ||
"fieldPath": "col2.col2_3", | ||
"nativeType": "RECORD", | ||
"nullable": true | ||
} | ||
] | ||
} | ||
], | ||
"schemaType": "SQL", | ||
"sqlSchema": { | ||
"materialization": "SNAPSHOT", | ||
"snapshotTime": "2024-11-05T00:00:00+00:00" | ||
} | ||
} | ||
] |
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 @@ | ||
[ | ||
{ | ||
"fields": [ | ||
{ | ||
"fieldName": "col1", | ||
"fieldPath": "col1", | ||
"nativeType": "INT", | ||
"nullable": true | ||
}, | ||
{ | ||
"fieldName": "col2", | ||
"fieldPath": "col2", | ||
"nativeType": "ARRAY<STRUCT>", | ||
"nullable": false, | ||
"subfields": [ | ||
{ | ||
"fieldName": "col2_1", | ||
"fieldPath": "col2.col2_1", | ||
"nativeType": "ARRAY<TEXT>", | ||
"nullable": false | ||
}, | ||
{ | ||
"fieldName": "col2_1", | ||
"fieldPath": "col2.col2_1", | ||
"nativeType": "BOOL", | ||
"nullable": true | ||
}, | ||
{ | ||
"fieldName": "col2_3", | ||
"fieldPath": "col2.col2_3", | ||
"nativeType": "RECORD", | ||
"nullable": true | ||
} | ||
] | ||
} | ||
], | ||
"schemaType": "SQL", | ||
"sqlSchema": { | ||
"materialization": "TABLE" | ||
} | ||
} | ||
] |
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,43 @@ | ||
[ | ||
{ | ||
"fields": [ | ||
{ | ||
"fieldName": "col1", | ||
"fieldPath": "col1", | ||
"nativeType": "INT", | ||
"nullable": true | ||
}, | ||
{ | ||
"fieldName": "col2", | ||
"fieldPath": "col2", | ||
"nativeType": "ARRAY<STRUCT>", | ||
"nullable": false, | ||
"subfields": [ | ||
{ | ||
"fieldName": "col2_1", | ||
"fieldPath": "col2.col2_1", | ||
"nativeType": "ARRAY<TEXT>", | ||
"nullable": false | ||
}, | ||
{ | ||
"fieldName": "col2_1", | ||
"fieldPath": "col2.col2_1", | ||
"nativeType": "BOOL", | ||
"nullable": true | ||
}, | ||
{ | ||
"fieldName": "col2_3", | ||
"fieldPath": "col2.col2_3", | ||
"nativeType": "RECORD", | ||
"nullable": true | ||
} | ||
] | ||
} | ||
], | ||
"schemaType": "SQL", | ||
"sqlSchema": { | ||
"materialization": "VIEW", | ||
"tableSchema": "CREATE VIEW AS SELECT * FROM my-project.dataset.upstream" | ||
} | ||
} | ||
] |
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,58 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from google.cloud import bigquery | ||
|
||
from metaphor.bigquery.table import TableExtractor | ||
from tests.test_utils import load_json | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"table_type", | ||
[ | ||
"TABLE", | ||
"VIEW", | ||
"MATERIALIZED_VIEW", | ||
"EXTERNAL", | ||
"SNAPSHOT", | ||
], | ||
) | ||
def test_extract_table(test_root_dir: str, table_type: str): | ||
table_ref = bigquery.TableReference( | ||
dataset_ref=bigquery.DatasetReference( | ||
project="project", | ||
dataset_id="dataset1", | ||
), | ||
table_id="table1", | ||
) | ||
table = bigquery.Table( | ||
table_ref=table_ref, | ||
schema=[ | ||
bigquery.SchemaField("col1", "INT"), | ||
bigquery.SchemaField( | ||
"col2", | ||
"STRUCT", | ||
mode="REPEATED", | ||
fields=[ | ||
bigquery.SchemaField("col2_1", "TEXT", mode="REPEATED"), | ||
bigquery.SchemaField("col2_1", "BOOL", mode="NULLABLE"), | ||
bigquery.SchemaField("col2_3", "RECORD", mode="NULLABLE"), | ||
], | ||
), | ||
], | ||
) | ||
table._properties["type"] = table_type # type: ignore | ||
table.mview_query = "CREATE VIEW AS SELECT * FROM my-project.dataset.upstream" | ||
table.view_query = "CREATE VIEW AS SELECT * FROM my-project.dataset.upstream" | ||
table._properties["snapshotDefinition"] = { | ||
"snapshotTime": "2024-11-05T00:00:00.000Z" | ||
} # :( | ||
schema = TableExtractor.extract_schema(table).to_dict() | ||
expected = ( | ||
Path(test_root_dir) | ||
/ "bigquery" | ||
/ "data" | ||
/ "tables" | ||
/ f"{table_type.lower()}.json" | ||
) | ||
assert [schema] == load_json(expected) |