id
int64
0
1.29M
original_id
stringlengths
32
32
swhid
stringlengths
100
170
sha1
stringlengths
40
40
repo_name
stringlengths
2
45
repo_group
stringclasses
12 values
filepath
stringlengths
5
153
name
stringlengths
1
14.9k
type
stringclasses
3 values
code
stringlengths
7
2.12M
1,200
9119717a44aac61ee4c3ec754510789f
swh:1:cnt:5569b9180502b5e36b1bb0b00b16f990910d543e;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=7-28/
888ca0cd8855a509103cfaf07712b22107e79047
eventstreams
analytics
test/lib/eventstreams-util.js
createKafkaMessageWithDefaults
function
/** * Creates a helper function to make kafka messages with default values * * @param {Object} value_defaults * @return {function(Object): {value: string}} */ function createKafkaMessageWithDefaults(value_defaults) { return (value_overrides = {}, key = null) => { return { // KafkaSSE will ...
1,201
2142d5457f30ff0a2e5994d3299f4820
swh:1:cnt:5569b9180502b5e36b1bb0b00b16f990910d543e;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=67-79/
888ca0cd8855a509103cfaf07712b22107e79047
eventstreams
analytics
test/lib/eventstreams-util.js
assertKeyDeserialization
function
/** * Helper function to DRY assertions for testing kafka key deserialization. * The key will be serialized using serializeKey, and then * that value will be passed through eventstream-util deserializer. * key will be asserted to be deep equal to the deserialized key....
1,202
72fda531752d35466eeab19b53b38baa
swh:1:cnt:06e98789002e1009b882244dbfb152c11915e8e3;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=7-17/
02b8788c793204e22917f89fb1abde90303736e9
eventstreams
analytics
test/utils/assert.js
deepEqual
function
function deepEqual(result, expected, message) { try { assert.deepEqual(result, expected, message); } catch (e) { console.log(`Expected:\n${JSON.stringify(expected, null, 2)}`); console.log(`Result:\n${JSON.stringify(result, null, 2)}`); throw e; } }
1,203
e44bb3ed0fa8f2dfe3db67705916caed
swh:1:cnt:06e98789002e1009b882244dbfb152c11915e8e3;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=19-29/
02b8788c793204e22917f89fb1abde90303736e9
eventstreams
analytics
test/utils/assert.js
status
function
/** * Asserts whether the return status was as expected * @param {Object} res * @param {integer} expected */ function status(res, expected) { deepEqual(res.status, expected, `Expected status to be ${expected}, but was ${res.status}`); }
1,204
b2d654682be8044a7d0d426b262cc996
swh:1:cnt:06e98789002e1009b882244dbfb152c11915e8e3;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=56-66/
02b8788c793204e22917f89fb1abde90303736e9
eventstreams
analytics
test/utils/assert.js
notDeepEqual
function
function notDeepEqual(result, expected, message) { try { assert.notDeepEqual(result, expected, message); } catch (e) { console.log(`Not expected:\n${JSON.stringify(expected, null, 2)}`); console.log(`Result:\n${JSON.stringify(result, null, 2)}`); throw e; } }
1,205
fc8e269872bfe3c2e1d0c318067b2c3f
swh:1:cnt:06e98789002e1009b882244dbfb152c11915e8e3;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=45-54/
02b8788c793204e22917f89fb1abde90303736e9
eventstreams
analytics
test/utils/assert.js
isDeepEqual
function
function isDeepEqual(result, expected, message) { try { assert.deepEqual(result, expected, message); return true; } catch (e) { return false; } }
1,206
f9e875a69bf604668d82f97b6775b33e
swh:1:cnt:06e98789002e1009b882244dbfb152c11915e8e3;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=31-43/
02b8788c793204e22917f89fb1abde90303736e9
eventstreams
analytics
test/utils/assert.js
contentType
function
/** * Asserts whether content type was as expected * @param {Object} res * @param {string} expectedRegexString */ function contentType(res, expectedRegexString) { // preq and fetch compatible const actual = res.headers['content-type'] ?? res.headers.get('content-type'); assert.ok(RegExp(expectedRegexSt...
1,207
58764b3b5aec14d949ab374b400e5355
swh:1:cnt:06e98789002e1009b882244dbfb152c11915e8e3;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=68-85/
02b8788c793204e22917f89fb1abde90303736e9
eventstreams
analytics
test/utils/assert.js
fails
function
function fails(promise, onRejected) { let failed = false; function trackFailure(e) { failed = true; return onRejected(e); } function check() { if (!failed) { throw new Error('expected error was not thrown'); } } return promise.catch(trackFailure).t...
1,208
a98eab98144941477f1ed20d61ff248a
swh:1:cnt:06e98789002e1009b882244dbfb152c11915e8e3;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=72-75/
02b8788c793204e22917f89fb1abde90303736e9
eventstreams
analytics
test/utils/assert.js
fails::trackFailure
function
function trackFailure(e) { failed = true; return onRejected(e); }
1,209
4db3aba94341c55d7ffd005617269ebb
swh:1:cnt:06e98789002e1009b882244dbfb152c11915e8e3;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=77-81/
02b8788c793204e22917f89fb1abde90303736e9
eventstreams
analytics
test/utils/assert.js
fails::check
function
function check() { if (!failed) { throw new Error('expected error was not thrown'); } }
1,210
6e08d4da3629b2c67c8aa16b7c0b99fa
swh:1:cnt:ae1e54f47f4d2b343103356e794be9ce04c5f48d;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=9-67/
3e03f8b1f516082ec24627b109c6987a08c846f8
eventstreams
analytics
test/utils/server.js
TestExpressServer
type
class TestExpressServer { configDirectory; running = false; conf; app; spec; uri; constructor(configDirectory = `${__dirname}/../../`) { this.configDirectory = configDirectory; } async start() { if (this.running) { return; } this.conf = (...
1,211
444cf7b30c8167b52109c54d58911775
swh:1:cnt:ae1e54f47f4d2b343103356e794be9ce04c5f48d;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=17-19/
3e03f8b1f516082ec24627b109c6987a08c846f8
eventstreams
analytics
test/utils/server.js
TestExpressServer::constructor
function
constructor(configDirectory = `${__dirname}/../../`) { this.configDirectory = configDirectory; }
1,212
1ab7753576e66e01dd3539bb3be855b9
swh:1:cnt:ae1e54f47f4d2b343103356e794be9ce04c5f48d;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=64-66/
3e03f8b1f516082ec24627b109c6987a08c846f8
eventstreams
analytics
test/utils/server.js
TestExpressServer::stop
function
async stop() { await this.app.close(); }
1,213
5ab270250a1925bb70abe41c662d4697
swh:1:cnt:ae1e54f47f4d2b343103356e794be9ce04c5f48d;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=21-51/
3e03f8b1f516082ec24627b109c6987a08c846f8
eventstreams
analytics
test/utils/server.js
TestExpressServer::start
function
async start() { if (this.running) { return; } this.conf = (await ServiceUtils .loadConfig({ cwd: this.configDirectory, envName: 'test', configFile: 'config', overrides: { logging: { level: 'debug', format: 's...
1,214
31cd5b9a0674b4045f1159bc051147ce
swh:1:cnt:ae1e54f47f4d2b343103356e794be9ce04c5f48d;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=53-62/
3e03f8b1f516082ec24627b109c6987a08c846f8
eventstreams
analytics
test/utils/server.js
TestExpressServer::config
function
get config() { if (!this.running) { throw new Error('Accessing test service config before starting the service'); } return { uri: this.uri, conf: this.conf, spec: this.spec, }; }
1,215
8d57d1fcd5f4592ecf58481336e92ad1
swh:1:cnt:0278cdf7cf39579f7a087c2301791a72b23c34c6;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=3-15/
085192e7d244bfb84951e7f449ec3e09ad03df7e
eventstreams
analytics
ui/src/apis/EventStreamsApi.js
getAvailableStreams
function
/** * Gets the list of stream names that can be consumed * from the configured EventStreams instance. * @return {promise} When resolved, will contain the list of stream names * that can be consumed from the configured EventStreams. */ function getAvailableStreams () { return new Promise(functio...
1,216
bbd73771855e68dfbf80a74dfa852222
swh:1:cnt:0278cdf7cf39579f7a087c2301791a72b23c34c6;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=23-37/
085192e7d244bfb84951e7f449ec3e09ad03df7e
eventstreams
analytics
ui/src/apis/EventStreamsApi.js
consumeStreams
function
/** * Opens an SSE EventSource that consumes the passed stream names. * Subscribes the passed callback to be called whenever an event is consumed. * Finally, returns the EventSource object, so it can be closed. * @param streamList {array} List of stream names to be consumed. * @param onMessage {function} To be cal...
1,217
b75efa47826a2c2be7a2a8bbf60b8bfc
swh:1:cnt:0278cdf7cf39579f7a087c2301791a72b23c34c6;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=17-21/
085192e7d244bfb84951e7f449ec3e09ad03df7e
eventstreams
analytics
ui/src/apis/EventStreamsApi.js
formatAvailableStreams
function
// Extracts the stream names from the EventStreams spec. function formatAvailableStreams (spec) { // /v2/stream/{streams} endpoint spec has a list of all available streams. return spec.paths['/v2/stream/{streams}'].get.parameters[0].schema.items.enum; }
1,218
4f603bef0101a0c346811755850c8622
swh:1:cnt:5c296dc06f143e5843b29aafec0c454b48ff8213;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=1-24/
553bb908c22bdfbde3ff18807029d77ce34baedd
eventstreams
analytics
ui/src/utils/index.js
yamlToHtml
function
/** * Returns an HTML blob that represents the passed yaml text. * The values will be color-highlighted, depending on type. */ function yamlToHtml (yamlText) { const lines = yamlText.trim().split('\n'); const formattedLines = lines.map(function (line) { if (/^\s*-/.test(line)) { // Line is a list item...
1,219
dac286f08d61e4a0f80f7306b85ac21f
swh:1:cnt:5c296dc06f143e5843b29aafec0c454b48ff8213;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=26-41/
553bb908c22bdfbde3ff18807029d77ce34baedd
eventstreams
analytics
ui/src/utils/index.js
valueToHtml
function
// Returns the passed value withing an HTML span, // color-highlighting it depending on type. function valueToHtml (value) { var color; if (value === 'true' || value === 'false') { color = 'blue'; } else if (isNaN(Number(value))) { color = 'green'; } else { color = 'red'; } const htmlValue = v...
1,220
a3012100f5badcdcd2aadf1923be3f69
swh:1:cnt:5c296dc06f143e5843b29aafec0c454b48ff8213;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventstreams.git;lines=43-55/
553bb908c22bdfbde3ff18807029d77ce34baedd
eventstreams
analytics
ui/src/utils/index.js
downloadText
function
/** * Triggers a download of the given text * within a file with the specified filename. */ function downloadText (text, filename) { const element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); element.setAttribute('download', filename)...
1,221
377c5dc49b539776a0e55e34db99cc46
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=88-92/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
flink_datastream_factory(fixture_schema_uris, fixture_stream_config_uri)
function
def flink_datastream_factory(fixture_schema_uris, fixture_stream_config_uri): factory = EventDataStreamFactory.of( fixture_schema_uris.split(","), fixture_stream_config_uri, None ) return factory
1,222
39e8023b9a32be50b19b034b5cd96316
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=29-30/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
test_event_example_files()
function
def test_event_example_files(): return [os.path.join(fixtures_path, "test.event.json")]
1,223
d046407e37b1d910beae77aeff449e72
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=43-44/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
test_event_example()
function
def test_event_example(): return EventStreamDescriptor(name="test.event.example", version="1.1.0")
1,224
3c39e137d77867c02353c624c5196b37
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=47-48/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
test_event_example_keyed()
function
def test_event_example_keyed(): return EventStreamDescriptor(name="test.event.keyed.example", version="1.1.0")
1,225
07970b6a025fc61eed0d1af967cc7d43
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=34-38/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
test_event_example_data(inp=f"{fixtures_path}/test.event.json")
function
def test_event_example_data(inp=f"{fixtures_path}/test.event.json"): with open(inp, "r") as fp: data = fp.readlines() return [json.loads(d) for d in data]
1,226
d2258ad2a840c85e03c41ca3338a3267
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=51-52/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
test_event_enriched()
function
def test_event_enriched(): return EventStreamDescriptor(name="test.event.enriched", version="1.1.0")
1,227
b58cffdc96940d26a20951d6a85bd2a8
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=56-57/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
test_event_error()
function
def test_event_error(): return EventStreamDescriptor(name="enrichment.error", version="2.1.0")
1,228
f4fd65f2958167c472767443b862cda8
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=61-68/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
flink_env()
function
def flink_env(): env = get_flink_env() env.set_runtime_mode(RuntimeExecutionMode.BATCH) # set parallelism for tests to so we might catch errors # from running more than one taskmanager. env.set_parallelism(2) yield env env.close()
1,229
f5e661a0e361a839936165c09c8c2c14
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=72-73/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
fixture_schema_uris()
function
def fixture_schema_uris(): return schema_uris
1,230
341ba112c643a4d8348113fb4573dc7d
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=77-78/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
fixture_stream_config_uri()
function
def fixture_stream_config_uri(): return stream_config_uri
1,231
72089c69fe801930d40b652c4923b685
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=82-84/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
fixture_eventutilities_environ(monkeypatch, fixture_schema_uris, fixture_stream_config_uri)
function
def fixture_eventutilities_environ(monkeypatch, fixture_schema_uris, fixture_stream_config_uri): monkeypatch.setenv("SCHEMA_URIS", fixture_schema_uris) monkeypatch.setenv("STREAM_CONFIG_URI", fixture_stream_config_uri)
1,232
3b19199d56e5ec38c130e54108e922cc
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=96-101/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
source_descriptor_file_test_event_example(test_event_example, test_event_example_files)
function
def source_descriptor_file_test_event_example(test_event_example, test_event_example_files): return SourceDescriptor( connector="file", stream=str(test_event_example), options={"uris": test_event_example_files}, )
1,233
6ab8b819237623f78ca8d6841137dd79
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=115-127/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
fixture_stream_manager_kwargs( fixture_schema_uris, fixture_stream_config_uri, source_descriptor_file_test_event_example, sink_descriptor_file_test_event_enriched, )
function
def fixture_stream_manager_kwargs( fixture_schema_uris, fixture_stream_config_uri, source_descriptor_file_test_event_example, sink_descriptor_file_test_event_enriched, ): return { "job_name": "test_stream_manager_config", "schema_uris": fixture_schema_uris, "stream_config_uri...
1,234
6cc5b6263dfafc39f4ba65438bde03c4
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=131-153/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
fixture_stream_manager_argv(tmp_path, fixture_stream_manager_kwargs)
function
def fixture_stream_manager_argv(tmp_path, fixture_stream_manager_kwargs): return [ "--stream_manager.job_name", fixture_stream_manager_kwargs["job_name"], "--stream_manager.schema_uris", fixture_stream_manager_kwargs["schema_uris"], "--stream_manager.stream_config_uri", ...
1,235
89b94c70e9996f6bad7c23e661822ce5
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=157-167/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
fixture_stream_manager_config_file(tmp_path, fixture_stream_manager_kwargs)
function
def fixture_stream_manager_config_file(tmp_path, fixture_stream_manager_kwargs): config_file_path = tmp_path / "config.yaml" with open(str(config_file_path), "w") as config_file: yaml.dump( {stream_manager.argparse_namespace: fixture_stream_manager_kwargs}, config_file, ...
1,236
7dca40354c958408fbc648b5b66f628e
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=105-111/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
sink_descriptor_file_test_event_enriched(tmp_path, test_event_enriched)
function
def sink_descriptor_file_test_event_enriched(tmp_path, test_event_enriched): main_output_path = tmp_path / "main_output" return SinkDescriptor( connector="file", stream=str(test_event_enriched), options={"uri": f"file://{str(main_output_path)}"}, )
1,237
ee77f68f0cdc543e0e770d5701e1eed6
swh:1:cnt:6931a48d5a26d703d1ed62fbcd8ab74142df5fca;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=171-199/
8a44ae928498bd74b28cab48f36030969af3c6d3
eventutilities-python
analytics
conftest.py
stream_with_error_sink( tmp_path, fixture_schema_uris, fixture_stream_config_uri, source_descriptor_file_test_event_example, test_event_enriched, test_event_error, )
function
def stream_with_error_sink( tmp_path, fixture_schema_uris, fixture_stream_config_uri, source_descriptor_file_test_event_example, test_event_enriched, test_event_error, ): main_output_path = tmp_path / "main_output" error_output_path = tmp_path / "error_output" return stream_manager(...
1,238
1b437813abb0ab33c479bc438c74fa10
swh:1:cnt:a4f17d311fd3309543dadb546cadf59ba5908eb1;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=20-21/
bed3c62c7998292a81a0bd0bee2e98b00a533a42
eventutilities-python
analytics
cookiecutter-event-application/{{ cookiecutter.project_name }}/conftest.py
fixture_events_files()
function
def fixture_events_files(): return [os.path.join(tests_path, "events.json")]
1,239
ff4e0de7f65fd421d01ec8c631a1401a
swh:1:cnt:a4f17d311fd3309543dadb546cadf59ba5908eb1;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=35-39/
bed3c62c7998292a81a0bd0bee2e98b00a533a42
eventutilities-python
analytics
cookiecutter-event-application/{{ cookiecutter.project_name }}/conftest.py
fixture_stream_manager_default_config_files()
function
def fixture_stream_manager_default_config_files(): """ Returns a config file path for use with all python tests. """ return [os.path.join(tests_path, "config.test.defaults.yaml")]
1,240
0cf81c3259131f373c85e062a7a43439
swh:1:cnt:a4f17d311fd3309543dadb546cadf59ba5908eb1;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=30-31/
bed3c62c7998292a81a0bd0bee2e98b00a533a42
eventutilities-python
analytics
cookiecutter-event-application/{{ cookiecutter.project_name }}/conftest.py
fixture_error_path(tmp_path_factory)
function
def fixture_error_path(tmp_path_factory): return str(tmp_path_factory.mktemp("error"))
1,241
750fbbe773f5d999e66e141605ee3996
swh:1:cnt:a4f17d311fd3309543dadb546cadf59ba5908eb1;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=25-26/
bed3c62c7998292a81a0bd0bee2e98b00a533a42
eventutilities-python
analytics
cookiecutter-event-application/{{ cookiecutter.project_name }}/conftest.py
fixture_sink_path(tmp_path_factory)
function
def fixture_sink_path(tmp_path_factory): return str(tmp_path_factory.mktemp("output"))
1,242
e8cbc1cf96a354d69178315dbab67f45
swh:1:cnt:a4f17d311fd3309543dadb546cadf59ba5908eb1;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=43-56/
bed3c62c7998292a81a0bd0bee2e98b00a533a42
eventutilities-python
analytics
cookiecutter-event-application/{{ cookiecutter.project_name }}/conftest.py
fixture_stream_manager_defaults( fixture_events_files, fixture_sink_path, fixture_error_path )
function
def fixture_stream_manager_defaults( fixture_events_files, fixture_sink_path, fixture_error_path ): """ Returns a dict of jsonargparse defaults for stream_manager to use in tests. Most importantly the input and output uri paths are generated dynamically in tmp_path. """ return { "st...
1,243
74a813ccbf8960e731a1edb6abed0324
swh:1:cnt:deab9511852ac46aec5ffa45004cef0dba6fd1d6;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=11-27/
edd4ff8e7bacdbabac70d95e5932d7f03b4cb8c9
eventutilities-python
analytics
cookiecutter-event-application/{{ cookiecutter.project_name }}/tests/test_app.py
test_enrich( fixture_stream_manager_default_config_files, fixture_stream_manager_defaults, )
function
def test_enrich( fixture_stream_manager_default_config_files, fixture_stream_manager_defaults, ): config = get_config( argv=[], # "--config", fixture_stream_manager_default_config_files[0]], default_config_files=fixture_stream_manager_default_config_files, defaults=fixture_stream_ma...
1,244
5f7c43a3bc4d196b3d171495a14eabcb
swh:1:cnt:12d866734ccb48709733f9a702fc55c306c414ee;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=41-60/
e026edf73684da95275c24884bb5580c717f0ac1
eventutilities-python
analytics
cookiecutter-event-application/{{ cookiecutter.project_name }}/{{ cookiecutter.project_name }}/app.py
main(config: Namespace = None)
function
def main(config: Namespace = None) -> None: config = config or load_config(parser=arg_parser, defaults=arg_parser_defaults) {% if cookiecutter.uses_http != 'N' %} @http_process_function(**config.http_session) def enrich(event: dict, http_session: requests.Session) -> dict: {% else %} def enrich...
1,245
5ac9f542a5f972ce251573bc9fe80e55
swh:1:cnt:12d866734ccb48709733f9a702fc55c306c414ee;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=48-48/
e026edf73684da95275c24884bb5580c717f0ac1
eventutilities-python
analytics
cookiecutter-event-application/{{ cookiecutter.project_name }}/{{ cookiecutter.project_name }}/app.py
main::enrich(event: dict)
function
def enrich(event: dict) -> dict:
1,246
dd4149eae65cd295f4cab9e51d951e97
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=152-223/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
convert_python_to_pyflink(value: Any, type_info: TypeInformation)
function
def convert_python_to_pyflink(value: Any, type_info: TypeInformation) -> Any: """ Iterates over type_info and value and recursively converts python native types back to PyFlink types. This should be the reverse operation of convert_pyflink_to_python. Do not use this function to convert a PyFlink pr...
1,247
0a42f554c40f218b142c3b5f9b3e1ca9
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=350-379/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::collection_source( self, stream_name: str, source_data: Collection[Dict[str, Any]], schema_version: Optional[str] = None, )
function
def collection_source( self, stream_name: str, source_data: Collection[Dict[str, Any]], schema_version: Optional[str] = None, ) -> Source: """Uses the provided source collection of dict to instantiate the input Source. Because PyFlink does not provide a way to use eve...
1,248
d3d37f6db697373e8bd8fcf3adc3b206
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=696-711/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::print_sink( self, stderr: bool = False, )
function
def print_sink( self, stderr: bool = False, ) -> SinkFunction: # pragma: no cover """ A simple print sink. No serializer will be used. Equivalent to using datastream.print(). :param stderr: If true, the print sink will print to stderr instead of stdout ...
1,249
ed229f5b81e47664b67c60cc342a6e3b
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=226-240/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
python_to_pyflink_converter(type_info: TypeInformation)
function
def python_to_pyflink_converter(type_info: TypeInformation) -> EventDictToRowConverter: """ Returns a converter function for `type_info`. `python_to_pyflink_converter` delegates python type to flink type transformation to `convert_dicts_to_rows` by means of partial function application. An input d...
1,250
93f9b9f47a702d4d41aeb787d65d0843
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=247-279/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::of( cls, schema_uris: Union[Sequence[str], str], stream_config_uri: str, http_client_routes: Optional[Dict[str, str]] = None, )
function
def of( cls, schema_uris: Union[Sequence[str], str], stream_config_uri: str, http_client_routes: Optional[Dict[str, str]] = None, ) -> "EventDataStreamFactory": """:param schema_uris: Event schema repository URIs. Event schemas will be loaded from these. Either a lis...
1,251
ccb9885bf61f7a08033607242010b28e
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=713-737/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::row_file_sink( self, stream_name: str, schema_version: str, uri: str, )
function
def row_file_sink( self, stream_name: str, schema_version: str, uri: str, ) -> Sink: """Returns a FileSink that will write Rows as JSON strings with the default bucket assigner and rolling policies. Mostly useful for integration testing. :param stream...
1,252
1285f0a42d67ddb8c2c78411324b6c5b
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=104-108/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
datetime_to_instant(dt: datetime)
function
def datetime_to_instant(dt: datetime) -> Instant: """ Converts a python datetime to a Flink Instant type. """ return Instant(int(dt.timestamp()), dt.microsecond * 1000)
1,253
183a9373d625671838b6bd4ad53a833f
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=430-483/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::kafka_source_builder( self, stream_name: str, bootstrap_servers: str, consumer_group: str, topics: Optional[Sequence[str]] = None, schema_version: Optional[str] = None, )
function
def kafka_source_builder( self, stream_name: str, bootstrap_servers: str, consumer_group: str, topics: Optional[Sequence[str]] = None, schema_version: Optional[str] = None, ) -> KafkaSourceBuilder: """Get a KafkaSourceBuilder that is primed with settings neede...
1,254
14d4ffc8ef46b4a8f301fae5b5fc2a5a
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=111-149/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
convert_pyflink_to_python(value: Any)
function
def convert_pyflink_to_python(value: Any) -> Any: """ Converts PyFlink types to native python types. Most basic types have already been converted to python types by PyFlink. However, there are a few types that eventutilities-python goes a little farther with: * Rows are converted to dicts. ...
1,255
b447007c9da9f6c75fb765b4495182bb
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=485-559/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::kafka_source( self, stream_name: str, bootstrap_servers: str, consumer_group: str, offsets_initializer: Optional[Union[KafkaOffsetsInitializer, int, str]] = None, properties: Optional[Dict[str, str]] = None, topics: Optional[Sequence[str]] ...
function
def kafka_source( self, stream_name: str, bootstrap_servers: str, consumer_group: str, offsets_initializer: Optional[Union[KafkaOffsetsInitializer, int, str]] = None, properties: Optional[Dict[str, str]] = None, topics: Optional[Sequence[str]] = None, sche...
1,256
4082649a976afbc12c73ff8bd429b4b2
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=54-75/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
load_lib_dir( flink_env: StreamExecutionEnvironment, lib_dir: Optional[str] = None, )
function
def load_lib_dir( flink_env: StreamExecutionEnvironment, lib_dir: Optional[str] = None, ) -> None: """Add all jars in lib_dir to flink_env. If lib_dir is not defined, the value of the environment variable EVENTUTILITIES_LIB_DIR will be used. If EVENTUTILITIES_LIB_DIR is not set, jars are expect...
1,257
6296319185ca014a837c133fc1b08d0a
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=294-310/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::get_row_type_info( self, stream_name: str, schema_version: str = "latest", )
function
def get_row_type_info( self, stream_name: str, schema_version: str = "latest", ) -> TypeInformation: """Return the Flink RowTypeInfo for a given stream name and version. :param stream_name: Name of the stream :param schema_version: Version of...
1,258
8836138cc71f5e401f19e377b6e5128a
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=561-617/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::kafka_sink_builder( self, stream_name: str, schema_version: str, bootstrap_servers: str, topic: str, )
function
def kafka_sink_builder( self, stream_name: str, schema_version: str, bootstrap_servers: str, topic: str, ) -> KafkaSinkBuilder: """Prepare a KafkaSinkBuilder with all the required components to produce to kafka using a json format matching the provided schema....
1,259
b28799f53be773c8efb608022c1ecb73
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=78-83/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
get_flink_env(lib_dir: Optional[str] = None)
function
def get_flink_env(lib_dir: Optional[str] = None) -> StreamExecutionEnvironment: """Get a flink StreamExecutionEnvironment with lib_dir loaded.""" env = StreamExecutionEnvironment.get_execution_environment() # Add all jars in lib_dir if it is defined. load_lib_dir(env, lib_dir) return env
1,260
b47e31ceeb8b0ed367978b55b5f259c3
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=312-348/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::file_source( self, stream_name: str, uris: Collection[Union[str, Path]], schema_version: Optional[str] = None, )
function
def file_source( self, stream_name: str, uris: Collection[Union[str, Path]], schema_version: Optional[str] = None, ) -> FileSource: """Gets a FileSource that will deserialize NLJSON files using the stream_descriptor's schema. Note that there is no correspondi...
1,261
4fd715526ee8de09a65d4e054cfdfaf0
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=619-694/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::kafka_sink( self, stream_name: str, schema_version: str, bootstrap_servers: str, topic: str, delivery_guarantee: Optional[Union[DeliveryGuarantee, str]] = None, transactional_id_prefix: Optional[str] = None, properties: Optional[Dic...
function
def kafka_sink( self, stream_name: str, schema_version: str, bootstrap_servers: str, topic: str, delivery_guarantee: Optional[Union[DeliveryGuarantee, str]] = None, transactional_id_prefix: Optional[str] = None, properties: Optional[Dict[str, str]] = None,...
1,262
cd75c7f47dcfc9e4f318bb6860b08805
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=86-93/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
dict_to_properties(d: Dict[str, str])
function
def dict_to_properties(d: Dict[str, str]) -> JavaObject: """ Converts a dict of string -> string key value pairs into java.util.Properties. """ properties = flink_jvm().java.util.Properties() for k, v in d.items(): properties.setProperty(k, str(v)) return properties
1,263
8ae0c27af168b73374896e3d4d85e94c
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=281-286/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::get_event_stream_factory(self)
function
def get_event_stream_factory(self): """Returns the eventutilities-core Java EventStreamFactory instance. We may one day want to provide a python wrapper for this too. """ return self.java_object.getEventStreamFactory()
1,264
4dc3b95bb4cd6118724daf91a2022370
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=50-51/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
flink_jvm()
function
def flink_jvm(): return get_gateway().jvm
1,265
0d55d99d806096e97f07bf4e4e6ef28b
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=96-101/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
instant_to_datetime(instant: Instant)
function
def instant_to_datetime(instant: Instant) -> datetime: """ Converts a Flink Instant type to a Python datetime. """ ts_with_ms = instant.seconds + instant.nanos / 1000000000.0 return datetime.fromtimestamp(ts_with_ms)
1,266
dff541f4ec845a7431948e1ea9444b68
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=288-292/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::stream_exists(self, stream_name: str)
function
def stream_exists(self, stream_name: str) -> bool: """Returns true if the stream is declared in stream config.""" return bool( self.get_event_stream_factory().getEventStreamConfig().streamExists(stream_name) )
1,267
797930f951d48cb183061fd06894bfcb
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=739-798/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::from_source( self, env: StreamExecutionEnvironment, stream_name: str, source: Union[Source, SourceFunction], watermark_strategy: Optional[WatermarkStrategy] = None, source_name: Optional[str] = None, schema_version: str = "latest", )
function
def from_source( self, env: StreamExecutionEnvironment, stream_name: str, source: Union[Source, SourceFunction], watermark_strategy: Optional[WatermarkStrategy] = None, source_name: Optional[str] = None, schema_version: str = "latest", ) -> DataStream: ...
1,268
9a79a2fd688b692a991d01b4b0ebee69
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=381-428/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory::sse_source( self, stream_name: str, uri: str = "https://stream.wikimedia.org/v2/stream", is_wmf_eventstreams_api: bool = True, schema_version: Optional[str] = None, )
function
# Excluded from coverage (for now) as it is difficult to test, and # should only be used for development anyway. def sse_source( self, stream_name: str, uri: str = "https://stream.wikimedia.org/v2/stream", is_wmf_eventstreams_api: bool = True, schema_version: Optional[str...
1,269
3d41a076e8f1bcdb00f07ea628c0fbf0
swh:1:cnt:46d93b023151756c79d0624b6ce7c3957579ec43;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=243-798/
89b61c9aecbbb8809986ec93429d96888172a176
eventutilities-python
analytics
eventutilities_python/flink.py
EventDataStreamFactory
type
class EventDataStreamFactory(JavaObjectWrapper): """A Python wrapper to eventutilities-flink's EventDataStreamFactory.""" @classmethod def of( cls, schema_uris: Union[Sequence[str], str], stream_config_uri: str, http_client_routes: Optional[Dict[str, str]] = None, ) -> "...
1,270
abc71370e4d57fe0908ef0cacc65c63e
swh:1:cnt:d358e809f49fda9b6d7da40e5ed88063a752e8f4;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=21-29/
d9dc098e4fed4148e1a002415343c1a5a7894fe8
eventutilities-python
analytics
eventutilities_python/type_aliases.py
UriAbsolute
type
# Registered with jsonargparse below. class UriAbsolute(str): """Subclass of str for URIs that jsonargparse can deserialize and resolve. Used as a type hint for URI parameters. Registered with jsonargparse to automatically deserialize and resolve incoming URI parameters. """ pass
1,271
d8dcf00d2b44912244f37619c76c12e2
swh:1:cnt:d358e809f49fda9b6d7da40e5ed88063a752e8f4;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=46-49/
d9dc098e4fed4148e1a002415343c1a5a7894fe8
eventutilities-python
analytics
eventutilities_python/type_aliases.py
is_absolute_path(path: str)
function
def is_absolute_path(path: str) -> bool: if path.find("://") > 0: return True return os.path.isabs(path)
1,272
9b7bbee281951e44907e20580a29f265
swh:1:cnt:d358e809f49fda9b6d7da40e5ed88063a752e8f4;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=52-114/
d9dc098e4fed4148e1a002415343c1a5a7894fe8
eventutilities-python
analytics
eventutilities_python/type_aliases.py
resolve_uris( uri: Union[str, NestedStr], relative_to: Optional[Sequence[str]] = None, )
function
# TODO: it would be better to move this method to utils, but utils imports EventDict from # here, causing a circular import. def resolve_uris( uri: Union[str, NestedStr], relative_to: Optional[Sequence[str]] = None, ) -> Union[str, NestedStr]: """Resolves u as an absolute URI. Uses jsonargparse url parsing,...
1,273
a524e3652019ef8982b84b9bf79f9da7
swh:1:cnt:d7918a54988e3dfda72413094d53a247bd64f2f8;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=20-22/
5ce048a82dd726a5565b13f858bd711359080ba3
eventutilities-python
analytics
eventutilities_python/utils.py
format_dt(dt: datetime)
function
def format_dt(dt: datetime) -> str: """Formats dt into an ISO-8601 UTC ('Z') string.""" return dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
1,274
0aea825498d7cebe5c13891735f07068
swh:1:cnt:d7918a54988e3dfda72413094d53a247bd64f2f8;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=30-41/
5ce048a82dd726a5565b13f858bd711359080ba3
eventutilities-python
analytics
eventutilities_python/utils.py
json_default_serializer(obj: Any)
function
def json_default_serializer(obj: Any) -> Any: """A serializer function that handles a few more types that python json serializer doesn't know how to handle. Used when serializing objects to json that have types like datetimes or Flink Instants. """ if isinstance(obj, datetime): return f...
1,275
bf624e8746b532214ac2e9147aa2dcb2
swh:1:cnt:d7918a54988e3dfda72413094d53a247bd64f2f8;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=57-66/
5ce048a82dd726a5565b13f858bd711359080ba3
eventutilities-python
analytics
eventutilities_python/utils.py
get_memory_usage_of(mem_info_key: str)
function
def get_memory_usage_of(mem_info_key: str) -> int: """Calls psutil.Process().memory_full_info() and returns the memory usage bytes value for mem_info_key. :param mem_info_key: See https://psutil.readthedocs.io/en/latest/#psutil.Process.memory_full_info :param mem_info_key: See https://psutil.re...
1,276
317532fc4cb04cada3f97684fe7543d9
swh:1:cnt:d7918a54988e3dfda72413094d53a247bd64f2f8;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=14-17/
5ce048a82dd726a5565b13f858bd711359080ba3
eventutilities-python
analytics
eventutilities_python/utils.py
find_lib_jars(lib_dir: str)
function
def find_lib_jars(lib_dir: str) -> Collection[str]: """Returns a list of file:// prefixed .jar file paths in the directory.""" pattern = os.path.join(lib_dir, "*.jar") return ["file://" + jar for jar in glob.glob(pattern)]
1,277
edcd067212344b4b147a8024a066754f
swh:1:cnt:d7918a54988e3dfda72413094d53a247bd64f2f8;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=25-27/
5ce048a82dd726a5565b13f858bd711359080ba3
eventutilities-python
analytics
eventutilities_python/utils.py
flink_instant_of_datetime(dt: datetime)
function
def flink_instant_of_datetime(dt: datetime) -> Instant: """Converts a python datetime to a PyFlink Instant.""" return Instant.of_epoch_milli(int(dt.timestamp()) * 1000)
1,278
8b1dc5fa9a0454c42d3954fef0408c19
swh:1:cnt:d7918a54988e3dfda72413094d53a247bd64f2f8;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=44-54/
5ce048a82dd726a5565b13f858bd711359080ba3
eventutilities-python
analytics
eventutilities_python/utils.py
callable_repr(func: Callable[..., Any])
function
def callable_repr(func: Callable[..., Any]) -> str: """Given a callable, returns a nice description string using its name, file and lineno, if available.""" desc = getattr(func, "__name__", repr(func)) code = getattr(func, "__code__", None) if code: file = code.co_filename lineno = ...
1,279
cc3f3d9ee2cab09ff75967a6bd2671bd
swh:1:cnt:d7918a54988e3dfda72413094d53a247bd64f2f8;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=69-89/
5ce048a82dd726a5565b13f858bd711359080ba3
eventutilities-python
analytics
eventutilities_python/utils.py
setup_logging( config_dict: Optional[Dict[Any, Any]] = None, level: str = "INFO", )
function
def setup_logging( config_dict: Optional[Dict[Any, Any]] = None, level: str = "INFO", ) -> None: """Sets up python logging either from a log config file or using basicConfig. :param config_dict: Setup logging from a config dict. If not set, then basicConfig will be used. :param level: b...
1,280
2c6c4553c02b9154dd84c1bf7f1e6bf1
swh:1:cnt:d7918a54988e3dfda72413094d53a247bd64f2f8;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=93-100/
5ce048a82dd726a5565b13f858bd711359080ba3
eventutilities-python
analytics
eventutilities_python/utils.py
JavaObjectWrapper
type
class JavaObjectWrapper(object): """A wrapper class that maintains an object implemented in Java via py4j. Based on pyflink's JavaFunctionWrapper. """ java_object: JavaObject """The underlying py4j JavaObject."""
1,281
29933a02a6aedcb37919daf1b71c91d9
swh:1:cnt:296d1eb0355a828514aa0276054eb048849d30d2;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=10-14/
ed39621c4d8cdf47144d2efd20342de5e313b784
eventutilities-python
analytics
eventutilities_python/__init__.py
get_version()
function
def get_version() -> str: try: return importlib_metadata.version(__name__) except importlib_metadata.PackageNotFoundError: # pragma: no cover return "unknown"
1,282
b55b0b789914beb12c9b2834361081a9
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=24-90/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
EventStreamDescriptor
type
class EventStreamDescriptor: """ Source and sink streams have an associated event version. Example: >>> stream = EventStreamDescriptor(name="test.event.stream", version="1.1.0") >>> stream.name, stream.version """ name: str version: Optional[str] = "latest" def __str__(sel...
1,283
ed6cbecb4aa57f090a9d919b7490c18b
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=135-229/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
SourceDescriptor
type
class SourceDescriptor(ConnectorDescriptor): supported_connectors: ClassVar[List[str]] = ["file", "collection", "kafka", "sse"] def source(self, datastream_factory: EventDataStreamFactory) -> Union[Source, SourceFunction]: """Instantiates a Flink Source. :param datastream_factory: ...
1,284
3cb0d6e4558aeb58b5aea79e3685f100
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=94-131/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
ConnectorDescriptor
type
class ConnectorDescriptor: supported_connectors: ClassVar[List[str]] = [] """List of supported connectors. These will be checked before instantiating a concrete Connector (Source or Sink). """ connector: str """A supported connector name, e.g. "file" or "kafka".""" stream: str """...
1,285
7a6ccbaf9ef1ded70bd5e4585e75b593
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=233-352/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
SinkDescriptor
type
class SinkDescriptor(ConnectorDescriptor): supported_connectors: ClassVar[List[str]] = ["null", "file", "kafka", "print"] """ Note: "null" is a special case, and not a real sink. It causes both sink and sink_to to return None. """ def __post_init__(self): """If connector is kafka, one o...
1,286
45f5aae438b4e998c80896553e9d9727
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=240-255/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
SinkDescriptor::__post_init__(self)
function
def __post_init__(self): """If connector is kafka, one of "topic" or "kafka_topic_prefix" is required in options. If topic is not given, "kafka_topic_prefix" will be used to create the "topic" like kafka_topic_prefix + stream_descriptor.name """ super().__post_in...
1,287
8c3d1f83a5f4132154f34c3415d93721
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=36-37/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
EventStreamDescriptor::__str__(self)
function
def __str__(self): return f"{self.name}:{self.version}"
1,288
ebeb91fafa64e6cd913b4ffdd07600c4
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=66-90/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
EventStreamDescriptor::from_string( stream_name: str, )
function
def from_string( stream_name: str, ) -> Any: # TODO: how do we annotate a static method? """A factory method that parses `stream_name` and returns an instance of EventStream. Example: >>> stream = EventStreamDescriptor.from_string("test.event.stream:1.1.0") ...
1,289
dbc971de549a1db3c70f56d630a6c89b
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=121-128/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
ConnectorDescriptor::__post_init__(self)
function
def __post_init__(self): self.stream_descriptor = EventStreamDescriptor.from_string(self.stream) self.name = self.name or f"{self.connector}__{self.stream_descriptor.name}" assert self.connector in self.supported_connectors, ( f"{self.stream_descriptor} connector '{self.connector}' ...
1,290
20a83288fdbde6c7e6a27cf48c46f289
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=40-58/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
EventStreamDescriptor::is_valid_stream_name(stream_name)
function
def is_valid_stream_name(stream_name): """Check if `stream_name` contains invalid characters. This method should be invoked every time we generate a stream name from the library (e.g. error_stream auto-detection). Stream name validation should not be enabled by default on all streams: ...
1,291
6ba1f35415600ca1474f068deae991c2
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=60-63/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
EventStreamDescriptor::is_version_pinned(self)
function
def is_version_pinned(self) -> bool: # This expression has type Union[str, None, bool]. # Ignore type checking and coerce to bool return self.version and not self.version == "latest" # type: ignore
1,292
1365bdd53a455a4a8c2141d809967ad1
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=130-131/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
ConnectorDescriptor::__str__(self)
function
def __str__(self): return f"{self.name}"
1,293
2afd438a32c9383761cbe526df5e0321
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=138-173/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
SourceDescriptor::source(self, datastream_factory: EventDataStreamFactory)
function
def source(self, datastream_factory: EventDataStreamFactory) -> Union[Source, SourceFunction]: """Instantiates a Flink Source. :param datastream_factory: An EventDataStreamFactory that will be used to create the Flink source using this SourceDescriptor. """ if s...
1,294
f8e9b6fe4aded9449d7ffabc4a8832f7
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=175-229/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
SourceDescriptor::datastream( self, env: StreamExecutionEnvironment, datastream_factory: EventDataStreamFactory, watermark_strategy: Optional[WatermarkStrategy] = None, convert_to_native_python: bool = True, )
function
def datastream( self, env: StreamExecutionEnvironment, datastream_factory: EventDataStreamFactory, watermark_strategy: Optional[WatermarkStrategy] = None, convert_to_native_python: bool = True, ) -> DataStream: """Instantiates a Flink DataStream reading from source. ...
1,295
f3a737c974363ce5d6ea03535fb65c73
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=257-295/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
SinkDescriptor::sink( self, datastream_factory: EventDataStreamFactory )
function
def sink( self, datastream_factory: EventDataStreamFactory ) -> Optional[Union[Sink, SinkFunction]]: """Instantiates a Flink Sink. :param datastream_factory: An EventDataStreamFactory that will be used to create the Flink source using the SourceDe...
1,296
6a9b89a28f24d539862a898dfd3eeca5
swh:1:cnt:559b5d1c7de45dba6552fb929a9b8ca09176acb5;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=297-352/
0e4983d2c001b5dc0fd7f0a4e8daaf4a4b53981b
eventutilities-python
analytics
eventutilities_python/stream/descriptor.py
SinkDescriptor::sink_to( self, datastream_factory: EventDataStreamFactory, datastream: DataStream, convert_to_pyflink: bool = True, )
function
def sink_to( self, datastream_factory: EventDataStreamFactory, datastream: DataStream, convert_to_pyflink: bool = True, ) -> Optional[DataStreamSink]: """Instantiates a Flink Sink and sinks the datastream to it. :param datastream_factory: An EventDataStre...
1,297
3901e103f6fbf55433e569632b9b1a00
swh:1:cnt:1b0410edbeedb0fa7dcf78654da2f4260186e260;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=16-96/
10ec3718e46ffbef823f80d51614ca6c378daa2f
eventutilities-python
analytics
eventutilities_python/stream/error.py
create_error_event( error: Union[Exception, str], emitter_id: str, error_dt: Union[datetime, str, Instant], error_stream_name: Optional[str] = None, errored_event: Optional[Union[Dict[str, Any], str]] = None, )
function
def create_error_event( error: Union[Exception, str], emitter_id: str, error_dt: Union[datetime, str, Instant], error_stream_name: Optional[str] = None, errored_event: Optional[Union[Dict[str, Any], str]] = None, ) -> Dict[str, Any]: """An error that can be serialized into a WMF error event. ...
1,298
7024cba045bb919279b6375ef3b29397
swh:1:cnt:8757d5a62950e91c090d1957556892e3d7193053;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=13-61/
5eccad71aaf57ef31da4140ea9a3cef176fe73a0
eventutilities-python
analytics
eventutilities_python/stream/functions.py
http_process_function( max_retries: int = 3, retry_backoff_factor: float = 0.1, retry_status_forcelist: Optional[List[int]] = None, pool_maxsize: int = 1, )
function
def http_process_function( max_retries: int = 3, retry_backoff_factor: float = 0.1, retry_status_forcelist: Optional[List[int]] = None, pool_maxsize: int = 1, ) -> Callable[..., Any]: """Decorator that wraps a function and handles instantiation of a requests Session object, with a retry policy a...
1,299
32fb3aec6f6c6f5728d69997649ad430
swh:1:cnt:8757d5a62950e91c090d1957556892e3d7193053;origin=https://gitlab.wikimedia.org/repos/data-engineering/eventutilities-python.git;lines=45-59/
5eccad71aaf57ef31da4140ea9a3cef176fe73a0
eventutilities-python
analytics
eventutilities_python/stream/functions.py
http_process_function::decorator(func)
function
def decorator(func): @wraps(func) def wrapper(): http_session = requests.Session() retries = Retry( total=max_retries, backoff_factor=retry_backoff_factor, status_forcelist=retry_status_forcelist, ) adapter =...