Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(raster-loader|bq): Round JSON_PARSE by default #117

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions raster_loader/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ def write_metadata(
UPDATE `{table_ref}`
SET attrs = (
WITH parsed_meta AS (
SELECT PARSE_JSON(attrs) AS attrs
SELECT PARSE_JSON(attrs, wide_number_mode=>'round') AS attrs
FROM `{table_ref}`
WHERE {location} IS NULL
),
Expand Down Expand Up @@ -1228,8 +1228,8 @@ def write_metadata(
JSON_VALUE(attrs, '$.crs') AS crs,
JSON_QUERY_ARRAY(attrs, '$.gdal_transform') AS gdal_transform
{get_resolution}
FROM
(SELECT PARSE_JSON({sql_quote(json.dumps(metadata))}) AS attrs)
FROM (SELECT PARSE_JSON({sql_quote(json.dumps(metadata))},
wide_number_mode=>'round') AS attrs)
),
united AS (
SELECT * FROM meta1
Expand Down Expand Up @@ -1389,7 +1389,8 @@ def inject_areas_query(raster_table: str, is_quadbin: bool) -> str:
width_in_pixel_query = f"""
SELECT MAX(row_width) FROM (
SELECT SUM(block_width) OVER (
PARTITION BY INT64(JSON_QUERY(PARSE_JSON(attrs), {block_y}))
PARTITION BY INT64(JSON_QUERY(
PARSE_JSON(attrs, wide_number_mode=>'round'), {block_y}))
) AS row_width
{from_blocks_source}
)
Expand All @@ -1398,24 +1399,28 @@ def inject_areas_query(raster_table: str, is_quadbin: bool) -> str:
height_in_pixel_query = f"""
SELECT MAX(col_height) FROM (
SELECT SUM(block_height) OVER (
PARTITION BY INT64(JSON_QUERY(PARSE_JSON(attrs), {block_x}))
PARTITION BY INT64(JSON_QUERY(
PARSE_JSON(attrs, wide_number_mode=>'round'), {block_x}))
) AS col_height
{from_blocks_source}
)
"""

width_in_pixel_block_query = f"""
SELECT COUNT(DISTINCT INT64(JSON_QUERY(PARSE_JSON(attrs), {block_x})))
SELECT COUNT(DISTINCT INT64(JSON_QUERY(
PARSE_JSON(attrs, wide_number_mode=>'round'), {block_x})))
{from_blocks_source}
"""

height_in_pixel_block_query = f"""
SELECT COUNT(DISTINCT INT64(JSON_QUERY(PARSE_JSON(attrs), {block_y})))
SELECT COUNT(DISTINCT INT64(JSON_QUERY(
PARSE_JSON(attrs, wide_number_mode=>'round'), {block_y})))
{from_blocks_source}
"""

sparse_pixel_block_query = f"""
(SELECT INT64(JSON_QUERY(PARSE_JSON(attrs), '$.nb_pixel_blocks'))
(SELECT INT64(JSON_QUERY(
PARSE_JSON(attrs, wide_number_mode=>'round'), '$.nb_pixel_blocks'))
{from_metadata_source})
< ({width_in_pixel_block_query}) * ({height_in_pixel_block_query})
"""
Expand Down Expand Up @@ -1449,7 +1454,7 @@ def only_if_unique_crs_query(query):
AS r'return {{...a, ...b}};';
UPDATE `{raster_table}`
SET attrs = TO_JSON_STRING(_mergeJSONs(
PARSE_JSON(attrs),
PARSE_JSON(attrs, wide_number_mode=>'round'),
TO_JSON(STRUCT(
({area_query}) AS raster_area,
({avg_pixel_area_query}) AS avg_pixel_area,
Expand Down
Loading