Skip to content

Instantly share code, notes, and snippets.

@miguno
miguno / interactive-queries_app-instances-for-a-store.md
Created October 31, 2018 16:27 — forked from enothereska/interactive-queries_app-instances-for-a-store.md
List running app instances that currently manage (parts of) state store "top-five-songs"
# List running app instances that currently manage (parts of) state store "top-five-songs"
$ http://localhost:7070/kafka-music/instances/top-five-songs
[
	{
		"host": "localhost",
 "port": 7070,
@miguno
miguno / interactive-queries_list-app-instances.md
Last active May 14, 2021 15:37 — forked from enothereska/interactive-queries_list-app-instances.md
List all running instances of this application
# List all running instances of this application
$ http://localhost:7070/kafka-music/instances
[
	{
		"host": "localhost",
 "port": 7070,
@miguno
miguno / hll.py
Last active November 9, 2022 14:58
HyperLogLog (HLL) experiments: register bits, register counts, estimation error, error bounds
# Runs HLL experiments, using randomly generated strings as input data.
#
# Requirements
# ============
#
# # https://github.com/ascv/HyperLogLog
# $ pip install HLL
#
#
# How to use
@miguno
miguno / udaf.java
Created June 29, 2018 08:12
UDAF example
package com.myorg.ksql.udaf;
import io.confluent.ksql.function.udaf.UdafFactory;
import io.confluent.ksql.function.udf.UdfDescription;
@UdfDescription(name = "totalStringLength", author = "Confluent", version = "1.0")
public class TotalStringLength {
@UdafFactory(description = "sums the length of strings")
public static Udaf<String, Long> createSumLengthString() {
@miguno
miguno / define-a-struct.sql
Last active June 27, 2018 07:58
Creating a stream with a STRUCT column
CREATE STREAM orders (orderid VARCHAR, itemid VARCHAR, address STRUCT<city VARCHAR, state VARCHAR, zicode BIGINT>)
WITH (kafka_topic = 'orders_topic', value_format = 'JSON', key = 'orderId');
@miguno
miguno / docker.sh
Created June 18, 2018 09:01
Quick tip: Running a Java or Scala application with Docker (e.g., a Java/Scala app using Apache Kafka's Streams API), assuming the application is packaged as a fat jar / uber jar
$ docker container run --rm \
--net streams_streams-net \
-v /docker/host/path/to/app.jar:/docker/container/path/to/app.jar \
openjdk:8-jre java -jar /docker/container/path/to/app.jar
@miguno
miguno / gist:548cd72eaec017c475448cb9b2ced258
Last active April 7, 2023 19:24
Taking Java JVM memory snapshots with gdb and jmap (for YourKit)

Notes

  • Good: very quick snapshotting even for large heap spaces (e.g. works if your JVM process would otherwise timeout and die)
  • Bad: such a memory snapshot contains significantly less useful information than YourKit's "enhanced" memory snapshots.

Usage

# 1. Find the relevant JVM pid on the target machine
$ ps ...

Live Coding a KSQL Application

Introduction

@miguno
miguno / example.sql
Created January 31, 2018 17:26
KSQL example for SELECT
SELECT user_id, page, action FROM clickstream c
LEFT JOIN users u ON c.user_id = u.user_id
WHERE u.level = 'Platinum';
@miguno
miguno / explain.txt
Last active December 20, 2017 22:32
EXPLAIN example output.txt
ksql> EXPLAIN ctas_ip_sum;
Type : QUERY
SQL : CREATE TABLE IP_SUM as SELECT ip, SUM(bytes)/1024 as kbytes FROM CLICKSTREAM WINDOW SESSION (300 SECONDS) GROUP BY ip;
Local runtime statistics
------------------------
messages-per-sec: 104.38 total-messages: 14238 last-message: 12/14/17 4:30:42 PM GMT
failed-messages: 0 last-failed: n/a
(Statistics of the local KSQL Server interaction with the Kafka topic IP_SUM)