function generateEncodedRecord()

in node/lib/kpl-agg.js [174:210]


function generateEncodedRecord(records) {
	if (common.debug) {
		console.log("generate " + records.length + " records.");
	}

	if (records.length == 0) {
		return;
	}

	// do our best to find a valid partition key to use
	let pk;
	for (var i = 0; i < records.length; i++) {
		if (records[i].partitionKey) {
			pk = records[i].partitionKey;
			break;
		}
	}

	// do our best to find a valid explicit hash key to use
	let ehk;
	for (var j = 0; j < records.length; j++) {
		if (records[j].explicitHashKey) {
			ehk = records[0].explicitHashKey;
			break;
		}
	}
	const encodedRecord = {
		partitionKey: pk,
		data: aggregateRecord(records)
	}
	// if we find an ExplicitHashKey set it
	if(ehk !== undefined) {
		encodedRecord["ExplicitHashKey"] = ehk
	}
	// return encoded record
	return encodedRecord
}