I saw there was a request for the Data mapping in this thread…so here is my data transformer script for mapping to BigQuery…I’m sure it can be improved from here, but it gives you a flavor for how the JSonnet script works in the Data Transformer task. I highly recommend using the Data Transformer Playground developed by one of our Customer Engineers – I found it very helpful when developing this.
local f = import 'functions'; // Import additional functions
// TEMPLATE OUTPUT
// Json Object is expected as on output. The key of the object would be the variable whose value needs to be set.
// Example:
// {
// hello: "world"
// }
local ShopifyProducts = std.extVar('`Task_2_connectorOutputPayload`');
local c = 0;
local parseJson(d) = std.parseJson( std.strReplace(std.stripChars(d, "\n \r\n" ),"\n", " " ));
local parseNumber(str) = std.parseInt( std.substr( str, 0, std.length(str)-3));
local createBQRow(product) =
local variant = parseJson(product.Variants)[0];
local image = parseJson(product.Images)[0];
{
"Handle": product.Handle,
"Title": product.Title,
"Body_HTML": product.BodyHtml,
"Vendor": product.Vendor,
"Product_Category": "",
"Type": product.ProductType,
"Tags": product.Tags,
"Published": (if product.PublishedScope == "global" then true else false),
"Option1_Name": "Title",
"Option1_Value": variant.option1,
"Option2_Name": variant.option2,
"Option2_Value": variant.option2,
"Option3_Name": variant.option3,
"Option3_Value": variant.option3,
"Variant_SKU": (if variant.sku == null then "" else variant.sku),
"Variant_Grams": variant.grams,
"Variant_Inventory_Tracker": variant.inventory_management,
"Variant_Inventory_Qty": variant.inventory_quantity,
"Variant_Inventory_Policy": variant.inventory_policy,
"Variant_Fulfillment_Service": variant.fulfillment_service,
"Variant_Price": parseNumber(variant.price),
"Variant_Compare_At_Price": parseNumber(variant.compare_at_price),
"Variant_Requires_Shipping": variant.requires_shipping,
"Variant_Taxable": variant.taxable,
"Variant_Barcode": (if variant.barcode == null then "" else variant.barcode),
"Image_Src": image.src,
"Image_Position": image.position,
"Image_Alt_Text": image.alt,
"Gift_Card": "", //gift card isn't in the API"
"SEO_Title": "", //seo_title isn't in the API output"
"SEO_Description": "", //seo_description isn't in the API output"
"Google_Shopping_Google_Product_Category": "", //google shopping category"
"Google_Shopping_Gender": "", //google shopping gender"
"Google_Shopping_Age_Group": "", //google shopping / age group"
"Google_Shopping_MPN": "", //google shopping / MPN"
"Google_Shopping_Condition": "", //google shopping / Condition"
"Google_Shopping_Custom_Product": "", //google shopping / Custom Product"
"Google_Shopping_Custom_Label_0": "", //google shopping / Custom Label 0"
"Google_Shopping_Custom_Label_1": "", //google shopping / Custom Label 1"
"Google_Shopping_Custom_Label_2": "", //google shopping / Custom Label 2"
"Google_Shopping_Custom_Label_3": "", //google shopping / Custom Label 3"
"Google_Shopping_Custom_Label_4": "", //google shopping / Custom Label 4"
"Variant_Image": variant.image_id,
"Variant_Weight_Unit": variant.weight_unit,
"Variant_Tax_Code": "", //variant tax code"
"Cost_per_item": "", //cost per item"
"Included_United_States": true, //included / united states"
"Price_United_States": "", //price / united states"
"Compare_At_Price_United_States": "", //compare at United states"
"Included_International": true, //included / Interntional"
"Price_International": "", //price / International"
"Compare_At_Price_International": "", //Compare at price / International"
"Status": product.Status,
};
{
// Add mapping here
BigQueryRequest: {
rows: [createBQRow(product) for product in ShopifyProducts]
},
}
I