Skip to content

Commit

Permalink
feat: Enhance parent tree bigquery
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiao Peng authored and Xiao Peng committed Sep 18, 2024
1 parent 8c89700 commit f8d14ba
Showing 1 changed file with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,57 @@ public interface ParentTreeRepository extends JpaRepository<ParentTreeEntity, Lo

@Query(
value =
"""
SELECT PT.PARENT_TREE_ID AS \"parentTreeId\",
PT.PARENT_TREE_NUMBER AS \"parentTreeNumber\",
PTO.ORCHARD_ID AS \"orchardId\",
PTSPU.SEED_PLAN_UNIT_ID AS \"spu\",
PT.TESTED_IND AS \"tested\",
Q.GENETIC_TYPE_CODE AS \"geneticTypeCode\",
Q.GENETIC_WORTH_CODE AS \"geneticWorthCode\",
Q.GENETIC_QUALITY_VALUE AS \"geneticQualityValue\"
FROM parent_tree PT
JOIN parent_tree_orchard PTO ON PTO.parent_tree_id = PT.parent_tree_id
LEFT JOIN parent_tree_seed_plan_unit PTSPU ON PTSPU.parent_tree_id = PT.parent_tree_id
LEFT JOIN parent_tree_genetic_quality Q ON PT.parent_tree_id = Q.parent_tree_id
AND Q.seed_plan_unit_id = PTSPU.seed_plan_unit_id
AND Q.genetic_worth_calc_ind = 'Y'
WHERE PT.VEGETATION_CODE = ?1
AND PT.ACTIVE_IND = 'Y'
AND PT.parent_tree_reg_status_code = 'APP'
ORDER BY PT.parent_tree_id
""",
"""
WITH filtered_parent_tree AS (
SELECT
PT.PARENT_TREE_ID,
PT.PARENT_TREE_NUMBER,
PT.TESTED_IND
FROM parent_tree PT
WHERE PT.VEGETATION_CODE = ?1
AND PT.ACTIVE_IND = 'Y'
AND PT.parent_tree_reg_status_code = 'APP'
),
orchard_data AS (
SELECT
PTO.parent_tree_id,
PTO.ORCHARD_ID
FROM parent_tree_orchard PTO
WHERE PTO.parent_tree_id IN (SELECT PARENT_TREE_ID FROM filtered_parent_tree)
),
seed_plan_unit_data AS (
SELECT
PTSPU.parent_tree_id,
PTSPU.SEED_PLAN_UNIT_ID
FROM parent_tree_seed_plan_unit PTSPU
WHERE PTSPU.parent_tree_id IN (SELECT PARENT_TREE_ID FROM filtered_parent_tree)
),
genetic_quality_data AS (
SELECT
Q.parent_tree_id,
Q.seed_plan_unit_id,
Q.GENETIC_TYPE_CODE,
Q.GENETIC_WORTH_CODE,
Q.GENETIC_QUALITY_VALUE
FROM parent_tree_genetic_quality Q
WHERE Q.genetic_worth_calc_ind = 'Y'
)
SELECT
fpt.PARENT_TREE_ID AS \"parentTreeId\",
fpt.PARENT_TREE_NUMBER AS \"parentTreeNumber\",
od.ORCHARD_ID AS \"orchardId\",
spud.SEED_PLAN_UNIT_ID AS \"spu\",
fpt.TESTED_IND AS \"tested\",
gqd.GENETIC_TYPE_CODE AS \"geneticTypeCode\",
gqd.GENETIC_WORTH_CODE AS \"geneticWorthCode\",
gqd.GENETIC_QUALITY_VALUE AS \"geneticQualityValue\"
FROM filtered_parent_tree fpt
JOIN orchard_data od ON od.parent_tree_id = fpt.PARENT_TREE_ID
LEFT JOIN seed_plan_unit_data spud ON spud.parent_tree_id = fpt.PARENT_TREE_ID
LEFT JOIN genetic_quality_data gqd ON gqd.parent_tree_id = fpt.PARENT_TREE_ID
AND gqd.seed_plan_unit_id = spud.SEED_PLAN_UNIT_ID
ORDER BY fpt.PARENT_TREE_ID;
""",
nativeQuery = true)
List<ParentTreeProj> findAllParentTreeWithVegCode(String vegCode);
}

0 comments on commit f8d14ba

Please sign in to comment.