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,800 | e0e2018f8b9940e91c590458c2a674a3 | swh:1:cnt:c2fdaf91a5458a1132c92710f5ef4643c9345011;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery.git;lines=127-134/ | 221299ea44e93b1a5f9761515ae36a636ef81c1f | refinery | analytics | jobs/python/kafka_to_iceberg/active_reader_baseline/kafka_to_iceberg_active_reader_baseline/process_active_reader_baseline.py | get_job(parsed_stream, checkpoint=None) | function | def get_job(parsed_stream, checkpoint=None):
return (
parsed_stream.writeStream
.option('checkpointLocation', checkpoint)
.outputMode('append')
.foreachBatch(process_batch)
.trigger(availableNow=True)
) |
1,801 | 91e4c5bec00acb9f851ff1bfcf653abc | swh:1:cnt:c2fdaf91a5458a1132c92710f5ef4643c9345011;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery.git;lines=156-165/ | 221299ea44e93b1a5f9761515ae36a636ef81c1f | refinery | analytics | jobs/python/kafka_to_iceberg/active_reader_baseline/kafka_to_iceberg_active_reader_baseline/process_active_reader_baseline.py | test_run() | function | def test_run():
args = parse_args([
'--kafka_bootstrap', 'kafka-jumbo1011.eqiad.wmnet:9092',
'--kafka_topic', 'product_metrics.web_base.active_reader_baseline',
'--destination_table', 'tchin.test_kafka_to_iceberg',
'--max_minutes', '1',
'--max_offsets_per_trigger', '10000',
... |
1,802 | c7fb6d86fb8e982098db2d03bfdd82ec | swh:1:cnt:c2fdaf91a5458a1132c92710f5ef4643c9345011;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery.git;lines=79-104/ | 221299ea44e93b1a5f9761515ae36a636ef81c1f | refinery | analytics | jobs/python/kafka_to_iceberg/active_reader_baseline/kafka_to_iceberg_active_reader_baseline/process_active_reader_baseline.py | process_batch(df, batch_id) | function | # do the actual processing
def process_batch(df, batch_id):
df.createOrReplaceTempView("active_reader_baseline_events")
spark = df.sparkSession
# transform the batch
spark.sql("""
SELECT DISTINCT
CAST(CAST(dt AS TIMESTAMP) AS DATE) AS event_date,
action_context AS hashed_user_id,
... |
1,803 | fa05b754c1acb08a5a8b0d4d3aa80859 | swh:1:cnt:b443f7a30cbdcdf13740ef2223b6fd33d83fcc29;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery.git;lines=31-53/ | 8983c43c7f7f407c6ae592ba5d89ecdfe0ce0e2d | refinery | analytics | jobs/python/kafka_to_iceberg/attribution/kafka_to_iceberg_attribution/process_attribution.py | parse_args(args) | function | def parse_args(args) -> argparse.Namespace:
parser = argparse.ArgumentParser(
description='consume product_metrics.web_base events from Kafka, transform, then write to Iceberg'
)
parser.add_argument('--kafka_bootstrap', help='Kafka broker (like kafka-jumbo1010.eqiad.wmnet:9092)')
parser.add_argu... |
1,804 | 9da783e717198917efb6bf1f8bf90e3a | swh:1:cnt:b443f7a30cbdcdf13740ef2223b6fd33d83fcc29;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery.git;lines=87-88/ | 8983c43c7f7f407c6ae592ba5d89ecdfe0ce0e2d | refinery | analytics | jobs/python/kafka_to_iceberg/attribution/kafka_to_iceberg_attribution/process_attribution.py | main() | function | def main() -> None:
run(parse_args(sys.argv[1:])) |
1,805 | 475d72f9e429b9841e7865ad34d419d9 | swh:1:cnt:b443f7a30cbdcdf13740ef2223b6fd33d83fcc29;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery.git;lines=142-170/ | 8983c43c7f7f407c6ae592ba5d89ecdfe0ce0e2d | refinery | analytics | jobs/python/kafka_to_iceberg/attribution/kafka_to_iceberg_attribution/process_attribution.py | get_stream(spark, kafka_bootstrap, kafka_topic, max_offsets_per_trigger) | function | def get_stream(spark, kafka_bootstrap, kafka_topic, max_offsets_per_trigger):
return (
spark.readStream
.format('kafka')
.option('kafka.bootstrap.servers', kafka_bootstrap)
.option('subscribe', f'eqiad.{kafka_topic},codfw.{kafka_topic}')
.option('startingOffse... |
1,806 | b2a12c39f8a68c0a807fae87f6bab06b | swh:1:cnt:b443f7a30cbdcdf13740ef2223b6fd33d83fcc29;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery.git;lines=182-208/ | 8983c43c7f7f407c6ae592ba5d89ecdfe0ce0e2d | refinery | analytics | jobs/python/kafka_to_iceberg/attribution/kafka_to_iceberg_attribution/process_attribution.py | create_output_table(destination_table) | function | def create_output_table(destination_table):
spark.sql("""
CREATE TABLE IF NOT EXISTS {destination_table} (
id string COMMENT 'unique id for event request meta.id',
dt timestamp COMMENT 'meta.dt converted to timestamp, truncated to hour',
database... |
1,807 | 3e59e7ed3583dee44d519cc3dcb798bb | swh:1:cnt:b443f7a30cbdcdf13740ef2223b6fd33d83fcc29;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery.git;lines=55-85/ | 8983c43c7f7f407c6ae592ba5d89ecdfe0ce0e2d | refinery | analytics | jobs/python/kafka_to_iceberg/attribution/kafka_to_iceberg_attribution/process_attribution.py | run(args: argparse.Namespace) | function | def run(args: argparse.Namespace) -> None:
# needed in foreachBatch callback, no easy way to pass
global destination_table
global top_pages_table
global namespaces_table
spark = SparkSession.builder.getOrCreate()
spark.sparkContext.setLogLevel("WARN")
destination_table = args.destination_t... |
1,808 | e0e2018f8b9940e91c590458c2a674a3 | swh:1:cnt:b443f7a30cbdcdf13740ef2223b6fd33d83fcc29;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery.git;lines=172-179/ | 8983c43c7f7f407c6ae592ba5d89ecdfe0ce0e2d | refinery | analytics | jobs/python/kafka_to_iceberg/attribution/kafka_to_iceberg_attribution/process_attribution.py | get_job(parsed_stream, checkpoint=None) | function | def get_job(parsed_stream, checkpoint=None):
return (
parsed_stream.writeStream
.option('checkpointLocation', checkpoint)
.outputMode('append')
.foreachBatch(process_batch)
.trigger(availableNow=True)
) |
1,809 | 55d55af901c4fff6412bca6bc8916534 | swh:1:cnt:b443f7a30cbdcdf13740ef2223b6fd33d83fcc29;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery.git;lines=210-219/ | 8983c43c7f7f407c6ae592ba5d89ecdfe0ce0e2d | refinery | analytics | jobs/python/kafka_to_iceberg/attribution/kafka_to_iceberg_attribution/process_attribution.py | test_run() | function | def test_run():
args = parse_args([
'--kafka_bootstrap', 'kafka-jumbo1011.eqiad.wmnet:9092',
'--kafka_topic', 'product_metrics.web_base.attribution_research',
'--destination_table', 'milimetric.test_kafka_to_iceberg',
'--max_minutes', '1',
'--max_offsets_per_trigger', '10000'... |
1,810 | b02702fdba4c692a06be3e97c08ac10e | swh:1:cnt:b443f7a30cbdcdf13740ef2223b6fd33d83fcc29;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery.git;lines=90-140/ | 8983c43c7f7f407c6ae592ba5d89ecdfe0ce0e2d | refinery | analytics | jobs/python/kafka_to_iceberg/attribution/kafka_to_iceberg_attribution/process_attribution.py | process_batch(df, batch_id) | function | # do the actual processing
def process_batch(df, batch_id):
df.createOrReplaceTempView("attribution_events")
spark = df.sparkSession
spark.sql("""
CREATE OR REPLACE TEMPORARY FUNCTION get_referer_data AS 'org.wikimedia.analytics.refinery.hive.GetRefererDataUDF';
""")
# transform the batch
... |
1,811 | 223370337c91d7128dfcb6c1e451628d | swh:1:cnt:9a217c60e42aa7672ba32ba1f4ca9422976581f5;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=18-236/ | b0b478179aa5663d27347ac695218377f21e9ca0 | presto-query-logger | analytics | src/main/java/org/wikimedia/presto/QueryEventListener.java | QueryEventListener | type | /**
* Log Presto queries to a file.
*
*/
@SuppressWarnings({ "checkstyle:IllegalCatch" })
public class QueryEventListener implements EventListener {
Logger logger;
FileHandler fh;
final String loggerName = "QueryLog";
public QueryEventListener() {
createLogFile();
}
public Que... |
1,812 | 296398694e51e392e1a395363dde612b | swh:1:cnt:9a217c60e42aa7672ba32ba1f4ca9422976581f5;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=43-104/ | b0b478179aa5663d27347ac695218377f21e9ca0 | presto-query-logger | analytics | src/main/java/org/wikimedia/presto/QueryEventListener.java | QueryEventListener::queryCreated(QueryCreatedEvent queryCreatedEvent) | function | public void queryCreated(QueryCreatedEvent queryCreatedEvent) {
StringBuilder msg = new StringBuilder();
try {
msg.append("---------------Query Created----------------------------");
msg.append("\n");
msg.append(" ");
msg.append("Query ID: ");
... |
1,813 | f03eebb4f8bf7227725192239208e88c | swh:1:cnt:9a217c60e42aa7672ba32ba1f4ca9422976581f5;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=106-186/ | b0b478179aa5663d27347ac695218377f21e9ca0 | presto-query-logger | analytics | src/main/java/org/wikimedia/presto/QueryEventListener.java | QueryEventListener::queryCompleted(QueryCompletedEvent queryCompletedEvent) | function | public void queryCompleted(QueryCompletedEvent queryCompletedEvent) {
String errorCode = null;
StringBuilder msg = new StringBuilder();
try {
errorCode = queryCompletedEvent.getFailureInfo().get().getErrorCode().getName().toString();
} catch (NoSuchElementException noElEx) ... |
1,814 | 0cba6961542164714c3d28102682e9ef | swh:1:cnt:9a217c60e42aa7672ba32ba1f4ca9422976581f5;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=215-235/ | b0b478179aa5663d27347ac695218377f21e9ca0 | presto-query-logger | analytics | src/main/java/org/wikimedia/presto/QueryEventListener.java | QueryEventListener::createLogFile() | function | public void createLogFile() {
SimpleDateFormat dateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT);
String timeStamp = dateTime.format(new Date());
StringBuilder logPath = new StringBuilder();
logPath.append("/var/log/presto/queries-");
logPath.append(timeStam... |
1,815 | b0024fb7d3438dc8395734fda46a624b | swh:1:cnt:9a217c60e42aa7672ba32ba1f4ca9422976581f5;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=188-213/ | b0b478179aa5663d27347ac695218377f21e9ca0 | presto-query-logger | analytics | src/main/java/org/wikimedia/presto/QueryEventListener.java | QueryEventListener::splitCompleted(SplitCompletedEvent splitCompletedEvent) | function | public void splitCompleted(SplitCompletedEvent splitCompletedEvent) {
StringBuilder msg = new StringBuilder();
try {
msg.append("---------------Split Completed----------------------------");
msg.append("\n");
msg.append(" ");
msg.append("Query ID: ")... |
1,816 | 14e18da44874e3fa8281fbd7f559b2a8 | swh:1:cnt:ee34adcf46300d0dc26b413af1970935fdd45357;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=8-16/ | 2911f458611b80264eb75f4115e326692a06ffeb | presto-query-logger | analytics | src/main/java/org/wikimedia/presto/QueryEventListenerFactory.java | QueryEventListenerFactory | type | public class QueryEventListenerFactory implements EventListenerFactory {
public String getName() {
return "event-listener";
}
public EventListener create(Map<String, String> config) {
return new QueryEventListener(config);
}
} |
1,817 | c126d0913282a4547c7323096428b58d | swh:1:cnt:ee34adcf46300d0dc26b413af1970935fdd45357;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=9-11/ | 2911f458611b80264eb75f4115e326692a06ffeb | presto-query-logger | analytics | src/main/java/org/wikimedia/presto/QueryEventListenerFactory.java | QueryEventListenerFactory::getName() | function | public String getName() {
return "event-listener";
} |
1,818 | 2815be9e99570934ea914eda51e55214 | swh:1:cnt:ee34adcf46300d0dc26b413af1970935fdd45357;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=13-15/ | 2911f458611b80264eb75f4115e326692a06ffeb | presto-query-logger | analytics | src/main/java/org/wikimedia/presto/QueryEventListenerFactory.java | QueryEventListenerFactory::create(Map<String, String> config) | function | public EventListener create(Map<String, String> config) {
return new QueryEventListener(config);
} |
1,819 | d3e1cc94e61588f5011215a1b8ff4f8a | swh:1:cnt:6281b81f9b0f1cfd218f0407347e47d05699bd2a;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=10-21/ | 8d126b3c69f5529d56692b239305bb78a400674e | presto-query-logger | analytics | src/main/java/org/wikimedia/presto/QueryEventListenerPlugin.java | QueryEventListenerPlugin | type | public class QueryEventListenerPlugin implements Plugin {
public Iterable<EventListenerFactory> getEventListenerFactories() {
EventListenerFactory listenerFactory = new QueryEventListenerFactory();
List<EventListenerFactory> listenerFactoryList = new ArrayList<EventListenerFactory>();
liste... |
1,820 | c6a50d45e96f476bd34ce85a4e917f05 | swh:1:cnt:6281b81f9b0f1cfd218f0407347e47d05699bd2a;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=12-20/ | 8d126b3c69f5529d56692b239305bb78a400674e | presto-query-logger | analytics | src/main/java/org/wikimedia/presto/QueryEventListenerPlugin.java | QueryEventListenerPlugin::getEventListenerFactories() | function | public Iterable<EventListenerFactory> getEventListenerFactories() {
EventListenerFactory listenerFactory = new QueryEventListenerFactory();
List<EventListenerFactory> listenerFactoryList = new ArrayList<EventListenerFactory>();
listenerFactoryList.add(listenerFactory);
List<EventListener... |
1,821 | c8bd62d98304f0c4fb74164a7d0a4c32 | swh:1:cnt:ff773c9dd08817677b69b550c8bb78ae05bfbe5f;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=7-18/ | 54b9481a1230cee65dcca8e4cacc0afa93fd07fd | presto-query-logger | analytics | src/test/java/org/wikimedia/presto/AppTest.java | AppTest | type | /**
* TODO.
*/
public class AppTest {
/**
* TODO.
*/
@Test
public void shouldAnswerWithTrue() {
assertTrue(true);
}
} |
1,822 | dcfc72daefb192058555c6ac8a5efba9 | swh:1:cnt:ff773c9dd08817677b69b550c8bb78ae05bfbe5f;origin=https://gitlab.wikimedia.org/repos/data-engineering/presto-query-logger.git;lines=11-17/ | 54b9481a1230cee65dcca8e4cacc0afa93fd07fd | presto-query-logger | analytics | src/test/java/org/wikimedia/presto/AppTest.java | AppTest::shouldAnswerWithTrue() | function | /**
* TODO.
*/
@Test
public void shouldAnswerWithTrue() {
assertTrue(true);
} |
1,823 | 14aa5e791a93dec6e95c56e3403e6410 | swh:1:cnt:4311577a480bb865336b1981461d228cd1ac4fa6;origin=https://gitlab.wikimedia.org/repos/data-engineering/schemas-event-secondary.git;lines=8-36/ | 0802c4dc3a71a206b10489123e6e33b2965a8929 | schemas-event-secondary | analytics | scripts/eventlogging_legacy_schema_convert.js | convertDraft4RequiredProperties | function | /**
* Recurses through schema converting Draft 4 JSONSchema style
* required to Draft 7.
* @param {Object} schema
* @return {Object}
*/
function convertDraft4RequiredProperties( schema ) {
if ('properties' in schema) {
const required = [];
for (const [propertyName, property] of Object.entrie... |
1,824 | d4b1b0291c08b2ef50c88ad9c7ee3ea4 | swh:1:cnt:4311577a480bb865336b1981461d228cd1ac4fa6;origin=https://gitlab.wikimedia.org/repos/data-engineering/schemas-event-secondary.git;lines=52-54/ | 0802c4dc3a71a206b10489123e6e33b2965a8929 | schemas-event-secondary | analytics | scripts/eventlogging_legacy_schema_convert.js | eventLoggingSchemaNameToFileUri | function | function eventLoggingSchemaNameToFileUri(schemaName, filename) {
return '/' + eventLoggingSchemaNameToTitle(schemaName) + `/${filename}`;
} |
1,825 | 8ccb19634a0b2415e8ca7f597e94c3a2 | swh:1:cnt:4311577a480bb865336b1981461d228cd1ac4fa6;origin=https://gitlab.wikimedia.org/repos/data-engineering/schemas-event-secondary.git;lines=38-43/ | 0802c4dc3a71a206b10489123e6e33b2965a8929 | schemas-event-secondary | analytics | scripts/eventlogging_legacy_schema_convert.js | eventLoggingSchemaNameToMetaUrl | function | /**
* Gets URL from which to request the EventLogging metawiki event schema.
*/
function eventLoggingSchemaNameToMetaUrl(schemaName) {
return `https://meta.wikimedia.org/w/api.php?action=jsonschema&format=json&formatversion=2&title=${schemaName}`;
} |
1,826 | 007a8c96a37b75440a38e1ac110cf59e | swh:1:cnt:4311577a480bb865336b1981461d228cd1ac4fa6;origin=https://gitlab.wikimedia.org/repos/data-engineering/schemas-event-secondary.git;lines=57-69/ | 0802c4dc3a71a206b10489123e6e33b2965a8929 | schemas-event-secondary | analytics | scripts/eventlogging_legacy_schema_convert.js | getEventLoggingSchema | function | /**
* Gets the EventLogging legacy event schema from metawiki.
*/
async function getEventLoggingSchema(schemaName) {
const schemaUrl = eventLoggingSchemaNameToMetaUrl(schemaName);
const response = await fetch(schemaUrl);
if (response.ok) {
return response.json();
} else {
throw new Er... |
1,827 | e03e9fc9318b6113f4ee71a81f15526f | swh:1:cnt:4311577a480bb865336b1981461d228cd1ac4fa6;origin=https://gitlab.wikimedia.org/repos/data-engineering/schemas-event-secondary.git;lines=45-50/ | 0802c4dc3a71a206b10489123e6e33b2965a8929 | schemas-event-secondary | analytics | scripts/eventlogging_legacy_schema_convert.js | eventLoggingSchemaNameToTitle | function | /**
* Converts an EventLogging legacy metawiki SchemaName to a schema title.
*/
function eventLoggingSchemaNameToTitle(schemaName) {
return `analytics/legacy/${schemaName.toLowerCase()}`;
} |
1,828 | 31236a41ebbacf13bd22aa40d2995dba | swh:1:cnt:4311577a480bb865336b1981461d228cd1ac4fa6;origin=https://gitlab.wikimedia.org/repos/data-engineering/schemas-event-secondary.git;lines=96-130/ | 0802c4dc3a71a206b10489123e6e33b2965a8929 | schemas-event-secondary | analytics | scripts/eventlogging_legacy_schema_convert.js | convertEventLoggingSchema | function | /**
* Converts a metawiki legacy EventLogging schema to an Event Platform formatted schema.
* The examples will need to be manually filled in.
*/
async function convertEventLoggingSchema(schemaName) {
const eventSubSchema = await getEventLoggingSchema(schemaName);
let newSchema = Object.assign({}, legacySch... |
1,829 | 1250afb1beaa65c6396840db45b442f5 | swh:1:cnt:4311577a480bb865336b1981461d228cd1ac4fa6;origin=https://gitlab.wikimedia.org/repos/data-engineering/schemas-event-secondary.git;lines=136-150/ | 0802c4dc3a71a206b10489123e6e33b2965a8929 | schemas-event-secondary | analytics | scripts/eventlogging_legacy_schema_convert.js | main | function | async function main(args) {
if (args.length <= 0 || args[0] == 'help' || args[0].includes('--')) {
console.error(`Must provide SchemaName\n${usage}\n`);
process.exit(1);
}
const schemaName = args[0];
try {
const s = await convertEventLoggingSchema(schemaName);
console.lo... |
1,830 | 3a32a07e840a2e56086a052de3ce2269 | swh:1:cnt:e1da7e59d44bc1515a9385b0a45b48a4b97c70db;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=12-26/ | f86a27c14bdc5ecc9ba3a9c409bcbbc2676ca014 | refinery-deequ-python | analytics | conftest.py | spark(spark_session: SparkSession) | function | def spark(spark_session: SparkSession):
"""
A pytest yield finalizer to make sure
pydeequ does not leave any spark / py4j process runnng.
Wraps the `spark_session` fixture provided by the pytest-spark
package.
:param spark_session:
:return:
"""
yield spark_session
spark_sessio... |
1,831 | dfae6f5978d188ff504781f0d3f6802b | swh:1:cnt:e1da7e59d44bc1515a9385b0a45b48a4b97c70db;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=29-42/ | f86a27c14bdc5ecc9ba3a9c409bcbbc2676ca014 | refinery-deequ-python | analytics | conftest.py | partition(spark: SparkSession) | function | def partition(spark: SparkSession):
return HivePartition(
spark,
"wmf",
"webrequest",
None,
{
"source_key": "testDataset",
"year": "2023",
"month": "11",
"day": "7",
"hour": "0",
},
) |
1,832 | 8e4b1fc6a8faa724a1e9d821d14a95c6 | swh:1:cnt:e1da7e59d44bc1515a9385b0a45b48a4b97c70db;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=46-49/ | f86a27c14bdc5ecc9ba3a9c409bcbbc2676ca014 | refinery-deequ-python | analytics | conftest.py | data(spark: SparkSession) | function | def data(spark: SparkSession):
return spark.sparkContext.parallelize(
[Row(a="foo", b=1, c=5), Row(a="bar", b=2, c=6), Row(a="baz", b=3, c=None)]
).toDF() |
1,833 | 06ed6715d1aca62d86f7e14844010598 | swh:1:cnt:0bb30358d052e808448dc4051274203a13924144;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=9-44/ | 15e2e2792f66a3d80f21a81d14628b19aedd76f2 | refinery-deequ-python | analytics | refinery_deequ_python/dataset.py | HivePartition | type | class HivePartition:
"""
Represents a partition in a Hive table.
Parameters:
spark (SparkSession): The Spark session.
database (str): The name of the Hive database.
table (str): The name of the Hive table.
location (Optional[str], optional): The location of the partition. De... |
1,834 | ec6a0aed066d7be360332f1bf2056a10 | swh:1:cnt:0bb30358d052e808448dc4051274203a13924144;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=30-44/ | 15e2e2792f66a3d80f21a81d14628b19aedd76f2 | refinery-deequ-python | analytics | refinery_deequ_python/dataset.py | HivePartition::__new__(
cls,
spark: SparkSession,
database: str,
table: str,
location: Optional[str] = None,
partitions: Optional[Dict[str, str]] = None,
) | function | def __new__(
cls,
spark: SparkSession,
database: str,
table: str,
location: Optional[str] = None,
partitions: Optional[Dict[str, str]] = None,
) -> "HivePartition":
java = PythonUtils(spark)
j_HivePartition: JavaClass = (
java.jvm.org.wikim... |
1,835 | dddd555c7b33d8784ecb85904a80de87 | swh:1:cnt:a78293d7159c9a0d342666b774d6d87ff7bb83e4;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=10-51/ | 3dc57c4c09851cfac27f307c6a5da2c7f4fe2d3c | refinery-deequ-python | analytics | refinery_deequ_python/dq.py | DeequAnalyzersToDataQualityMetrics | type | class DeequAnalyzersToDataQualityMetrics:
"""
Converts Deequ analyzers result to data quality metrics.
Parameters:
spark (SparkSession): The Spark session that holds a py4j gateway.
repository (pydeequ.repository.MetricsRepository): A repository containing deequ metrics.
partition (... |
1,836 | 92053689567e02f5b17126e0ec640e6d | swh:1:cnt:a78293d7159c9a0d342666b774d6d87ff7bb83e4;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=54-101/ | 3dc57c4c09851cfac27f307c6a5da2c7f4fe2d3c | refinery-deequ-python | analytics | refinery_deequ_python/dq.py | DeequVerificationSuiteToDataQualityAlerts | type | class DeequVerificationSuiteToDataQualityAlerts:
"""
Converts Deequ analyzers result to data quality metrics.
Parameters:
spark (SparkSession): The Spark session that holds a py4j gateway.
verification_suite (JavaObject): The result of Deequ constraint checker.
partition (JavaObject... |
1,837 | 9d7968803a376d772e01c883850553a7 | swh:1:cnt:a78293d7159c9a0d342666b774d6d87ff7bb83e4;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=30-51/ | 3dc57c4c09851cfac27f307c6a5da2c7f4fe2d3c | refinery-deequ-python | analytics | refinery_deequ_python/dq.py | DeequAnalyzersToDataQualityMetrics::__new__(
cls,
spark: SparkSession,
repository: MetricsRepository,
partition: JavaObject,
run_id: str,
) | function | def __new__(
cls,
spark: SparkSession,
repository: MetricsRepository,
partition: JavaObject,
run_id: str,
) -> "DeequAnalyzersToDataQualityMetrics":
java = PythonUtils(spark)
j_DeequAnalyzersToDataQualityMetrics = (
java.jvm.org.wikimedia.analytics... |
1,838 | 35330c1a3cfffdd8d525d6433ce4408c | swh:1:cnt:a78293d7159c9a0d342666b774d6d87ff7bb83e4;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=74-101/ | 3dc57c4c09851cfac27f307c6a5da2c7f4fe2d3c | refinery-deequ-python | analytics | refinery_deequ_python/dq.py | DeequVerificationSuiteToDataQualityAlerts::__new__(
cls,
spark: SparkSession,
verification_suite: JavaObject,
partition: JavaObject,
run_id: str,
result_key: Optional[ResultKey] = None
) | function | def __new__(
cls,
spark: SparkSession,
verification_suite: JavaObject,
partition: JavaObject,
run_id: str,
result_key: Optional[ResultKey] = None
) -> "DeequVerificationSuiteToDataQualityAlerts":
java = PythonUtils(spark)
j_DeequVerificationSuiteToData... |
1,839 | 9576550bbb232a81da3ca04df12a1b9a | swh:1:cnt:2d8338ae4af3c1ca1ce316c87dfb781a9ae0a465;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=7-57/ | 10a3dc6eca1f736a02545c010bb1235d552a59b1 | refinery-deequ-python | analytics | refinery_deequ_python/java.py | PythonUtils | type | class PythonUtils:
"""
Utility class for Python to Java interoperability.
Parameters:
spark (SparkSession): The Spark session.
Attributes:
jvm: The Java Virtual Machine instance.
Example:
utils = PythonUtils(spark)
"""
def __init__(self, spark: SparkSession):
... |
1,840 | e84c9881a889d409abe4397c64b85c1d | swh:1:cnt:2d8338ae4af3c1ca1ce316c87dfb781a9ae0a465;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=21-31/ | 10a3dc6eca1f736a02545c010bb1235d552a59b1 | refinery-deequ-python | analytics | refinery_deequ_python/java.py | PythonUtils::__init__(self, spark: SparkSession) | function | def __init__(self, spark: SparkSession):
"""
Initializes PythonUtils.
This is a tiny wrapper around Spark's py4j gateway,
and provides conversion method for immutable types.
Parameters:
spark (SparkSession): The Spark session.
"""
self._jvm = spark.s... |
1,841 | 10f0e1e500a0bc939de1eed7b8957f55 | swh:1:cnt:2d8338ae4af3c1ca1ce316c87dfb781a9ae0a465;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=34-35/ | 10a3dc6eca1f736a02545c010bb1235d552a59b1 | refinery-deequ-python | analytics | refinery_deequ_python/java.py | PythonUtils::jvm(self) | function | def jvm(self):
return self._jvm |
1,842 | 265b8274595a2fb6a8cf5592e728724b | swh:1:cnt:2d8338ae4af3c1ca1ce316c87dfb781a9ae0a465;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=37-57/ | 10a3dc6eca1f736a02545c010bb1235d552a59b1 | refinery-deequ-python | analytics | refinery_deequ_python/java.py | PythonUtils::to_scala_list_map(self, pmap: Dict[Any, Any]) | function | def to_scala_list_map(self, pmap: Dict[Any, Any]) -> JavaObject:
"""
Converts a Python dictionary to a Scala ListMap.
Parameters:
pmap (Dict[Any, Any]): The Python dictionary to be converted.
Returns:
JavaObject: A Scala ListMap object containing the key-value p... |
1,843 | 8d0c3092dba8960f33005d90c2f79217 | swh:1:cnt:d090c538bb19e2e0e96e9fb6dc61711ebc6ae624;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=8-48/ | de8c0c4bdfae6a984854715bce4a9c9b2304d98b | refinery-deequ-python | analytics | tests/test_alerts.py | test_alerts_dataframe(spark, partition, data) | function | def test_alerts_dataframe(spark, partition, data):
check = Check(spark, CheckLevel.Warning, "Review Check")
verification_suite = (
VerificationSuite(spark)
.onData(data)
.addCheck(
check.hasSize(lambda x: x >= 3)
.hasMin("b", lambda x: x == 0)
.isComp... |
1,844 | 0a82fe1f8e6fb798c516459595797a22 | swh:1:cnt:024d380883a59b88ccffacc99298475941276b6c;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=1-4/ | c2e99b0da4fe11bf4a1de5ff5057f643ed30b148 | refinery-deequ-python | analytics | tests/test_hive.py | test_hive_partition(partition) | function | def test_hive_partition(partition):
assert (
partition.hiveQL() == 'source_key="testDataset",year=2023,month=11,day=7,hour=0'
) |
1,845 | 58fd0fc515402117b1171cccf348889c | swh:1:cnt:32841634a99f579e3111b9537650c4c372b141e4;origin=https://gitlab.wikimedia.org/repos/data-engineering/refinery-deequ-python.git;lines=8-41/ | dc45b1b195428ffae2af0ef20b1c21984497e9dc | refinery-deequ-python | analytics | tests/test_metrics.py | test_metrics_dataframe(spark, partition, data) | function | def test_metrics_dataframe(spark, partition, data):
repository: InMemoryMetricsRepository = InMemoryMetricsRepository(spark)
resultKey: ResultKey = ResultKey(
spark, ResultKey.current_milli_time(), {"tag": "sometag"}
)
AnalysisRunner(spark).onData(data).addAnalyzer(Size()).addAnalyzer(
... |
1,846 | 2717947d87b7efe0e2fc795a0ab9f19f | swh:1:cnt:813a8541c53f00f0c384ef9b70ea4e49fb30d6fd;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=7-16/ | aa064b1a807e958a8cc279f52cbf456c1aeef827 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/metrics_util.py | save_metrics(
spark: SparkSession,
metrics_table: str,
repository: MetricsRepository,
partition: HivePartition,
run_id: str
) | function | def save_metrics(
spark: SparkSession,
metrics_table: str,
repository: MetricsRepository,
partition: HivePartition,
run_id: str
):
metrics = DeequAnalyzersToDataQualityMetrics(spark, repository, partition, run_id)
metrics_writer = metrics.write().iceberg().output(metrics_... |
1,847 | 1523ef59abe642b94afcb91b406cc9b7 | swh:1:cnt:813a8541c53f00f0c384ef9b70ea4e49fb30d6fd;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=19-21/ | aa064b1a807e958a8cc279f52cbf456c1aeef827 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/metrics_util.py | save_alerts(alerts_table: str, alerts: DeequVerificationSuiteToDataQualityAlerts) | function | def save_alerts(alerts_table: str, alerts: DeequVerificationSuiteToDataQualityAlerts):
alerts_writer = alerts.write().iceberg().output(alerts_table)
alerts_writer.save() |
1,848 | dc3a61c65471fdf36902bcd293b27c0d | swh:1:cnt:813a8541c53f00f0c384ef9b70ea4e49fb30d6fd;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=24-48/ | aa064b1a807e958a8cc279f52cbf456c1aeef827 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/metrics_util.py | write_alerts(spark: SparkSession, alerts_output_path: str, *alerts: DeequVerificationSuiteToDataQualityAlerts) | function | def write_alerts(spark: SparkSession, alerts_output_path: str, *alerts: DeequVerificationSuiteToDataQualityAlerts):
"""Writes alerts to a file on hdfs. This is then detected by Airflow using a different operator
to actually send an alert via email, with the contents of the file being the body of the email.
... |
1,849 | 4ce96e5a724fe57c03c45773fb6b3fb0 | swh:1:cnt:5b80f14781d8fcf5d7b6c860a8cbec9dec5f5854;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=8-39/ | ece08ceeba60977caf9a9a10dcfa74c98c137a13 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/replicas_util.py | resolve_shard_for_wikidb(wikidb, datacenter='eqiad') | function | def resolve_shard_for_wikidb(wikidb, datacenter='eqiad'):
"""
Given a wikidb (i.e. 'simplewiki'), return the target shard that will contain that database.
Datacenter can be optionally provided, but the Hadoop cluster so far is only available at eqiad.
"""
if not hasattr(resolve_shard_for_wikidb, "wi... |
1,850 | fac719fe5da3cc7ac1c4d74ac667ffeb | swh:1:cnt:5b80f14781d8fcf5d7b6c860a8cbec9dec5f5854;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=53-64/ | ece08ceeba60977caf9a9a10dcfa74c98c137a13 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/replicas_util.py | resolve_pw_for_analytics_mariadb_replicas(password_file) | function | def resolve_pw_for_analytics_mariadb_replicas(password_file):
"""
Shells out to discover the password to be able to access the analytics mariadb replicas.
The password file permissions must match the current user to succeed.
"""
pw = subprocess.run(
f"hdfs dfs -cat {password_file}",
... |
1,851 | e5543186d789cb9ef3ccefdaf08cca84 | swh:1:cnt:5b80f14781d8fcf5d7b6c860a8cbec9dec5f5854;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=42-50/ | ece08ceeba60977caf9a9a10dcfa74c98c137a13 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/replicas_util.py | resolve_mariadb_host_port_for_wikidb(wikidb) | function | def resolve_mariadb_host_port_for_wikidb(wikidb):
"""
Given a wikidb (i.e. 'simplewiki'), return the host and port of the MariaDB instance that will contain a replica
of that MediaWiki instance's tables.
"""
shard = resolve_shard_for_wikidb(wikidb)
answers = dns.resolver.resolve('_' + shard + '-... |
1,852 | b2b17992fb821593bd3e26f1858d4ac2 | swh:1:cnt:5b80f14781d8fcf5d7b6c860a8cbec9dec5f5854;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=67-105/ | ece08ceeba60977caf9a9a10dcfa74c98c137a13 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/replicas_util.py | df_from_mariadb_replica(
spark,
query,
lower_bound,
upper_bound,
partition_column,
num_partitions,
wiki_id,
host,
port,
user,
password
) | function | def df_from_mariadb_replica(
spark,
query,
lower_bound,
upper_bound,
partition_column,
num_partitions,
wiki_id,
host,
port,
user,
password
):
"""
Returns a DataFrame from a JDBC source.
If partition_column is defined, th... |
1,853 | c0e7736b0cdfaad1e1ee77a78182ac9b | swh:1:cnt:f723cb1c916fd0f0fcdd073600314098e10dacf5;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=7-21/ | 0abc73b7b6b6f9c3a95901220166785e506ee559 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_current/process_changes.py | parse_args(args) | function | def parse_args(args) -> argparse.Namespace: # pragma: no cover
parser = argparse.ArgumentParser(
description='Run a MERGE INTO to get the mediawiki_content_current table up to date with '
'the changes incoming from the mediawiki_content_history table.'
)
parser.add_argument('--s... |
1,854 | f6ff4931d29e0f9806c057cebc4db077 | swh:1:cnt:f723cb1c916fd0f0fcdd073600314098e10dacf5;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=239-251/ | 0abc73b7b6b6f9c3a95901220166785e506ee559 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_current/process_changes.py | main() | function | def main() -> None: # pragma: no cover
args = parse_args(sys.argv[1:])
spark = SparkSession.builder.getOrCreate()
process_changes(
spark,
args.source_table,
args.target_table,
args.join_strategy
)
spark.stop() |
1,855 | 6b54d708c09e9f3665d44ec8030ef98d | swh:1:cnt:f723cb1c916fd0f0fcdd073600314098e10dacf5;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=24-236/ | 0abc73b7b6b6f9c3a95901220166785e506ee559 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_current/process_changes.py | process_changes(spark, source_table, target_table, join_strategy) | function | def process_changes(spark, source_table, target_table, join_strategy) -> None:
sql_merge_into = \
f"""
WITH revisions_row_numbered_by_dt_and_id AS (
SELECT wiki_id,
page_id,
revision_id,
GREATEST(row_content_update_dt, row_visibility_update_dt, row_move_update_dt) AS row_update... |
1,856 | 47464d810700eb378bdcbfbfd59ef990 | swh:1:cnt:d9d2a72f8f07a84e5ad7f20d1b60ef5bf4956806;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=19-54/ | 2fcd0c1019cec2a494fc15c69f8dc429eb75d611 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_daily.py | parse_args(
args, parser: argparse.ArgumentParser
) | function | def parse_args(
args, parser: argparse.ArgumentParser
) -> argparse.Namespace: # pragma: no cover
"""Parses command-line arguments for the completeness SLO computation.
Args:
args: Command-line arguments to parse.
argparse.ArgumentParser: Parser that will be used to return the arguments.
... |
1,857 | e3e1d04cea555ebd06e5e32e440d0cee | swh:1:cnt:d9d2a72f8f07a84e5ad7f20d1b60ef5bf4956806;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=122-156/ | 2fcd0c1019cec2a494fc15c69f8dc429eb75d611 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_daily.py | generate_deletes_and_undeletes_select(
partition_datetime: datetime,
source_mw_event_page_change_table: str,
) | function | def generate_deletes_and_undeletes_select(
partition_datetime: datetime,
source_mw_event_page_change_table: str,
) -> str:
"""The following function generates the query used to compute the metric.
Args:
partition_datetime (datetime): partition_datetime value used for the filtering.
mode... |
1,858 | ce7e23f9df06e78fe14aace2f9eb36cc | swh:1:cnt:d9d2a72f8f07a84e5ad7f20d1b60ef5bf4956806;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=57-119/ | 2fcd0c1019cec2a494fc15c69f8dc429eb75d611 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_daily.py | generate_source_select(
partition_datetime: datetime,
source_mw_event_page_change_table: str,
source_mw_revision_visibility_change_table: str,
source_mw_inconsistent_rows_table: str,
source_mw_content_history_reconcile_enriched_table: str,
) | function | def generate_source_select(
partition_datetime: datetime,
source_mw_event_page_change_table: str,
source_mw_revision_visibility_change_table: str,
source_mw_inconsistent_rows_table: str,
source_mw_content_history_reconcile_enriched_table: str,
) -> str:
"""The following function generates the qu... |
1,859 | dd683ff46a7cd9066ec40a8d6bd3a07a | swh:1:cnt:d9d2a72f8f07a84e5ad7f20d1b60ef5bf4956806;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=340-456/ | 2fcd0c1019cec2a494fc15c69f8dc429eb75d611 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_daily.py | main() | function | def main() -> None: # pragma: no cover
"""Main execution function for the completeness SLO computation.
Parses arguments, computes completeness metrics, writes results to metrics table,
generates alerts if needed, and exports metrics to Prometheus.
"""
args = parse_args(sys.argv[1:], build_args_par... |
1,860 | 79dbe1da9714aa54faf59fa5aaebffd7 | swh:1:cnt:d9d2a72f8f07a84e5ad7f20d1b60ef5bf4956806;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=159-337/ | 2fcd0c1019cec2a494fc15c69f8dc429eb75d611 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_daily.py | generate_query_daily(
partition_datetime: datetime,
mode: str,
run_id: str,
source_mw_content_history_table: str,
source_data_select: str,
deletes_and_undeletes_select: str,
) | function | def generate_query_daily(
partition_datetime: datetime,
mode: str,
run_id: str,
source_mw_content_history_table: str,
source_data_select: str,
deletes_and_undeletes_select: str,
):
"""The following function generates the query used to compute the metric.
Args:
partition_datetime... |
1,861 | 7530303a59c6e44e20dcff086d891ba4 | swh:1:cnt:f78ccc83e8090ccde4a508a68597d245a0c34933;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=48-84/ | 66e8ec02ba1b371d9ec0d9d6a6cfe5c098c91233 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_monthly.py | generate_source_select(
source_wmf_mw_history_table: str,
wmf_history_snapshot_filter: str,
) | function | def generate_source_select(
source_wmf_mw_history_table: str,
wmf_history_snapshot_filter: str,
) -> str:
"""The following function generates the query used to compute the metric.
Args:
partition_datetime (datetime): partition_datetime value used for the filtering.
source_mw_event_page_... |
1,862 | 42b5a94860090835387205ea7c51fc9a | swh:1:cnt:f78ccc83e8090ccde4a508a68597d245a0c34933;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=148-287/ | 66e8ec02ba1b371d9ec0d9d6a6cfe5c098c91233 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_monthly.py | generate_query_monthly(
partition_datetime: datetime,
mode: str,
run_id: str,
source_mw_content_history_table: str,
source_data_select: str,
deletes_and_undeletes_select: str,
) | function | def generate_query_monthly(
partition_datetime: datetime,
mode: str,
run_id: str,
source_mw_content_history_table: str,
source_data_select: str,
deletes_and_undeletes_select: str,
) -> str:
"""The following function generates the query used to compute the metric.
Args:
partition... |
1,863 | c0e0dbeb7b0d78fdcaa1392f7f5619f3 | swh:1:cnt:f78ccc83e8090ccde4a508a68597d245a0c34933;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=19-45/ | 66e8ec02ba1b371d9ec0d9d6a6cfe5c098c91233 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_monthly.py | parse_args(
args, parser: argparse.ArgumentParser
) | function | def parse_args(
args, parser: argparse.ArgumentParser
) -> argparse.Namespace: # pragma: no cover
"""Parses command-line arguments for the completeness SLO computation.
Args:
args: Command-line arguments to parse.
argparse.ArgumentParser: Parser that will be used to return the arguments.
... |
1,864 | 9e5d9f4b7d22ac25ff84a7b68498fb20 | swh:1:cnt:f78ccc83e8090ccde4a508a68597d245a0c34933;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=290-333/ | 66e8ec02ba1b371d9ec0d9d6a6cfe5c098c91233 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_monthly.py | validate_snapshot_partition(
spark: SparkSession,
source_wmf_mw_history_table: str,
snapshot_date: str,
) | function | def validate_snapshot_partition(
spark: SparkSession,
source_wmf_mw_history_table: str,
snapshot_date: str,
) -> bool:
"""This function validates that the requested snapshot is present in the history
table.
This is necessary because the older partitions of this table are deleted and in case
... |
1,865 | b68f9e3007228562e0f392ccf53bc083 | swh:1:cnt:f78ccc83e8090ccde4a508a68597d245a0c34933;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=87-145/ | 66e8ec02ba1b371d9ec0d9d6a6cfe5c098c91233 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_monthly.py | generate_deletes_and_undeletes_select(
source_wmf_mw_history_table: str,
wmf_history_snapshot_filter: str,
) | function | def generate_deletes_and_undeletes_select(
source_wmf_mw_history_table: str,
wmf_history_snapshot_filter: str,
) -> str:
"""The following function generates the query used to compute the metric.
Args:
partition_datetime (datetime): partition_datetime value used for the filtering.
mode (... |
1,866 | 880806ac02545e1aaba14eb5b03900b3 | swh:1:cnt:f78ccc83e8090ccde4a508a68597d245a0c34933;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=336-434/ | 66e8ec02ba1b371d9ec0d9d6a6cfe5c098c91233 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_monthly.py | main() | function | def main() -> None: # pragma: no cover
"""Main execution function for the completeness SLO computation.
Parses arguments, computes completeness metrics, writes results to metrics table,
generates alerts if needed, and exports metrics to Prometheus.
"""
args = parse_args(sys.argv[1:], build_args_par... |
1,867 | ad12caedafaa8dec061502b2f0dc1adf | swh:1:cnt:295a6acb455ab95cbf85ea94c4768376ad2adcba;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=66-177/ | 925c933038d2396960b6148d16c646317c80fcfe | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_utils.py | generate_root_query(
partition_datetime: datetime,
source_mw_content_history_table: str,
source_data_select: str,
deletes_and_undeletes_select: str,
) | function | def generate_root_query(
partition_datetime: datetime,
source_mw_content_history_table: str,
source_data_select: str,
deletes_and_undeletes_select: str,
) -> str:
"""The following function generates the query used to compute the metric.
Args:
partition_datetime (datetime): partition_dat... |
1,868 | 2455478bceab975c115ef3e91e0f6372 | swh:1:cnt:295a6acb455ab95cbf85ea94c4768376ad2adcba;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=200-287/ | 925c933038d2396960b6148d16c646317c80fcfe | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_utils.py | export_metric_to_prometheus(
spark: SparkSession,
metric_name: str,
metrics_table: str,
all_wiki_id: str,
mode: str,
source_mw_content_history_table_name: str,
source_mw_content_history_table_formatted: str,
partition_datetime: datetime,
slo_alerts_threshold: float,
) | function | def export_metric_to_prometheus(
spark: SparkSession,
metric_name: str,
metrics_table: str,
all_wiki_id: str,
mode: str,
source_mw_content_history_table_name: str,
source_mw_content_history_table_formatted: str,
partition_datetime: datetime,
slo_alerts_threshold: float,
) -> None:
... |
1,869 | f07cfe9861c899718eeb7523d161123d | swh:1:cnt:295a6acb455ab95cbf85ea94c4768376ad2adcba;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=346-374/ | 925c933038d2396960b6148d16c646317c80fcfe | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_utils.py | export_alerts(
spark: SparkSession,
alerts_df: DataFrame,
alerts_output_path: str,
alerts_threshold: float,
) | function | def export_alerts(
spark: SparkSession,
alerts_df: DataFrame,
alerts_output_path: str,
alerts_threshold: float,
) -> None:
"""Exports alerts to HDFS as a text file.
Args:
spark (SparkSession): Spark session.
alerts_df (DataFrame): DataFrame containing alerts to export.
a... |
1,870 | 9888744d380450b4a2a09e901f6b4505 | swh:1:cnt:295a6acb455ab95cbf85ea94c4768376ad2adcba;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=9-63/ | 925c933038d2396960b6148d16c646317c80fcfe | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_utils.py | build_args_parser() | function | def build_args_parser() -> argparse.ArgumentParser: # pragma: no cover
"""Parser to parse command-line arguments for the completeness SLO computation.
Returns:
argparse.ArgumentParser: Parser that will be used to return the arguments.
"""
parser = argparse.ArgumentParser(
description="... |
1,871 | cada3f8370b526a3aec8cf801b488c56 | swh:1:cnt:295a6acb455ab95cbf85ea94c4768376ad2adcba;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=180-197/ | 925c933038d2396960b6148d16c646317c80fcfe | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_utils.py | generate_partition_id(partition_datetime) | function | def generate_partition_id(partition_datetime) -> str:
"""This function generates the partition_id used in the out of the query to match
the format of the metric_table.
Args:
partition_datetime (datetime): partition_datetime value used for the filtering.
Returns:
str: formatted string t... |
1,872 | 7cf76f3a0341d3bc26f81f70f5153cd2 | swh:1:cnt:295a6acb455ab95cbf85ea94c4768376ad2adcba;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=290-343/ | 925c933038d2396960b6148d16c646317c80fcfe | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_utils.py | compute_alerts_df(
spark: SparkSession,
mode: str,
metrics_table: str,
source_mw_content_history_table_formatted: str,
partition_datetime: datetime,
run_id: str,
alerts_threshold: float,
all_wiki_id: str,
) | function | def compute_alerts_df(
spark: SparkSession,
mode: str,
metrics_table: str,
source_mw_content_history_table_formatted: str,
partition_datetime: datetime,
run_id: str,
alerts_threshold: float,
all_wiki_id: str,
) -> DataFrame:
"""Creates the alerts dataframe to then write in the alerts... |
1,873 | 9f4e5734c98dbedd2955f02b183d395f | swh:1:cnt:295a6acb455ab95cbf85ea94c4768376ad2adcba;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=377-417/ | 925c933038d2396960b6148d16c646317c80fcfe | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_utils.py | delete_past_run(
spark: SparkSession,
metrics_table: str,
alerts_table: str,
partition_datetime: str,
source_table_formatted: str,
mode: str,
source_mw_content_history_table_name: str,
) | function | def delete_past_run(
spark: SparkSession,
metrics_table: str,
alerts_table: str,
partition_datetime: str,
source_table_formatted: str,
mode: str,
source_mw_content_history_table_name: str,
) -> None:
"""The function executes the deletes on the metrics_table and alerts_table to have
a... |
1,874 | 62071b6c6c4328a2ec9f633bd59c2f1e | swh:1:cnt:295a6acb455ab95cbf85ea94c4768376ad2adcba;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=420-428/ | 925c933038d2396960b6148d16c646317c80fcfe | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/compute_completeness_slo_utils.py | terminate(spark: SparkSession) | function | def terminate(spark: SparkSession) -> None:
"""Function to shut down the spark context and exit the process.
Args:
spark (SparkSession): Spark session.
"""
# Shut down the Spark session to prevent any hanging processes.
spark.sparkContext._gateway.shutdown_callback_server()
spark.stop() |
1,875 | bcfefa470be9f6409789c036b6ae8ebf | swh:1:cnt:83dd73da60d19cfd60c12e306636196cd943ffac;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=14-31/ | 5492f6196399636d28e2045d30e6badfa0b344ee | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/consistency_check.py | parse_args(args) | function | def parse_args(args) -> argparse.Namespace: # pragma: no cover
parser = argparse.ArgumentParser(
description='Runs consistency checks between a source of truth mariadb replica and a target data lake table.'
)
parser.add_argument('--wiki_id', help='wiki_id to do quality checks against.', required=Tr... |
1,876 | e477f61e1ff93cc7c14461ea8ee69565 | swh:1:cnt:83dd73da60d19cfd60c12e306636196cd943ffac;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=85-243/ | 5492f6196399636d28e2045d30e6badfa0b344ee | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/consistency_check.py | df_from_mariadb_replica_adaptive(
spark,
# NOTE: include the partition column in the select clause
select_clause,
# NOTE: will automatically add a filter for your lower and upper bounds
where_clause,
table,
# can be timestamps or numeric columns, but not strings f... | function | def df_from_mariadb_replica_adaptive(
spark,
# NOTE: include the partition column in the select clause
select_clause,
# NOTE: will automatically add a filter for your lower and upper bounds
where_clause,
table,
# can be timestamps or numeric columns, but not strin... |
1,877 | 944424fca3e9cce609cac217b796cca9 | swh:1:cnt:83dd73da60d19cfd60c12e306636196cd943ffac;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=123-125/ | 5492f6196399636d28e2045d30e6badfa0b344ee | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/consistency_check.py | df_from_mariadb_replica_adaptive::update_query_and_log(query) | function | def update_query_and_log(query):
opts.update({"dbtable": f"({query}) t"})
print(f'INFO: Running query on {opts["url"]}: {query}') |
1,878 | 4ba80074cd36c1597f4138f39c0a79bb | swh:1:cnt:83dd73da60d19cfd60c12e306636196cd943ffac;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=524-551/ | 5492f6196399636d28e2045d30e6badfa0b344ee | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/consistency_check.py | main() | function | def main() -> None: # pragma: no cover
args = parse_args(sys.argv[1:])
spark = SparkSession.builder.getOrCreate()
host, port = resolve_mariadb_host_port_for_wikidb(args.wiki_id)
username = args.mariadb_username
pw = resolve_pw_for_analytics_mariadb_replicas(args.mariadb_password_file)
mariadb... |
1,879 | 7a219524df1619902734c34abc5edf52 | swh:1:cnt:83dd73da60d19cfd60c12e306636196cd943ffac;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=246-521/ | 5492f6196399636d28e2045d30e6badfa0b344ee | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/consistency_check.py | find_inconsistent_rows(
spark,
wiki_id,
target_table,
results_table,
min_timestamp,
max_timestamp,
computation_class,
computation_dt,
mariadb_args
) | function | def find_inconsistent_rows(
spark,
wiki_id,
target_table,
results_table,
min_timestamp,
max_timestamp,
computation_class,
computation_dt,
mariadb_args
) -> None:
# Delete old runs for this (wiki_id, computation_class, computation_dt), if any, ... |
1,880 | 389984aa808f177409f2828dffcbfb4b | swh:1:cnt:c70d1319afd7a8a9ed8bd503e8d474c1d8fd27f8;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=11-21/ | 53cff9791ca6abbe812961e24f22f979de14801f | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/copy_localuser_table_from_mariadb_to_datalake.py | parse_args(args) | function | def parse_args(args) -> argparse.Namespace: # pragma: no cover
parser = argparse.ArgumentParser(
description="Copies centralauth's localuser table from a MariaDB replica into the datalake, to be used by "
"emit_reconcile_events_to_kafka.py to resolve the user_central_id."
)
pars... |
1,881 | 8667a7df27cbfed2e80f62af89af8cbf | swh:1:cnt:c70d1319afd7a8a9ed8bd503e8d474c1d8fd27f8;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=80-102/ | 53cff9791ca6abbe812961e24f22f979de14801f | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/copy_localuser_table_from_mariadb_to_datalake.py | main() | function | def main() -> None: # pragma: no cover
args = parse_args(sys.argv[1:])
spark = SparkSession.builder.getOrCreate()
host, port = resolve_mariadb_host_port_for_wikidb("centralauth")
username = args.mariadb_username
pw = resolve_pw_for_analytics_mariadb_replicas(args.mariadb_password_file)
mariad... |
1,882 | 3786335db8e040af5529e1278863e4fe | swh:1:cnt:c70d1319afd7a8a9ed8bd503e8d474c1d8fd27f8;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=24-77/ | 53cff9791ca6abbe812961e24f22f979de14801f | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/copy_localuser_table_from_mariadb_to_datalake.py | copy_localuser_table_from_mariadb_to_datalake(
spark,
localuser_target_table,
read_partitions,
mariadb_args
) | function | def copy_localuser_table_from_mariadb_to_datalake(
spark,
localuser_target_table,
read_partitions,
mariadb_args
) -> None:
localuser_min_max_sql = """
SELECT min(lu_global_id) as min,
max(lu_global_id) as max
... |
1,883 | c9c4f1dac02112453b0206aead7c43a9 | swh:1:cnt:1008e974bcd1f1fe345e027bf0b084ed1cd0cac8;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=43-47/ | 0d15aec75b90be28a7ffc50e653118bf39d4f9cb | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/emit_reconcile_events_to_kafka.py | truncated_print(s: str, limit: int = 2048) | function | def truncated_print(s: str, limit: int = 2048) -> None:
if len(s) > limit:
print(s[:limit] + "...")
else:
print(s) |
1,884 | 13f7aee858ca60781c9dc3d13cf22cb4 | swh:1:cnt:1008e974bcd1f1fe345e027bf0b084ed1cd0cac8;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=11-40/ | 0d15aec75b90be28a7ffc50e653118bf39d4f9cb | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/emit_reconcile_events_to_kafka.py | parse_args(args) | function | def parse_args(args) -> argparse.Namespace: # pragma: no cover
parser = argparse.ArgumentParser(
description='Creates, formats and submits events to Kafka from a table that has a log of inconsistent rows. '
'This script works iteratively in chunks of the specified size until all events ... |
1,885 | b5600cc18a728b6933c9dd3b177d36e8 | swh:1:cnt:1008e974bcd1f1fe345e027bf0b084ed1cd0cac8;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=50-453/ | 0d15aec75b90be28a7ffc50e653118bf39d4f9cb | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/emit_reconcile_events_to_kafka.py | emit_reconcile_events_to_kafka(
spark,
wiki_id,
inconsistent_rows_table,
wikis_table,
namespaces_table,
namespaces_table_snapshot,
localuser_table,
computation_dt,
computation_class,
max_events_per_iteration,
mariadb_args,
w... | function | def emit_reconcile_events_to_kafka(
spark,
wiki_id,
inconsistent_rows_table,
wikis_table,
namespaces_table,
namespaces_table_snapshot,
localuser_table,
computation_dt,
computation_class,
max_events_per_iteration,
mariadb_args,
... |
1,886 | ae6e50b8a5d3744f78e4aec9cc7ec703 | swh:1:cnt:1008e974bcd1f1fe345e027bf0b084ed1cd0cac8;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=149-189/ | 0d15aec75b90be28a7ffc50e653118bf39d4f9cb | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/emit_reconcile_events_to_kafka.py | emit_reconcile_events_to_kafka::revisions_source_sql_for_rev_ids(rev_ids) | function | def revisions_source_sql_for_rev_ids(rev_ids) -> str:
return f"""
SELECT
p.page_id AS page_id,
p.page_namespace AS page_namespace_id,
CONVERT(p.page_title USING utf8mb4) AS page_title,
a.actor_user AS user_id,
IF(LENGTH(CONVERT(a.... |
1,887 | cb737c6a46aea3ceec518e8bdc622728 | swh:1:cnt:1008e974bcd1f1fe345e027bf0b084ed1cd0cac8;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=456-499/ | 0d15aec75b90be28a7ffc50e653118bf39d4f9cb | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/emit_reconcile_events_to_kafka.py | main() | function | def main() -> None: # pragma: no cover
args = parse_args(sys.argv[1:])
spark = SparkSession.builder.getOrCreate()
host, port = resolve_mariadb_host_port_for_wikidb(args.wiki_id)
username = args.mariadb_username
pw = resolve_pw_for_analytics_mariadb_replicas(args.mariadb_password_file)
mariadb... |
1,888 | 65e75787b7220b53a096d33bfa972801 | swh:1:cnt:2309f1a6e224afdd9106fc2dfe07f99a8f4ce1a6;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=247-307/ | 46bc4676ab13c28b841784a77c7ab48d2c70ecb7 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/process_events.py | process_page_deletes(spark, source_table, target_table, year, month, day, hour, big_wikis=None) | function | def process_page_deletes(spark, source_table, target_table, year, month, day, hour, big_wikis=None) -> None:
sql_page_ids_per_wiki = \
f"""
SELECT
wiki_id,
sort_array(collect_set(page_id)) as page_ids
FROM (
SELECT
wiki_id,
page.page_id
FROM {source_table}
WHERE year={year}
AND month=... |
1,889 | d11dc0e7fc25a98e2063abb39c6a5bf2 | swh:1:cnt:2309f1a6e224afdd9106fc2dfe07f99a8f4ce1a6;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=25-90/ | 46bc4676ab13c28b841784a77c7ab48d2c70ecb7 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/process_events.py | process_revisions(spark, source_table, target_table, year, month, day, hour, big_wikis=None) | function | def process_revisions(spark, source_table, target_table, year, month, day, hour, big_wikis=None) -> None:
# pushdown the earliest touched revision_dt per wiki. example:
# ...
# OR
# (t.wiki_id = 'enwiki' AND t.revision_dt >= '2001-01-23T05:20:49')
# OR
# ...
sql_earliest_revision_dt_per_wik... |
1,890 | 6c7d2b75bcfb70dffb1bea933d46d45b | swh:1:cnt:2309f1a6e224afdd9106fc2dfe07f99a8f4ce1a6;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=329-388/ | 46bc4676ab13c28b841784a77c7ab48d2c70ecb7 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/process_events.py | process_page_moves(spark, source_table, target_table, year, month, day, hour, big_wikis=None) | function | def process_page_moves(spark, source_table, target_table, year, month, day, hour, big_wikis=None) -> None:
sql_page_ids_per_wiki = \
f"""
SELECT wiki_id,
sort_array(collect_set(page_id)) as page_ids
FROM (
SELECT
wiki_id,
page.page_id
FROM {source_table}
WHERE year={year}... |
1,891 | 54e774b87b903f1f27f99a7219d43ec0 | swh:1:cnt:2309f1a6e224afdd9106fc2dfe07f99a8f4ce1a6;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=7-22/ | 46bc4676ab13c28b841784a77c7ab48d2c70ecb7 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/process_events.py | parse_args(args) | function | def parse_args(args) -> argparse.Namespace: # pragma: no cover
parser = argparse.ArgumentParser(
description='Run various SQL DML from an event source table to an Iceberg sink table.'
)
parser.add_argument('--source_table', help='table we intend to read from')
parser.add_argument('--target_tabl... |
1,892 | 4a6691d902e0e2bf60774ab53b20a1b8 | swh:1:cnt:2309f1a6e224afdd9106fc2dfe07f99a8f4ce1a6;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=92-244/ | 46bc4676ab13c28b841784a77c7ab48d2c70ecb7 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/process_events.py | run_merge_into(spark, source_table, target_table, year, month, day, hour, source_predicate, optimization_predicates) | function | def run_merge_into(spark, source_table, target_table, year, month, day, hour, source_predicate, optimization_predicates):
sql_merge_into = \
f"""
WITH deduplicated_mediawiki_page_content_change AS (
-- we want to ingest the latest state of a (wiki_id, rev_id) pair
-- so below we pick latest event ba... |
1,893 | 3fb60c57f6a860036f517d269948988c | swh:1:cnt:2309f1a6e224afdd9106fc2dfe07f99a8f4ce1a6;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=309-326/ | 46bc4676ab13c28b841784a77c7ab48d2c70ecb7 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/process_events.py | run_delete(spark, target_table, delete_predicates) | function | def run_delete(spark, target_table, delete_predicates):
sql_delete = \
f"""
DELETE
FROM {target_table} t
WHERE (
-- pushdown wiki_ids and page_ids that are changing
-- to limit how much data we effectively read. See T369868#10142190.
{delete_predicates}
)
"""
print("Now doing DELETE via:")
... |
1,894 | 46a6fc937be8a2c034f8d69c4cf1b6aa | swh:1:cnt:2309f1a6e224afdd9106fc2dfe07f99a8f4ce1a6;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=390-457/ | 46bc4676ab13c28b841784a77c7ab48d2c70ecb7 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/process_events.py | run_move_merge_into(spark, source_table, target_table, year, month, day, hour, optimization_predicates) | function | def run_move_merge_into(spark, source_table, target_table, year, month, day, hour, optimization_predicates):
sql_merge_into = \
f"""
-- pick latest move event for a (wiki_id, page_id) tuple
WITH deduplicated_mediawiki_page_moves AS (
SELECT * FROM (
SELECT
*,
row_number() ove... |
1,895 | 3eb08b20d7a76c643000d03b8cb5e936 | swh:1:cnt:2309f1a6e224afdd9106fc2dfe07f99a8f4ce1a6;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=460-501/ | 46bc4676ab13c28b841784a77c7ab48d2c70ecb7 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/process_events.py | main() | function | def main() -> None: # pragma: no cover
args = parse_args(sys.argv[1:])
spark = SparkSession.builder.getOrCreate()
if 'revisions' in args.event_categories:
process_revisions(
spark,
args.source_table,
args.target_table,
args.year,
args.mo... |
1,896 | 884ac1746b2360ae082bb00277165a59 | swh:1:cnt:c1d02a7756e19389fe845984572336acd7d13520;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=7-18/ | 2070c93ad232b3c1730c20eab2416c0dfe5ae728 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/process_visibility_events.py | parse_args(args) | function | def parse_args(args) -> argparse.Namespace: # pragma: no cover
parser = argparse.ArgumentParser(
description='Run a MERGE INTO from a visibility event source table to an Iceberg sink table.'
)
parser.add_argument('--source_table', help='table we intend to read from')
parser.add_argument('--targ... |
1,897 | 1b9cc1f760a78126f29e3fc88e4a60b9 | swh:1:cnt:c1d02a7756e19389fe845984572336acd7d13520;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=111-126/ | 2070c93ad232b3c1730c20eab2416c0dfe5ae728 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/process_visibility_events.py | main() | function | def main() -> None: # pragma: no cover
args = parse_args(sys.argv[1:])
spark = SparkSession.builder.getOrCreate()
process_visibility_events(
spark,
args.source_table,
args.target_table,
args.year,
args.month,
args.day,
args.hour
)
spark.sto... |
1,898 | d0b768b39e13b17e44534d19e6b7697e | swh:1:cnt:c1d02a7756e19389fe845984572336acd7d13520;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=21-108/ | 2070c93ad232b3c1730c20eab2416c0dfe5ae728 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/content_history/process_visibility_events.py | process_visibility_events(spark, source_table, target_table, year, month, day, hour) | function | def process_visibility_events(spark, source_table, target_table, year, month, day, hour) -> None:
sql_rev_ids_per_page_ids_per_wiki = \
f"""
SELECT
database,
page_id,
sort_array(collect_set(rev_id)) as rev_ids
FROM {source_table}
WHERE year = {year}
AND month = {month}
AND day = {day}
{f"AND ho... |
1,899 | 65e75787b7220b53a096d33bfa972801 | swh:1:cnt:358f1ca82d270de66df45b4db08ea47f1a880c77;origin=https://gitlab.wikimedia.org/repos/data-engineering/mediawiki-content-pipelines.git;lines=247-307/ | f96210234bcd103deca3cc8c5ea6dcafaa5dbb85 | mediawiki-content-pipelines | analytics | mediawiki_content_pipelines/revision_history/process_events.py | process_page_deletes(spark, source_table, target_table, year, month, day, hour, big_wikis=None) | function | def process_page_deletes(spark, source_table, target_table, year, month, day, hour, big_wikis=None) -> None:
sql_page_ids_per_wiki = \
f"""
SELECT
wiki_id,
sort_array(collect_set(page_id)) as page_ids
FROM (
SELECT
wiki_id,
page.page_id
FROM {source_table}
WHERE year={year}
AND month=... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.