Skip to content

Instantly share code, notes, and snippets.

View kristoff-it's full-sized avatar
in your codebase, fixing your bugz

Loris Cro kristoff-it

in your codebase, fixing your bugz
View GitHub Profile
>>> counts = df.groupby("countryCode", "occupation").agg({"en_curid": "count"})
>>> counts.show(2)
+-----------+-------------+---------------+
|countryCode| occupation|count(en_curid)|
+-----------+-------------+---------------+
| FR|MATHEMATICIAN| 34|
| IT|SOCCER PLAYER| 81|
+-----------+-------------+---------------+
only showing top 2 rows
>>> from pyspark.sql.window import Window
>>> from pyspark.sql.functions import count, col, row_number
>>> w = Window().partitionBy("countryCode").orderBy(col("count(en_curid)").desc())
>>> result = counts.withColumn("rn", row_number().over(w)).where(col("rn") == 1).select("countryCode", "occupation")
>>> result.show(5)
+-----------+-------------+
|countryCode| occupation|
+-----------+-------------+
| DZ| POLITICIAN|
| LT| POLITICIAN|
$ redis-cli
> SCAN 0 MATCH people:* COUNT 3
1) "2048"
2) 1) "people:2113653"
2) "people:44849"
3) "people:399280"
4) "people:101393"
>>> result.where(col("occupation") == "POLITICIAN").count()
150
>>> no_pol = result.where(col("occupation") != "POLITICIAN")
>>> no_pol.write.format("org.apache.spark.sql.redis").option("table", "occupation").option("key.column", "countryCode").save()
$ redis-cli
> HGETALL occupation:IT
1) "occupation"
2) "RELIGIOUS FIGURE"
> HGETALL occupation:US
1) "occupation"
2) "ACTOR"
import redis
r = redis.Redis(decode_responses=True)
data = {"hello": "world", "ans": 42}
p1 = r.pubsub(ignore_subscribe_messages=True)
p1.subscribe("channel")
# Assuming we have an exposed RESP3 parser from the library
const redis = @cImport({
@cInclude("./redismodule.h");
});
export fn HelloWorld_Command(ctx: *redis.RedisModuleCtx, argv: [*c]*redis.RedisModuleString, argc: c_int) c_int {
_ = redis.RedisModule_ReplyWithSimpleString(ctx, c"Hello World!");
return redis.REDISMODULE_OK;
}
export fn RedisModule_OnLoad(ctx: *redis.RedisModuleCtx, argv: [*c]*redis.RedisModuleString, argc: c_int) c_int {
const redis = @import("./redismodule.zig");
export fn HelloWorld_Command(ctx: *redis.RedisModuleCtx, argv: [*c]*redis.RedisModuleString, argc: c_int) c_int {
_ = redis.RedisModule_ReplyWithSimpleString(ctx, c"Hello World!");
return redis.REDISMODULE_OK;
}
export fn RedisModule_OnLoad(ctx: *redis.RedisModuleCtx, argv: [*c]*redis.RedisModuleString, argc: c_int) c_int {
if (redis.RedisModule_Init(ctx, c"testmodule", 1, redis.REDISMODULE_APIVER_1)
const std = @import("std");
const hasher = std.hash.Fnv1a_64;
const cuckoo = @import("./cuckoofilter.zig");
fn fingerprint8(x: []const u8) u8 {
return x[0];
}
fn fingerprint16(x: []const u8) u16 {
return @ptrCast(*u16, x[0..1].ptr).*;