Open jacobmpeters opened 8 months ago
User-defined GoogleSQL Function: https://github.com/Analyticsphere/bq2/blob/0af3e0fee4e5fcc1be14e25f8931a308aa53323a/custom_sql_functions/yes_or_no.sql#L9-L14
Usage:
SELECT
Connect_ID,
yes_or_no(var) as var
FROM
FlatConnect.table
Notes from Nicole:
Adding this note after a discussion with @jeannewu:
Note: If we were to fix this directly in the flattening scheduled queries, we would simply need to change 1/0 to be 353358909/104430631 in the following function in each query:
function handleRowJS(row) {
for (let arrPath of Object.keys(arraysToBeFlattened)) {
let currObj = {};
let inputConceptIdList = getNestedObjectValue(row, arrPath);
if (!inputConceptIdList || inputConceptIdList.length === 0) continue;
inputConceptIdList = inputConceptIdList.map(v => +v);
for (let cid of arraysToBeFlattened[arrPath]) {
if (inputConceptIdList.indexOf(cid) >= 0) {
currObj["%s" + cid] = 1;
} else currObj["%s" + cid] = 0;
}
setNestedObjectValue(row, arrPath, currObj);
}
return JSON.stringify(row);
}
const row = JSON.parse(input_row);
return handleRowJS(row);
If we did this, it would cause many changes to the data structure in BQ1 modules that would disrupt Kelsey's reports. We are choosing to leave it as is in BQ1 (for now) and resolve it with SQL for BQ2.
Thanks, Jake.
Description:
Responses to select-all-that-apply questions in the Quest surveys are given as arrays:
They are then flattened as:
where "0" and "1" represent "no" and "yes", respectively.
However, the data dictionary prescribes that "no" and "yes" should be represented by the CIDs
104430631
and353358909
, respectively.Action Items:
yesorno
to convert "0" and "1" to104430631
and353358909
.yesorno
function to this list in the queries, using thegenerate_bq2_queries.qmd
script.