Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dariakharlan committed Feb 11, 2020
2 parents 098ae60 + 47260a5 commit a7967c7
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
"value" : "state['TOPIC_NAME'] = 'test';\nstate['TIMESTAMP_COLUMN'] = 'timestamp_unix';\nstate['DIMENSIONS'] = ['ver', 'AdSize', 'Country', 'AdType', 'Exchange'];\nstate['VALUES_COLUMN'] = ['Clicks', 'Impressions'];\nstate['TARGET_TYPES'] = ['gauge', 'counter'];\nstate['MEASUREMENT_NAMES'] = ['clicks', 'impressions'];\nstate['COUNT_RECORDS'] = 1\nstate['COUNT_RECORDS_MEASUREMENT_NAME'] = 'dsf'\nstate['STATIC_WHAT'] = 1"
}, {
"name" : "script",
"value" : "for(var i = 0; i < records.length; i++) {\n try {\n\n // Create a new record with map field \n var properties = {}\n for (var j = 0; j < state['DIMENSIONS'].length; j++) {\n if (records[i].value[state['DIMENSIONS'][j]] !== null) {\n properties[state['DIMENSIONS_NAMES'][j].replace(/[\\. \\/]+/g, '_')] = records[i].value[state['DIMENSIONS'][j]].replace(/[\\. ]+/g, '_')\n }\n }\n \n for (var j = 0; j < state['VALUES_COLUMNS'].length; j++) {\n var newRecord = sdcFunctions.createRecord(records[i].sourceId + ':' + i);\n if (state['STATIC_WHAT']) {\n properties['what'] = state['MEASUREMENT_NAMES'][j];\n properties['target_type'] = state['TARGET_TYPES'][j];\n } else {\n properties['what'] = records[i].value[state['MEASUREMENT_NAMES'][j]];\n properties['target_type'] = records[i].value[state['TARGET_TYPES'][j]];\n\t }\n \n newRecord.value = {'timestamp' : records[i].value[state['TIMESTAMP_COLUMN']],\n 'properties' : properties,\n 'value': records[i].value[state['VALUES_COLUMNS'][j]]};\n output.write(newRecord);\n }\n if (state['COUNT_RECORDS']) {\n var newRecord = sdcFunctions.createRecord(records[i].sourceId + ':' + i);\n properties['what'] = state['COUNT_RECORDS_MEASUREMENT_NAME'];\n properties['target_type'] = 'counter';\n newRecord.value = {'timestamp' : records[i].value[state['TIMESTAMP_COLUMN']],\n 'properties' : properties,\n 'value': 1};\n output.write(newRecord);\n }\n\n // output.write(records[i]);\n } catch (e) {\n // Send record to error\n error.write(records[i], e);\n }\n}"
"value" : "for(var i = 0; i < records.length; i++) {\n try {\n\n // Create a new record with map field \n var properties = {}\n for (var j = 0; j < state['DIMENSIONS'].length; j++) {\n if (records[i].value[state['DIMENSIONS'][j]] !== null) {\n properties[state['DIMENSIONS_NAMES'][j].replace(/[\\. \\/]+/g, '_')] = String(records[i].value[state['DIMENSIONS'][j]]).replace(/[\\. ]+/g, '_')\n }\n }\n \n for (var j = 0; j < state['VALUES_COLUMNS'].length; j++) {\n var newRecord = sdcFunctions.createRecord(records[i].sourceId + ':' + i);\n if (state['STATIC_WHAT']) {\n properties['what'] = state['MEASUREMENT_NAMES'][j];\n properties['target_type'] = state['TARGET_TYPES'][j];\n } else {\n properties['what'] = records[i].value[state['MEASUREMENT_NAMES'][j]];\n properties['target_type'] = records[i].value[state['TARGET_TYPES'][j]];\n\t }\n \n newRecord.value = {'timestamp' : records[i].value[state['TIMESTAMP_COLUMN']],\n 'properties' : properties,\n 'value': records[i].value[state['VALUES_COLUMNS'][j]]};\n output.write(newRecord);\n }\n if (state['COUNT_RECORDS']) {\n var newRecord = sdcFunctions.createRecord(records[i].sourceId + ':' + i);\n properties['what'] = state['COUNT_RECORDS_MEASUREMENT_NAME'];\n properties['target_type'] = 'counter';\n newRecord.value = {'timestamp' : records[i].value[state['TIMESTAMP_COLUMN']],\n 'properties' : properties,\n 'value': 1};\n output.write(newRecord);\n }\n\n // output.write(records[i]);\n } catch (e) {\n // Send record to error\n error.write(records[i], e);\n }\n}"
}, {
"name" : "destroyScript",
"value" : "/**\n * Available Objects:\n * \n * state: a dict that is preserved between invocations of this script. \n * Useful for caching bits of data e.g. counters and long-lived resources.\n *\n * log.<loglevel>(msg, obj...): use instead of print to send log messages to the log4j log instead of stdout.\n * loglevel is any log4j level: e.g. info, error, warn, trace.\n * sdcFunctions.getFieldNull(Record, 'field path'): Receive a constant defined above \n * to check if the field is typed field with value null\n * sdcFunctions.createMap(boolean listMap): Create a map for use as a field in a record. \n * Pass true to this function to create a list map (ordered map)\n * sdcFunctions.createEvent(String type, int version): Creates a new event.\n * Create new empty event with standard headers.\n * sdcFunctions.toEvent(Record): Send event to event stream\n * Only events created with sdcFunctions.createEvent are supported.\n */\n\n// state['connection'].close();"
Expand Down

0 comments on commit a7967c7

Please sign in to comment.