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 |
|---|---|---|---|---|---|---|---|---|---|
2,700 | bb46b77ca00dbfa6bb3ffa3bc4f9530f | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=272-344/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::testSplitCompressed() | function | @Test
public void testSplitCompressed() throws IOException {
JobConf job = new JobConf(conf);
FileSystem fs = FileSystem.getLocal(conf);
Path dir = new Path(System.getProperty("test.build.data", ".") + "/mapred");
Path txtFile = new Path(dir, "testSplitCompressed.bz2");
fs.delete(dir, true);
... |
2,701 | 16c7a0e7351c3c9c100070d5b4a7e28b | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=420-422/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::getStderrReporter::incrCounter(String group, String counter, long amount) | function | @Override public void incrCounter(String group, String counter, long amount) {
//System.err.println(group.toString() + " " + counter + " is incremented by " + amount);
} |
2,702 | a6de8332dcb23270994392ffd838ea04 | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=450-501/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::main(String[] args) | function | public static void main(String[] args) throws IOException {
Configuration conf = new Configuration();
JobConf job = new JobConf(conf);
FileSystem fs = FileSystem.getLocal(conf);
Path dir = new Path(System.getProperty("test.build.data", ".") + "/mapred");
Path txtFile = new Path(dir, args[0]);
f... |
2,703 | 79a96c40133acd824ea5eddf5e1002d0 | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=244-252/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::upperCaseRegion(String orig, int start, int end) | function | private static String upperCaseRegion(String orig, int start, int end) {
if ( 0 < start && start < end && end <= orig.length() ) {
return orig.substring(0, start) +
orig.substring(start, end).toUpperCase() +
orig.substring(end);
} else {
return orig;
}
} |
2,704 | f50c5309eba9cef4413ce03c59eb4a02 | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=429-441/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::read(FileSplit split, JobConf job) | function | private static String read(FileSplit split, JobConf job) throws IOException {
StringBuffer buff = new StringBuffer();
SeekableInputStream is = SeekableInputStream.getInstance(split, FileSystem.getLocal(conf), new CompressionCodecFactory(job));
byte[] buf = new byte[2048];
int len = 0;
while ( (len=i... |
2,705 | d689c7ccfbf44ae2b19d8c6526117cbd | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=49-85/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::testFormatWithNoPreviousRevision() | function | @Test
public void testFormatWithNoPreviousRevision() throws IOException {
JobConf job = new JobConf(conf);
FileSystem fs = FileSystem.getLocal(conf);
Path dir = new Path(System.getProperty("test.build.data", ".") + "/mapred");
Path txtFile = new Path(dir, "auto.txt");
fs.delete(dir, true);
S... |
2,706 | 59167c9285ac0fd612e4061844543725 | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=254-256/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::rand(int n) | function | private static int rand(int n) {
return (int)(n*Math.random());
} |
2,707 | d114905e560dbf2befbf3df9003f8a19 | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=423-425/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::getStderrReporter::getInputSplit() | function | @Override public InputSplit getInputSplit() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
} |
2,708 | e21a915663c85e498b78621b22b1787d | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=443-448/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::snip(String str, int snip) | function | private static String snip(String str, int snip) {
if ( str.length() > snip ) {
str = str.substring(0, snip/2) + " ... " + str.substring(str.length() - snip/2, str.length());
}
return str.replace("\n", "\\n");
} |
2,709 | 37d86600d5f819591f05a5c5efee40c0 | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=164-194/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::testFormatWithOneSplitCompressed() | function | @Test
public void testFormatWithOneSplitCompressed() throws IOException {
JobConf job = new JobConf(conf);
FileSystem fs = FileSystem.getLocal(conf);
Path dir = new Path(System.getProperty("test.build.data", ".") + "/mapred");
Path txtFile = new Path(dir, "auto.bz2");
fs.delete(dir, true);
S... |
2,710 | 4ec1c38558ca7b9a99beffb8700cac6e | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=384-399/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::collect(FileInputFormat<Text,Text> format, JobConf job, int n, Reporter reporter) | function | private static List<String> collect(FileInputFormat<Text,Text> format, JobConf job, int n, Reporter reporter) throws IOException {
List<String> found = new ArrayList<String>();
for (InputSplit split : format.getSplits(job, n)) {
RecordReader<Text,Text> reader = format.getRecordReader(split, job, reporter)... |
2,711 | 3b739b5495a92b91d6acdba539e3fb6d | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=403-405/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::getStderrReporter::setStatus(String s) | function | @Override public void setStatus(String s) {
System.err.println(s);
} |
2,712 | ae3c42a258130730307081a75f224788 | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=196-242/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::testSplitUncompressed() | function | @Test
public void testSplitUncompressed() throws IOException {
JobConf job = new JobConf(conf);
FileSystem fs = FileSystem.getLocal(conf);
Path dir = new Path(System.getProperty("test.build.data", ".") + "/mapred");
Path txtFile = new Path(dir, "auto.txt");
fs.delete(dir, true);
StreamWikiDu... |
2,713 | b2ab924bb9a822373139f4a0dea4c75f | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=401-427/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::getStderrReporter() | function | private static Reporter getStderrReporter() {
return new Reporter() {
@Override public void setStatus(String s) {
System.err.println(s);
}
@Override public void progress() {
}
public float getProgress() {
return 0;
}
@Override public Counters.Counter getCoun... |
2,714 | 62d1fa58456afb121133df0687b19b8b | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=406-407/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::getStderrReporter::progress() | function | @Override public void progress() {
} |
2,715 | 49a284f63c6e8c54f68d78ca5cedde3b | swh:1:cnt:056524533fe2f7e65bb99654cecd456f2c796973;origin=https://gerrit.wikimedia.org/r/analytics/wikihadoop.git;lines=408-410/ | 92f86bf6bec3fd304432042854e3fcdc5b6a3a25 | wikihadoop | analytics | src/test/java/org/wikimedia/wikihadoop/TestStreamWikiDumpInputFormat.java | TestStreamWikiDumpInputFormat::getStderrReporter::getProgress() | function | public float getProgress() {
return 0;
} |
2,716 | 94a1f12b1ad807ede6ab2f7de437736b | swh:1:cnt:02d710afd5dff82c17f8c1674c363a442ff31d1b;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=48-52/ | ccf85ed18cde041c379c8b42cd2b93604d84d6c5 | wmfdata-python | analytics | src/wmfdata/conda.py | active_name() | function | def active_name():
"""
Returns the name of the active conda env, or None.
"""
return env_vars().get("CONDA_DEFAULT_ENV", None) |
2,717 | 3ecad2c85609ec142ded5172636c4cdf | swh:1:cnt:02d710afd5dff82c17f8c1674c363a442ff31d1b;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=34-38/ | ccf85ed18cde041c379c8b42cd2b93604d84d6c5 | wmfdata-python | analytics | src/wmfdata/conda.py | env_vars() | function | def env_vars():
"""
Returns dict of conda environment variables.
"""
return info().get("env_vars", {}) |
2,718 | 82fe153e589bdd148ff7a8b541fa725a | swh:1:cnt:02d710afd5dff82c17f8c1674c363a442ff31d1b;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=63-70/ | ccf85ed18cde041c379c8b42cd2b93604d84d6c5 | wmfdata-python | analytics | src/wmfdata/conda.py | is_active() | function | def is_active():
"""
Returns True if a conda env is active, else False.
"""
if active_prefix() is None:
return False
else:
return True |
2,719 | 22d373c3ee2a7c5e75148da2e84a9a6f | swh:1:cnt:02d710afd5dff82c17f8c1674c363a442ff31d1b;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=24-31/ | ccf85ed18cde041c379c8b42cd2b93604d84d6c5 | wmfdata-python | analytics | src/wmfdata/conda.py | info() | function | def info():
"""
Returns the result of conda info --all --json as a dict.
"""
if conda_installed:
return json.loads(condacli("info", ["--all", "--json"])[0])
else:
return {} |
2,720 | 0cebd72363eb52656788f20e0a23d9de | swh:1:cnt:02d710afd5dff82c17f8c1674c363a442ff31d1b;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=41-45/ | ccf85ed18cde041c379c8b42cd2b93604d84d6c5 | wmfdata-python | analytics | src/wmfdata/conda.py | active_prefix() | function | def active_prefix():
"""
Returns the path to the active conda env, or None.
"""
return info().get("active_prefix", None) |
2,721 | d87adad04bf88f6298dde6c5a932c436 | swh:1:cnt:02d710afd5dff82c17f8c1674c363a442ff31d1b;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=55-60/ | ccf85ed18cde041c379c8b42cd2b93604d84d6c5 | wmfdata-python | analytics | src/wmfdata/conda.py | base_prefix() | function | def base_prefix():
"""
If the active conda env is stacked on another conda env, returns
the path to that base conda env, or None.
"""
return env_vars().get("CONDA_PREFIX_1", None) |
2,722 | 9bc263f2d4e372b24ba62e60b2838150 | swh:1:cnt:02d710afd5dff82c17f8c1674c363a442ff31d1b;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=73-79/ | ccf85ed18cde041c379c8b42cd2b93604d84d6c5 | wmfdata-python | analytics | src/wmfdata/conda.py | conda_base_env_prefix() | function | def conda_base_env_prefix():
"""
Returns the path to the conda base env, which on WMF servers is
'/opt/conda-analytics'. This can be overridden by setting the CONDA_BASE_ENV_PREFIX
env var.
"""
return os.environ.get("CONDA_BASE_ENV_PREFIX", "/opt/conda-analytics") |
2,723 | 92e5a4c4a02aec4577c248efc04140c7 | swh:1:cnt:02d710afd5dff82c17f8c1674c363a442ff31d1b;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=82-123/ | ccf85ed18cde041c379c8b42cd2b93604d84d6c5 | wmfdata-python | analytics | src/wmfdata/conda.py | pack(**conda_pack_kwargs) | function | def pack(**conda_pack_kwargs):
"""
Calls conda_pack.pack.
If the packed output file already exists, this will not repackage
it unless conda_pack_kwargs["force"] == True.
Returns the path to the output packed env file.
Arguments:
* `conda_pack_kwargs` args to pass to conda_pack.pack().
... |
2,724 | 8f280efc0811d42a7c00097d43f22e59 | swh:1:cnt:3f8e2fc732ef0978a92e7ead7961bbbf642ca23c;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=29-69/ | 91a7d222dd5483000aa9ceefe0454a01a728d4e7 | wmfdata-python | analytics | src/wmfdata/hive.py | run(commands) | function | def run(commands):
"""
Runs SQL commands against the Hive tables in the Data Lake.
Arguments:
* `commands`: the SQL to run. A string for a single command or a list of
strings for multiple commands within the same session (useful for things
like setting session variables). Passing more than ... |
2,725 | e0f160663386ed35ebcd67d26aed2c4d | swh:1:cnt:3f8e2fc732ef0978a92e7ead7961bbbf642ca23c;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=76-156/ | 91a7d222dd5483000aa9ceefe0454a01a728d4e7 | wmfdata-python | analytics | src/wmfdata/hive.py | load_csv(
path, field_spec, db_name, table_name, create_db=False, sep=",", headers=True
) | function | def load_csv(
path, field_spec, db_name, table_name, create_db=False, sep=",", headers=True
):
"""
Upload a CSV (or other delimiter-separated value file) to Data Lake's HDFS,
for use with Hive and other utilities.
`field_spec` specifies the field names and their formats, for the
`CREATE TABLE` ... |
2,726 | 33a315b7535fbce9c985b21dd83c40e7 | swh:1:cnt:4d2eea6f11e2187217379eeb50c18ce505ee242c;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=13-20/ | 54db214896085050fdbe1d3f7e2574d7750a7b30 | wmfdata-python | analytics | src/wmfdata/mariadb.py | decode_binary(x) | function | # Set up converter for binary data
def decode_binary(x):
try:
return x.decode("utf-8")
# This should only occur with NULLs and non-binary strings,
# which don't need conversion
except AttributeError:
return x |
2,727 | f1f36963c989b6001a599e1054e33a1f | swh:1:cnt:4d2eea6f11e2187217379eeb50c18ce505ee242c;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=99-167/ | 54db214896085050fdbe1d3f7e2574d7750a7b30 | wmfdata-python | analytics | src/wmfdata/mariadb.py | run(commands, dbs, use_x1=False, format="pandas", date_col=None, index_col=None) | function | def run(commands, dbs, use_x1=False, format="pandas", date_col=None, index_col=None):
"""
Run SQL queries or commands on the Analytics MediaWiki replicas.
Arguments:
* `commands`: the SQL to run. A string for a single command or a list of
strings for multiple commands within the same session (use... |
2,728 | 99c3fa8df45f6315ae5ff32e48a9f893 | swh:1:cnt:4d2eea6f11e2187217379eeb50c18ce505ee242c;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=41-45/ | 54db214896085050fdbe1d3f7e2574d7750a7b30 | wmfdata-python | analytics | src/wmfdata/mariadb.py | clean_up_connection() | function | def clean_up_connection():
# The connection variable may not be defined if the connection failed
# to open
if connection:
connection.close() |
2,729 | 4f41a81c32c9c647fcd519e9115878a0 | swh:1:cnt:4d2eea6f11e2187217379eeb50c18ce505ee242c;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=48-94/ | 54db214896085050fdbe1d3f7e2574d7750a7b30 | wmfdata-python | analytics | src/wmfdata/mariadb.py | connect(db, use_x1=False) | function | def connect(db, use_x1=False):
# The `analytics-mysql` script requires users to know that the `wikishared`
# database is located on x1.
if db == "wikishared":
use_x1 = True
host_command = "analytics-mysql {db} --print-target".format(db=db)
if use_x1:
host_command = host_command + " ... |
2,730 | 58be3d3e562136bc2fdb82d233eb5dd1 | swh:1:cnt:092e638a63741fa0e94c2d84f2f9febc90594c1b;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=15-19/ | e7480346f5761aa3ca7683ed3266fff6810f4a70 | wmfdata-python | analytics | src/wmfdata/presto.py | resolve_presto_host_cname() | function | def resolve_presto_host_cname():
dns_answers = dns.resolver.resolve(PRESTO_HOST, "CNAME")
if len(dns_answers.rrset) == 0:
return None
return dns_answers.rrset[0].to_text().rstrip(".") |
2,731 | 13909c89414195c6541bbb68a74d457e | swh:1:cnt:092e638a63741fa0e94c2d84f2f9febc90594c1b;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=22-107/ | e7480346f5761aa3ca7683ed3266fff6810f4a70 | wmfdata-python | analytics | src/wmfdata/presto.py | run(
commands: str | List[str],
catalog: str = "analytics_hive",
) | function | def run(
commands: str | List[str],
catalog: str = "analytics_hive",
) -> pd.DataFrame:
"""
Run SQL on the Data Lake using the Presto engine
Parameters
----------
commands : str or list of str
The SQL to run. A string for a single command or a list of
strings for... |
2,732 | b3449db378c039818b260555d3c61f33 | swh:1:cnt:092e638a63741fa0e94c2d84f2f9febc90594c1b;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=89-94/ | e7480346f5761aa3ca7683ed3266fff6810f4a70 | wmfdata-python | analytics | src/wmfdata/presto.py | run::setup_transform(col, desired_dtype) | function | def setup_transform(col, desired_dtype):
# Only Hive dates/times need special handling
if desired_dtype in ("timestamp", "date"):
return lambda df: pd.to_datetime(df[col])
else:
return lambda df: df[col] |
2,733 | e99355f1e015a59421247a443bb27103 | swh:1:cnt:63c5eb4cc112fb06292d731cf5401038c79dc2f1;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=68-72/ | a3b0b4bece032d727e8029a195d5214cbf6008e2 | wmfdata-python | analytics | src/wmfdata/spark.py | get_active_session() | function | def get_active_session():
"""
Returns the active session if there is one and None otherwise.
"""
return SparkSession.getActiveSession() |
2,734 | c09c11ab31312bb7fd82e5b4833145d3 | swh:1:cnt:63c5eb4cc112fb06292d731cf5401038c79dc2f1;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=188-233/ | a3b0b4bece032d727e8029a195d5214cbf6008e2 | wmfdata-python | analytics | src/wmfdata/spark.py | create_session(
type="yarn-regular",
app_name=None,
extra_settings={},
ship_python_env=False,
) | function | def create_session(
type="yarn-regular",
app_name=None,
extra_settings={},
ship_python_env=False,
):
"""
Creates a new Spark session based on one of the PREDEFINED_SPARK_SESSION
types, stopping any existing session first.
Arguments:
* `type`: the type of Spark session to create.
... |
2,735 | 7aad1f64daac98f0630638206d9d2385 | swh:1:cnt:63c5eb4cc112fb06292d731cf5401038c79dc2f1;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=75-185/ | a3b0b4bece032d727e8029a195d5214cbf6008e2 | wmfdata-python | analytics | src/wmfdata/spark.py | create_custom_session(
master: str = "yarn",
app_name: str = "wmfdata-custom",
spark_config: dict[str, Any] = {},
ship_python_env: bool = False,
conda_pack_kwargs: dict[str, Any] = {},
) | function | def create_custom_session(
master: str = "yarn",
app_name: str = "wmfdata-custom",
spark_config: dict[str, Any] = {},
ship_python_env: bool = False,
conda_pack_kwargs: dict[str, Any] = {},
) -> SparkSession:
"""
Creates a new Spark session, stopping any existing session first.
Use this ... |
2,736 | 36df812f273309559a730a1c1c9e6379 | swh:1:cnt:63c5eb4cc112fb06292d731cf5401038c79dc2f1;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=279-362/ | a3b0b4bece032d727e8029a195d5214cbf6008e2 | wmfdata-python | analytics | src/wmfdata/spark.py | upload_pandas(
df: pd.DataFrame,
destination_table: str,
write_mode: str = "overwrite",
table_format: str = "iceberg",
) | function | def upload_pandas(
df: pd.DataFrame,
destination_table: str,
write_mode: str = "overwrite",
table_format: str = "iceberg",
) -> None:
"""
Upload a Pandas data frame to a Data Lake table.
Any index on the data frame will be ignored.
Parameters
----------
df : pandas.DataFrame
... |
2,737 | 13dd27ba03291bf3500f0ebaf3de6489 | swh:1:cnt:63c5eb4cc112fb06292d731cf5401038c79dc2f1;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=236-276/ | a3b0b4bece032d727e8029a195d5214cbf6008e2 | wmfdata-python | analytics | src/wmfdata/spark.py | run(commands: Union[str, List[str]]) | function | def run(commands: Union[str, List[str]]) -> pd.DataFrame:
"""
Runs SQL commands against the Hive tables in the Data Lake using the
PySpark SQL interface.
Note: this command will use the existing Spark session if there is one and
otherwise create a predefined "yarn-regular" session. If you want to u... |
2,738 | c38a3a81f4df0d1ff343977d2168ac2d | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=17-22/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | print_err(*args, **kwargs) | function | def print_err(*args, **kwargs):
print(*args, file=sys.stderr, sep="\n\n", **kwargs)
# In Jupyter notebooks, std_err messages are highlighted in red. This puts a non-highlighted
# line afterward to more clearly separate this from other messages.
print() |
2,739 | cb995ce680606317cac0d57d7c3a45ed | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=31-33/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | pct_str(x, decimals=1) | function | def pct_str(x, decimals=1):
format_str = "{:,." + str(decimals) + "f}%"
return format_str.format(x * 100) |
2,740 | e6d698196c09bd11d08ebead32ee1cfc | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=44-53/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | pd_display_all(df) | function | def pd_display_all(df):
with pd.option_context(
"display.max_rows",
None,
"display.max_columns",
None,
"display.max_colwidth",
None,
):
display(df) |
2,741 | fbc5201bb2f6354c9ec869121d02a414 | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=90-136/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | insert_code_toggle() | function | def insert_code_toggle():
"""
Outputs a button that will show or hide the code cells in exported HTML
versions of the notebook.
"""
warnings.warn(
"\nwmf.utils.insert_code_toggle is deprecated. To produce an HTML version of a notebook\n"
"with the code cells folded, use Quarto. For m... |
2,742 | e110e7b807b917c0c24cdebc0aae7eae | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=147-160/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | df_to_remarkup(df, **kwargs) | function | def df_to_remarkup(df, **kwargs):
"""
Prints a Pandas dataframe as a Remarkup table suitable for pasting into Phabricator.
Note that among many kwargs the following are useful for editing the output:
index (bool): passing `False` removes the dataframe index (default is `True`)
Ex: `df_t... |
2,743 | 0268eb2bef22c4fac479e641b183dbfb | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=181-189/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | check_kerberos_auth() | function | def check_kerberos_auth():
klist = subprocess.call(["klist", "-s"])
if klist == 1:
raise OSError(
"You do not have Kerberos credentials. Authenticate using `kinit` "
"or run your script as a keytab-enabled user."
)
elif klist != 0:
raise OSError("There was an ... |
2,744 | f7342729d0b8f04ccf3a03be1708330d | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=205-219/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | get_dblist(dblist_name, dblist_path="/srv/mediawiki-config/dblists") | function | def get_dblist(dblist_name, dblist_path="/srv/mediawiki-config/dblists"):
"""
Given the name of a dblist (e.g. "wikipedia", "closed", "group0"), return the wiki database names in that list.
To see all the dblists, visit:
https://github.com/wikimedia/operations-mediawiki-config/tree/master/dblists
"... |
2,745 | 4474df822b77716a00597990477a350f | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=25-28/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | sig_figs(x, n_figs) | function | def sig_figs(x, n_figs):
exponent = floor(log10(abs(x)))
round_level = -exponent + (n_figs - 1)
return round(x, round_level) |
2,746 | 3b3b66fcb838dacfd78b134734f33c67 | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=36-41/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | num_str(x, n_figs=2) | function | def num_str(x, n_figs=2):
try:
sigfigified = sig_figs(x, n_figs)
return "{:,}".format(sigfigified)
except (ValueError, TypeError): # Catch numpy.NaNs and Nones
return None |
2,747 | 1b1ae6ce73a3cf68684e080258201264 | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=56-66/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | suppress_warning(fn, category, message) | function | def suppress_warning(fn, category, message):
"""
Return a decorator that suppresses a particular warning.
"""
@wraps(fn)
def suppressed(*args, **kwargs):
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=category, message=message)
return fn(*a... |
2,748 | 8e456d190a8046ed39dcdd1b2486ff3f | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=61-64/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | suppress_warning::suppressed(*args, **kwargs) | function | def suppressed(*args, **kwargs):
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=category, message=message)
return fn(*args, **kwargs) |
2,749 | 1b819c699718b6cc87eba953326b3017 | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=139-144/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | mediawiki_dt(dt) | function | def mediawiki_dt(dt):
"""
Converts a Python datetime.datetime object to the string datetime form
used in MediaWiki databases.
"""
return dt.strftime("%Y%m%d%H%M%S") |
2,750 | f629db37e9aaebcf9998642149baeb06 | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=163-178/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | check_remote_version(source_url, local_version) | function | def check_remote_version(source_url, local_version):
req = requests.get(source_url + "/raw/release/pyproject.toml", timeout=1)
req.raise_for_status()
remote_version = re.search(
r'^version\s*=\s*"(.*?)"$', req.text, re.MULTILINE
).group(1)
remote_version = Version(remote_version)
local_v... |
2,751 | 6d018eddd2778943e9122edd54b0a5b3 | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=192-202/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | ensure_list(str_or_list) | function | def ensure_list(str_or_list):
"""
Given a string, wraps it in a list; given a list, returns it unchanged.
Useful for allowing a function to take a string for a single item or a list
of strings for multiple items.
"""
if isinstance(str_or_list, str):
return [str_or_list]
else:
... |
2,752 | b0b4aff94c6e160847768d0daec516f9 | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=222-226/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | python_version() | function | def python_version():
"""
Returns currently running python major.minor version. E.g "3.7"
"""
return f"{sys.version_info.major}.{sys.version_info.minor}" |
2,753 | 094e338d1a77b7356c34b0e431ced3be | swh:1:cnt:44ab3a4d4c32368454363ba6632f7f948c2db051;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=229-275/ | 399c4e88a6d546c621dfab166d9da84bc24cf740 | wmfdata-python | analytics | src/wmfdata/utils.py | sql_tuple(i) | function | def sql_tuple(i):
"""
Given a Python iterable, returns a string representation that can be used in an SQL IN
clause.
For example:
> sql_tuple(["a", "b", "c"])
"('a', 'b', 'c')"
WARNING: In some cases, this function produces incorrect results with strings that contain
single quotes or b... |
2,754 | d31fcd2db868ab83e492aa2ffc204f2a | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=117-120/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_read_via_hive() | function | def test_read_via_hive():
test_data_1_via_hive = wmf.hive.run(READ_TABLE_1)
assert_dataframes_match(TEST_DATA_1, test_data_1_via_hive)
log_test_passed("Read via Hive") |
2,755 | 0a7f25d3fecc7663659b51e7a041a544 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=129-140/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_spark_log4j_config() | function | def test_spark_log4j_config():
import wmfdata.spark as spark_module
log4j_path = os.path.join(os.path.dirname(spark_module.__file__), "conf", "log4j.properties")
assert os.path.isfile(log4j_path), f"log4j.properties not found at {log4j_path}"
spark = wmf.spark.create_session(type="local", app_name="wm... |
2,756 | e9394ed4dada14dd84fb8c9c0f39bc29 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=212-219/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_upload_pandas() | function | def test_upload_pandas():
df = pd.read_csv(f"{this_directory}/test_data_2.csv", keep_default_na=False, na_values="")
wmf.spark.upload_pandas(df, f"{hive_db}.wmfdata_test_2", table_format="hive")
df_roundtripped = wmf.spark.run(READ_TABLE_2)
assert_dataframes_match(df, df_roundtripped)
log_test_pas... |
2,757 | cc2848a1dc75d92b2b6c4fb22e321084 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=123-126/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_silent_command_via_hive() | function | def test_silent_command_via_hive():
output = wmf.hive.run(SILENT_COMMAND)
assert output is None
log_test_passed("Silent command via Hive") |
2,758 | ac7e440c0a0355db932c87afcbb878d5 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=143-153/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_spark_session_apis() | function | def test_spark_session_apis():
# once create_session() is called, we should be able to retrieve it via get_active_session()
s1 = wmf.spark.create_session(type="local", app_name="wmfdata-test-session-api-1")
assert SparkSession.getActiveSession() is s1
# a later call to create_session() closes any previo... |
2,759 | 8070d465ebc75f0fd592471215223d20 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=222-236/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_sql_tuple() | function | def test_sql_tuple():
try:
wmf.utils.sql_tuple([])
# We want a ValueError in this case
except ValueError:
pass
else:
raise AssertionError(
"Passing an empty iterable to sql_tuple should raise a ValueError."
)
t = wmf.utils.sql_tuple(("enwiki", "arwiki", "... |
2,760 | c012886ae895730baf5594ec7c98cd7e | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=45-46/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | log_test_passed(test_name) | function | def log_test_passed(test_name):
print(f"TEST PASSED: {test_name}") |
2,761 | c5b7b984d6aa934b83c1ed1217f87ae0 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=87-95/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | clean_tables() | function | def clean_tables():
wmf.hive.run(
[
f"DROP TABLE IF EXISTS {hive_db}.wmfdata_test_1",
f"DROP TABLE IF EXISTS {hive_db}.wmfdata_test_2",
f"DROP TABLE IF EXISTS {hive_db}.wmfdata_test_empty",
]
)
wmf.mariadb.run("DROP TABLE IF EXISTS wmfdata_test", dbs="stag... |
2,762 | 901e0a42b6917b26a4ebd38ec486de24 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=192-195/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_silent_command_via_MariaDB() | function | def test_silent_command_via_MariaDB():
output = wmf.mariadb.run(SILENT_COMMAND, dbs="staging")
assert output is None
log_test_passed("Silent command via MariaDB") |
2,763 | e4c81586881970922e8fbbb60f5538c1 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=239-273/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_df_to_remarkup() | function | def test_df_to_remarkup():
# Test to see that we can remove indexes and format numbers in df_to_remarkup outputs.
df_requests_dummy = pd.DataFrame(
data={
"http_status": [200, 404, 305],
"total_requests": [975, 20, 2],
"percent_of_total": [97.5, 2, 0.5],
}
... |
2,764 | c8a2f79e66964167a7f60049b491d74e | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=49-52/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | assert_dataframes_match(df1, df2) | function | def assert_dataframes_match(df1, df2):
assert df1.equals(df2)
assert df1.index.equals(df2.index)
assert df1.columns.equals(df2.columns) |
2,765 | f51a41971bd0f28079240dbd1227d6a1 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=198-209/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_load_csv() | function | def test_load_csv():
wmf.hive.load_csv(
f"{this_directory}/test_data_2.csv",
"name string, iso_code string, economic_region string, maxmind_continent string",
db_name=hive_db,
table_name="wmfdata_test_2",
)
test_data_2 = wmf.hive.run(READ_TABLE_2)
assert_dataframes_match... |
2,766 | 76b3944d9da3f4191efe3cdec2560f31 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=276-295/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | main() | function | def main():
clean_tables()
set_up_table_1()
set_up_mariadb_table()
test_read_via_hive()
test_silent_command_via_hive()
test_spark_log4j_config()
test_spark_session_apis()
test_read_via_spark()
test_silent_command_via_spark()
test_read_via_presto()
test_read_via_mariadb()
... |
2,767 | 301e38d19165faa79b9611481cf2ac82 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=174-189/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_read_via_mariadb() | function | # Our Presto setup does not support DDL or DML commands, so the issue
# of silent commands causing an error doesn't come up
def test_read_via_mariadb():
test_data_1_via_mariadb = wmf.mariadb.run(
"""
SELECT *
FROM wmfdata_test
""",
"staging",
)
assert_dataframes_ma... |
2,768 | b801ab9cdddac09beddd115cd9520801 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=55-58/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | set_up_table_1() | function | def set_up_table_1():
spark = wmf.spark.create_session(type="local", app_name="wmfdata-test")
spark_df = spark.read.load(f"file://{this_directory}/test_data_1.parquet")
spark_df.write.mode("overwrite").saveAsTable(f"{hive_db}.wmfdata_test_1") |
2,769 | b498de99876c5ed6ae826051c760947c | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=156-159/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_read_via_spark() | function | def test_read_via_spark():
test_data_1_via_spark = wmf.spark.run(READ_TABLE_1)
assert_dataframes_match(TEST_DATA_1, test_data_1_via_spark)
log_test_passed("Read via Spark") |
2,770 | 00b22672452b9ff54302974284a504da | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=168-171/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_read_via_presto() | function | def test_read_via_presto():
test_data_1_via_presto = wmf.presto.run(READ_TABLE_1)
assert_dataframes_match(TEST_DATA_1, test_data_1_via_presto)
log_test_passed("Read via Presto") |
2,771 | f381e08d22214a2f04d7f1bd89cd831a | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=61-84/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | set_up_mariadb_table() | function | def set_up_mariadb_table():
test_data_tuples = TEST_DATA_1.itertuples(index=False, name=None)
test_data_1_records = ",\n".join([str(t) for t in test_data_tuples])
CREATE_TABLE_SQL = """
CREATE TABLE wmfdata_test (
month VARCHAR(255),
wiki VARCHAR(255),
user_id BI... |
2,772 | 85fcfd63beb3763191223b544767d962 | swh:1:cnt:c239472f2da5c1e1c79290a2e28afc7c123077c7;origin=https://gitlab.wikimedia.org/repos/data-engineering/wmfdata-python.git;lines=162-165/ | f5431619052fb59f5ab1d5c518c41cf255bf332f | wmfdata-python | analytics | tests/integrations.py | test_silent_command_via_spark() | function | def test_silent_command_via_spark():
output = wmf.spark.run(SILENT_COMMAND)
assert output is None
log_test_passed("Silent command via Spark") |
2,773 | 5ed43cda14d3368993d27119b8581b41 | swh:1:cnt:4bfb3073406bc3fd9e30094e2bbf84ece949ec9a;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=9-121/ | de17a503ba6d91f1326b301033d2dd8ec601591f | uap-java | analytics | src/main/java/ua_parser/CachingParser.java | CachingParser | type | /**
* When doing webanalytics (with for example PIG) the main pattern is to process
* weblogs in clickstreams. A basic fact about common clickstreams is that in
* general the same browser will do multiple requests in sequence. This has the
* effect that the same useragent will appear in the logfiles and we will see... |
2,774 | 45d905ccbacda633b3e92cf8a64afee7 | swh:1:cnt:4bfb3073406bc3fd9e30094e2bbf84ece949ec9a;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=42-59/ | de17a503ba6d91f1326b301033d2dd8ec601591f | uap-java | analytics | src/main/java/ua_parser/CachingParser.java | CachingParser::parse(String agentString) | function | // ------------------------------------------
@Override
public Client parse(String agentString) {
if (agentString == null) {
return null;
}
if (cacheClient == null) {
cacheClient = new LRUMap<>(CACHE_SIZE);
}
Client client = cacheClient.get(agentString);
if (client != null) {
... |
2,775 | 1053614a270c1170a2af2148ec32decd | swh:1:cnt:4bfb3073406bc3fd9e30094e2bbf84ece949ec9a;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=99-117/ | de17a503ba6d91f1326b301033d2dd8ec601591f | uap-java | analytics | src/main/java/ua_parser/CachingParser.java | CachingParser::parseOS(String agentString) | function | // ------------------------------------------
@Override
public OS parseOS(String agentString) {
if (agentString == null) {
return null;
}
if (cacheOS == null) {
cacheOS = new LRUMap<>(CACHE_SIZE);
}
OS os = cacheOS.get(agentString);
if (os != null) {
return os;
}
... |
2,776 | 924022887b438eba032bc1a9a00e0bcf | swh:1:cnt:4bfb3073406bc3fd9e30094e2bbf84ece949ec9a;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=61-78/ | de17a503ba6d91f1326b301033d2dd8ec601591f | uap-java | analytics | src/main/java/ua_parser/CachingParser.java | CachingParser::parseUserAgent(String agentString) | function | // ------------------------------------------
@Override
public UserAgent parseUserAgent(String agentString) {
if (agentString == null) {
return null;
}
if (cacheUserAgent == null) {
cacheUserAgent = new LRUMap<>(CACHE_SIZE);
}
UserAgent userAgent = cacheUserAgent.get(agentString);
... |
2,777 | 6090815e36ff734396f3f35e8a578e13 | swh:1:cnt:4bfb3073406bc3fd9e30094e2bbf84ece949ec9a;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=80-97/ | de17a503ba6d91f1326b301033d2dd8ec601591f | uap-java | analytics | src/main/java/ua_parser/CachingParser.java | CachingParser::parseDevice(String agentString) | function | // ------------------------------------------
@Override
public Device parseDevice(String agentString) {
if (agentString == null) {
return null;
}
if (cacheDevice == null) {
cacheDevice = new LRUMap<>(CACHE_SIZE);
}
Device device = cacheDevice.get(agentString);
if (device != null... |
2,778 | c64a3d03fcb099040e6d9b86edd8e5f5 | swh:1:cnt:4b430df1679811ca806ee034c48e6403457d379a;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=19-59/ | 3b9f62de85ba32f0e5e175c3eeeedba30e25c98a | uap-java | analytics | src/main/java/ua_parser/Client.java | Client | type | /**
* Collection of parsed data for a given user agent string consisting of UserAgent, OS, Device
*
* @author Steve Jiang (@sjiang) <gh at iamsteve com>
*/
public class Client {
public final UserAgent userAgent;
public final OS os;
public final Device device;
public Client(UserAgent userAgent, OS os,... |
2,779 | 40723cd0738e5da89e75caae740445eb | swh:1:cnt:4b430df1679811ca806ee034c48e6403457d379a;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=35-44/ | 3b9f62de85ba32f0e5e175c3eeeedba30e25c98a | uap-java | analytics | src/main/java/ua_parser/Client.java | Client::equals(Object other) | function | @Override
public boolean equals(Object other) {
if (other == this) return true;
if (!(other instanceof Client)) return false;
Client o = (Client) other;
return ((this.userAgent != null && this.userAgent.equals(o.userAgent)) || this.userAgent == o.userAgent) &&
((this.os != null && this.os.... |
2,780 | 6b59f041099c2310bc633fd551bf68a9 | swh:1:cnt:4b430df1679811ca806ee034c48e6403457d379a;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=54-58/ | 3b9f62de85ba32f0e5e175c3eeeedba30e25c98a | uap-java | analytics | src/main/java/ua_parser/Client.java | Client::toString() | function | @Override
public String toString() {
return String.format("{\"user_agent\": %s, \"os\": %s, \"device\": %s}",
userAgent, os, device);
} |
2,781 | 4fbe558fe615a5b80de82794d0634c0c | swh:1:cnt:4b430df1679811ca806ee034c48e6403457d379a;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=46-52/ | 3b9f62de85ba32f0e5e175c3eeeedba30e25c98a | uap-java | analytics | src/main/java/ua_parser/Client.java | Client::hashCode() | function | @Override
public int hashCode() {
int h = userAgent == null ? 0 : userAgent.hashCode();
h += os == null ? 0 : os.hashCode();
h += device == null ? 0 : device.hashCode();
return h;
} |
2,782 | 1e6bb9cbb2229eecce098c640ede5a26 | swh:1:cnt:8f3eb25d093dec56d27288712cd32bcaad0d4c26;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=3-8/ | 0e4553e4aa3b2a1c05c2857d310661c16f348ffc | uap-java | analytics | src/main/java/ua_parser/Constants.java | Constants | type | /**
* @author sojern
*/
public class Constants {
public static final String EMPTY_STRING = "\"\"";
} |
2,783 | 1aa358fd310319d9fedd10abfa78b783 | swh:1:cnt:81c37cb42ae7b9268f15f994f65d15eb4d61f9d5;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=21-56/ | ed814990127ee02d5ea9aa483ca63d90cff33e91 | uap-java | analytics | src/main/java/ua_parser/Device.java | Device | type | /**
* Device parsed data class
*
* @author Steve Jiang (@sjiang) <gh at iamsteve com>
*/
public class Device {
public final String family;
public Device(String family) {
this.family = family;
}
public static Device fromMap(Map<String, String> m) {
return new Device((String) m.get("family"));... |
2,784 | 7edb3a9b076b3e36396cd5bbecafc6ad | swh:1:cnt:81c37cb42ae7b9268f15f994f65d15eb4d61f9d5;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=33-35/ | ed814990127ee02d5ea9aa483ca63d90cff33e91 | uap-java | analytics | src/main/java/ua_parser/Device.java | Device::fromMap(Map<String, String> m) | function | public static Device fromMap(Map<String, String> m) {
return new Device((String) m.get("family"));
} |
2,785 | ef8dd24f90a9075efce08f9cab4c3e12 | swh:1:cnt:81c37cb42ae7b9268f15f994f65d15eb4d61f9d5;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=51-55/ | ed814990127ee02d5ea9aa483ca63d90cff33e91 | uap-java | analytics | src/main/java/ua_parser/Device.java | Device::toString() | function | @Override
public String toString() {
return String.format("{\"family\": %s}",
family == null ? Constants.EMPTY_STRING : '"' + family + '"');
} |
2,786 | 6bd6396425eae6189f017245b0a8d179 | swh:1:cnt:81c37cb42ae7b9268f15f994f65d15eb4d61f9d5;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=46-49/ | ed814990127ee02d5ea9aa483ca63d90cff33e91 | uap-java | analytics | src/main/java/ua_parser/Device.java | Device::hashCode() | function | @Override
public int hashCode() {
return family == null ? 0 : family.hashCode();
} |
2,787 | 8af8b70f365f1b9b69babc50a590da83 | swh:1:cnt:81c37cb42ae7b9268f15f994f65d15eb4d61f9d5;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=37-44/ | ed814990127ee02d5ea9aa483ca63d90cff33e91 | uap-java | analytics | src/main/java/ua_parser/Device.java | Device::equals(Object other) | function | @Override
public boolean equals(Object other) {
if (other == this) return true;
if (!(other instanceof Device)) return false;
Device o = (Device) other;
return (this.family != null && this.family.equals(o.family)) || this.family == o.family;
} |
2,788 | 74e8dd18a3cd1796a3d720cb8983b35b | swh:1:cnt:eb8fe5d3c1a104727a170a4684b7398caafb2142;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=26-123/ | 043ee5d75d2e147a07ddb028f01982fba512adb6 | uap-java | analytics | src/main/java/ua_parser/DeviceParser.java | DeviceParser | type | /**
* Device parser using ua-parser regexes. Extracts device information from user agent strings.
*
* @author Steve Jiang (@sjiang) <gh at iamsteve com>
*/
public class DeviceParser {
private final List<DevicePattern> patterns;
public DeviceParser(List<DevicePattern> patterns) {
this.patterns = patt... |
2,789 | e28fe47150fc77d891684de273c7458d | swh:1:cnt:eb8fe5d3c1a104727a170a4684b7398caafb2142;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=76-121/ | 043ee5d75d2e147a07ddb028f01982fba512adb6 | uap-java | analytics | src/main/java/ua_parser/DeviceParser.java | DeviceParser::DevicePattern | type | protected static class DevicePattern {
private static final Pattern SUBSTITUTIONS_PATTERN = Pattern.compile("\\$\\d");
private final Pattern pattern;
private final String deviceReplacement;
public DevicePattern(Pattern pattern, String deviceReplacement) {
this.pattern = pattern;
this.deviceRep... |
2,790 | 4ad5db78b81c4e8a5c3725d8b7591905 | swh:1:cnt:eb8fe5d3c1a104727a170a4684b7398caafb2142;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=55-64/ | 043ee5d75d2e147a07ddb028f01982fba512adb6 | uap-java | analytics | src/main/java/ua_parser/DeviceParser.java | DeviceParser::fromList(List<Map<String,String>> configList) | function | /**
* Constructs a thread-safe DeviceParser.
*/
public static DeviceParser fromList(List<Map<String,String>> configList) {
List<DevicePattern> configPatterns = new ArrayList<DevicePattern>();
for (Map<String,String> configMap : configList) {
configPatterns.add(DeviceParser.patternFromMap(configMap... |
2,791 | 8fb19ede4db0c6478def9ae8ffaf0f41 | swh:1:cnt:eb8fe5d3c1a104727a170a4684b7398caafb2142;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=39-53/ | 043ee5d75d2e147a07ddb028f01982fba512adb6 | uap-java | analytics | src/main/java/ua_parser/DeviceParser.java | DeviceParser::parse(String agentString) | function | public Device parse(String agentString) {
if (agentString == null) {
return null;
}
String device = null;
for (DevicePattern p : patterns) {
if ((device = p.match(agentString)) != null) {
break;
}
}
if (device == null) device = "Other";
return new Device(device);
... |
2,792 | 22eab77decec882731336a23523ba071 | swh:1:cnt:eb8fe5d3c1a104727a170a4684b7398caafb2142;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=86-110/ | 043ee5d75d2e147a07ddb028f01982fba512adb6 | uap-java | analytics | src/main/java/ua_parser/DeviceParser.java | DeviceParser::DevicePattern::match(String agentString) | function | public String match(String agentString) {
Matcher matcher = pattern.matcher(agentString);
if (!matcher.find()) {
return null;
}
String device = null;
if (deviceReplacement != null) {
if (deviceReplacement.contains("$")) {
device = deviceReplacement;
for ... |
2,793 | 9c3d3d04a9e0bfcae50fb7895da8bef1 | swh:1:cnt:eb8fe5d3c1a104727a170a4684b7398caafb2142;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=112-119/ | 043ee5d75d2e147a07ddb028f01982fba512adb6 | uap-java | analytics | src/main/java/ua_parser/DeviceParser.java | DeviceParser::DevicePattern::getSubstitutions(String deviceReplacement) | function | private List<String> getSubstitutions(String deviceReplacement) {
Matcher matcher = SUBSTITUTIONS_PATTERN.matcher(deviceReplacement);
List<String> substitutions = new ArrayList<String>();
while (matcher.find()) {
substitutions.add(matcher.group());
}
return substitutions;
} |
2,794 | ee80be4647341e8c45779b1b7bf5c4fe | swh:1:cnt:eb8fe5d3c1a104727a170a4684b7398caafb2142;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=66-74/ | 043ee5d75d2e147a07ddb028f01982fba512adb6 | uap-java | analytics | src/main/java/ua_parser/DeviceParser.java | DeviceParser::patternFromMap(Map<String, String> configMap) | function | protected static DevicePattern patternFromMap(Map<String, String> configMap) {
String regex = configMap.get("regex");
if (regex == null) {
throw new IllegalArgumentException("Device is missing regex");
}
Pattern pattern = "i".equals(configMap.get("regex_flag")) // no ohter flags used (by now) ... |
2,795 | f75aaf10d80cd6d51f5e83a3e7004b95 | swh:1:cnt:f514b8d9ba6900f15592ab41bc405c3ae3d7054c;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=21-73/ | 21280cf2493c437a98e18bf71b46b37e9569a16d | uap-java | analytics | src/main/java/ua_parser/OS.java | OS | type | /**
* Operating System parsed data class
*
* @author Steve Jiang (@sjiang) <gh at iamsteve com>
*/
public class OS {
public final String family, major, minor, patch, patchMinor;
public OS(String family, String major, String minor, String patch, String patchMinor) {
this.family = family;
this.majo... |
2,796 | 503667983546ab989fc2256189577267 | swh:1:cnt:f514b8d9ba6900f15592ab41bc405c3ae3d7054c;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=37-39/ | 21280cf2493c437a98e18bf71b46b37e9569a16d | uap-java | analytics | src/main/java/ua_parser/OS.java | OS::fromMap(Map<String, String> m) | function | public static OS fromMap(Map<String, String> m) {
return new OS(m.get("family"), m.get("major"), m.get("minor"), m.get("patch"), m.get("patch_minor"));
} |
2,797 | 326642251912707bdeca9042dd6aa628 | swh:1:cnt:f514b8d9ba6900f15592ab41bc405c3ae3d7054c;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=54-62/ | 21280cf2493c437a98e18bf71b46b37e9569a16d | uap-java | analytics | src/main/java/ua_parser/OS.java | OS::hashCode() | function | @Override
public int hashCode() {
int h = family == null ? 0 : family.hashCode();
h += major == null ? 0 : major.hashCode();
h += minor == null ? 0 : minor.hashCode();
h += patch == null ? 0 : patch.hashCode();
h += patchMinor == null ? 0 : patchMinor.hashCode();
return h;
} |
2,798 | 76d601977b85bfcf698cb9397fccf9d5 | swh:1:cnt:f514b8d9ba6900f15592ab41bc405c3ae3d7054c;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=41-52/ | 21280cf2493c437a98e18bf71b46b37e9569a16d | uap-java | analytics | src/main/java/ua_parser/OS.java | OS::equals(Object other) | function | @Override
public boolean equals(Object other) {
if (other == this) return true;
if (!(other instanceof OS)) return false;
OS o = (OS) other;
return ((this.family != null && this.family.equals(o.family)) || this.family == o.family) &&
((this.major != null && this.major.equals(o.major)) || t... |
2,799 | 8b684b26047438c1221ab83256b99f89 | swh:1:cnt:f514b8d9ba6900f15592ab41bc405c3ae3d7054c;origin=https://gerrit.wikimedia.org/r/analytics/ua-parser/uap-java.git;lines=64-72/ | 21280cf2493c437a98e18bf71b46b37e9569a16d | uap-java | analytics | src/main/java/ua_parser/OS.java | OS::toString() | function | @Override
public String toString() {
return String.format("{\"family\": %s, \"major\": %s, \"minor\": %s, \"patch\": %s, \"patch_minor\": %s}",
family == null ? Constants.EMPTY_STRING : '"' + family + '"',
major == null ? Constants.EMPTY_STRING : '"' + major + '"'... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.