# Dataform Incremental Errors

**URL:** <https://discuss.google.dev/t/dataform-incremental-errors/126730>\
**Category:** Data Analytics\
**Tags:** dataform, bigquery, dataprep\
**Created:** [August 4, 2023, 12:38pm UTC](https://discuss.google.dev/t/dataform-incremental-errors/126730 "2023-08-04T12:38:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![francisatoyebi](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/francisatoyebi/32/126819_2.png) [@francisatoyebi](https://discuss.google.dev/u/francisatoyebi)\
**Post date:** [August 4, 2023, 12:38pm UTC](https://discuss.google.dev/t/dataform-incremental-errors/126730/1 "2023-08-04T12:38:12Z")

</div>

I created an incremental Dataform code that when I run as not incremental, it runs so smooth and perfect but when I run it as incremental, I get errors.

Please see code below and what could be the cause of the error

config {  
type: “incremental”,  
schema: “dataform\_production”,  
name: “ga\_adobe\_combined”,  
tags: [“visits\_lk”],  
uniqueKey: [“pk”],  
bigquery: {  
partitionBy: “visit\_date”,  
clusterBy: [“pk”]  
}  
}

with adobe\_ as (  
SELECT  
GENERATE\_UUID() AS pk,  
“AA” as data\_source,  
date as visit\_date,  
country,  
site\_reconfigured as site,  
platform,  
operating\_system AS device\_operating\_system,  
adobe.mobile\_device\_type AS device\_category,  
sum(page\_views) as pageviews,  
sum(visits) as visits,  
sum(content\_starts) AS video\_views,  
sum(content\_time\_spent) AS total\_time\_spent  
FROM ${ref(‘visits\_adobe\_clean’)} adobe  
WHERE adobe.date \< ‘2021-06-01’  
group by 1,2,3,4,5,6,7,8  
)  
,

ega AS (  
SELECT  
GENERATE\_UUID() AS pk,  
“GA” as data\_source,  
date(visit\_start) as visit\_date,  
country,  
site,  
platform,  
device\_operating\_system,  
device\_category,  
sum(pageview\_cnt) as pageviews,  
count(distinct visit\_id) as visits,  
sum(video\_view\_cnt) as video\_views,  
sum(visit\_length\_sec) AS total\_time\_spent  
FROM ${ref(‘visits\_ga’)} visits  
WHERE visits.visit\_start \> ‘2021-06-01’  
${when(incremental(), `AND DATE(visit_start) > COALESCE((SELECT MAX(DATE(visit_start)) FROM ${self()}), DATE('2021-01-01'))`)}  
group by 1,2,3,4,5,6,7,8)

SELECT \* FROM adobe\_  
UNION ALL  
SELECT \* FROM ega

whenever I run as incremental, I get the error below, I expected incremental runs to use lesser computation, so why am I having this error?  
reason:“invalidQuery” location:“query” message:“Resources exceeded during query execution: The query could not be executed in the allotted memory. Peak usage: 160% of limit.\nTop memory consumer(s):\n JOIN operations: 100%\n. at [cfc-2017-site-login.dataform\_production.ga\_adobe\_combined\_procedure:4:15]”: invalid argument

Please help @ms4446

---

<div class="post-metadata">

**Author:** ![ms4446](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/ms4446/32/69120_2.png) [@ms4446](https://discuss.google.dev/u/ms4446)\
**Post date:** [August 4, 2023, 2:32pm UTC](https://discuss.google.dev/t/dataform-incremental-errors/126730/2 "2023-08-04T14:32:07Z")

</div>

Hi @francisatoyebi ,

The error you are getting indicates that the query is using too much memory and is being rejected by BigQuery. This could be due to several reasons:

- The two subqueries you are combining with `UNION ALL` are producing large result sets.
- The aggregation functions and grouping in your query are causing BigQuery to do a lot of work.

To reduce the memory usage of your query, you can try the following:

- Reduce the size of the result sets by filtering out rows that you don’t need. You are already filtering by date, but additional filtering might be possible depending on your requirements.
- Consider breaking down the query into smaller parts or using intermediate tables to handle the complexity.
- Review the grouping and aggregation logic to ensure that it’s optimized for your specific use case.

In your specific code, there is no join operation, so suggestions related to join conditions are not applicable. Also, replacing the `sum()` function with the `count()` function would likely produce incorrect results, so that suggestion may not be appropriate for this query.

The error message is pointing to a memory issue, so careful analysis and optimization of the query will be needed to resolve it.
